From 19985dbb8c0aa66dc4bf7905abc1148de909097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 11 Jan 2022 12:35:47 +0100 Subject: prvi-commit --- .../survey/classes/class.SurveyStatusProfiles.php | 1247 ++++++++++++++++++++ 1 file changed, 1247 insertions(+) create mode 100644 admin/survey/classes/class.SurveyStatusProfiles.php (limited to 'admin/survey/classes/class.SurveyStatusProfiles.php') diff --git a/admin/survey/classes/class.SurveyStatusProfiles.php b/admin/survey/classes/class.SurveyStatusProfiles.php new file mode 100644 index 0000000..11946a3 --- /dev/null +++ b/admin/survey/classes/class.SurveyStatusProfiles.php @@ -0,0 +1,1247 @@ +'6',5=>'5',4=>'4',3=>'3',2=>'2',1=>'^1',0=>'0','null'=>'-1'); # texti za statuse. 6=>'6',5=>'5',4=>'4',3=>'3',2=>'2',1=>'^1',0=>'0',null=>'-1' Pri 1 je ^pomemben, če ne lahko vzame tudi -1 + + static private $allUserCount = 0; #Koliko je vseh userjev + static private $allValidCount = 0; #Koliko je veljavnih userjev + + static private $survayDefaultUstrezni = 2; #privzet ustrezni profil: 2-ustrezni (5,6) 3-končani(6) + + static function Init($sid, $uid = null) { + # nastavimo surveyId + self::setSId($sid); + SurveyInfo :: getInstance()->SurveyInit(self::$sid); + # nastavimo userja + self::setGlobalUserId($uid); + + if ((int)SurveyInfo :: getInstance()->getSurveyColumn('defValidProfile') == 3) { + self::$survayDefaultUstrezni = 3; + } + + # preštejemo userje + $str_all = "SELECT count(*) FROm srv_user WHERE ank_id='".self::$sid."' AND deleted='0' AND preview = '0'"; + if (self::$survayDefaultUstrezni == 2) { + $str_valid = "SELECT count(*) FROM srv_user WHERE ank_id='".self::$sid."' AND last_status IN (5,6) AND lurker = 0 AND deleted='0' AND preview = '0' AND testdata='0'"; + } else { + $str_valid = "SELECT count(*) FROM srv_user WHERE ank_id='".self::$sid."' AND last_status = '6' AND lurker = 0 AND deleted='0' AND preview = '0' AND testdata='0'"; + } + $query_all = sisplet_query($str_all); + $query_valid = sisplet_query($str_valid); + list($all) = mysqli_fetch_row($query_all); + list($valid) = mysqli_fetch_row($query_valid); + self::$allUserCount = $all; + self::$allValidCount = $valid; + SurveyUserSetting :: getInstance()->Init(self::$sid, self::getGlobalUserId()); + self :: RefreshData(); + } + + static function getAllValidCount() { + return self::$allValidCount; + } + static function getAllUserCount() { + return self::$allUserCount; + } + + + static function RefreshData() { + global $lang; + + $lang_admin = SurveyInfo :: getInstance()->getSurveyColumn('lang_admin'); + + self::$profiles = array(); + # dodamo sejo če obstaja + if (isset($_SESSION['statusProfile'])) { + if ( $lang_admin != 1 ) { + $_SESSION['statusProfile']['name'] = $lang['srv_temp_profile']; + } + self::$profiles[$_SESSION['statusProfile']['id']] = $_SESSION['statusProfile']; + } + # preberemo podatke vseh porfilov ki so na voljo in jih dodamo v array + $stringSelect = "SELECT * FROM srv_status_profile WHERE uid='".self::getGlobalUserId()."' OR ank_id = '".self::$sid."' OR (uid = '0' AND `system`=1) ORDER BY id"; + $querySelect = sisplet_query($stringSelect); + + while ( $rowSelect = mysqli_fetch_assoc($querySelect) ) { + if ( $lang_admin != 1 && $rowSelect['system'] == 1 ) { + # imamo sistemski profil v tujem jeziku popravimo tekste + $rowSelect['name'] = $lang['srv_status_profile_system_'.$rowSelect['id']]; + } + self::$profiles[$rowSelect['id']] = $rowSelect; + } + + # ker si Vasja skoz nekaj zmišljuje glede imen sistemskih profilov (ki so zaenkrat v bazi) jih ročno prepišemo + # pa še jezikovno tabelo lahko uporabimo, tak da je to boljše + self::$profiles[1]['name'] = $lang['srv_status_profile_system_1']; + self::$profiles[2]['name'] = $lang['srv_status_profile_system_2']; + self::$profiles[3]['name'] = $lang['srv_status_profile_system_3']; + # vsi statusi ni pomembno ali je lurker ali ne + # pri ustreznih ne sme biti lurker in ne testni + self::$profiles[1]['statuslurker'] = 2; + self::$profiles[2]['statuslurker'] = 0; + self::$profiles[3]['statuslurker'] = 0; + + self::$profiles[1]['statustestni'] = 2; + self::$profiles[2]['statustestni'] = 0; + self::$profiles[3]['statustestni'] = 0; + + // Uporabnost - vedno so vsi vklopljeni po defaultu + self::$profiles[1]['statusnonusable'] = 1; + self::$profiles[2]['statuspartusable'] = 1; + self::$profiles[3]['statususable'] = 1; + + # poiscemo privzet profil + #določimo podstran + if (isset($_POST['meta_akcija']) && $_POST['meta_akcija'] != '') { + $_podstran = $_POST['meta_akcija']; + } else if (isset($_POST['podstran']) && $_POST['podstran'] != '') { + $_podstran = $_POST['podstran']; + } else if (isset($_GET['a']) && $_GET['a'] != '') { + $_podstran = $_GET['a']; + } else { + $_podstran = A_COLLECT_DATA; + } + + if ( (($_podstran !== A_COLLECT_DATA && $_podstran !== A_COLLECT_DATA_EXPORT && $_podstran !== 'para_graph') || (isset($_GET['b']) && $_GET['b'] == 'export')) && $_podstran !== 'usable_resp' && $_podstran !== 'reminder_tracking') { + $_podstran = A_ANALYSIS; + } + + // Pri izvozu podatkov uporabimo isti profil kot pri ostalih podatkih + if ($_podstran == A_COLLECT_DATA_EXPORT) { + $_podstran = A_COLLECT_DATA; + } + + # če smo v vpogledu pohandlammo posebej + if (($_podstran == A_COLLECT_DATA && $_GET['m'] == 'quick_edit') || $_POST['podstran'] == 'quick_edit') { + $_podstran = 'vpogled'; + } + self::$currentProfileId = SurveyUserSetting :: getInstance()->getSettings('default_status_profile_'.$_podstran); + + if (!self::$currentProfileId) { + + #self::$currentProfileId = 2; + self::$currentProfileId = self::$survayDefaultUstrezni; # je lahko 2 ali 3 + } + # ustrezni je lahko samo če so kakšni ustrezni zapisi v bazi ob pogoju da pa neustrezni obstajajao + if (self::$allValidCount == 0 && self::$allUserCount > 0) { + if (self::$currentProfileId == 2 || self::$currentProfileId == 3 ) { + # privzeto nastavimo na vsi + self::$currentProfileId = 1; + } + } + + # ce imamo nastavljen curent pid in profil z tem pid ne obstaja nastavomo na privzet profil + if (self::$currentProfileId != 1) { + if (!isset(self::$profiles[self::$currentProfileId])) { + self::$currentProfileId = 1; + } + } + + # ce ne obstajajo podatki za cpid damo error + if (!isset(self::$profiles[self::$currentProfileId])) { + die("Profile data is missing!"); + return false; + } else { + return true; + } + } + + public static function getSystemDefaultProfile() { + $sysDefProf = self::$survayDefaultUstrezni; # je lahko 2 ali 3 + + # ustrezni je lahko samo če so kakšni ustrezni zapisi v bazi ob pogoju da pa neustrezni obstajajao + if (self::$allValidCount == 0 && self::$allUserCount > 0) { + if ($sysDefProf == 2 || $sysDefProf == 3 ) { + # privzeto nastavimo na vsi + $sysDefProf = 1; + } + } + return (int)$sysDefProf; + } + + public static function getDefaultProfile() { + return self::$currentProfileId; + } + + static function DisplayProfile( $pid = null) { + global $lang; + + if ($pid == null ) { + $pid = self::$currentProfileId; + } + + $popUp = new PopUp(); + $popUp->setId('divStatusProfile'); + $popUp->setHeaderText($lang['srv_status_settings']); + + #vsebino shranimo v buffer + ob_start(); + if ( self::$currentProfileId != SSP_DEFAULT_PROFILE ) { + echo '
'; + echo $lang['srv_not_default_setting']; + echo '

