anketa = $_GET['anketa'];
} elseif (isset ($_POST['anketa'])) {
$this->anketa = $_POST['anketa'];
} elseif ($anketa != 0) {
$this->anketa = $anketa;
}
}
/**
* preveri dostop do ankete
*
* @param mixed $anketa
*/
function checkDostop($anketa = 0)
{
global $admin_type;
global $global_user_id;
if ($anketa == 0) {
$anketa = $this->anketa;
}
SurveyInfo::getInstance()->SurveyInit($anketa);
$rowa = SurveyInfo::getInstance()->getSurveyRow();
// meta admin vidi kao spet vse
if (self::isMetaAdmin()) {
return TRUE;
}
// za demonstracijsko je posebno preverjanje
if (isDemoSurvey($anketa)) {
return TRUE;
}
// posebej dostop za vsazga userja posebej
$sql = sisplet_query("SELECT ank_id, uid FROM srv_dostop WHERE ank_id = '$anketa' AND uid='$global_user_id'");
if (mysqli_num_rows($sql) > 0) {
return TRUE;
}
// dodatno imamo se ce je manager ali admin, potem vidi ankete podrejenih userjev
if ($admin_type == 1 || $admin_type == 0) {
$sql = sisplet_query("SELECT COUNT(*) FROM srv_dostop WHERE ank_id='$anketa' AND uid IN (SELECT user FROM srv_dostop_manage WHERE manager='$global_user_id')");
$row = mysqli_fetch_array($sql);
if ($row[0] > 0) {
return TRUE;
}
}
// ce imajo administratorji poseben dostop do ankete za help
if ($admin_type == 0 && strtotime($rowa['dostop_admin']) >= strtotime(date("Y-m-d"))) {
return TRUE;
}
return FALSE;
}
/**
* Meta admin, ki vidi vse ankete
*/
static function isMetaAdmin(){
global $global_user_id;
global $admin_type;
// Ce ni admin ni nikoli metaadmin
if($admin_type != '0'){
return FALSE;
}
$meta_admin_ids = AppSettings::getInstance()->getSetting('meta_admin_ids');
// Ce imamo nastavljene id-je za metaadmine v settings_optional
if(isset($meta_admin_ids) && !empty($meta_admin_ids)){
if (in_array($global_user_id, $meta_admin_ids)) {
return TRUE;
}
}
// Gorenje ima svoje metaadmine
elseif(Common::checkModule('gorenje')){
global $meta_admin_emails;
$sql = sisplet_query("SELECT email FROM users WHERE id = '$global_user_id'");
$row = mysqli_fetch_array($sql);
if(in_array($row['email'], $meta_admin_emails)){
return TRUE;
}
}
return FALSE;
}
/**
* preveri, ce ima uporabnik aktiven dostop do ankete
* zdaj ko nimamo vec aktivnih in pasivnih uporabnikov, gledamo ali ima edit
* dostop do ankete
*
* ta funkcija je v bistvu deprecated, naj se raje uporablja
* checkDostopSub('edit'...); ostaja za zdruzljivost za nazaj
*
* @param mixed $anketa
*/
function checkDostopAktiven($anketa = 0)
{
global $admin_type;
global $global_user_id;
return $this->checkDostopSub('edit', $anketa);
}
/**
* preveri tocen dostop do podstoritev
*
* @param mixed $anketa
*/
public function checkDostopSub($type, $anketa = 0){
global $admin_type;
global $global_user_id;
if ($anketa == 0) {
$anketa = $this->anketa;
}
SurveyInfo::getInstance()->SurveyInit($anketa);
$rowa = SurveyInfo::getInstance()->getSurveyRow();
// meta admin vidi kao spet vse
if (self::isMetaAdmin()) {
return TRUE;
}
// za demonstracijsko je posebno preverjanje
if (isDemoSurvey($anketa)) {
return TRUE;
}
// ce je avtor ima vedno dostop do vsega
if ($global_user_id == $rowa['insert_uid']) {
return TRUE;
}
$sql = sisplet_query("SELECT dostop FROM srv_dostop WHERE ank_id = '$anketa' AND uid='$global_user_id'");
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_array($sql);
$dostop = explode(',', $row['dostop']);
if (in_array($type, $dostop)) {
// Odklepanje anekte - vrne ravno obratno
if($type == 'lock')
return FALSE;
else
return TRUE;
}
// managerji in admini majo vedno lepe linke in maile
if ($admin_type <= 1 && in_array($type, ['link', 'mail'])) {
return TRUE;
}
}
// administratorji in managerji imajo do max kar imajo njegovi podrejeni userji
if ($admin_type <= 1) {
$sql = sisplet_query("SELECT dostop FROM srv_dostop WHERE ank_id='$anketa' AND uid IN (SELECT user FROM srv_dostop_manage WHERE manager='$global_user_id')");
while ($row = mysqli_fetch_array($sql)) {
$dostop = explode(',', $row['dostop']);
if (in_array($type, $dostop)) {
return TRUE;
}
// managerji in admini majo vedno lepe linke in maile
if ($admin_type <= 1 && in_array($type, ['link', 'mail'])) {
return TRUE;
}
}
}
// ce imajo administratorji poseben dostop do ankete za help
if ($admin_type == 0 && strtotime($rowa['dostop_admin']) >= strtotime(date("Y-m-d"))) {
return TRUE;
}
// Odklepanje anekte - vrne ravno obratno
if($type == 'lock')
return TRUE;
else
return FALSE;
}
public function checkDostopSubFromNavigation($navigation){
global $admin_type;
global $global_user_id;
if ($navigation == NAVI_STATUS) {
$type = 'dashboard';
}
elseif ($navigation == NAVI_UREJANJE) {
if ($_GET['a'] == 'telephone')
$type = 'phone';
else
$type = 'edit';
}
elseif ($navigation == NAVI_TESTIRANJE) {
$type = 'test';
}
elseif ($navigation == NAVI_OBJAVA) {
$type = 'publish';
}
elseif ($navigation == NAVI_RESULTS && $_GET['m'] != 'monitoring') {
$type = 'data';
}
elseif ($navigation == NAVI_ANALYSIS) {
$type = 'analyse';
}
else{
return TRUE;
}
return $this->checkDostopSub($type);
}
// Izposemo obvestilo, da urednik nima dostopa do podstrani
public function displayDostopNoAccess($what=''){
global $lang;
global $site_url;
echo '
';
echo '
'.$lang['srv_dostop_sub_locked_title'].'
';
echo '
';
echo '
'.$lang['srv_dostop_sub_locked_text'].'
';
echo '
';
echo '
';
}
function ajax(){
$a = isset($_GET['a']) ? $_GET['a'] : '';
$m = isset($_GET['m']) ? $_GET['m'] : '';
if ($a == 'manager_add_user') {
$this->ajax_manager_add_user();
}
elseif($a == 'add_new_user'){
$this->ajax_add_new_user();
}
elseif ($a == 'anketa_user_dostop') {
$this->ajax_anketa_user_dostop();
}
elseif ($a == 'anketa_user_dostop_save') {
$this->ajax_anketa_user_dostop_save();
}
elseif ($a == 'edit_user') {
$this->ajax_edit_user();
}
elseif ($a == 'edit_user_save') {
$this->ajax_edit_user_save();
}
elseif ($a == 'admin_add_user') {
$this->ajax_admin_add_user();
}
elseif ($a == 'admin_add_user_popup') {
$this->ajax_admin_add_user_popup();
}
elseif($a == 'find_user'){
$this->ajax_find_user();
}
elseif ($a == 'edit_remove_user') {
$this->ajax_edit_remove_user();
}
elseif ($a == 'edit_remove_user_manager') {
$this->ajax_edit_remove_user_manager();
}
elseif ($a == 'edit_remove_user_admin') {
$this->ajax_edit_remove_user_admin();
}
elseif ($a == 'all_users_list') {
if ($m == 'delete') {
$this->ajax_all_users_list_delete();
}
if ($m == 'ban') {
$this->ajax_all_users_list_ban();
}
else {
$this->ajax_all_users_list();
}
}
elseif($a == 'my_users_list'){
$this->ajax_all_users_list_my();
}
elseif ($a == 'delete_users_list') {
$this->ajax_delete_users_list();
}
elseif ($a == 'unsigned_users_list') {
$this->ajax_unsigned_users_list();
}
elseif ($a == 'unconfirmed_mail_user_list') {
if ($m == 'delete') {
$this->ajax_unconfirmed_mail_user_list_delet_user();
}
elseif ($m == 'accept') {
$this->ajax_confirm_user_email();
}
else {
$this->ajax_unconfirmed_mail_user_list();
}
}
elseif ($a == 'dodeljeni_uporabniki_display') {
$this->ajax_dodeljeni_uporabniki_display();
}
}
/**
* Dodamo novega uporabnika v 1KA sistem
*/
public function ajax_add_new_user()
{
global $pass_salt, $site_url, $site_domain, $lang;
$email = $_POST['email'];
$name = $_POST['name'];
$surnname = $_POST['surname'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$jezik = $_POST['jezik'];
include root_dir('lang/'.$jezik.'.php');
$error = '';
if ($email != '') {
$sqlu = sisplet_query("SELECT id FROM users WHERE email='$email'");
if (mysqli_num_rows($sqlu) == 0) {
if ($password == '' || $password == $password2) {
$s = sisplet_query("INSERT INTO users (name, surname, email, pass, type, when_reg, came_from, lang) VALUES ('$name', '$surnname', '$email', '" . base64_encode((hash('SHA256', $password . $pass_salt))) . "', '3', DATE_FORMAT(NOW(), '%Y-%m-%d'), '1', $jezik)");
$id = mysqli_insert_id($GLOBALS['connect_db']);
} else {
$error = 'pass';
}
} else {
// ne more si dodati že obstoječega uporabnika, ker potem bi si lahko kar kogarkoli dodal in bi videl njegove ankete
$id = 0;
$error = 'email';
}
if ($id > 0) {
$UserContent = $lang['add_new_user_content'];
// Podpis
$signature = Common::getEmailSignature();
$UserContent .= $signature;
$UserContent .= $lang['register_add_user_content_edit'];
$PageName = AppSettings::getInstance()->getSetting('app_settings-app_name');
$change = '';
// Ce gre slucajno za virtualko
$Subject = (isVirtual()) ? $lang['register_user_subject_virtual'] : $lang['register_user_subject'];
$UserContent = str_replace("SFNAME", $name, $UserContent);
$UserContent = str_replace("SFMAIL", $email, $UserContent);
$UserContent = str_replace("SFWITH", $email, $UserContent);
$UserContent = str_replace("SFPAGENAME", $PageName, $UserContent);
$UserContent = str_replace("SFCHANGE", $change, $UserContent);
$UserContent = str_replace("SFEND", '', $UserContent);
$Subject = str_replace("SFPAGENAME", $PageName, $Subject);
// Ce gre slucajno za virtualko
if(isVirtual())
$Subject = str_replace("SFVIRTUALNAME", $site_domain, $Subject);
if ($password2 == "") {
$UserContent = str_replace("SFPASS", "( ".$lang['without']." ) ", $UserContent);
}
else {
$UserContent = str_replace("SFPASS", $password2 ." (".$lang['register_add_user_password'].")", $UserContent);
}
if ($name == "") {
$UserContent = str_replace("SFNAME", $lang['mr_or_mrs'], $UserContent);
}
else {
$UserContent = str_replace("SFNAME", $name, $UserContent);
}
$ZaMail = ''.''.$Subject.'';
$ZaMail .= $UserContent;
if(isDebug()){
echo $ZaMail;
die();
}
// Posljemo mail vsakemu uporabniku posebej
try {
$MA = new MailAdapter(null, 'account');
$MA->addRecipients($email);
$resultX = $MA->sendMail(stripslashes($ZaMail), $Subject);
}
catch (Exception $e) {
}
if ($resultX) {
$status = 1; // poslalo ok
}
else {
$status = 2; // ni poslalo
}
}
} else {
$error = 'email';
}
header("Location: index.php?a=diagnostics&t=uporabniki&m=all&add=new&error=".$error);
}
/**
* Manager: dodajanje svojih novih uporabnikov
*
*/
function ajax_manager_add_user()
{
global $pass_salt;
global $lang;
global $global_user_id, $site_path, $site_domain;
global $admin_type;
$error = FALSE;
$sqlu = sisplet_query("SELECT email, type FROM users WHERE id = '" . $global_user_id . "'");
list($MailReply) = mysqli_fetch_row($sqlu);
$aktiven = $_POST['aktiven'];
$email = $_POST['email'];
$name = $_POST['name'];
$surnname = $_POST['surname'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$error = '';
if ($email != '') {
$sqlu = sisplet_query("SELECT id FROM users WHERE email='$email'");
if (mysqli_num_rows($sqlu) == 0) {
if ($password == '' || $password == $password2) {
$s = sisplet_query("INSERT INTO users (name, surname, email, pass, type, when_reg, came_from) VALUES ('$name', '$surnname', '$email', '" . base64_encode((hash('SHA256', $password . $pass_salt))) . "', '3', DATE_FORMAT(NOW(), '%Y-%m-%d'), '1')");
$id = mysqli_insert_id($GLOBALS['connect_db']);
} else {
$error = 'pass';
}
} else {
// ne more si dodati že obstoječega uporabnika, ker potem bi si lahko kar kogarkoli dodal in bi videl njegove ankete
$id = 0;
$error = 'email';
}
if ($id > 0) {
$s = sisplet_query("INSERT INTO srv_dostop_manage (manager, user) VALUES ('$global_user_id', '$id')");
if (!$s) {
echo mysqli_error($GLOBALS['connect_db']);
}
$subject = sprintf($lang['srv_dodanmail_1'], $site_domain);
$content = sprintf($lang['srv_dodanmail_2'], $MailReply, $site_domain).'
';
// Če gre za Hierarhijo
if (SurveyInfo::checkSurveyModule('hierarhija', $this->anketa)) {
$tip = sisplet_query("SELECT type FROM srv_hierarhija_users WHERE user_id='" . $uid . "' AND anketa_id='" . $this->anketa . "'", "obj");
if (!empty($tip) && !empty($tip->type)) {
echo '
';
echo 'Uporabnik hierarhije s pravicami:';
echo '';
echo '
';
}
}
// Ce je katerikoli od treh checkboxou ugasnjen imamo enablano editiranje samo posameznega jezik
$enable_lang = (!in_array('edit', $dostop) || !in_array('test', $dostop) || !in_array('publish', $dostop)) ? TRUE : FALSE;
$sqll = sisplet_query("SELECT * FROM srv_language WHERE ank_id = '$this->anketa'");
echo '
';
if (mysqli_num_rows($sqll) > 0) {
echo '' . $lang['srv_passive_multilang'] . ':';
echo '';
}
while ($rowl = mysqli_fetch_array($sqll)) {
$sqldl = sisplet_query("SELECT * FROM srv_dostop_language WHERE ank_id = '$this->anketa' AND uid = '$uid' AND lang_id='$rowl[lang_id]'");
if (!$sqldl) {
echo mysqli_error($GLOBALS['connect_db']);
}
if (mysqli_num_rows($sqldl) > 0) {
$checked = ' checked';
} else {
$checked = '';
}
echo '
';
echo '';
echo '';
echo '
';
}
echo '
';
echo '';
}
// Manager - brez moznosti uporabe 1ka streznika
elseif ($r['type'] == 1) {
$sql = sisplet_query("SELECT dostop FROM srv_dostop WHERE ank_id='$this->anketa' AND uid='$uid'");
$row = mysqli_fetch_array($sql);
$dostop = explode(',', $row['dostop']);
// Admin lahko managerju spreminja samo posiljanje vabil preko 1ka streznika
if ($admin_type == 0) {
echo '';
echo '
';
}
function ajax_anketa_user_dostop_save() {
$uid = $_POST['uid'];
$aktiven = $_POST['aktiven'];
$dostop = implode(',', $_POST['dostop']);
$sql = sisplet_query("UPDATE srv_dostop SET aktiven='$aktiven', dostop='$dostop' WHERE uid = '$uid' AND ank_id='$this->anketa'");
if (isset($_POST['dostop_language_edit']) && $_POST['dostop_language_edit'] == '1') {
sisplet_query("DELETE FROM srv_dostop_language WHERE ank_id = '$this->anketa' AND uid='$uid'");
foreach ($_POST['dostop_language'] AS $val) {
$val = explode('-', $val);
$uid = $val[0];
$lang_id = $val[1];
sisplet_query("INSERT INTO srv_dostop_language (ank_id, uid, lang_id) VALUES ('$this->anketa', '$uid', '$lang_id')");
}
}
if (isset($_POST['hierarchy_type']) && SurveyInfo::checkSurveyModule('hierarhija', $this->anketa)) {
$tip = (!empty($_POST['hierarchy_type']) ? $_POST['hierarchy_type'] : NULL);
$result = sisplet_query("SELECT id FROM srv_hierarhija_users WHERE user_id='" . $uid . "' AND anketa_id='" . $this->anketa . "'", "obj");
if (!empty($result) && !empty($result->id) && !is_null($tip)) {
sisplet_query("UPDATE srv_hierarhija_users SET type='" . $tip . "' WHERE id='" . $result->id . "'");
}
}
}
function ajax_edit_user(){
global $lang;
global $global_user_id;
global $admin_type;
$uid = $_POST['uid'];
echo '
';
// NASTAVITVE UPORABNIKA
echo '
';
$sql = sisplet_query("SELECT name, surname, email, type, status, gdpr_agree FROM users WHERE id ='" . $uid . "'");
$row = mysqli_fetch_array($sql);
echo '';
echo '
';
// SEZNAM ANKET
echo '
';
echo '
' . $lang['srv_ankete'] . '
';
echo '
';
$sql = sisplet_query("SELECT srv_anketa.id, srv_anketa.naslov FROM srv_dostop, srv_anketa WHERE srv_dostop.uid='". $uid ."' AND srv_dostop.ank_id=srv_anketa.id ORDER BY srv_anketa.edit_time DESC");
while ($row = mysqli_fetch_array($sql)) {
echo '
';
// Seznam dodeljenih uporabnikov
$sqlUsers = sisplet_query("SELECT u.id, u.name, u.surname, u.email, u.status
FROM users u, srv_dostop_manage m
WHERE u.id=m.user AND m.manager='".$manager."'
");
if(mysqli_num_rows($sqlUsers) > 0){
echo '
';
}
function isAnketar()
{
global $admin_type;
# preverimo ali je anketar
return ($this->checkDostopSub('phone') && $admin_type > 1);
}
/**
* vrne seznam vseh uporabnikov z dostopom do ankete
*
*/
function getDostop()
{
$dostop = [];
$dostop[0] = $this->getAdminsDostop();
$dostop[1] = $this->getManagersDostop();
$dostop[2] = $this->getUsersDostop();
return $dostop;
}
/**
* preveri ali imajo do ankete dostop administratorji
* ta funkcija ni!!! primerna za preverjat, ce prikazemo anketo
* administratorju, ker se mora poleg tega preverjati se, ce je uporabnik
* admin pa to
*
*/
function getAdminsDostop()
{
SurveyInfo::getInstance()->SurveyInit($this->anketa);
$rowa = SurveyInfo::getInstance()->getSurveyRow();
if (strtotime($rowa['dostop_admin']) >= strtotime(date("Y-m-d"))) {
return $rowa['dostop_admin'];
}
return FALSE;
}
/**
* kdo ima managerski dostop (od managerjev in administratorjev)
*
*/
function getManagersDostop()
{
$dostop = array();
$sql = sisplet_query("SELECT u.* FROM users u, srv_dostop_manage m WHERE u.id=m.manager AND m.user IN (SELECT uid FROM srv_dostop WHERE ank_id='$this->anketa') ");
while ($row = mysqli_fetch_array($sql)) {
$dostop[] = $row;
}
return $dostop;
}
/**
* kdo od uporabnikov ima dostop
*
*/
function getUsersDostop()
{
$sql = sisplet_query("SELECT u.* FROM srv_dostop d, users u WHERE u.id=d.uid AND d.ank_id = '$this->anketa'");
while ($row = mysqli_fetch_array($sql)) {
$dostop[] = $row;
}
return $dostop;
}
/**
* Vrenemo besedni izraz za 1/0 iz podatkovne baze
*
* @param int $val
*
* @return mixed
*/
private function vrniDaNe($val = 0)
{
global $lang;
if ($val == 1) {
return $lang['yes'];
}
return $lang['no1'];
}
}
?>