'; + } + + echo ''; + + echo '
'; + self :: DisplayProfileOptions($pid); + echo '
'; + + echo '
'; + self :: DisplayProfileData($pid); + echo '
'; + echo '
'; + + // cover Div + echo '
'; + + // div za shranjevanje novega profila + echo '
'.$lang['srv_missing_profile_name'].': '; + echo ''; + $button = new PopUpButton($lang['srv_save_profile']); + echo $button -> setFloat('right') + ->setButtonColor('orange') + -> addAction('onClick','statusProfileAction(\'newSave\'); return false;'); + $button = new PopUpButton($lang['srv_cancel']); + echo $button -> setFloat('right') + -> addAction('onClick','statusProfileAction(\'newCancel\'); return false;'); + echo '
'; + + // div za preimenovanje + echo '
'.$lang['srv_missing_profile_name'].': '; + echo ''; + echo ''; + $button = new PopUpButton($lang['srv_rename_profile_yes']); + echo $button -> setFloat('right') + ->setButtonColor('orange') + -> addAction('onClick','statusProfileAction(\'renameProfile\'); return false;'); + + $button = new PopUpButton($lang['srv_cancel']); + echo $button -> setFloat('right') + -> addAction('onClick','statusProfileAction(\'renameCancel\'); return false;'); + echo '
'; + + // div za brisanje + echo '
'.$lang['srv_missing_profile_delete_confirm'].': ' . self::$profiles[$pid]['name'] . '?'; + echo ''; + + $button = new PopUpButton($lang['srv_delete_profile_yes']); + echo $button -> setFloat('right') + ->setButtonColor('orange') + -> addAction('onClick','statusProfileAction(\'deleteConfirm\'); return false;'); + + $button = new PopUpButton($lang['srv_cancel']); + echo $button -> setFloat('right') + -> addAction('onClick','statusProfileAction(\'deleteCancel\'); return false;'); + + echo '
'; + + $content = ob_get_clean(); + + #dodamo vsebino + $popUp->setContent($content); + + /* + if ($pid < 0) { #Imamo sejo, lahko poženemo samo kot sejo + $run_lbl = $lang['srv_run_as_session_profile']; + echo ''.$run_lbl.''; + } else { + # shrani - pozeni + $run_lbl = $lang['srv_run_profile']; + echo ''.$run_lbl.''; + $run_lbl = $lang['srv_run_as_session_profile']; + echo ''.$run_lbl.''; + + } + */ + $button = new PopUpButton($lang['srv_choose_profile']); + $button -> setFloat('right') + ->setButtonColor('orange') + -> addAction('onClick','statusProfileAction(\'choose\'); return false;'); + $popUp->addButton($button); + + #dodamo gumb shrani + if (self::$profiles[$pid]['system'] != 1 && $pid != -1) + { + $button = new PopUpButton($lang['srv_save_profile']); + $button -> setFloat('right') + -> addAction('onClick','statusProfileAction(\'save\'); return false;'); + $popUp->addButton($button); + } + + $button = new PopUpButton($lang['srv_new_profile_name']); + $button -> setFloat('right') + -> addAction('onClick','statusProfileAction(\'newName\'); return false;'); + $popUp->addButton($button); + + # dodamo gumb Prekliči + $button = new PopUpCancelButton(); + $button -> setFloat('right'); + $popUp->addButton($button); + + echo $popUp; + } + + static function DisplayProfileData($pid) { + global $lang; + $curentProfileData = self :: $profiles[$pid]; +// echo '
help?'.'
'; + + echo '
'; + echo '
'; + echo '
'; + echo '' . $lang['srv_missing_profile_title4'] . ''; + + $cnt = 1; + + $disabled = $curentProfileData['system'] == 1 ? true : false; + + # preverimo kaere statuse disejblamo na podlagi izbire načina kreiranja datoteke (samo 5,6 / vsi satusi) + list($collect_all_status) = mysqli_fetch_row(sisplet_query("SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'")); + + echo ''; + // dodamo veljavne + foreach (self::$appropriateStatus as $index) { + if ($cnt&1) { + echo ''; + } + echo ''; + $cnt++; + } + // dodamo neveljavne + foreach (self::$unAppropriateStatus as $index) { + if ($cnt&1) + echo ''; + echo ''; + $cnt++; + } + // dodamo null + foreach (self::$unKnownStatus as $index) { + + if ($cnt&1) + echo ''; + echo ''; + $cnt++; + } + + echo '
'; + echo '
'; + echo '
'; + echo '
'; + + echo '
'; + + + if ($disabled ) { + $html_disabled = ' disabled="true"'; + $css_disabled = ' class="gray"'; + } + + + echo '
'; + echo '' . $lang['srv_invalid_units'] . ''; + + // lurkerji + # lurker = 0 - obveezno ni lurker, lurker = 1 - obvezno je lurker, lurker = 2 - je ali ni lurker + #echo '
'; + echo ''.$lang['srv_lurkers'].''; + echo ' '.$lang['no'].''; + echo ' '.$lang['srv_only_empty'].''; + echo ' '.$lang['srv_also'].''; + echo '
'; + + // testni vnosi + # testni = 0 - obveezno ni testni, testni = 1 - obvezno je tesni, testni = 2 - je ali ni testni + echo '

'.$lang['srv_testni_vnos'].''; + echo ' '.$lang['no'].''; + echo ' '.$lang['srv_only_test'].''; + echo ' '.$lang['srv_also'].''; + + echo '
'; + + + // Filter na uporabnost + echo '
'; + echo '' . $lang['srv_usableResp_usable_unit'] . ''; + + // 2->uporabni, 1->delno uporabni, 0->neuporabni + echo ' '.$lang['srv_usableResp_unusable'].''; + echo ''.$lang['srv_usableResp_partusable'].''; + echo ''.$lang['srv_usableResp_usable'].''; + + + echo '
'; + echo '
'; + echo '
'; + } + + static function DisplayProfileOptions($pid) { + global $lang; + + $_sql_string = "SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'"; + $_sql_qry = sisplet_query($_sql_string); + $_sql_row = mysqli_fetch_assoc($_sql_qry); + + echo '
'; + foreach ( self::$profiles as $key => $profile ) { + if ($key != 1 || ($key == 1 && (int)$_sql_row['collect_all_status'] > 0 )) { + + echo '
'; + + echo $profile['name']; + + if($profile['id'] == $pid){ + #dodamo gumb izbriši + if (self::$profiles[$pid]['system'] != 1 ){ + echo ' '."\n"; + } + #dodamo gumb preimenuj + if (self::$profiles[$pid]['system'] != 1 && $pid != -1){ + echo ' '."\n"; + } + } + + echo '
'; + } + } + echo '
'; + + echo ''; + } + + /** klici ajax funkcij + * + */ + static function ajax() { + $pid = $_POST['pid']; + switch ($_GET['a']) { + case 'displayProfile' : + if (isset($pid) && $pid != null) + { + self :: setCurentProfileId($pid); + } + self :: DisplayProfile($pid); + break; + case 'chooseProfile' : + self :: setDefaultProfileId($pid); + break; + case 'saveProfile': + self :: saveProfile($pid); + break; + case 'run_status_profile': + self :: saveProfile($pid); + self :: setDefaultProfileId($pid); + break; + case 'save_status_profile': + $new_id = self :: saveNewProfile($pid); + self :: setDefaultProfileId($new_id); + echo $new_id; + break; + case 'deleteProfile': + self :: DeleteProfile($pid); + break; + case 'renameProfile': + self :: renameProfile($pid); + + break; + case 'showColectDataSetting': + self :: showColectDataSetting(); + break; + case 'saveCollectDataSetting': + self :: saveCollectDataSetting(); + break; + case 'changeOnlyValidRadio': + self :: changeOnlyValidRadio(); + break; + + default: + echo 'ERROR! Missing function for action: '.$_GET['a'].'!'; + break; + } + } + + /** getProfiles + * + */ + static function getProfiles() { + return self::$profiles; + } + + /** setSurveyId + * + */ + static function setSId($surveyId) { + self::$sid = $surveyId; + } + + /** setGlobalUserId + * + */ + static function setGlobalUserId($uid = null) { + if ($uid == null) { + global $global_user_id; + self::$uid = $global_user_id; + } else { + self::$uid = $uid; + } + } + + /** getGlobalUserId + * + */ + static function getGlobalUserId() { + return self::$uid; + } + static function getCurentProfileId() { + return (int)self::$currentProfileId; + } + + public function getProfileName($pid) { + return self::$profiles[$pid]['name']; + } + + /* Vrne ID in ime trenutno izbranega profila + * + */ + function getCurentProfile() { + return array('id'=>self::$currentProfileId,'name'=>self::$profiles[self::$currentProfileId]['name']); + } + /** + * + * @param unknown_type $pid + */ + static function setCurentProfileId($pid) { + # preverimo ali profil obstaja + if (!isset(self::$profiles[$pid])) + { # če ne obstaja damo privzeto ustrezne + $pid = 2; + } + # ce je seja, preverimo ali obstaja cene nardimo privzetega 1 + if ($pid == -1) { + if (!(isset($_SESSION['statusProfile']['-1']))) + $pid = 1; + } else if (!$pid) { + $pid = 1; + } + + return self::$currentProfileId = $pid; + } + + static function setDefaultProfileId($pid=null, $podstran = null) { + # ce je seja, preverimo ali obstaja cene nardimo privzetega 1 + if ($pid == -1) { + if (!(isset($_SESSION['statusProfile']))) { + $pid = null; + } + } + if ($podstran == null ) { + if ( isset($_POST['meta_akcija']) ) { + $_action = $_POST['meta_akcija']; + } else if (isset($_POST['podstran']) ) { + $_action = $_POST['podstran']; + } else if (isset($_POST['a']) ) { + $_action = $_POST['a']; + } else if (isset($_GET['a']) ) { + $_action = $_GET['a']; + } else { + $_action = 'data'; + } + } else { + $_action = $podstran; + } + + // Pri izvozu podatkov uporabimo isti profil kot pri ostalih podatkih + if ($_action == A_COLLECT_DATA_EXPORT) { + $_action = A_COLLECT_DATA; + } + + # če smo v vpogledu pohandlammo posebej + if (($_action == A_COLLECT_DATA && $_GET['m'] == 'quick_edit') || $_POST['podstran'] == 'quick_edit') { + $_action = 'vpogled'; + } + + # če je $pid == null odvisno od akcije nastavimo privzet profil + # v podatkih = 1 v analizah = 2 + if ($pid == null || (int)$pid==0) { + /* po novem je privzeto vedno le ustrezni statusi + if ($_action == 'data') { + $pid = 1; + } else { + $pid = 2; + } + */ + $pid = 2; + } + + # če lovimo samo ustrezne, potem ne morem o izbratz vsi statusi + $_sql_string = "SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'"; + $_sql_qry = sisplet_query($_sql_string); + list($collect_all_status) = mysqli_fetch_row($_sql_qry); + if ($pid == 1 && (int)$collect_all_status == 0) { + $pid = 2; + } + + # ustrezni je lahko samo če so kakšni ustrezni zapisi v bazi ob pogoju da pa neustrezni obstajajao + if ($pid == 2 && self::$allValidCount == 0 && self::$allUserCount > 0) { + $pid = 1; + } + + # če smo izbrali drug profil resetiramo še profil profilov na trenutne nastavitve + SurveyUserSetting :: getInstance()->saveSettings('default_profileManager_pid', '0'); + + SurveyUserSetting :: getInstance()->saveSettings('default_status_profile_'.$_action, $pid); + + + self::$currentProfileId = $pid; + return true; + } + + static function getStatusAsArrayString() { + + $mpds = self::getStatusArray(self::$currentProfileId); + + $result = array(); + + if ($mpds) { + foreach ( self::$appropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) + $result[$index] = $index; + } + foreach ( self::$unAppropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) + $result[$index] = $index; + } + foreach ( self::$unKnownStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) + $result[$index] = $index; + } + # lurker = 0 - obveezno ni lurker, lurker = 1 - obvezno je lurker, lurker = 2 - je ali ni lurker + if (isset($mpds['statuslurker']) && ((int)$mpds['statuslurker'] == 0 || (int)$mpds['statuslurker'] == 1)) { + $result['lurker'] = 'lurker'; + } + # testni = 0 - obveezno ni testni, testni = 1 - obvezno je testni, testni = 2 - je ali ni testni + if (isset($mpds['statustestni']) && ((int)$mpds['statustestni'] == 0 || (int)$mpds['statustestni'] == 1)) { + $result['testni'] = 'testni'; + } + # Uporabnost + if (isset($mpds['statusnonusable']) && $mpds['statusnonusable'] == 1) { + $result['nonusable'] = 1; + } + if (isset($mpds['statuspartusable']) && $mpds['statuspartusable'] == 1) { + $result['partusable'] = 1; + } + if (isset($mpds['statususable']) && $mpds['statususable'] == 1) { + $result['usable'] = 1; + } + } + + return $result; + } + static public function getStatusAsQueryString($pid = null) { + if ($pid == null || (int)$pid <= 0 ) { + $mpds = self::getStatusArray(self::$currentProfileId); + } else { + $mpds = self::getStatusArray((int)$pid); + } + $result = ''; + + if ($mpds) { + $result .= ' AND last_status IN ('; + foreach ( self::$appropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) { + $result .= $prefix.$index; + $prefix = ', '; + } + } + foreach ( self::$unAppropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) { + $result .= $prefix.$index; + $prefix = ', '; + } + } + foreach ( self::$unKnownStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1) { + $result .= $prefix.$index; + $prefix = ', '; + + } + } + $result .= ')'; + # lurker = 0 - obveezno ni lurker, lurker = 1 - obvezno je lurker, lurker = 2 - je ali ni lurker + if (isset($mpds['statuslurker']) && (int)$mpds['statuslurker'] == 1) { + $result .= ' AND lurker = 1'; + } else if (isset($mpds['statuslurker']) && (int)$mpds['statuslurker'] == 0) { + $result .= ' AND lurker = 0'; + } else { + # lurker ni pogoj + } + # testni = 0 - obveezno ni testni, testni = 1 - obvezno je testni, testni = 2 - je ali ni testni + if (isset($mpds['statustestni']) && (int)$mpds['statustestni'] == 1) { + $result .= ' AND (testdata = 1 OR testdata = 2)'; + } else if (isset($mpds['statustestni']) && (int)$mpds['statustestni'] == 0) { + $result .= ' AND testdata = 0'; + } else { + # testdata ni pogoj + } + } + + return $result; + } + static function getStatusArray($pid=null) { + if ($pid == null) { + $pid = self::$currentProfileId; + } + $mpd = self::$profiles[$pid]; + return $mpd; + } + + static function getStatusAsAWKString($pid=null) { + if ($pid==null){ + $pid=self::$currentProfileId; + } + $mpds = self::getStatusArray($pid); + $result = array(); + if ($mpds) { + foreach ( self::$appropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1 ) { + $result[$index] = self::$_AWK_FILTER_TEXT[$index]; + } + } + foreach ( self::$unAppropriateStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1 ) { + $result[$index] = self::$_AWK_FILTER_TEXT[$index]; + } + } + foreach ( self::$unKnownStatus as $index) { + if (isset($mpds['status'.$index]) && $mpds['status'.$index] == 1 ) { + $result[$index] = self::$_AWK_FILTER_TEXT[$index]; + } + } + } + + + if (count($result) > 0) { + $forReturn = STATUS_FIELD."~/".implode(STR_DLMT,$result)."/"; + } else { + $forReturn = STATUS_FIELD."~/*/"; + } + + # ali dodamo tudi lurkerje + if (isset($mpds['statuslurker']) && (int)$mpds['statuslurker'] == 0 ) { + $forReturn = '('.$forReturn.')&&('.LURKER_FIELD.'==0)'; + } else if (isset($mpds['statuslurker']) && $mpds['statuslurker'] == 1 ) { + $forReturn = '('.$forReturn.')&&('.LURKER_FIELD.'==1)'; + } else { + $forReturn = '('.$forReturn.')'; + } + return $forReturn; + } + + static function getStatusTestAsAWKString($test_data_sequence) { + $forReturn = null; + $mpds = self::getStatusArray(self::$currentProfileId); + if ($mpds && (int)$test_data_sequence > 0) { + # ali dodamo tudi testne + if (isset($mpds['statustestni']) && (int)$mpds['statustestni'] == 0 ) { + $forReturn = '$'.$test_data_sequence.'==0'; + } else if (isset($mpds['statustestni']) && $mpds['statustestni'] == 1 ) { + $forReturn = '$'.$test_data_sequence.'==1'; + } else { + $forReturn = null; + } + } + return $forReturn; + } + + static function getStatusUsableAsAWKString($usable_data_sequence) { + + $forReturn = null; + + $mpds = self::getStatusArray(self::$currentProfileId); + $result = array(); + if ($mpds && (int)$usable_data_sequence > 0) { + if(isset($mpds['statusnonusable']) && (int)$mpds['statusnonusable'] == 1) + $result[] = '0'; + + if(isset($mpds['statuspartusable']) && $mpds['statuspartusable'] == 1) + $result[] = '1'; + + if(isset($mpds['statususable']) && $mpds['statususable'] == 1) + $result[] = '2'; + } + + + if (count($result) > 0) { + $forReturn = '$'.$usable_data_sequence."~/".implode(STR_DLMT,$result)."/"; + } else { + $forReturn = '$'.$usable_data_sequence."~/*/"; + } + + + return $forReturn; + } + + /** Shranimo v obstoječ profil + * + * @param unknown_type $pid + * @param unknown_type $name + * @param unknown_type $status + */ + static function saveProfile($pid) { + global $lang; + $insert_id = 0; + + $status = $_POST['status']; + + if (isset($pid) && $pid != null && isset($status) && $status != null) { + if ($pid == 1) { # ce mamo privzet profil ga ne shranjujemo + return 1; + } + # ce imamo session pozenemo kot sejo + if ($pid == -1) { + $statusi = explode(',',$status); + $_SESSION['statusProfile'] = array('id'=>'-1','uid'=>0,'name'=>$lang['srv_temp_profile'],'system'=>0); + foreach (self::$allStatus as $_status) { + $_SESSION['statusProfile']['status'.$_status] = (in_array((string)$_status,$statusi) ? '1' : '0'); + } + # lurker: + $_SESSION['statusProfile']['statuslurker'] = ''.(int)$_POST['lurker']; + # testni: + $_SESSION['statusProfile']['statustestni'] = ''.(int)$_POST['testni']; + + # uporabnost: + $_SESSION['statusProfile']['statusnonusable'] = ''.(int)$_POST['nonusable']; + $_SESSION['statusProfile']['statuspartusable'] = ''.(int)$_POST['partusable']; + $_SESSION['statusProfile']['statususable'] = ''.(int)$_POST['usable']; + + return -1; + } + # imamo podatke, updejtamo profil v bazi + + $statusi = explode(',',$status); + if (count(self::$allStatus) > 0 ) { + + $updateString = "UPDATE srv_status_profile SET "; + $prefix = ''; + foreach (self::$allStatus as $_status) { + $updateString .= $prefix . 'status'.$_status. ' = '.(in_array((string)$_status,$statusi) ? '1' : '0'); + $prefix =', '; + } + # lurker: + $updateString .= $prefix . 'statuslurker'. ' = '.''.(int)$_POST['lurker']; + # testni: + $updateString .= $prefix . 'statustestni'. ' = '.''.(int)$_POST['testni']; + + # uporabnost: + $updateString .= $prefix . 'statusnonusable'. ' = '.''.(int)$_POST['nonusable']; + $updateString .= $prefix . 'statuspartusable'. ' = '.''.(int)$_POST['partusable']; + $updateString .= $prefix . 'statususable'. ' = '.''.(int)$_POST['usable']; + + $updateString .= " WHERE id = '".$pid."'"; + + } + $queryUpdate = sisplet_query($updateString) + or die(mysqli_error($GLOBALS['connect_db'])); + + return $pid; + } + + } + + /** Shranimo kot nov profil + * + * @param unknown_type $pid + * @param unknown_type $name + * @param unknown_type $status + */ + static function saveNewProfile($pid) { + $name = $_POST['name']; + $status = $_POST['status']; + $insert_id = 0; + if (isset($pid) && $pid != null && isset($name) && $name != null && isset($status) && $status != null) { + # imamo podatke, vstavimo nov profil v bazo + #id uid name system statusnull status0 status1 status2 status3 status4 status5 status6 + + $statusi = explode(',',$status); + $str_lbl = ''; + $str_vle = ''; + foreach ($statusi as $_status) { + $str_lbl .= ', status'.$_status; + $str_vle .= ', 1'; + } + $insertString = "INSERT INTO srv_status_profile (uid,ank_id,name,system".$str_lbl.",statuslurker,statustestni,statusnonusable,statuspartusable,statususable) + VALUES ('".self::getGlobalUserId()."', '".self::$sid."', '".$name."', 0".$str_vle.",'".(int)$_POST['lurker']."','".(int)$_POST['testni']."','".(int)$_POST['nonusable']."','".(int)$_POST['partusable']."','".(int)$_POST['usable']."')"; + $queryInsert = sisplet_query($insertString) + or die(mysqli_error($GLOBALS['connect_db']).$insertString); + $insert_id = mysqli_insert_id($GLOBALS['connect_db']); + } + return $insert_id; + } + + static function DeleteProfile($pid) { + if ($pid == -1) { + unset($_SESSION['statusProfile']); + } + # izbrišemo lahko samo nesistemske profile + if (self::$profiles[$pid]['system'] != 1) { + $sqlDelete = sisplet_query("DELETE FROM srv_status_profile WHERE id = '$pid' AND `system` != '1'"); + } + self::setDefaultProfileId(); + +# meta_akcija analysis + } + + static function renameProfile($pid) + { + $name = trim($_POST['name']); + + if (!empty($name)) + { + + if ($pid == -1) + { # preimenujemo v seji + $_SESSION['statusProfile']['name'] = $name; + } + + # preimenujemo lahko samo nesistemske profile + if (self::$profiles[$pid]['system'] != 1) + { + $sqlRename = sisplet_query("UPDATE srv_status_profile SET name='$name' WHERE id = '$pid' AND `system` != '1'"); + } + } + } + + static function DisplayLink($hideAdvanced = true, $hideSeperator = false) { + global $lang; + // profili statusov + $statusProfiles = self :: getProfiles(); + $izbranStatusProfile = self :: getCurentProfileId(); + + $css = ($izbranStatusProfile == SSP_DEFAULT_PROFILE ? ' gray' : ''); + if ($hideAdvanced == false || $izbranStatusProfile != SSP_DEFAULT_PROFILE) { + if ($hideSeperator == false) { + echo '
  •  
  • '; + } + echo '
  • '; + echo '' . $lang['srv_statusi'] . ''; + echo '
  • '; + + } + } + + public static function FileGeneratingSetting($hideAdvanced = true) { + global $lang, $admin_type; + + $_sql_string = "SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'"; + $_sql_qry = sisplet_query($_sql_string); + $_sql_row = mysqli_fetch_assoc($_sql_qry); + + echo '
  •  
  • '; + echo '
  • '; + $css = ((int)$_sql_row['collect_all_status'] > 0 ? ' gray' : ''); + echo '' . $lang['srv_collect_data_setting_note'] . ''; + echo '
  • '; + + return; + } + + static function showColectDataSetting() { + global $lang, $admin_type; + + $_sql_string = "SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'"; + $_sql_qry = sisplet_query($_sql_string); + list($collect_all_status) = mysqli_fetch_row($_sql_qry); + + $str_qry_cnt_user = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".self::$sid."'"; + $_qry_cnt_user = sisplet_query($str_qry_cnt_user); + list($all_user_cnt) = mysqli_fetch_row($_qry_cnt_user); + + #vsebino shranimo v buffer + $content = ''; + + # kadar imamo uporabnikov več kakor ONLY_VALID_LIMIT (5000) ne dovolimo nastaviti na vse statuse, zato dodamo obvestilo + # le admin lahko nastavi da generira tudi nad 5000 takrat nastavimo collect_all_status = 2 + if ($all_user_cnt > ONLY_VALID_LIMIT && (int)$admin_type > 1) + { + $content .= ''; + $content .= 'Anketa vsebuje več kakor '.ONLY_VALID_LIMIT.' respondentov, zato je dovoljen prikaz le ustreznih!'; + $content .= '

    '; + $content .= ''.$lang['srv_collect_data_setting_note'] . Help :: display('srv_collect_data_setting').''; + $content .= ''; + } + else + { + $content .= ''.$lang['srv_collect_data_setting_note'] . Help :: display('srv_collect_data_setting').''; + $content .= ''; + $content .= ' 0 ? '' : ' checked').' autocomplete="off"'.($admin_type <= 1 ? '' : ' disabled="disabled"').'>'; + $content .= $lang['srv_collect_all_status_0'].''; + } + $content .= '
    '; + $content .= '
    '; + $content .= ''.$lang['srv_deleteSurveyDataFile_link'].''; + + + $popUp = new PopUp(); + $popUp->setId('div_data_file'); + $popUp -> setHeaderText($lang['srv_file_settings']); + + #dodamo vsebino + $popUp -> setContent($content); + + #dodamo gumb izberi profil + $button = new PopUpButton($lang['srv_save_profile']); + $button -> setFloat('right') + -> setButtonColor('orange') + -> addAction('onClick','changeColectDataStatus(); return false;'); + $popUp->addButton($button); + + # dodamo gumb Prekliči + $button = new PopUpCancelButton(); + $button -> setFloat('right'); + $popUp->addButton($button); + + echo $popUp; + } + + + static function savecollectdatasetting() { + global $admin_type; + + // Najprej pobrišemo vse datoteke + $SDF = SurveyDataFile::get_instance(); + $SDF->init(self::$sid); + $SDF->clearFiles(); + + $_collect_all_status = (isset($_POST['collect_all_status']) && (int)$_POST['collect_all_status'] == 1 ) ? '1' : '0'; + if ($admin_type == '0' && $_collect_all_status == '1') { + $_collect_all_status = '2'; + } + + // Ce imamo socialna omrezja, zacasno vedno generiramo samo ustrezne + if(SurveyInfo::getInstance()->checkSurveyModule('social_network')){ + $_collect_all_status = '0'; + } + + // če smo zbrali samo statuse ustrezno, popravimo profile da ni izbran profil vsi statusi + if ((int)$_collect_all_status == 0) { + // Ce smo izbrali drug profil resetiramo še profil profilov na trenutne nastavitve + SurveyUserSetting :: getInstance()->saveSettings('default_profileManager_pid', '0'); + + SurveyUserSetting :: getInstance()->saveSettings('default_status_profile_data', 2); + SurveyUserSetting :: getInstance()->saveSettings('default_status_profile_analysis', 2); + } + } + + static function getProfilesValues() + { + $_sql_string = "SELECT collect_all_status FROM srv_data_files WHERE sid = '".self::$sid."'"; + $_sql_qry = sisplet_query($_sql_string); + list($collect_all_status) = mysqli_fetch_row($_sql_qry); + + + return array('all_status'=>(int)$collect_all_status); + } + + static function getActiveProfileUserCount() + { + $pid = self::$currentProfileId; + if ($pid == 1) + { + return (int)self::$allUserCount; + } + else if( $pid == 2) + { + return (int)self::$allValidCount; + } + else + { + # preštejemo userje + $str_all = "SELECT count(*) FROm srv_user WHERE ank_id='".self::$sid."' AND deleted='0' AND preview = '0' ".self::getStatusAsQueryString($pid); + $query_all = sisplet_query($str_all); + list($all) = mysqli_fetch_row($query_all); + return $all; + } + } + + static function displayOnlyValidCheckbox(){ + global $lang; + + $pid = self::$currentProfileId; + + $values = self::getProfilesValues(); + $collect_all_status = $values['all_status']; + + // če ni ustreznih uporabnikov je privzeto vsi + if (self::$allValidCount == 0) { + + $pid = 1; + $disabledValid = ' disabled="disabled"'; + $disabledGray = ' gray'; + } + else if (self::$allValidCount > 0 && $collect_all_status == 0) { + + /*if ( $pid == 1 ) { + #$pid = 2; + $pid = self::$survayDefaultUstrezni; + }*/ + + if((int)self::$allUserCount > 1000){ + $disabledAll = ' disabled="disabled"'; + $disabledAllGray = ' gray'; + } + } + + echo ''; + echo ' '; + + if (self::$survayDefaultUstrezni == 2) { + echo ''; + } + else { + echo '