0) { $this->Init($sid); // Zacasno povecamo ram samo za veliko nijz anketo global $mysql_database_name; if($sid == '123146' && $mysql_database_name == 'www1kasi'){ ini_set('memory_limit', '2048M'); } } else { echo $lang[''].'Napaka! Missing SID!'; return false; exit(); } } /** Inicializacija * * @param $sid */ public function Init($sid = null) { global $site_path,$lang; if (is_numeric($sid) && (int)$sid > 0) { $this->folder = $site_path . EXPORT_FOLDER.'/'; #nastavimo imena datotek $this->header_file_name = $this->folder . 'export_header_'.$sid.'.dat'; $this->data_file_name = $this->folder . 'export_data_'.$sid.'.dat'; #resetiramo vse pointerje $this->cleanup(); # nastavimo id ankete $this->sid = $sid; # aktivne tabele $str_survey = "SELECT db_table FROM srv_anketa WHERE id = '".$this->sid."'"; $qry_survey = sisplet_query($str_survey); list($db_table) = mysqli_fetch_row($qry_survey); if ((int)$db_table == 1) { $this->db_table = '_active'; } else { $this->db_table = ''; } # nastavimo globalni folder $this->folder = $site_path . EXPORT_FOLDER.'/'; SurveyStatusProfiles::Init($this->sid); SurveySetting::getInstance()->Init($this->sid); // Preverimo ce moramo pobrisati datoteko da je zgeneriramo na novo (ce imamo vklopljen filter na uporabnost) $this->checkUsability(); // Preverimo ce imamo testne podatke $this->checkTestData(); # če gremo preko ajaxa ne kreiramo datoteke $arrStr = explode("/", $_SERVER['SCRIPT_NAME'] ); $arrStr = array_reverse($arrStr ); if ((isset($_REQUEST['setSkipCreate']) && $_REQUEST['setSkipCreate'] == '1') || $arrStr[0] == 'ajax.php') { $this->setSkipCreate(true); } $this->checkFileStatus(); } else { return null; } } public function checkFileStatus() { # nastavimo privzete vrednosti $head_file_time = 0; $data_file_time = 0; $collect_all_status = 1; #privzeto lovimo vse statuse $collect_full_meta = true; # privzeto lovimo meta podatke $last_update = 0; # kdaj je bil zadnji updejt $is_valid_user_limit = ''; # privzeto lovimo vse statuse # preverimo katere podatke vse lovimo $_sql_string = "SELECT UNIX_TIMESTAMP(head_file_time), UNIX_TIMESTAMP(data_file_time), collect_all_status, collect_full_meta, DATE_FORMAT(last_update,'%d.%m.%Y %H:%i:%s') FROM srv_data_files WHERE sid = '".$this->sid."'"; $_sql_qry = sisplet_query($_sql_string); if (mysqli_num_rows($_sql_qry) > 0) { # preberemo vrednosti ankete list($head_file_time, $data_file_time, $collect_all_status, $collect_full_meta, $last_update) = mysqli_fetch_row($_sql_qry); } $head_file_time = (int)$head_file_time; $data_file_time = (int)$data_file_time; # preberemo max time iz datoteke in uporabimo manjšega if (IS_WINDOWS) { $command = 'awk -F"|" "BEGIN {max = 0} {if ('.TIME_FIELD.' > max && '.TIME_FIELD.' > 0) max='.TIME_FIELD.' } END {print max}" '.$this->data_file_name; } else { $command = 'awk -F\'|\' \'BEGIN {max = 0} {if ('.TIME_FIELD.' > max && '.TIME_FIELD.' > 0) max='.TIME_FIELD.' } END {print max}\' '.$this->data_file_name; } $user_time_from_file = shell_exec($command); $user_time_from_file = (int)$user_time_from_file; if ( (int)$user_time_from_file > 0) { # updejtamo v bazi če je slučajno datum v datoteki manjši kot v bazi if ((int)$user_time_from_file < (int)$data_file_time && (int)$data_file_time > 0 ) { $str_qry_update = "UPDATE srv_data_files SET data_file_time = '".(int)$user_time_from_file."' WHERE sid = '".$this->sid."'"; $updated = sisplet_query($str_qry_update); sisplet_query('COMMIT'); } $data_file_time = min((int)$data_file_time,(int)$user_time_from_file); } # če je respondentov več kot ONLY_VALID_LIMIT (5000) lovimo samo ustrezne $str_qry_cnt_user = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0'"; $_qry_cnt_user = sisplet_query($str_qry_cnt_user); list($all_user_cnt) = mysqli_fetch_row($_qry_cnt_user); $all_user_cnt = (int)$all_user_cnt; # če je collect_all_status = 2 je admin nastavil da se lovijo vsi statusi, popravimo tudi čas, da se datoteka zgenerira na novo if ((int)$all_user_cnt > ONLY_VALID_LIMIT && (int)$collect_all_status == 1) { $collect_all_status = 0; $str_qry_update = "INSERT INTO srv_data_files (sid, collect_all_status, data_file_time) VALUES ('".$this->sid."','".(int)$collect_all_status."', '0000-00-00') ON DUPLICATE KEY UPDATE collect_all_status = '".(int)$collect_all_status."', data_file_time = '0000-00-00'"; $updated = sisplet_query($str_qry_update); sisplet_query('COMMIT'); } if ((int)$collect_all_status > 0 ) { $collect_all_status = true; $is_valid_user_limit = ''; } else { $collect_all_status = false; $is_valid_user_limit = VALID_USER_LIMIT_STRING; } # če datoteka s podatki ne obstaja nastavimo data_time na 0, da generiramo vse userje $data_file_name = $this->folder . 'export_data_'.$this->sid.'.dat'; if (!file_exists($data_file_name)) { $data_file_time = 0; } $this->data_file_name = $data_file_name; $this->head_file_time = (int)$head_file_time; $this->data_file_time = (int)$data_file_time; $this->collect_all_status = (int)$collect_all_status; $this->collect_full_meta = $collect_full_meta; $this->is_valid_user_limit = $is_valid_user_limit; $this->last_update = $last_update; $str_survey = "SELECT *, UNIX_TIMESTAMP(edit_time) AS srv_edit_time FROM srv_anketa WHERE id = '".$this->sid."' AND active IN (0,1)"; $qry_survey = sisplet_query($str_survey); $this->survey = mysqli_fetch_assoc($qry_survey); $this->max_anketa_time = (int)$this->survey['srv_edit_time']; # polovimo datum zadnjega userja $str_qry_usr_time = "SELECT max(UNIX_TIMESTAMP(GREATEST(u.time_insert,u.time_edit))) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$this->is_valid_user_limit; $qry_usr_time = sisplet_query($str_qry_usr_time); if (mysqli_num_rows($qry_usr_time)) { list($max_usr_time) = mysqli_fetch_row($qry_usr_time); $this->max_usr_time = (int)$max_usr_time; } // Ce ne belezimo parapodatka datum responsa $no_paradata_date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date'); if($no_paradata_date == 1) $this->max_usr_time = time(); #prikazujemo sistemske # ali prisilimo prikaz sistemskih spremenljivk if ($this->survey['show_email'] == 1 || SurveyInfo::getInstance()->checkSurveyModule('360_stopinj')) { $this->force_show_hiden_system = true; } else { $this->force_show_hiden_system = false; } # če še nimamo respondentov - deluje ok samo ce je vklopljeno zbiranje parapodatka datum if ((int)$this->max_usr_time == 0 && $no_paradata_date == 0) { $this->fileStatus = FILE_STATUS_NO_DATA; return; } # preverimo da anketa ni izbrisana if ((int)$this->survey['active'] >= 0) { # najprej preverimo head datoteko if ((int)$this->head_file_time != (int)$this->max_anketa_time || (int)$this->max_anketa_time == 0) { # head datoteka je stara, pobrišemo obe datoteki $this->fileStatus = FILE_STATUS_NO_FILE; #pobrišemo vse morebitne ostanke datotek $this->clearSurveyDataFiles(); return; } // Ce imamo izklopljeno belezenje parapodatka datum in imamo vsaj 1 vnos moramo vedno generirati datoteko if($no_paradata_date == 1 && $all_user_cnt > 0){ $this->fileStatus = FILE_STATUS_NO_FILE; # preverimo obstoj header datoteke if (file_exists($this->folder . 'export_header_'.$this->sid.'.dat')) { # če datoteka obstaja, nastavimo status na stari podatki if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { $this->fileStatus = FILE_STATUS_OLD; } } } // Ce imamo vnos uporabnika nastavimo status na ni datoteke elseif ((int)$this->max_usr_time > 0) { $this->fileStatus = FILE_STATUS_NO_FILE; # preverimo obstoj header datoteke if (file_exists($this->folder . 'export_header_'.$this->sid.'.dat')) { # če datoteka obstaja, nastavimo status na stari podatki if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { $this->fileStatus = FILE_STATUS_OLD; # če so podatki up to date nastavimo status na OK if ((int)$this->data_file_time == (int)$this->max_usr_time && (int)$this->max_usr_time > 0) { $this->fileStatus = FILE_STATUS_OK; } } } } } else { # Anketa je izbrisana $this->fileStatus = FILE_STATUS_SRV_DELETED; } } // Preverimo ce imamo vklopljen filter na uporabnost in ce imamo v headerju zapisan stolpec za usability (drugace moramo generirati datoteko na novo) public function checkUsability(){ // Preverimo ce imamo vklopljen filter na usability if(SurveyStatusProfiles::usabilitySettings()){ // Preverimo ce imamo usability stolpec v header datoteki $usability = $this->getHeaderVariable('usability'); if($usability == null){ $this->clearSurveyDataFiles(); } } } // Preverimo ce imamo testne podatke na novo -> potem moramo generirati datoteko na novo public function checkTestData(){ # test data $str_qry_cnt_testdata = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND preview='0' AND (u.testdata = '1' OR u.testdata = '2') AND u.deleted = '0'"; $_qry_cnt_testdata = sisplet_query($str_qry_cnt_testdata); list($has_test_data) = mysqli_fetch_row($_qry_cnt_testdata); $this->has_test_data = $has_test_data > 0 ? true : false; // Preverimo ce prej nismo imeli testnih podatkov $settings = $this->getHeaderVariable('_settings'); if($settings['hasTestData'] != 1 && $this->has_test_data){ $this->clearSurveyDataFiles(); } } public function getStatus() { if ($this->fileStatus != null) { return $this->fileStatus; } else { $this->checkFileStatus(); } return $this->fileStatus; } public function getFiles($logClass = null) { global $site_url, $lang, $site_path; # pobrišemo izbrisane userje $this->deleteUsers(); $crf = $this->checkRealFile(); SurveyTrackIncremental::write($this->sid,'getFiles: STATUS: => '. $this->fileStatus); if ( $this->fileStatus == FILE_STATUS_OK ) { return true; } # če datoteke še ni ali če je stara if ( $this->fileStatus == FILE_STATUS_NO_FILE || $this->fileStatus == FILE_STATUS_OLD ) { if ($this->fileStatus != FILE_STATUS_NO_FILE && (int)$this->data_file_time > 0 && file_exists($this->data_file_name)) { SurveyTrackIncremental::write($this->sid,'getFiles: OLD! => '."$crf[result],$crf[file],$crf[db]"); # delamo inkremental $inkremental_user_limit = " AND u.time_edit > FROM_UNIXTIME('".(int)$this->data_file_time."') "; } else { #forsamo status no file $this->fileStatus == FILE_STATUS_NO_FILE; # lovimo vse userje - datoteko generiramo na novo SurveyTrackIncremental::write($this->sid,'getFiles: NO FILE! => '."$crf[result],$crf[file],$crf[db]"); $inkremental_user_limit = ''; } $str_qry_usr_cnt = "SELECT count(u.id) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$this->is_valid_user_limit.$inkremental_user_limit; $qry_usr_cnt = sisplet_query($str_qry_usr_cnt); list($user_cnt) = mysqli_fetch_row($qry_usr_cnt); SurveyTrackIncremental::write($this->sid,'getFiles: New user count=> '.(int)$user_cnt); if ((int) $user_cnt == 0) { SurveyTrackIncremental::write($this->sid,'getFiles: no new user! Is this true realy??? Check line above!!!'); return; } # pozenemo generiranje datoteke if ($this->fileStatus == FILE_STATUS_OLD && $this->skipCreate == true) { # ne posodabljamo SurveyTrackIncremental::write($this->sid,'getFiles: Skip creating.'); } else { if ($this->_force_quick_create == true ) { SurveyTrackIncremental::write($this->sid,'getFiles: ForceQuickCreate.'); # če vsilimo hitro kreiranje $lock = new ExclusiveLock( "survey_lock_".$this->sid, FALSE); if( $lock->lock( ) == FALSE ) { SurveyTrackIncremental::write($this->sid,'LOCK: alreadyLocked for survey: '.$this->sid); $this->writeLockMessage($lock->getLockDate()); #error("Locking failed"); } else { $CH = (int)$this->createHeadFile(); $CD = (int)$this->createDataFile(); $autoCreate = ($CH == true && $CD == true); } $lock->unlock(); } else if ((int)$user_cnt < AUTO_CREATE_LIMIT ) { SurveyTrackIncremental::write($this->sid,'getFiles: AutoCreateWithOutProgressBar.'); $lock = new ExclusiveLock( "survey_lock_".$this->sid, FALSE); if( $lock->lock( ) == FALSE ) { SurveyTrackIncremental::write($this->sid,'LOCK: alreadyLocked for survey: '.$this->sid); $this->writeLockMessage($lock->getLockDate()); #error("Locking failed"); } else { # če je uporabnikov malo, jih dodamo brez progressbara $CH = (int)$this->createHeadFile(); $CD = (int)$this->createDataFile(); $autoCreate = ($CH == true && $CD == true); } $lock->unlock(); } else { # preverimo ali je kreacija že v teku, nato še 1x polovimo statuse ankete # morda je bilo zagnano z drugom browserjem, in je medtem prišlo do spremembe v datoteki $lock = new ExclusiveLock( "survey_lock_".$this->sid, FALSE); if( $lock->lock( ) == FALSE ) { SurveyTrackIncremental::write($this->sid,'LOCK: alreadyLocked for survey: '.$this->sid); $this->writeLockMessage($lock->getLockDate()); #error("Locking failed"); } else { # še 1x preverimo datoteko za vsak slučajm če je morda procedura čakala zaradi lock-a iz drugega browserja $this->checkFileStatus(); SurveyTrackIncremental::write($this->sid,'Status checked once again!'); if ($this->fileStatus == FILE_STATUS_OK) { # lahko da je vmes druga procedura uspešno končala. zato vrnemo da je vse ok. SurveyTrackIncremental::write($this->sid,'Status changed to OK!'); return true; } # kdaj je bio nazadnje updejtano $u = strtotime($this->last_update); # zaradi konsistentnosti polovimo trenutni čas z mysql-om $qry = sisplet_query("SELECT NOW()"); list($_now) = mysqli_fetch_row($qry); $n = strtotime($_now); # ugotovimo razliko v sekundah $diff = (int)($n-$u); # ne pustimo konstantnega osveževanja - največ na 60 s if ($diff > AUTO_CREATE_TIME_LIMIT || $this->fileStatus == FILE_STATUS_NO_FILE) { SurveyTrackIncremental::write($this->sid,'getFiles: AutoCreateWithProgressBar. Calling AJAX!'); $autoCreate = $this->showAutoCreateIncrementalFile(); } else { SurveyTrackIncremental::write($this->sid,'getFiles: Skip creating due time limit.'.$diff); # echo 'Posodobljeno: '.date('d.m.Y h:i:s', strtotime($this->last_update)); } } } } $this->checkFileStatus(); return $autoCreate; } return; } public function setCollectMassive($isMasive = false) { $this->isCollectingMassive = $isMasive; } public function setForeceQuickCreate($force_quick_create = false) { $this->_force_quick_create = $force_quick_create; } public function getFilesMassive($logClass = null) { global $site_url, $lang, $site_path; # pobrišemo izbrisane userje $this->deleteUsers(); $crf = $this->checkRealFile(); SurveyTrackIncremental::write($this->sid,'this->getFilesMassive -> status'.(int)$this->fileStatus); SurveyTrackIncremental::write($this->sid,'Check file result:'."$crf[result],$crf[file],$crf[db]"); if ( $this->fileStatus == FILE_STATUS_OK ) { return true; } # če datoteke še ni ali če je stara if ( $this->fileStatus == FILE_STATUS_NO_FILE || $this->fileStatus == FILE_STATUS_OLD ) { try { $lock = new ExclusiveLock( "survey_lock_".$this->sid, FALSE); if( $lock->lock( ) == FALSE ) { SurveyTrackIncremental::write($this->sid,'LOCK: alreadyLocked for survey: '.$this->sid); $this->writeLockMessage($lock->getLockDate()); #error("Locking failed"); } else { # pozenemo generiranje datoteke $CH = (int)$this->createHeadFile(); $CD = (int)$this->createDataFile(); $this->checkFileStatus(); $autoCreate = ($CH == true && $CD == true); } $lock->unlock(); return $autoCreate; } catch (Exception $e) { if ($logClass != null) { SurveyTrackIncremental::write($this->sid,'getFilesMassive() Exception:'.$e->getMessage()); } } } return; } public function testFilesMassive($logClass = null) { global $site_url, $lang, $site_path; $SL = new SurveyLog(); $SL->addMessage(SurveyLog::INFO, " -".$this->sid." FS->".(int)$this->fileStatus); $SL->write(); return (int)$this->fileStatus; } public function resetDataFile() { if ($this->sid > 0) { # pobrišemo zapis v bazi $qstr = "DELETE FROM srv_data_files WHERE sid = '".$this->sid."'"; $qry = sisplet_query($qstr); $qry = sisplet_query("COMMIT"); # odstranimo sejo session_start(); $_SESSION['incrementalProgressBar'][$this->sid] = null; unset($_SESSION['incrementalProgressBar'][$this->sid]); session_commit(); #pobrišemo še vse datoteke $this->clearSurveyDataFiles(); } } public function showAutoCreateIncrementalFile() { global $lang; # da ne podvajamo skripte za kreiranje datoteke if ($this->skipCreate == true) { return false; } echo '
'; #TODO!!! dodati povezavo do resetiranja kompletne datoteke s podatki, naj pobriše iz baze, datoteko, in sejo echo $lang['srv_incremental_in_progress'].'
'; echo '
'; echo ''.$lang['srv_incremental_start_note'].''; echo '
 
'; echo '
'; echo '
'; echo '
'; echo '
'.$lang['srv_incremental_all_reccords'].''.$lang[''].'Zbiram osnovne podatke. Prosim počakajte...
'; echo '
'.$lang['srv_incremental_current_reccords'].'...
'; echo '
'.$lang['srv_incremental_left_reccords'].'...
'; echo '
'; global $admin_type; # če je admin ponudimo možnost resetiranja if ($admin_type == '0') { echo '

'.$lang[''].'V primeru težav, oziroma v kolikor se skripta za dlje časa ustavi, poženite ponovno generiranje: tukaj'; } echo '
'; ?> skipCreateIfInProgress() == true) { return false; } # nastavimo status da smo v kreiranju $this->setStartInProgress('header'); $result = false; # pripravimo ime header datoteke $head_file_name = $this->folder . 'export_header_'.$this->sid.'.dat'; $need_new_head_file = false; # če je head deatoteka že bila kreirana if ( (int)$this->max_anketa_time > 0 && $this->max_anketa_time == $this->head_file_time ) { # ali datoteka fizično obstaja if (!file_exists($head_file_name)) { #head datoteka ne obstaja potrebno je kreirat novo $need_new_head_file = true; } } else { # datoteka še ni bila kreirana $need_new_head_file = true; # pobrišemo morebitne predhodne datoteke ankete $this->clearSurveyDataFiles(); } # head file is old, need to create new if ($need_new_head_file == true) { $this->_HEADER = null; # za vsak slučaj $this->create_qry_questions(); # ne sme bit '' $this->get_qry_groups(); # polovimo podatke loopa $this->collectLoop(); if ( $this->_str_questions !== '') { $this->CollectHeaders(); #zapišemo header datoteko session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 99; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 1; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 1; session_commit(); file_put_contents($head_file_name, serialize($this->_HEADER)); unset($this->_HEADER); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 100; session_commit(); if ($this->noErrors) { #updejtamo zapis v bazi # data time damo na 0 ker moramo datoteko s podatki zgenerirati čisto na novo. $str_qry_exist_files_update = "INSERT INTO srv_data_files (sid, head_file_time, data_file_time) VALUES ('".$this->sid."',FROM_UNIXTIME('".$this->max_anketa_time."'), '0000-00-00') ON DUPLICATE KEY UPDATE head_file_time = FROM_UNIXTIME('".$this->max_anketa_time."'), data_file_time = '0000-00-00'"; $updated = sisplet_query($str_qry_exist_files_update); sisplet_query("COMMIT"); if ($updated) { $result = true; } else { $this->trigerError('updateHeader', $str_qry_exist_files_update . " ".mysqli_error($GLOBALS['connect_db'])); $result = false; } } } else { $this->trigerError('createHeaderFile', 'Not set this->survey[edit_header_time] ('.$this->sid.')'); $result = false; } } else { if ((int)$this->max_anketa_time > 0) { # Head file is ok! $result = true; } else { # survey time error! $this->trigerError('createHeaderFile', 'Survey time error this->survey[edit_header_time] ('.$this->sid.')'); $result= false; } } $this->setStopInProgress('header'); return $result; } public function createDataFile() { SurveyTrackIncremental::write($this->sid,'createDataFile()'); # če je generacija že v teku ne pustimo ponovnega zagona if ($this->skipCreateIfInProgress() == true) { SurveyTrackIncremental::write($this->sid,'createDataFile()->skipCreateIfInProgress'); return false; } # nastavimo status da smo v kreiranju $this->setStartInProgress('data'); $result = false; # ali moramo dodati userje v datoteko $need_new_data = false; # pripravimo ime data datoteke $data_file_name = $this->folder . 'export_data_'.$this->sid.'.dat'; if ((int)$this->data_file_time > 0) { if ((int)$this->data_file_time != (int)$this->max_usr_time) { # potrebno je dodati userje $need_new_data = true; } } else { # imeli smo spremembo v head datoteki, ali pa userjev še nismo dodajali, pobrišemo morebitno data datoteko $this->clearSurveyDataFiles($data_file_name); #samo z podatki # potrebno je dodati userje $need_new_data = true; } # če moramo dodati userjSe v datoteko if ($need_new_data == true) { #pobrišemo še morebitne prazne vrstice if (IS_WINDOWS) { $cmd1 = 'sed "/^$/d" '.$this->data_file_name.' > '.$this->data_file_name.'.empt && mv '.$this->data_file_name.'.empt '.$this->data_file_name; } else { $cmd1 = 'sed \'/^$/d\' '.$this->data_file_name.' > '.$this->data_file_name.'.empt && mv '.$this->data_file_name.'.empt '.$this->data_file_name; } $out_command1 = shell_exec($cmd1); if (file_exists($this->data_file_name.'.empt')) { unlink($this->data_file_name.'.empt'); } SurveyTrackIncremental::write($this->sid,'createDataFile() -> adding new data: true'); # naredimo aray z query-i/ string-i vseh uporabnikov ( naredimmo v loopih, da ne pride out_of memory) $this->create_qry_users(); # preverimo ali datoteka obstaja in ali že imamo zapise da prilagodimo line seperator $this->new_line_seperator = null; $lines = $this->getLinesCnt(); if ((int)$lines > 0) { $this->new_line_seperator = NEW_LINE; } # datoteko pripravimo za dodajanje $file_handler = fopen($data_file_name,"a"); $this->create_qry_questions(); # ne sme bit '' $this->get_qry_groups(); // Randomizacija v blokih in vprasanjih $this->get_array_random(); # naredimo pointerje na podatke če še ne obstajajo $this->create_array_vrednosti(); # za vrednosti ankete $this->create_array_gridi(); # za gride ankete $this->create_array_SPSS(); # skreira array z polji za spss $_array_vrednosti = $this->get_array_vrednosti(); # za vrednosti ankete $_array_gridi = $this->get_array_gridi(); # za vrednosti ankete if ($this->noErrors) { SurveyTrackIncremental::write($this->sid,'createDataFile()->No errors so far! :)'); # zloopamo skozi vprašanja if ($this->_cnt_questions > 0) { mysqli_data_seek($this->_qry_questions, 0); } $_tmpCnt = 0; # polovimo podatke loopa $this->collectLoop(); # skreiramo vrstni red vprašanj $this->createAllQuestionsOrder(); # polovimo missing vrednosti če so nastavljene drugače kot privzeto #TODO če uporabnik na anketi spremeni da naj bo -1 -6 se to ne upošteva. $this->setSurveyMissingValues(); # v loopu dodamo podatke v data file if ($this->noErrors && count($this->_str_users) > 0) { if ($this->isCollectingMassive == false ) { #updejtamo status session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['current'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['total'] = $this->_cnt_all_users; session_commit(); } foreach ($this->_str_users AS $c => $string_user) { # resetiramo POINTER-je - Array-je do podatkov $this->_qry_data_vrednost = null; $this->_array_data_vrednost = null; $this->_qry_data_text = null; $this->_array_data_text = null; $this->_qry_data_grids = null; $this->_array_data_grids = null; $this->_qry_data_check_grids = null; $this->_array_data_check_grids = null; $this->_qry_data_number = null; $this->_array_data_number = null; $this->_qry_data_rating = null; $this->_array_data_rating = null; $this->_qry_data_text_grid = null; $this->_array_data_text_grid = null; $this->_qry_data_vrednost_cond = null; $this->_array_data_vrednost_cond = null; $this->_qry_data_map = null; $this->_array_data_map = null; $this->_qry_data_heatmap = null; $this->_qry_data_heatmap_regions = null; $this->_array_data_heatmap = null; $this->_array_data_heatmap_regions = null; $this->_qry_data_random = null; $this->_array_data_random = null; # polovimo id-je strani do katerih je prišel posamezen uporabnik $this->create_array_user_grupa($string_user); # naredimo vse potrebne querije v pointerje $this->create_array_data_vrednost($string_user); $this->create_array_data_text($string_user); $this->create_array_data_grids($string_user); $this->create_array_data_check_grids($string_user); $this->create_array_data_number($string_user); $this->create_array_data_rating($string_user); $this->create_array_data_text_grid($string_user); $this->create_array_data_text_upload($string_user); $this->create_array_data_vrednost_cond($string_user); $this->create_array_data_map($string_user); $this->create_array_data_heatmap($string_user); $this->create_array_data_heatmap_regions($string_user); $this->create_array_data_random($string_user); if ($this->noErrors) { $this->CollectData($c,$file_handler); } } } else { SurveyTrackIncremental::write($this->sid,'createDataFile()->some errors: ucount:'.(int)count($this->_str_users)); if ($this->noErrors == false) { $SL = new SurveyLog(); $SL->addMessage(SurveyLog::ERROR, ' ---> SCD::creatingData file failed! ($this->noErrors == false) (sid:'.$this->sid.')'); $SL->write(); } } #preverimo da res ni prišlo do napak if ($this->noErrors) { SurveyTrackIncremental::write($this->sid,'createDataFile() last_user_time:'.$this->last_usr_time); SurveyTrackIncremental::write($this->sid,'createDataFile() max_user_time:'.$this->max_usr_time); $strSel = "SELECT count(*) FROM srv_data_files WHERE sid = '$this->sid'"; $qrySel = sisplet_query($strSel); list($cntSel) = mysqli_fetch_row($qrySel); if ($cntSel > 0) { $str_qry = "UPDATE srv_data_files SET data_file_time = FROM_UNIXTIME('".$this->max_usr_time."'), last_update = NOW() WHERE sid = '".$this->sid."'"; $updated = sisplet_query($str_qry); sisplet_query('COMMIT'); } else { $str_qry = "INSERT INTO srv_data_files (sid, data_file_time, last_update ) VALUES ('".$this->sid."',FROM_UNIXTIME('".$this->max_usr_time."'), NOW())"; $updated = sisplet_query($str_qry); sisplet_query('COMMIT'); } if ($updated) { $result = true; SurveyTrackIncremental::write($this->sid,'createDataFile()->Mysql Write Success! RESULT:'.(int)$result ); } else { $result = false; SurveyTrackIncremental::write($this->sid,'createDataFile()->ERROR! Mysql Write Error! RESULT:'.(int)$result); $this->trigerError('updateDataSql', 'MYSQL ERROR in qry: '.$str_qry_exist_files_update . " ".mysqli_error($GLOBALS['connect_db'])); } } #$this->logClass->write(); } else { SurveyTrackIncremental::write($this->sid,'createDataFile()->Errors! :('); } # zapremo datoteko if ($file_handler !== null) { fclose($file_handler); // Se enkrat izvedemo generiranje ce imamo filter za uporabnost (ker ga racunamo na podlagi ze obstojece datoteke) if (SurveyStatusProfiles::usabilitySettings()) { $SUR = new SurveyUsableResp($this->sid, $generateDataFile=true); // Resetiramo status filter (da izracunamo za vse enote) $SUR->setStatusFilter($status_filter=''); // Izracunamo uporabnost za vsako enoto $usability = $SUR->calculateData(); $file_handler_old = fopen($data_file_name,"r"); $data_file_name_new = $this->folder . 'export_data_'.$this->sid.'_2.dat'; $file_handler_new = fopen($data_file_name_new,"a"); // Beremo datoteko vrstico po vrstico $cnt = 1; while (($line = fgets($file_handler_old)) !== false) { // dodamo vrstici na koncu uporabnost $usability_status = (isset($usability['data'][$cnt]['status'])) ? $usability['data'][$cnt]['status'] : 0; $line = str_replace($this->new_line_seperator, '', $line); $line .= STR_DLMT . $usability_status; fwrite($file_handler_new, $line . $this->new_line_seperator); $cnt++; } fclose($file_handler_old); fclose($file_handler_new); // Pobrisemo staro datoteko unlink($file_handler_old); // Preimenujemo novo datoteko rename($data_file_name_new, $data_file_name); } } # če datoteka s pod atki ne obstaja nastavimo filestatus na 0, če ne pa na 1 $data_file_name = $this->folder . 'export_data_'.$this->sid.'.dat'; if (file_exists($data_file_name)) { $fileStatus = 1; $this->fileStatus = FILE_STATUS_OK; } else { $fileStatus = 0; } } if ($this->isCollectingMassive == false) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['current'] = $_SESSION['incrementalProgressBar'][$this->sid]['total']; $_SESSION['incrementalProgressBar'][$this->sid]['fileStatus'] = (int)$fileStatus; $_SESSION['incrementalProgressBar'][$this->sid]['status'] = 0; session_commit(); } #echo number_format(memory_get_usage() / 1024) . " KB (before cleanup data)
"; # naredimo še cleanup $this->cleanup(); # nastavimo status da smo končali kreiranje $this->setStopInProgress('data'); return $result; } /** * Vsako spremenljivko shranimo pod svojim ID-jem * spremenljivka ima enega ali več gridov ( odviso od dimenzi: eno=>(radio, check, vsota...) multi=>(multigrid, multicheck, multibox) * vsak grid pa lahko ima eno ali več variabel (odgovor, tekstovni odgovor... ) * * vse skupaj shranjujemo v urejenem arrayu * HEADERS[SPR_ID] => array( tip => tip variable * variable => ime Variable * naslov => Naslov variable * cnt_grids => koliko je gridov * grids[ID] => array( * variables[ID] => array(variable => ime variable * naslov => naslov variable * other => ali je polje drugo * text => ali je tekstovni odgovor * spss => polje za spss * ) * ) * ) */ public function CollectHeaders() { global $lang; global $admin_type; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['total'] = $this->_cnt_all_users; session_commit(); # v header dodomo userid $sequence = 1; # vodimo zaporedno števiko polja v bazi $_data_sequence = 1; # vodimo zaporedno števiko polja v bazi kjer se začnejo "resni" podatki # dodamo dodatne nastavitve if ((int)$this->collect_all_status > 0) { # vse statuse $_HEADER['_settings']['collectAllStatus'] = '1'; } else { # samo statuse 6 in 5 $_HEADER['_settings']['collectAllStatus'] = '0'; } if ($this->has_test_data == true) { # ali vsebuje test data $_HEADER['_settings']['hasTestData'] = '1'; } else { $_HEADER['_settings']['hasTestData'] = '0'; } if ($this->collect_full_meta == true) { # ali vsebuje Meta data $_HEADER['_settings']['collectFullMeta'] = '1'; } else { $_HEADER['_settings']['collectFullMeta'] = '0'; } if ($this->force_show_hiden_system == true) { # ali vsebuje Meta data $_HEADER['_settings']['force_show_hiden_system'] = '1'; } else { $_HEADER['_settings']['force_show_hiden_system'] = '0'; } # count normal variables - preštejemo normalne variable, ki niso sistemske kot je email, ime.... in se v podatkih prikazujejo normalno $_HEADER['_settings']['count_normal_data_variables'] = 0; # count system variables - preštejemo sistemske kot je email, ime.... in se v podatkih ne smejo prikazovat $_HEADER['_settings']['count_system_data_variables'] = 0; # user ID $_HEADER['uid']= array ('tip'=>'m', 'variable'=>'uid', 'naslov' =>'User ID', 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'uid', 'naslov'=>'User ID','spss'=>'F11.0','sequence'=>$sequence)) ,'naslov'=>'uid','cnt_vars' => 1))); $_HEADER['uid']['sequences'] = $sequence; $sequence++; $_data_sequence++; # ustreznost uporabnika $_HEADER['relevance']= array ('tip'=>'m', 'variable'=>'relevance', 'naslov' =>$lang['srv_data_relevance'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'relevance', 'naslov'=>$lang['srv_data_relevance'],'spss'=>'F3.0','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_relevance'],'cnt_vars' => 1))); $_HEADER['relevance']['sequences'] = $sequence; $sequence++; $_data_sequence++; # EMAIL VABILO - invitation $_HEADER['invitation']= array ('tip'=>'m', 'variable'=>'invitation', 'naslov' =>$lang['srv_data_invitation'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'invitation', 'naslov'=>$lang['srv_data_invitation'],'spss'=>'F3.0','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_invitation'],'cnt_vars' => 1))); $_HEADER['invitation']['sequences'] = $sequence; $sequence++; $_data_sequence++; # status uporabnika $_HEADER['status']= array ('tip'=>'m', 'variable'=>'status', 'naslov' =>$lang['srv_data_status'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'status', 'naslov'=>$lang['srv_data_status'],'spss'=>'F3.0','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_status'],'cnt_vars' => 1))); $_HEADER['status']['sequences'] = $sequence; $sequence++; $_data_sequence++; # ali je uporabnik lurker $_HEADER['lurker']= array ('tip'=>'m', 'variable'=>'lurker', 'naslov' =>$lang['srv_data_lurker'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'lurker', 'naslov'=>$lang['srv_data_lurker'],'spss'=>'F3.0','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_lurker'],'cnt_vars' => 1))); $_HEADER['lurker']['sequences'] = $sequence; $sequence++; $_data_sequence++; # $_HEADER['unx_ins_date']= array ('tip'=>'m', 'variable'=>'unx_ins_date', 'naslov' =>'unx_ins_date', 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'unx_ins_date', 'naslov'=>'unx_ins_date','spss'=>'F20.0','sequence'=>$sequence)) ,'naslov'=>'unx_ins_date','cnt_vars' => 1))); $_HEADER['unx_ins_date']['sequences'] = $sequence; $sequence++; $_data_sequence++; $_HEADER['recnum'] = array('tip'=>'m', 'variable'=>'recnum', 'naslov' =>'Record number', 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'recnum','naslov'=>'Record number','spss'=>'F5.0','sortType'=>'number','sequence'=>$sequence)), 'naslov'=>'recnum','cnt_vars' => 1))); $_HEADER['recnum']['sequences'] = $sequence; $sequence++; $_data_sequence++; #dodamo geslo - code if ($this->force_show_hiden_system == true) { $_HEADER['code'] = array('tip'=>'m', 'variable'=>'code', 'naslov' =>'Geslo', 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'code','naslov'=>'Geslo','spss'=>'A6','sequence'=>$sequence)), 'naslov'=>'Geslo','cnt_vars' => 1))); $_HEADER['code']['sequences'] = $sequence; $sequence++; $_data_sequence++; } # če vsebuje testne podatke dodamo tudi to polje if ($this->has_test_data) { $_HEADER['testdata']= array ('tip'=>'m', 'variable'=>'testdata', 'naslov' =>$lang['srv_data_test'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'testdata', 'naslov'=>$lang['srv_data_test'],'spss'=>'F3.0','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_test'],'cnt_vars' => 1))); $_HEADER['testdata']['sequences'] = $sequence; $sequence++; $_data_sequence++; } # date insert (Meta) $_HEADER['itime']= array ('tip'=>'m', 'variable'=>'itime', 'naslov' =>$lang['srv_data_date'], 'grids' => array(0 => Array('variables'=>array(0 => Array ('variable'=>'itime', 'naslov'=>$lang['srv_data_date'],'spss'=>'DATETIMEw','sortType'=>'date','sequence'=>$sequence)) ,'naslov'=>$lang['srv_data_date'],'cnt_vars' => 1))); $_HEADER['itime']['sequences'] = $sequence; $sequence++; $_data_sequence++; # s katero sekvenco se začnejo podatki $_HEADER['_settings']['dataSequence'] = $_data_sequence; # naredimo pointerje na podatke če še ne obstajajo $this->create_array_vrednosti(); # za vrednosti ankete $this->create_array_gridi(); # za gride ankete $this->create_array_SPSS(); # skreira array z polji za spss $_array_vrednosti = $this->get_array_vrednosti(); # za vrednosti ankete $_array_gridi = $this->get_array_gridi(); # za vrednosti ankete // Randomizacija v blokih in vprasanjih $this->get_array_random(); # zloopamo skozi vprašanja if ($this->_cnt_questions > 0) { mysqli_data_seek($this->_qry_questions, 0); } $this->createAllQuestionsOrder(); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 8; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = count($this->AllQuestionsOrder); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); $cntHs=0; // Stejemo loope za numeric vprasanje $num_loop_cnt = array(); # dodamo vprašanja ki so v loopu if ($this->noErrors && count($this->AllQuestionsOrder) > 0) { foreach ($this->AllQuestionsOrder AS $_vprasanje_array) { $cntHs++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cntHs; session_commit(); # dodelimo vrednosti loopa $rowVprasanje = $this->AllQuestionsData[$_vprasanje_array['id']]; // nastavimo vrstni red ce loopamo po numericu $num_loop_cnt[$_vprasanje_array['id']]++; # spremenljivki dodamo loop_id da je konsistentno z podatki $rowVprasanje['spr_id'] = $rowVprasanje['spr_id'].'_'.$_vprasanje_array['loop_id']; // $rowVprasanje['loop_id'] = $_vprasanje_array['loop_id']; $_vrednosti = $this->get_array_vrednosti($this->_array_loop_on_spr[$rowVprasanje['if_id']]); $_loop_vrednost = $this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']]; // $rowVprasanje['loop_vre_id'] = $_loop_vrednost; $spr_id = $rowVprasanje['spr_id']; $vrednostLoopSufix = ''; # popravimo ime variable če smo v loopu if(isset($this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']])) { // Posebej obravnavamo loop po numeric vprasanju - samo nastavimo suffix _1, _2... if($this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']] == 'num_loop'){ $rowVprasanje['variable'] = strip_tags($rowVprasanje['variable'])."_".$num_loop_cnt[$_vprasanje_array['id']]; } else{ # id spremenljivke po kateri loopamo $_loop_on_spr_id = $this->_array_loop_on_spr[$rowVprasanje['if_id']]; #variabla spremenljivke po kateri loopamo $_loop_on_spr_variable = $this->AllQuestionsData[$_loop_on_spr_id]['variable']; # id variable po kateri loopamo (v okviru $_loop_on_spr_id) $_loop_on_variable_id = $_vrednosti[$_loop_vrednost]; # naslov variable po keteri loopamo (v okviru $_loop_on_spr_id) $_vrednost_naslov = $_array_vrednosti[$_loop_on_spr_id][$_loop_on_variable_id['id']]['naslov']; $rowVprasanje['variable'] = strip_tags($rowVprasanje['variable'])."_".$_vrednosti[$_loop_vrednost]['variable']; $vrednostLoopSufix = "_".$_vrednosti[$_loop_vrednost]['variable']; if ($_vrednost_naslov != '' && $_loop_on_spr_variable != '' && $rowVprasanje['naslov'] != '') { # zamenjamo ime spremenljivke med #q1# (#q1# z naslovom trenutne variable) $rowVprasanje['naslov'] = str_replace("#$_loop_on_spr_variable#", "$_vrednost_naslov", $rowVprasanje['naslov']); } } } # pomožne variable $tip = $rowVprasanje['tip']; $_tmp_spr_id = explode('_',$rowVprasanje['spr_id']); $spr_id = $_tmp_spr_id[0]; $spr_data_id = $rowVprasanje['spr_id']; // Pri kalkulaciji izpisemo labelo v imenu, ce jo imamo $spr_naslov = ($tip == '22' && $rowVprasanje['label'] != '') ? strip_tags($rowVprasanje['label']) : strip_tags($rowVprasanje['naslov']); $spr_naslov_graf = strip_tags($rowVprasanje['naslov_graf']); $spr_edit_graf = $rowVprasanje['edit_graf']; $spr_wide_graf = $rowVprasanje['wide_graf']; $spr_antonucci = $rowVprasanje['antonucci']; $spr_variable = strip_tags($rowVprasanje['variable']); $spr_size = $rowVprasanje['size']; $spr_cela = $rowVprasanje['cela']; $grid_subtitle1 = $rowVprasanje['grid_subtitle1']; $grid_subtitle2 = $rowVprasanje['grid_subtitle2']; $spr_decimalna = $rowVprasanje['decimalna']; $spr_skala = $rowVprasanje['skala']; $spr_sistem = $rowVprasanje['sistem']; $spr_upload = $rowVprasanje['upload']; $spr_signature = $rowVprasanje['signature']; $spr_random = $rowVprasanje['random']; #!!! po novem tako ali tako število znakov za spss lovimo iz datoteke s podatki # TODO $spss_lngth mora biti enak za vse in sicer je enak največjemu možnemu številu znakov # TODO zato je potrebno zdužit vse ($spss_lngth, $spss_lngth2, $spss_lngth3) $spss_lngth = $this->_array_SPSS[$spr_id]['text']; $spss_lngth2 = $this->_array_SPSS[$spr_id]['text2']; $spss_lngth3 = isset($this->_array_SPSS[$spr_id]['vrednost']) && $this->_array_SPSS[$spr_id]['vrednost'] != '' ? $this->_array_SPSS[$spr_id]['vrednost'] : 0; $_HEADER[$spr_data_id] = array('spr_id'=>$spr_id, 'tip'=>$tip, 'variable'=>$spr_variable, 'naslov'=>$spr_naslov, 'sistem'=>$spr_sistem, 'skala'=>$spr_skala, 'naslov_graf'=>$spr_naslov_graf, 'edit_graf'=>$spr_edit_graf, 'wide_graf'=>$spr_wide_graf); # kontrola sistemskih skritih spremenljivk # kadar ne vsilimo prikaza sistemskih spremenljivk (lahko omogoči le admin) if ($this->force_show_hiden_system == false && $spr_sistem == '1' && in_array($spr_variable,unserialize (SYSTEM_VARIABLES)) # unserialize (SYSTEM_VARIABLES) -> definition.php = array('email','telefon','ime','priimek','naziv','drugo') # pri formi ali glasovanjzu prikazujemo tudi sistemske && ( $this->survey['survey_type'] != 1 && $this->survey['survey_type'] != 0)) { $_HEADER[$spr_data_id]['hide_system'] = '1'; # povečamo števec sistemskih variabel $_HEADER['_settings']['count_system_data_variables'] ++; } else { # povečamo števec normalnih $_HEADER['_settings']['count_normal_data_variables'] ++; } # če je sistemska variabla jo označimo if (in_array($spr_variable,unserialize (SYSTEM_VARIABLES))) { $_HEADER[$spr_data_id]['is_system'] = '1'; } if ( $spr_upload == '1' || $spr_upload == '2') { $_HEADER[$spr_data_id]['upload'] = '1'; } if ( $spr_signature == '1' ) { $_HEADER[$spr_data_id]['signature'] = '1'; } if (isset($rowVprasanje['enota']) && $rowVprasanje['enota'] > 0) { $_HEADER[$spr_data_id]['enota'] = $rowVprasanje['enota']; } # dodoamo loop parent if (isset($rowVprasanje['loop_parent']) && $rowVprasanje['loop_parent'] > 0) { $_HEADER[$spr_data_id]['loop_parent'] = $rowVprasanje['loop_parent']; $_HEADER[$spr_data_id]['antonucci'] = $rowVprasanje['antonucci']; } # dodoamo parent loop id if (isset($_vprasanje_array['parent_loop_id']) && $_vprasanje_array['parent_loop_id'] > 0) { $_HEADER[$spr_data_id]['parent_loop_id'] = $_vprasanje_array['parent_loop_id']; } # Dodamo še loop id $_HEADER[$spr_data_id]['loop_id'] = $_vprasanje_array['loop_id']; $_GRIDS = array(); $_seq_prefix = ''; $_sequences = ''; // v odvisnosti od tipa vprašanja pohandlamo podatke switch ( $tip ) { # RADIO case 1: # DROPDOWN case 3: $cnt=0; # dodamo header variable $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$spr_naslov, 'variable'=>$spr_variable, 'other'=>false,'text'=>false,'spss'=>'F'.$spss_lngth3.'.0','sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost)>0) { foreach ($arrayVrednost as $kid=> $vrednost) { # dodamo še eno polje za tekstovne odgovore drugo if ($vrednost['other'] == 1) { $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$vrednost['naslov'], 'variable'=>$spr_variable.'_'.$vrednost['vrstni_red'].STR_OTHER_TEXT, 'other'=>true,'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_GRIDS[0]['cnt_other'] += 1; } // end if #dodamo opcije (za spss) if ($vrednost['other'] == 0 || $vrednost['other'] == 1) { $_HEADER[$spr_data_id]['options'][$vrednost['variable']] = ($vrednost['naslov'] != null) ? $vrednost['naslov'] : $vrednost['variable']; $_HEADER[$spr_data_id]['options_graf'][$vrednost['variable']] = ($vrednost['naslov_graf'] != null) ? $vrednost['naslov_graf'] : $_HEADER[$spr_data_id]['options'][$vrednost['variable']]; } } // end foreach } // end if $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_HEADER[$spr_data_id]['cnt_all'] = $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; if (isset($rowVprasanje['inline_edit'])) $_HEADER[$spr_data_id]['inline_edit'] = $rowVprasanje['inline_edit']; break; # CHECKBOX case 2: $arrayVrednost = $_array_vrednosti[$spr_id]; $cnt=0; if (count($arrayVrednost)>0) { foreach ($arrayVrednost as $vrednost) { # dodamo header variable samo za ne -missing variable if ($vrednost['other'] == 0 || $vrednost['other'] == 1) { $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$vrednostLoopSufix, 'other'=>false,'text'=>false,'spss'=>'F'.$spss_lngth3.'.0','sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; #dodamo še header za polja drugo if ($vrednost['other'] == 1) { // dodamo v array 'variables' $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$vrednostLoopSufix.STR_OTHER_TEXT, 'other'=>true,'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_GRIDS[0]['cnt_other'] += 1; } // end if } } // end foreach } // end if #dodamo opcije (za spss) $_HEADER[$spr_data_id]['options']['0'] = '0'; $_HEADER[$spr_data_id]['options']['1'] = '1'; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_HEADER[$spr_data_id]['cnt_all'] = $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # TEXT case 4: $cnt=0; # dodamo header variable $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$spr_naslov, 'variable'=>$spr_variable, 'other'=>false, 'text'=>true, 'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_HEADER[$spr_data_id]['cnt_all'] = $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # MULTIRADIO case 6: # ali je dvojni grid $double = (int)($rowVprasanje['enota'] == 3); $double_data = array(); # Pri multigridu je logika obratna. variable predstavljajo podvprašanja, srv_grid pa odgovore $cntGrid = 0; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost)>0) { # če imamo dvojni grid gremo 2_skozi for ($i=1; $i<=$double+1;$i++) { // for $double $double_data[$i]['subtitle'] = $rowVprasanje['grid_subtitle'.$i]; if ($double == 1) { $var_appendix = '_'.$i; } else { $var_appendix = ''; } $part = $i; foreach ($arrayVrednost as $kid=> $vrednost) { // Za kombinirane tabele popravimo ime variable if($rowVprasanje['gru_id'] == -2){ $arr = explode("_", $spr_variable, 2); $sprVar = $arr[0]; $vrednost['variable'] = $sprVar.'_'.$vrednost['variable']; } # dodamo header samo za nemissing variable if ($vrednost['other'] == 0 || $vrednost['other'] == 1) { $cnt = 0; $_GRIDS[$cntGrid]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'naslov'=>$vrednost['naslov'], 'naslov2'=>$vrednost['naslov2'], 'variable'=>$vrednost['variable'].$var_appendix.$vrednostLoopSufix, 'other'=>false, 'text'=>false, 'spss'=>'F'.$spss_lngth3.'.0','sequence'=>$sequence, 'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; if ($vrednost['other'] == 1) { $_GRIDS[$cntGrid]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$var_appendix.$vrednostLoopSufix.STR_OTHER_TEXT, 'other'=>true,'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_GRIDS[$cntGrid]['cnt_other'] += 1; } // end if $_GRIDS[$cntGrid]['cnt_vars'] = $cnt; $_GRIDS[$cntGrid]['naslov'] = $vrednost['variable'].$var_appendix; $_GRIDS[$cntGrid]['part'] = $i; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $cntGrid++; } } // end foreach } // end for $double } // end if #dodamo opcije (za spss) $arrayGrids = $_array_gridi[$spr_id]; if (count($arrayGrids) > 0) { foreach ($arrayGrids AS $kid => $grid) { if ($grid['other'] == 0 || $grid['other'] == 1) { $_HEADER[$spr_data_id]['options'][$grid['variable']] = ($grid['naslov'] != null) ? $grid['naslov'] : $grid['variable']; // Opcije za dodaten naslov grida pri grafu $_HEADER[$spr_data_id]['options_graf'][$grid['variable']] = ($grid['naslov_graf'] != null) ? $grid['naslov_graf'] : $_HEADER[$spr_data_id]['options'][$grid['variable']]; } } } $_HEADER[$spr_data_id]['cnt_grids'] = $cntGrid; $_HEADER[$spr_data_id]['sequences'] = $_sequences; if ($double == 1) { $_HEADER[$spr_data_id]['double'] = $double_data; } break; # NUMBER case 7: # pri number lahko imamo dve variabli grida, če je size 2 $cnt_v = 0; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost) > 0) { $cnt=0; foreach ($arrayVrednost as $kid=> $vrednost) { if ($vrednost['other'] == 0) { if ($spr_size > 1) { # če imamo več variabel $_variable = $vrednost['variable'].$vrednostLoopSufix; } else { #imamo samo eno variablo $_variable = $spr_variable.$vrednostLoopSufix; } $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'naslov'=>$vrednost['naslov'], 'variable'=>$_variable, 'other'=>false, 'text'=>false,'spss'=>'F'.($spr_cela+$spr_decimalna).($spr_decimalna > 0 ? ('.'.$spr_decimalna) : '.0'),'sortType'=>'number','sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt_v++; $cnt++; } // end if } // end foreach $_GRIDS[0]['cnt_vars'] = $cnt_v; $_GRIDS[0]['naslov'] = $spr_variable; } // end if $_GRIDS[0]['enota'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_HEADER[$spr_data_id]['cnt_all'] += $cnt_v; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # DATUM case 8: $cnt=0; # dodamo header variable $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$spr_naslov, 'variable'=>$spr_variable, 'other'=>false, 'text'=>true,'spss'=>'A10','sortType'=>'date','sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # MULTICHECKBOX case 16: # MULTITEXT case 19: # MULTINUMBER case 20: // srv_variable predstavljajo podvprašanja, srv_grid pa možne pododkovore $_spss = ($tip == 16) ? 'F'.$spss_lngth3.'.0' : (($tip == 19) ? 'A'.$spss_lngth2 : 'F'.($spr_cela+$spr_decimalna).($spr_decimalna > 0 ? ('.'.$spr_decimalna) : '.0')); $row = Cache::srv_spremenljivka($spr_id); $newParams = new enkaParameters($row['params']); $is_datum = $newParams->get('multigrid-datum'); #'sortType'=>'date' $grid_id=0; $arrayGrids = $_array_gridi[$spr_id]; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost) > 0) { foreach ($arrayVrednost as $kid=> $vrednost) { // Za kombinirane tabele popravimo ime variable if($rowVprasanje['gru_id'] == -2){ $arr = explode("_", $spr_variable, 2); $sprVar = $arr[0]; $vrednost['variable'] = $sprVar.'_'.$vrednost['variable']; } $cnt=0; if (count($arrayGrids) > 0) { foreach ($arrayGrids AS $kid => $grid) { if ($grid['other'] == 0 || $grid['other'] == 1) { $_GRIDS[$grid_id]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'gr_id'=>$grid['id'], 'naslov'=>$grid['naslov'], 'variable'=>$vrednost['variable'].'_'.$grid['variable'].$vrednostLoopSufix, 'other'=>false, 'text'=>false,'spss'=>$_spss,'sequence'=>$sequence,'naslov_graf'=>$grid['naslov_graf']); if((int)$is_datum === 1) { $_GRIDS[$grid_id]['variables'][$cnt]['sortType'] ='date'; } $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } } // end foreach if ($vrednost['other'] == 1) { $_GRIDS[$grid_id]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$vrednostLoopSufix.STR_OTHER_TEXT, 'other'=>true,'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_GRIDS[$grid_id]['cnt_other'] += 1; } // end if } // end if $_GRIDS[$grid_id]['cnt_vars'] = $cnt; $_GRIDS[$grid_id]['naslov'] = $vrednost['naslov']; $_GRIDS[$grid_id]['variable'] = $vrednost['variable']; $_GRIDS[$grid_id]['naslov_graf'] = $vrednost['naslov_graf']; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $grid_id++; } // end foreach } // end if if ($tip == 16) { #dodamo opcije (za spss) $_HEADER[$spr_data_id]['options']['0'] = '0'; $_HEADER[$spr_data_id]['options']['1'] = '1'; } $_HEADER[$spr_data_id]['cnt_grids'] = $grid_id; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # RANKING case 17: # VSOTA case 18: $_spss = ($tip == 17) ? 'F'.$spss_lngth3.'.0' : 'F'.($spr_cela+$spr_decimalna).($spr_decimalna > 0 ? ('.'.$spr_decimalna) : '.0'); $cnt=0; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost) > 0) { foreach ($arrayVrednost as $kid=> $vrednost) { $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$vrednostLoopSufix, 'other'=>false, 'text'=>false,'spss'=>$_spss,'sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; if ($tip == 17) { $_HEADER[$spr_data_id]['options'][$vrednost['vrstni_red']] = $vrednost['vrstni_red']; } } // end foreach } // end if $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0][ 'cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # BESEDILO* case 21: $cnt=0; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost) > 0) { foreach ($arrayVrednost as $kid=> $vrednost) { if ($vrednost['other'] == 0) { $_variable = (count($arrayVrednost) == 1) ? $spr_variable : $vrednost['variable'].$vrednostLoopSufix ; $_naslov = (trim($vrednost['naslov']) != '' && trim($vrednost['naslov']) != $lang['srv_new_text']) ? $vrednost['naslov'] : $spr_naslov; $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$_naslov, 'variable'=>$_variable, 'other'=>false, 'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } // end if } // end foreach } // end if $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # KALKULACIJA case 22: $cnt=0; # dodamo header variable $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$spr_naslov, 'variable'=>$spr_variable, 'other'=>false, 'text'=>true,'spss'=>'F'.$spss_lngth.'.0','sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # KVOTA case 25: $cnt=0; # dodamo header variable $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$spr_naslov, 'variable'=>$spr_variable, 'other'=>false, 'text'=>true,'spss'=>'F'.$spss_lngth.'.0','sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # SN - IMENA case 9: $cnt=0; $arrayVrednost = $this->SNVariablesForSpr[$_vprasanje_array['id']]; if (count($arrayVrednost) > 0) { foreach ($arrayVrednost as $kid=> $vrednost) { $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost,'naslov'=>($spr_variable.'_'.($cnt+1)), 'variable'=>($spr_variable.'_'.($cnt+1)), 'other'=>false, 'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } // end foreach } // end if $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; # Lokacija case 26: $row = Cache::srv_spremenljivka($spr_id); if($row['enota'] == 3){ $cnt=0; $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost) > 0) { foreach ($arrayVrednost as $kid=> $vrednost) { if ($vrednost['other'] == 0) { $_variable = (count($arrayVrednost) == 1) ? $spr_variable : $vrednost['variable'].$vrednostLoopSufix ; $_naslov = (trim($vrednost['naslov']) != '' && trim($vrednost['naslov']) != $lang['srv_new_text']) ? $vrednost['naslov'] : $_variable; $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'],'naslov'=>$_naslov, 'variable'=>$_variable, 'other'=>false, 'text'=>true,'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } // end if } // end foreach } // end if $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_GRIDS[0]['cnt_vars'] = $cnt; $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_all'] += $cnt; $_HEADER[$spr_data_id]['sequences'] = $_sequences; } else{ $newParams = new enkaParameters($row['params']); $is_podvprasanje = $newParams->get('marker_podvprasanje') == 1; $multi_input_type = $newParams->get('multi_input_type'); if($multi_input_type == 'marker'){ $arrayNaslovov = ($is_podvprasanje) ? array(array('naslov' => $lang['srv_data_column_naslov_map'], 'variable' => $spr_variable.'a'), array('naslov' => $lang['srv_data_column_vrednost_map'], 'variable' => $spr_variable.'b'), array('naslov' => $lang['srv_data_column_koordinate_map'], 'variable' => $spr_variable.'c')) : array(array('naslov' => $lang['srv_data_column_naslov_map'], 'variable' => $spr_variable.'a'), array('naslov' => $lang['srv_data_column_koordinate_map'], 'variable' => $spr_variable.'b')); } else $arrayNaslovov = array(array('naslov' => $lang['srv_data_column_koordinate_map'], 'variable' => $spr_variable.'a')); //kot grid $cnt=0; # dodamo header variable foreach($arrayNaslovov as $naslo){ $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$naslo['naslov'], 'variable'=>$naslo['variable'], 'other'=>false, 'text'=>true, 'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } //$cnt++; $_GRIDS[0]['cnt_vars'] = count($arrayNaslovov); $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = count($arrayNaslovov); $_HEADER[$spr_data_id]['cnt_all'] = count($arrayNaslovov); $_HEADER[$spr_data_id]['sequences'] = $_sequences; } break; # HEATMAP case 27: $arrayNaslovov = array($lang['srv_data_column_koordinate_map']); //kot grid $cnt=0; # dodamo header variable foreach($arrayNaslovov as $naslo){ $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>null, 'naslov'=>$naslo, 'variable'=>$spr_variable, 'other'=>false, 'text'=>true, 'spss'=>'A'.$spss_lngth,'sequence'=>$sequence); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; } //checkbox vrednosti za imena obmocij $arrayVrednost = $_array_vrednosti[$spr_id]; if (count($arrayVrednost)>0) { foreach ($arrayVrednost as $vrednost) { # dodamo header variable samo za ne -missing variable if ($vrednost['other'] == 0 || $vrednost['other'] == 1) { $_GRIDS[0]['variables'][$cnt] = array('vr_id'=>$vrednost['id'], 'naslov'=>$vrednost['naslov'], 'variable'=>$vrednost['variable'].$vrednostLoopSufix, 'other'=>false,'text'=>false,'spss'=>'F'.$spss_lngth3.'.0','sequence'=>$sequence,'naslov_graf'=>$vrednost['naslov_graf']); $_sequences .= $_seq_prefix.$sequence; $_seq_prefix = '_'; $sequence++; $cnt++; #dodamo še header za polja drugo } } // end foreach } // end if //checkbox vrednosti za imena obmocij - konec #dodamo opcije (za spss) $_HEADER[$spr_data_id]['options']['0'] = '0'; $_HEADER[$spr_data_id]['options']['1'] = '1'; $_GRIDS[0]['cnt_vars'] = $cnt; //stevilo stolpcev pod enim vprasanjem $_GRIDS[0]['naslov'] = $spr_variable; $_HEADER[$spr_data_id]['cnt_grids'] = 1; $_HEADER[$spr_data_id]['cnt_all'] = $cnt; //koliko stolpcev mora pokriti naslov tega vprasanja $_HEADER[$spr_data_id]['sequences'] = $_sequences; break; } $_HEADER[$spr_data_id]['grids'] = $_GRIDS; } // end foreach ($this->AllQuestionsOrder AS $_vprasanje_array) { } // end if (count($this->AllQuestionsOrder) > 0) ################# # DODAMO SPECIAL META if ($this->collect_full_meta) { # s katero sekvenco se začnejo meta podatki $_HEADER['_settings']['metaSequence'] = $sequence; $_HEADER['meta'] = array('tip'=>'sm', 'variable'=>'smeta', 'naslov' =>$lang['srv_displaydata_meta'],'cnt_all'=>2); # Datum insert, datum edit, datume in čase za posamezno stran $_g_cnt = 0; $_tmp_seq = $sequence; // Na zacetku prikazemo randomizacijo ce je prisotna pri kaksnem vprasanju ali bloku foreach ($this->_array_random as $random_parent) { if($random_parent['type'] == 'spr'){ $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'Random '.$random_parent['variable']); $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'random_'.$random_parent['id'],'naslov'=>$random_parent['variable'],'sequence'=>$sequence); $_g_cnt++; $sequence++; } elseif($random_parent['type'] == 'blok_spr'){ $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'Random B'.$random_parent['number']); $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'random_'.$random_parent['id'],'naslov'=>'B'.$random_parent['number'],'sequence'=>$sequence); $_g_cnt++; $sequence++; } elseif($random_parent['type'] == 'blok_blok'){ $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'Random B'.$random_parent['number']); $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'random_'.$random_parent['id'],'naslov'=>'B'.$random_parent['number'],'sequence'=>$sequence); $_g_cnt++; $sequence++; } } # če mamo da prepozna uporabnika iz sispleta if ((int)$this->survey['user_from_cms'] > 0) { $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'E-mail iz CMS'); $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'usr_from_cms','naslov'=>'E-mail iz CMS','spss'=>'A256','sequence'=>$sequence); $sequence++; $_g_cnt ++; } # datum $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['date']); #time insert $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'t_insert','naslov'=>$lang['date_insert'],'spss'=>'DATETIMEw','sortType'=>'date','sequence'=>$sequence); $sequence++; #time header $_HEADER['meta']['grids'][$_g_cnt]['variables'][1] = Array ('variable'=>'t_edit','naslov'=>$lang['date_edit'],'spss'=>'DATETIMEw','sortType'=>'date','sequence'=>$sequence); $sequence++; # dodamo št. variabel na grupo $_HEADER['meta']['grids'][$_g_cnt]['cnt_vars'] = 2; $_g_cnt ++; # datumi in časi po posameznih straneh # zaloopamo skozi strani # zaloopamo skozi strani $page = 1; foreach ($this->_array_groups as $gid => $grupa) { $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['page'].' '.$page); # date on page $_HEADER['meta']['grids'][$_g_cnt]['variables'][0] = Array ('variable'=>'date_'.$page,'naslov'=>'datum_'.$page,'spss'=>'DATETIMEw','sortType'=>'date','sequence'=>$sequence); $sequence++; /* zaradi hitrosti ne računamo časa na strani //time on page $_HEADER['meta']['grids'][$_g_cnt]['variables'][1] = Array ('variable'=>'time_'.$page,'naslov'=>'cas_'.$page,'spss'=>'F5','sequence'=>$sequence); $sequence++; $_HEADER['meta']['grids'][$_g_cnt]['cnt_vars'] = 2; */ $_HEADER['meta']['grids'][$_g_cnt]['cnt_vars'] = 1; $page++; $_g_cnt++; } /* ZARADI VAROVANJA PODATKOV SMO ZAČASNO ONEMOGOČILI LOVLJENJE IP-jev */ #IP $ip = SurveySetting::getInstance()->getSurveyMiscSetting('survey_ip'); $ip_show = SurveySetting::getInstance()->getSurveyMiscSetting('survey_show_ip'); if($ip==0 && $ip_show==1 && ($admin_type == 0 || $admin_type == 1)){ $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'IP', 'variables' => array( 0 => Array ('variable'=>'IP','naslov'=>'IP','spss'=>'A32','sequence'=>$sequence))); $sequence++; $_g_cnt++; } # JS $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'JS', 'variables' => array( 0 => Array ('variable'=>'JS','naslov'=>'JavaScript','spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # Browser $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['browser'], 'variables' => array( 0 => Array ('variable'=>'Browser','naslov'=>$lang['browser'],'spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # Browser version $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['browser_version'], 'variables' => array( 0 => Array ('variable'=>'BrowserVersion','naslov'=>$lang['browser_version'],'spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # OS $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'OS', 'variables' => array( 0 => Array ('variable'=>'OS','naslov'=>$lang['srv_para_graph_os'],'spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # Device $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['srv_para_graph_device'], 'variables' => array( 0 => Array ('variable'=>'Device','naslov'=>$lang['srv_para_graph_device'],'spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # Referer $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'Referer', 'variables' => array( 0 => Array ('variable'=>'Referer','naslov'=>'Referer','spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # unsubscribed $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>'Unsubscribed', 'variables' => array( 0 => Array ('variable'=>'Unsubscribed','naslov'=>'Unsubscribed','spss'=>'A2','sequence'=>$sequence))); $sequence++; $_g_cnt++; # jezik - language $_HEADER['meta']['grids'][$_g_cnt] = Array('naslov'=>$lang['lang'], 'variables' => array( 0 => Array ('variable'=>'Language','naslov'=>$lang['lang'],'spss'=>'A256','sequence'=>$sequence))); $sequence++; $_g_cnt++; # dodamo št. variabel za celotno skupino $_HEADER['meta']['cnt_all'] = $sequence - $_tmp_seq; } #### META #### // USABILITY # če vsebuje nastavitev da filtriramo po uporabnosti dodamo tudi to polje if (SurveyStatusProfiles::usabilitySettings()) { $_HEADER['usability'] = Array('naslov'=>$lang['srv_usableResp_usability'], 'variables' => array( 0 => Array ('variable'=>'Usability','naslov'=>$lang['srv_usableResp_usability'],'spss'=>'A2','sequence'=>$sequence))); $sequence++; } $this->_HEADER = $_HEADER; } /*** * */ public function CollectData($c,$file_handler) { global $site_path, $site_url, $lang, $admin_type; # zloopamo skozi userje #$new_line_seperator = ($c==0) ? '' : NEW_LINE; # osvežimo podatke if (mysqli_num_rows($this->_qry_users[$c]) > 0) { mysqli_data_seek($this->_qry_users[$c], 0); } $_tmpCnt = $c * MAX_USER_PER_LOOP; $_dataLine = ""; $p = new Prevajanje($this->sid); $jeziki = $p->get_all_langs(); # lang od 0 je privzet $jeziki[0] = $lang['language']; $jeziki[$lang['id']] = $lang['language']; if ($this->noErrors) { while ($rowUser = mysqli_fetch_assoc($this->_qry_users[$c])) { #sleep(1); $_tmpCnt++; #updejtamo status (v masovnem dodajnju ne uporabljamo seje) if ($this->isCollectingMassive == false) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['current'] = $_tmpCnt; $_SESSION['incrementalProgressBar'][$this->sid]['total'] = $this->_cnt_all_users; session_commit(); } $uid = $rowUser['usr_id']; # dodamo usr id k podatkom $_dataLine .= $rowUser['usr_id']; # dodamo ustreznost k podatkom - relevance $_dataLine .= STR_DLMT. (($rowUser['status'] == 5 || $rowUser['status'] == 6) && $rowUser['lurker'] == 0 ? '1' : '0'); # dodamo email (invitation)k podatkom - če je bilo poslano z emailom ali je uporabnik ročno vnesel email $_dataLine .= STR_DLMT. ((int)$rowUser['inv_res_id'] > 0 # uporabnik je bil dodan z email vabilom ? ((int)$rowUser['status'] == 1 || (int)$rowUser['status'] >= 3 # email je bil odposlan ? '1' # email ni bil odposlan ali je bila napaka : '2') # uporabnik ni bil dodan z email vabilom : '0'); # dodamo status k podatkom $_dataLine .= STR_DLMT.$rowUser['status']; # dodamo lurkerje $_dataLine .= STR_DLMT.$rowUser['lurker']; #dodamo unx_ins_date $_dataLine .= STR_DLMT.max($rowUser['unx_ins_date'],$rowUser['unx_edt_date']); #dodamo recnum $_dataLine .= STR_DLMT.$rowUser['recnum']; #dodamo geslo if ($this->force_show_hiden_system == true) { $_dataLine .= STR_DLMT.$rowUser['pass']; } # če vsebuje testne podatke dodamo tudi kolono z tem statusom if ($this->has_test_data) { $_dataLine .= STR_DLMT.(int)$rowUser['testdata']; } # dodamo insert time k podatkom $_dataLine .= STR_DLMT.date("d.m.Y",strtotime($rowUser['time_insert'])); #dodamo uporabnikove podatke # zloopamo skozi vprašanja # TOLE SEM ZAKOMENTIRAL KER SE MI ZDI DA NI POTRBNO, KER TAKO AL TAKO LOOPAMO PO arrayu /*if ($this->_cnt_questions > 0) { mysqli_data_seek($this->_qry_questions, 0); }*/ # dodamo vprašanja ki so v loopu $userAnswerLine = ''; #resetiramo $this->_user_spr_answer_count = array('cnt'=>0, 'last'=>0, 'spremenljivke'=>array()); $pages = array(); if ($this->noErrors && count($this->AllQuestionsOrder) > 0) { foreach ($this->AllQuestionsOrder AS $_vprasanje_array) { // if ($this->noErrors) { // while ($rowVprasanje = mysqli_fetch_assoc($this->_qry_questions)) { $rowVprasanje = $this->AllQuestionsData[$_vprasanje_array['id']]; # spremenljivki dodamo loop_id da je konsistentno z podatki $rowVprasanje['spr_id'] = $rowVprasanje['spr_id'].'_'.$_vprasanje_array['loop_id']; if (isset($this->_array_loop_on_spr[$rowVprasanje['if_id']])) { $_vrednosti = $this->get_array_vrednosti($this->_array_loop_on_spr[$rowVprasanje['if_id']]); } if(isset($this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']])) { $_loop_vrednost = $this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']]; } # popravimo ime variable če smo v loopu if(isset($this->_array_vre_on_loop[$rowVprasanje['if_id']][$_vprasanje_array['loop_id']])) { $rowVprasanje['variable'] = strip_tags($rowVprasanje['variable'])."_".$_vrednosti[$_loop_vrednost]['variable']; } # pomožne variable $tip = $rowVprasanje['tip']; $_tmp_spr_id = explode('_',$rowVprasanje['spr_id']); $spr_id = $_tmp_spr_id[0]; $spr_data_id = $rowVprasanje['spr_id']; $spr_naslov = strip_tags($rowVprasanje['naslov']); $spr_variable = strip_tags($rowVprasanje['variable']); $spr_size = $rowVprasanje['size']; $spr_cela = $rowVprasanje['cela']; $grid_subtitle1 = $rowVprasanje['grid_subtitle1']; $grid_subtitle2 = $rowVprasanje['grid_subtitle2']; $spr_decimalna = $rowVprasanje['decimalna']; $spr_skala = $rowVprasanje['skala']; $spr_sistem = $rowVprasanje['sistem']; $spr_page = $rowVprasanje['gru_id']; $spr_upload = $rowVprasanje['upload']; $spr_signature = $rowVprasanje['signature']; $spr_visible = $rowVprasanje['visible']; $spr_dostop = $rowVprasanje['dostop']; $pages[$spr_page] = true; # ponastavimo katere vrednosti se beležijo kot neodgovori na spremenljivko # ali je to -3 ali -1. Če uporabnik še ni bil na tej strani je -3 če ne je -1 # ali pa če gre za email vabila dodamo status -3 if ((($rowUser['status'] == 6 || $rowUser['status'] == 5 ) && $rowUser['lurker'] != 1) ) { // Ce je skrito je -2 (-2d da ga pobrisemo z -3 ce je potrebno) if($spr_visible == 0 || !(($admin_type <= $spr_dostop && $admin_type>=0) || ($admin_type==-1 && $spr_dostop==4))){ $VALUE_FOR_MISSING = '-2d'; } else{ # če so veljavni odgovori damo -1 ali -3 # na -3 popravimo na okncu #$VALUE_FOR_MISSING = isset($this->_array_user_grupa[$uid][$spr_page]) ? '-1' : '-1'; $VALUE_FOR_MISSING = '-1'; } } else if ( $rowUser['status'] == 0 || $rowUser['status'] == 1 || $rowUser['status'] == 2 ) { # če je email vabilo #$VALUE_FOR_MISSING = '-3'; $VALUE_FOR_MISSING = '-5'; } else { # to so lurkerji # če imamo neveljavne odgovore damo -5 $VALUE_FOR_MISSING = '-5'; } # array z vrednosmi rabimo za podatke in za polja drugo if (isset($this->_array_vrednosti[$spr_id])) { $spr_vrednosti = $this->_array_vrednosti[$spr_id]; } #gridi if (isset($this->_array_gridi[$spr_id])) { $spr_gridi = $this->_array_gridi[$spr_id]; } #ODGOVORI #tekstovno odgovori $spr_data_text = $this->get_array_data_text($uid,$spr_data_id); unset($this->_array_data_text[$uid][$spr_data_id]); # vrednostni odgovori $spr_data_vred = $this->get_array_data_vrednost($uid,$spr_data_id); unset($this->_array_data_vrednost[$uid][$spr_data_id]); # preslkočeni vrednostni odgovori $spr_data_vrednost_cond = $this->get_array_data_vrednost_cond($uid,$spr_data_id); unset($this->_array_data_vrednost_cond[$uid][$spr_data_id]); # grid odgovori $spr_data_grid = $this->get_array_data_grids($uid,$spr_data_id); unset($this->_array_data_grids[$uid][$spr_data_id]); # grid odgovori za checkbox $spr_data_grid_check = $this->get_array_data_check_grids($uid,$spr_data_id); unset($this->_array_data_check_grids[$uid][$spr_data_id]); # ranking odgovori $spr_data_ranking = $this->get_array_data_rating($uid,$spr_data_id); unset($this->_array_data_rating[$uid][$spr_data_id]); # textgrid odgovori $spr_data_grid_text = $this->get_array_data_text_grid($uid,$spr_data_id); unset($this->_array_data_text_grid[$uid][$spr_data_id]); # lokacijski odgovori $spr_data_map = $this->get_array_data_map($uid,$spr_data_id); unset($this->_array_data_map[$uid][$spr_data_id]); # heatmap odgovori $spr_data_heatmap = $this->get_array_data_heatmap($uid,$spr_data_id); unset($this->_array_data_heatmap[$uid][$spr_data_id]); $spr_data_heatmap_regions = $this->get_array_data_heatmap_regions($uid,$spr_data_id); unset($this->_array_data_heatmap_regions[$uid][$spr_data_id]); switch ( $tip ) { // v odvisnosti od tipa vprašanja pohandlamo podatke # RADIO BUTTON case 1: # DROPDOWN - SELECT case 3: $answer = null; $_vred = null; if (is_array($spr_data_vred)) { $key = key($spr_data_vred); if (isset($spr_data_vred[$key])) { $_vred = $spr_data_vred[$key]; } } else { $_vred = $VALUE_FOR_MISSING; } if ($_vred > 0) { $answer = $spr_vrednosti[$_vred]['variable']; } else { $answer = $_vred; } if ( $answer == '' || $answer == null) { $answer = $VALUE_FOR_MISSING; } # dodamo podatek $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); #Tip 3 sem dodal , ker se zaradi buga lahko tudi pri roleti pojavi polje drugo if ($tip == 1 || $tip == 3) { // radio # poiščemo polja drugo if (count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { if ($vrednost['other'] == 1) { if ($this->isNotAnswerMissing($answer)) { $answerOther = $answer; } else { if (isset($spr_data_text[$vid]['text'])) { $answerOther = ($spr_data_text[$vid]['text'] == "" || $spr_data_text[$vid]['text'] == null) ? $VALUE_FOR_MISSING : $spr_data_text[$vid]['text']; } elseif($spr_vrednosti[$vid]['variable'] != $answer){ // Ce je bil -1 texta ni mogel vnesti in mora bit -2 if($VALUE_FOR_MISSING == -1) $answerOther = '-2d'; else $answerOther = $VALUE_FOR_MISSING; } else { $answerOther = $VALUE_FOR_MISSING; } } # dodamo podatek $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } } break; # CHECKBOX case 2: $answer = null; $_tmp_answers = array(); ## če ni lurker damo celemu checboxu 0 kadar ni izbran in ne -1 /*if ((int)$rowUser['lurker'] == 1) { $_anything_set = false; } else { $_anything_set = true; }*/ $_anything_set = false; $_has_missing = NULL; # najprej dodelimo odgovore posameznim vrednostim če obstatajo if (count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { if (isset($spr_data_vred[$vid]) && $_has_missing == NULL) { # če je spr_data_vrednost obstaja je checkbox obkljukan #preverimo ali imamo missing if ($vrednost['other'] != 0 && $vrednost['other'] != 1 ) { # odgovor je missing, vse vrednosti nastavimo na ta missing, zato pobrišemo morebitne že dodane odgovore unset($_tmp_answers); unset($spr_data_vred[$vid]); #$_anything_set = false; $_has_missing = $spr_vrednosti[$vid]['variable']; } else { $_tmp_answers[$vid] = 1; unset($spr_data_vred[$vid]); $_anything_set = true; } } else if (isset($spr_data_vrednost_cond[$vid])) { $_tmp_answers[$vid] = $spr_data_vrednost_cond[$vid]; #$_anything_set = true; } } // če ni nič nastavljeno, je lahko samo -1, -2, -3,-4 $missing_answers = 0; # preverimo ali so ostale še kakšne vrednosti, potem so najbrž missingi #najprej preverimo missing na variabli if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { unset($_tmp_answers); $_has_missing = end($spr_data_vred); $missing_answers = $_has_missing; $_anything_set = false; } if ($_anything_set == false || $_has_missing != null) { if ($_has_missing != null) { # immamo misssing value $missing_answers = $_has_missing; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $missing_answers = end($spr_data_vred); # lahko da je -2, -4 } else { // lahko je -1, -3 $missing_answers = $VALUE_FOR_MISSING; } } # še enkrat zloopamo skozi vrednosti in dodelimo odgovore, tudi za polja drugo if (count($spr_vrednosti) > 0) { if ($missing_answers == 0 ) { $missing_answers = $VALUE_FOR_MISSING; } foreach ($spr_vrednosti AS $vid => $vrednost) { # dodamo samo variable ki niso missing if ($vrednost['other'] == 0 || $vrednost['other'] == 1) { if (isset($_tmp_answers[$vid])) { $answer = $_tmp_answers[$vid]; } else if ($_anything_set == true){ #pri checkboxu je lahko tudi 0 $answer = 0; } else { $answer = $missing_answers; } # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); #dodamo še polje drugo if ($vrednost['other'] == 1) { #ce smo meli checkboc obkljukan if (isset($_tmp_answers[$vid])) { $answerOther = ($spr_data_text[$vid]['text'] == "" || $spr_data_text[$vid]['text'] == null) ? $VALUE_FOR_MISSING : $spr_data_text[$vid]['text']; } else if ($missing_answers !== null) { // Ce je bil 0 texta ni mogel vnesti in mora bit -2 if($VALUE_FOR_MISSING == -1) $answerOther = '-2d'; else $answerOther = $missing_answers; } else if ($answer == 0) { $answerOther = $VALUE_FOR_MISSING; } else { $answerOther = $answer; } # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } } } break; # TEXT case 4: $answer = null; # ce obstaja $spr_data_vred je po vsej vrjetnosti missing if ( count($spr_data_vred) > 0 ) { $key = key($spr_data_vred); $answer = $spr_data_vred[$key]; //unset ($spr_data_vred[$key]); } else { $answer = $spr_data_text[0]['text']; } if ( $answer == '' || $answer == null) { $answer = $VALUE_FOR_MISSING; } # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); break; # NAGOVOR /* case 5: # dodamo odgovor $userAnswerLine .= STR_DLMT.' '; break; */ # MULTI RADIO BUTTON case 6: # dvojni gridi so zapisani v $spr_data_grid_check if ((int)$rowVprasanje['enota'] != 3) { # ni dvojni grid $answer = null; # zloopamo skozi podvprašanja (srv_vrednost if (count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { $missing_answer=false; if (is_array($spr_data_vred) && count($spr_data_vred) == 1 ) { $answer = end($spr_data_vred); # lahko da je -2, -4 $missing_answer = true; } else if (isset($spr_data_grid[$vid])) { if ($spr_data_grid[$vid] > 0) { if ($spr_gridi[$spr_data_grid[$vid]]['other'] == 0) { # preberemo grid vrednost $answer = $spr_gridi[$spr_data_grid[$vid]]['variable']; // tukaj dodelimo ime variable, lahko bi tudi id ali vrstni red??? $missing_answer = false; } else { $answer = $spr_gridi[$spr_data_grid[$vid]]['other']; } }else { # je missing $answer = $spr_data_grid[$vid]; $missing_answer = true; } } else { $answer = $VALUE_FOR_MISSING; $missing_answer = true; } # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); if ($vrednost['other'] == 1) { # če answer ni missing if ($missing_answer == false) { if (isset($spr_data_text[$vid]['text'])) { $answerOther = ($spr_data_text[$vid]['text'] == "" || $spr_data_text[$vid]['text'] == null) ? $VALUE_FOR_MISSING : $spr_data_text[$vid]['text']; }else { $answerOther = $VALUE_FOR_MISSING; } } else { $answerOther = $answer; } # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } } else { # DOUBLE GRID # če imamo dvojni grid gremo 2_skozi $double = (int)($rowVprasanje['enota'] == 3); $_tmp_answers = array(); for ($i=1; $i<=$double+1;$i++) { // for $double # sfiltriramo odgovore za posamezen part $_tmp_part_answers = array(); if (count($spr_data_grid_check) > 0) { foreach($spr_data_grid_check as $vre_id => $grids) { if (count($grids) > 0) { foreach($grids AS $gid => $grid) { if ($spr_gridi[$gid]['part'] == $i) { if ($spr_gridi[$gid]['other'] == 0) { $_tmp_part_answers[$vre_id] = $spr_gridi[$gid]['variable']; } else { $_tmp_part_answers[$vre_id] = $spr_gridi[$gid]['other']; } } } } } } $answer = null; # zloopamo skozi podvprašanja (srv_vrednost if (count($spr_vrednosti) > 0) { foreach ($spr_vrednosti AS $vid => $vrednost) { $missing_answer=false; if (is_array($spr_data_vred) && count($spr_data_vred) == 1 ) { $answer = end($spr_data_vred); # lahko da je -2, -4 $missing_answer = true; } else if (isset($_tmp_part_answers[$vid])) { if ($_tmp_part_answers[$vid] > 0) { # preberemo grid vrednost $answer = $_tmp_part_answers[$vid]; // tukaj dodelimo ime variable, lahko bi tudi id ali vrstni red??? $missing_answer = false; } else { $answer = $_tmp_part_answers[$vid]; // tukaj dodelimo ime variable, lahko bi tudi id ali vrstni red??? $missing_answer = true; } } else { $answer = $VALUE_FOR_MISSING; $missing_answer = true; } # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); if ($vrednost['other'] == 1) { # če answer ni missing if ($missing_answer == false) { $answerOther = ($spr_data_text[$vid]['text'] == "" || $spr_data_text[$vid]['text'] == null) ? $VALUE_FOR_MISSING : $spr_data_text[$vid]['text']; } else { $answerOther = $answer; } # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } } } // for $double } break; # NUMBER case 7: # DATE case 8: $_vred = null; $answer0 = null; # ce imamo odgovor if (isset ($spr_data_text[0])) { $answer0 = ($spr_data_text[0]['text'] != '') ? $spr_data_text[0]['text'] : $VALUE_FOR_MISSING; } else if (is_array($spr_data_vred)) { $key = key($spr_data_vred); if (isset($spr_data_vred[$key])) { $_vred = $spr_data_vred[$key]; } #pogledamo če je odgovor missing: if (isset($spr_vrednosti[$_vred])) { $answer0 = $spr_vrednosti[$_vred]['variable']; } else { $answer0 = $_vred; } } $answer0 = ($answer0 == null ) ? $VALUE_FOR_MISSING : $answer0; # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer0,$uid); # ve imamo size = 2 if ($tip == 7 && $spr_size > 1) { $answer1 = null; # ce imamo odgovor if (isset ($spr_data_text[0])) { $answer1 = ($spr_data_text[0]['text2'] != '') ? $spr_data_text[0]['text2'] : $VALUE_FOR_MISSING; } else if (is_array($spr_data_vred)) { $key = key($spr_data_vred); if (isset($spr_data_vred[$key])) { $_vred = $spr_data_vred[$key]; } #pogledamo če je odgovor missing: if (isset($spr_vrednosti[$_vred])) { $answer1 = $spr_vrednosti[$_vred]['variable']; } else { $answer1 = $_vred; } } $answer1 = ($answer1 == null ) ? $VALUE_FOR_MISSING : $answer1; # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer1,$uid); } break; # MULTI CHECKBOX case 16: # delamo na nivoju $spr_vrednosti kar predstavlja podvprašanje if (count($spr_vrednosti) > 0) { foreach ($spr_vrednosti AS $vid => $vrednost) { $_tmp_answers = array(); $_anything_set = false; $_missing_answer = NULL; # zloopamo skozi podvprašanja in nastavimo izbrane odgovore if (count($spr_gridi) > 0) { foreach ($spr_gridi AS $gid => $grid) { if (isset($spr_data_grid_check[$vid][$gid]) && $_missing_answer == NULL) { # če je spr_data_vrednost obstaja je checkbox obkljukan #Najprej preverimo ali je odgovro missing... if ($spr_gridi[$gid]['other'] == 0 || $spr_gridi[$gid]['other'] == 1) { $_tmp_answers[$vid][$gid] = 1; $_anything_set = true; } else { $_missing_answer = $spr_gridi[$gid]['other']; # izrišemo morebitne 1 ke pri vrednostih ki imajo kakršnkoli missing # ker ne more bit hkrati -99 ne vem in veljavni odgovor unset($_tmp_answers); $_anything_set = false; } unset($spr_data_grid_check[$vid][$gid]); } } } # nastavimo ali missinge, ali neveljavne ali 0; if ($_anything_set == false) { if ($_missing_answer != NULL) { # missing je že nastavljen } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $_missing_answer = end($spr_data_vred); } else { $_missing_answer = $VALUE_FOR_MISSING; } } # dodamo odgovore if (count($spr_gridi)>0) { foreach ($spr_gridi AS $gid => $grid) { # dodamo samo gride ki niso missingi if ($spr_gridi[$gid]['other'] == 0 || $spr_gridi[$gid]['other'] == 1) { $answer = '0'; # če je nastavljen missing so vsi gridi na podvprašanje enaki missingu if ($_missing_answer != NULL ) { $answer = $_missing_answer; } else if (isset($_tmp_answers[$vid][$gid])) { $answer = $_tmp_answers[$vid][$gid]; } $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id, $answer,$uid); } } # dodamo še odgovore other text if ($vrednost['other'] == 1) { if ($_missing_answer != null) { $answerOther = $_missing_answer; } else if (isset($spr_data_text[$vid]['text']) && $spr_data_text[$vid]['text'] !== '') { $answerOther = $spr_data_text[$vid]['text']; } else { if ($_anything_set == false) { if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answerOther = end($spr_data_vred); } else { $answerOther = $VALUE_FOR_MISSING; } } else { $answerOther = $VALUE_FOR_MISSING; } } # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } } // end foreach spr_vrednost } // end if count spr_vrednost break; # RANKING case 17: if (count($spr_vrednosti ) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { $answer = null; if (isset($spr_data_ranking[$vid])) { $answer = $spr_data_ranking[$vid]; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answer = end($spr_data_vred); } if ($answer == "" || $answer == null) { $answer = $VALUE_FOR_MISSING; } // end if # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); } // end foreach break; #VSOTA case 18: if (count($spr_vrednosti ) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { $answer = null; if (isset($spr_data_text[$vid]['text'])) { $answer = $spr_data_text[$vid]['text']; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answer = end($spr_data_vred); } if ($answer == "" || $answer == null) { $answer = $VALUE_FOR_MISSING; } // end if # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); } // end foreach break; # MULTITEXT case 19: # MULTINUMBER case 20: $answer = null; $_tmp_answers = array(); $_anything_set = array(); //$_missing_value = null; # missing je na celo variablo (old) $missing_value_temp = $VALUE_FOR_MISSING; # preverimo al mamo missing (-2 ali -4, ce je bila naknadno dodana) nad celo spremenljivko if (isset($spr_data_vred) && count($spr_data_vred) == 1) { $missing_value_temp = (is_array($spr_data_vred) && count($spr_data_vred) == 1 ) ? end($spr_data_vred) : $VALUE_FOR_MISSING; #Imamo missing // missingise po novem shranjujeo v srv_vrednost za celotno spremenljivko //$_missing_value = reset($spr_data_vred); (old) } $is_grid_missing = array(); # zloopamo skozi podvprašanja in nastavimo izbrane odgovore if (count($spr_vrednosti ) > 0) { foreach ($spr_vrednosti AS $vid => $vrednost) { if (count($spr_gridi) > 0) { foreach ($spr_gridi AS $gid => $grid) { # dodajamo samo odgovore ki so veljavni if ($grid['other'] == 0) { if (isset($spr_data_grid_text[$vid][$gid])) { # imamo veljaven odgovor $_tmp_answers[$vid][$gid] = $spr_data_grid_text[$vid][$gid]; $_anything_set[$vid] = true; } else if (isset($spr_data_grid[$vid])) { $_tmp_answers[$vid][$gid] = $spr_gridi[$spr_data_grid[$vid]]['other']; } else { $_tmp_answers[$vid][$gid] = $missing_value_temp; } } } } } } # dodamo odgovore if(count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { if(count($spr_gridi) > 0) foreach ($spr_gridi AS $gid => $grid) { if ($grid['other'] == 0) { # dodamo samo veljavne gride $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$_tmp_answers[$vid][$gid],$uid); } } # dodamo še odgovore other text if ($vrednost['other'] == 1) { # če mamo missing dodamo missing if (isset($is_grid_missing[$vid])) { $answerOther = $is_grid_missing[$vid]; } else if ($_anything_set[$vid]) { $answerOther = ($spr_data_text[$vid]['text'] == "" || $spr_data_text[$vid]['text'] == null) ? $missing_value_temp : $spr_data_text[$vid]['text']; } else { $answerOther = $missing_value_temp; } # dodamo odgvor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerOther,$uid); } } break; # BESEDILO * case 21: # zloopamo skozi podvprašanja in nastavimo izbrane odgovore if(count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { if ($vrednost['other'] == 0) { $answer = null; # imamo signature vprašanje if($spr_signature == 1){ if(isset($spr_data_text[$vid]['text'])) $answer = $spr_data_text[$vid]['text'] . ' '; if(@getimagesize($site_url.'main/survey/uploads/'.$rowUser['usr_id'].'_'.$spr_id.'_'.$this->sid.'.png')) $answer .= '('.$site_url.'main/survey/uploads/'.$rowUser['usr_id'].'_'.$spr_id.'_'.$this->sid.'.png)'; } else if (isset($spr_data_text[$vid]['text']) && $spr_signature != 1) { if ($spr_upload == 1 || $spr_upload == 2) { # imamo upload vprašanje # imena datotek $filename = substr($this->get_array_data_text_upload($spr_data_text[$vid]['text']),strlen($uid.'_')); $answer = ''.$site_url.'main/survey/download.php?anketa='.$this->sid.'&code='.$spr_data_text[$vid]['text'].''; } else { # imamo normalno text vprašanje $answer = $spr_data_text[$vid]['text']; } } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { #$answer = end($spr_data_vred); $key = key($spr_data_vred); if (isset($spr_data_vred[$key])) { $_vred = $spr_data_vred[$key]; } #pogledamo če je odgovor missing: if (isset($spr_vrednosti[$_vred])) { $answer = $spr_vrednosti[$_vred]['variable']; } else { $answer = $_vred; } } if ($answer == "" || $answer == null) { $answer = $VALUE_FOR_MISSING; } // end if $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); } } break; # Kalkulacija case 22: $_vred = null; $answer0 = null; # ce imamo odgovor if (isset ($spr_data_text[0]) && $spr_data_text[0]['text'] != '') { $answer0 = $spr_data_text[0]['text']; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answer0 = end($spr_data_vred); } $answer0 = ($answer0 == null ) ? $VALUE_FOR_MISSING : $answer0; # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer0,$uid); break; # Kvota case 25: $_vred = null; $answer0 = null; # ce imamo odgovor if (isset ($spr_data_text[0]) && $spr_data_text[0]['text'] != '') { $answer0 = $spr_data_text[0]['text']; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answer0 = end($spr_data_vred); } $answer0 = ($answer0 == null ) ? $VALUE_FOR_MISSING : $answer0; # dodamo odgovor $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer0,$uid); break; # SN - IMENA * case 9: # zloopamo skozi podvprašanja in nastavimo izbrane odgovore $arrayVrednost = $this->SNVariablesForSpr[$_vprasanje_array['id']]; if (!is_array($arrayVrednost)) { $arrayVrednost = array(); } if(count($spr_vrednosti) > 0) foreach ($spr_vrednosti AS $vid => $vrednost) { if (in_array($vid,$arrayVrednost)) { $answer = null; if (isset($spr_data_text[$vid]['text'])) { # imamo normalno text vprašanje $answer = $spr_data_text[$vid]['text']; } else if (is_array($spr_data_vred) && count($spr_data_vred) > 0 ) { $answer = end($spr_data_vred); } if ($answer == "" || $answer == null) { $answer = $VALUE_FOR_MISSING; } // end if $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); } } break; # Lokacija case 26: $row = Cache::srv_spremenljivka($spr_id); if($row['enota'] == 3){ if(count($spr_vrednosti) > 0){ # zloopamo skozi podvprašanja in nastavimo izbrane odgovore if (isset ($spr_data_map)) { if(empty($spr_data_map)){ //missingi, lahko da je -4 $missing_value_temp = (is_array($spr_data_vred) && count($spr_data_vred) == 1 ) ? end($spr_data_vred) : $VALUE_FOR_MISSING; for($i = 0; $i < count($spr_vrednosti); $i++){ $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$missing_value_temp,$uid); } } else{ $answerArr = (count($spr_data_map['izpis']) > 0) ? $spr_data_map['izpis'] : $VALUE_FOR_MISSING; if(count($spr_data_map) > 0) foreach ($spr_data_map['izpis'] AS $izpis) { $answer = null; if (isset($izpis['vrednost'])) { # imamo normalno text vprašanje $answer = $izpis['vrednost']; } if ($answer == "" || $answer == null) { $answer = $VALUE_FOR_MISSING; } // end if $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answer,$uid); } } } } } else{ $_vred = null; $answerArr = null; $answerAdd = null; $answerVre = null; $answerKoo = null; $newParams = new enkaParameters($row['params']); $is_podvprasanje = $newParams->get('marker_podvprasanje') == 1; //$podvprasanje_naslov = ''; $is_podvprasanje ? $podvprasanje_naslov = $newParams->get('naslov_podvprasanja_map') : $podvprasanje_naslov = ''; $multi_input_type = $newParams->get('multi_input_type'); # ce imamo odgovor if (isset ($spr_data_map)) { $missing_value_temp = (is_array($spr_data_vred) && count($spr_data_vred) == 1 ) ? end($spr_data_vred) : $VALUE_FOR_MISSING; $answerArr = (is_countable($spr_data_map['izpis']) && count($spr_data_map['izpis']) > 0) ? $spr_data_map['izpis'] : $missing_value_temp; } else if (is_array($spr_data_map)) { $key = key($spr_data_map); if (isset($spr_data_map[$key])) { $_vred = $spr_data_map[$key]; } #pogledamo če je odgovor missing: if (isset($spr_vrednosti[$_vred])) { $answerAdd = $spr_vrednosti[$_vred]['variable']; $answerVre = $spr_vrednosti[$_vred]['variable']; $answerKoo = $spr_vrednosti[$_vred]['variable']; } else { $answerAdd = $_vred; $answerVre = $_vred; $answerKoo = $_vred; } } if ($answerArr == null || $answerArr == $missing_value_temp){ $answerAdd = $answerVre = $answerKoo = $missing_value_temp; } elseif($answerArr[0]['address'] == '-2'){ $answerAdd = $answerVre = $answerKoo = '-2'; } else{ foreach($answerArr as $varArr){ if($answerKoo != null){ $answerAdd .= '
'.$varArr['address']; $answerVre .= '
'.$varArr['vrednost']; $answerKoo .= '
'.$varArr['koordinate']; } else{ $answerAdd = $varArr['address']; $answerVre = $varArr['vrednost']; $answerKoo = $varArr['koordinate']; } } //rabil prej, da so se linki izrisali - ce se bo rabilo, prestavi v SurveyDisplayData /*$answerAdd = ''.$answerAdd.''; $answerKoo = ''.$answerKoo.'';*/ } # dodamo odgovor if($multi_input_type == 'marker') $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerAdd,$uid); if($is_podvprasanje) $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerVre,$uid); $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerKoo,$uid); } break; # Heatmap case 27: $_vred = null; $answerArr = null; $answerAdd = null; $answerVre = null; $answerKoo = null; $row = Cache::srv_spremenljivka($spr_id); $newParams = new enkaParameters($row['params']); //echo ''; //echo ''; # ce imamo odgovor if (isset ($spr_data_heatmap)) { $answerArr = (is_countable($spr_data_heatmap['izpis']) && count($spr_data_heatmap['izpis']) > 0) ? $spr_data_heatmap['izpis'] : $VALUE_FOR_MISSING; } else if (is_array($spr_data_heatmap)) { $key = key($spr_data_heatmap); if (isset($spr_data_heatmap[$key])) { $_vred = $spr_data_heatmap[$key]; $_vred = $spr_data_heatmap[$key]; } #pogledamo če je odgovor missing: if (isset($spr_vrednosti[$_vred])) { $answerAdd = $spr_vrednosti[$_vred]['variable']; $answerVre = $spr_vrednosti[$_vred]['variable']; $answerKoo = $spr_vrednosti[$_vred]['variable']; } else { $answerAdd = $_vred; $answerVre = $_vred; $answerKoo = $_vred; } } if ($answerArr == null || $answerArr == $VALUE_FOR_MISSING){ $answerAdd = $answerVre = $answerKoo = $VALUE_FOR_MISSING; } elseif($answerArr[0]['address'] == '-2'){ $answerAdd = $answerVre = $answerKoo = '-2'; } else{ foreach($answerArr as $varArr){ $answerAdd .= '
'.$varArr['address']; $answerVre .= '
'.$varArr['vrednost']; $answerKoo .= '
'.$varArr['koordinate']; } } # dodamo odgovor za koordinate $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerKoo,$uid); //za območja if (is_array($spr_data_heatmap_regions)) { //priprava spremenljivk za koordinate točk $pointx = $this->preparePointCoords($answerKoo, 1, 0); $pointy = $this->preparePointCoords($answerKoo, 0, 1); $numberOfPointsInside=array(); if (count($spr_vrednosti) > 0) { $i=0; foreach ($this->_array_data_heatmap_regions[(int)$spr_id] AS $regions){ $answerReg = null; $numberOfPointsInside[$regions['region_name']] = 0; //belezi stevilo tock znotraj trenutnega obmocja $poly = $this->convertPolyString($regions['region_coords']); //pretvori polje s tockami obmocja v ustrezno obliko //preveri, ali je posamezna tocka znotraj trenutnega obmocja for ($z=0; $zinsidePoly($poly, $pointx[$z]["x"], $pointy[$z]["y"]); if ($inside == true){ $numberOfPointsInside[$regions['region_name']]++; } } //preveri, ali je posamezna tocka znotraj trenutnega obmocja - konec //priprava odgovora za preglednico s podatki if($answerKoo < 0) //ce je missing { $answerReg = $answerKoo; }else { $answerReg = $numberOfPointsInside[$regions['region_name']]; } $i++; # dodamo odgovor s stevilom tock znotraj obmocja $userAnswerLine .= STR_DLMT.$this->recode_answer($spr_id,$answerReg,$uid); } } } //za območja - konec break; } } // end while } // end if ($this->noErrors) // popravimo -1, -4 in -2d (text za drugo) => -3, začnemo odzadaj in spreminjamo -1, -4 in -2d v -3 dokler obstajajo ampak samo če status ni 6 $changed = false; if ((int)$rowUser['status'] !== 6 && !empty($userAnswerLine)) { # ugotovimo do katere spremenljivke sploh zamenjujemo vrednosti ker če je pri tabelah odgovor vsaj na 1 variablo, potem tam pustimo -1 $valuesToChange = $this->calculateValuesToChange($uid); $userAnswerLineArray = explode('|',$userAnswerLine); $reversed = array_reverse($userAnswerLineArray); foreach ($reversed AS $key => $value) { if ($key+1 > $valuesToChange) { break; } if ($value == -1 || $value == -4 || $value == '-2d') { $reversed[$key] = -3; $changed = true; } else { $reversed[$key] = $value; } } if ($changed) { $userAnswerLineArray = array_reverse($reversed); $userAnswerLine = (implode('|', $userAnswerLineArray)); } } // Popravimo -2d (text za drugo, ce je naknadno nastavljen na -2, ker ni bil oznacen radio/checkbox za drugo) $userAnswerLine = str_replace('-2d','-2',$userAnswerLine); // Naknadno popravimo se -2, ce je lurker (-5), ker nekatere drugace ostanejo if ($VALUE_FOR_MISSING == -5) { $userAnswerLine = str_replace('-2','-5',$userAnswerLine); } // dodamo podatke k userju $_dataLine .= $userAnswerLine; ############ # DODAMO META PODATKE if ($this->noErrors && $this->collect_full_meta) { // Random vrstni redi foreach ($this->_array_random as $random_parent) { $type = ($random_parent['type'] == 'spr') ? 'spr' : 'block'; $random_data = $this->get_array_data_random($uid, $random_parent['id'], $type); unset($this->_array_data_random[$uid][$type][$random_parent['id']]); $_dataLine .= STR_DLMT.$random_data; } # če mamo da prepozna uporabnika iz sispleta if ((int)$this->survey['user_from_cms'] > 0) { $_dataLine .= STR_DLMT; if ((int)$rowUser['user_id'] > 0) { $_dataLine .= $this->get_user_CMS_email((int)$rowUser['user_id']); } } # datum insert, datum edit $_dataLine .= STR_DLMT.datetime($rowUser['time_insert']); $_dataLine .= STR_DLMT.datetime($rowUser['time_edit']); # strani in časi foreach ($this->_array_groups AS $gid => $grupa) { if ($this->_array_user_grupa[$uid][$gid] != '') { $_dataLine .= STR_DLMT.datetime($this->_array_user_grupa[$uid][$gid]); } else { $_dataLine .= STR_DLMT.''; } } /* ZARADI VAROVANJA PODATKOV SMO ZAČASNO ONEMOGOČILI LOVLJENJE IP-jev */ $ip = SurveySetting::getInstance()->getSurveyMiscSetting('survey_ip'); $ip_show = SurveySetting::getInstance()->getSurveyMiscSetting('survey_show_ip'); if($ip==0 && $ip_show==1 && ($admin_type == 0 || $admin_type == 1)){ $_dataLine .= STR_DLMT.$rowUser['ip']; } $_dataLine .= STR_DLMT.$rowUser['javascript']; $_dataLine .= STR_DLMT.$rowUser['useragent']; $_dataLine .= STR_DLMT.$rowUser['browser']; $_dataLine .= STR_DLMT.$rowUser['os']; $_dataLine .= STR_DLMT.$lang['srv_para_graph_device'.$rowUser['device']]; $_dataLine .= STR_DLMT.$rowUser['referer']; $_dataLine .= STR_DLMT.$rowUser['unsubscribed']; $_dataLine .= STR_DLMT.$jeziki[$rowUser['language']]; } // Pocistimo vrednosti, ker drugace v nekaterih primereih prihaja do zelo cudnih bugov unset($rowVprasanje); unset($spr_vrednosti); unset($spr_gridi); #zapišemo vsako vrstico posebej if ($this->noErrors && !empty($_dataLine)) { # zapišemo vrstico z predhodnim vrivom nove vrstice $success = fwrite($file_handler, $this->new_line_seperator . $_dataLine); fflush($file_handler); if ((int)$success > 0) { $this->last_usr_time = max($this->last_usr_time,$rowUser['unx_ins_date'],$rowUser['unx_edt_date']); } else { # imamo napako vse skupaj prekinemo $this->noErrors = false; } $_dataLine = null; unset($_dataLine); } else { # dodamo v log napako $SL = new SurveyLog(); $SL->addMessage(SurveyLog::ERROR, " ERROR user ".$rowUser['usr_id']." for ank_id".$this->sid); $SL->write(); } $this->new_line_seperator = NEW_LINE; } // end while user loop } // end if ($this->noErrors) # za progressbar dodamo števec (samo ko nismo v masovnem) if ($this->isCollectingMassive == false) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['current'] = $_tmpCnt; session_commit(); } } /** zgeneriramo order string za userje (recorde) */ private function getRecOrderString($isStatus = null) { // samo če imamo polje isStatus = status vrnemo Order za st.status čene vrnemo u. //$orderStr = " ORDER BY u.recnum ASC"; $orderStr = " ORDER BY u.id ASC"; return $orderStr; } /** isNotAnswerMissing() * @desc vrne true če odgovor NI manjkajoča vrednost * * @return boolean */ private function isNotAnswerMissing($answer) { if ($answer == -1 || $answer == -2 || $answer == -3 || $answer == -4 || $answer == -96 || $answer == -97 || $answer == -98 || $answer == -99 ) { return true; } else { return false; } } /** * @desc vrne qry z vsemi stranmi * ko prvič pokličemo naredimo query */ private function get_qry_groups () { if ($this->_qry_groups === null ) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 2; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); $str_qry_groups = "SELECT id FROM srv_grupa WHERE ank_id='".$this->sid."' ORDER BY vrstni_red"; $this->_qry_groups = sisplet_query($str_qry_groups); if (!$this->_qry_groups) { $this->trigerError('get_qry_groups', 'MYSQL ERROR in qry: '.$str_qry_groups . " ".mysqli_error($GLOBALS['connect_db'])); } # koliko zapicov $this->_cnt_groups = mysqli_num_rows($this->_qry_groups); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $this->_cnt_groups; session_commit(); #naredimo še string z id grupami za večkratno uporabo $str = ''; $cnt=0; if ($this->_cnt_groups > 0) { $this->_array_groups = array(); $prefix =''; while ($row = mysqli_fetch_assoc($this->_qry_groups)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_groups[$row['id']] = $row['id']; $str.=$prefix.$row['id']; $prefix = ','; } $this->_str_groups = $str; } } if ($this->_cnt_groups > 0) { mysqli_data_seek($this->_qry_groups, 0); } return $this->_qry_groups; } /** * @desc vrne qry z vsemi spremenljivkami (vprašanji) * ko prvič pokličemo naredimo query */ private function create_qry_questions () { if ($this->_qry_questions === null) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 1; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); //po novem lovimo tudi sistemske pa jih odstranimo pri prikazu in izvozih $str_qry_questions = "SELECT s.id, s.tip, s.variable, REPLACE(REPLACE(REPLACE(s.naslov,'\n',' '),'\r','
'),'|','
') as naslov, s.label, s.gru_id, s.gru_id, s.random, s.size, s.cela, s.decimalna, s.skala, s.enota, s.sistem, s.upload, s.signature, s.grid_subtitle1, s.grid_subtitle2, s.inline_edit, REPLACE(REPLACE(REPLACE(s.naslov_graf,'\n',' '),'\r','
'),'|','
') as naslov_graf, s.edit_graf, s.wide_graf, antonucci, s.visible, s.dostop FROM srv_spremenljivka AS s, srv_grupa AS g WHERE s.gru_id = g.id AND g.ank_id = '".$this->sid."' AND s.tip != '5' ORDER BY g.vrstni_red, s.vrstni_red"; $this->_qry_questions = sisplet_query($str_qry_questions); if (!$this->_qry_questions) { $this->trigerError('create_qry_questions', 'MYSQL ERROR in qry: '.$str_qry_questions . " ".mysqli_error($GLOBALS['connect_db'])); } $this->_cnt_questions = mysqli_num_rows($this->_qry_questions); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $this->_cnt_questions; session_commit(); #naredimo še string z id spremenljivkami za večkratno uporabo $str = ''; $cnt=0; if ($this->_cnt_questions > 0) { $sprIds = array(); while ($row = mysqli_fetch_assoc($this->_qry_questions)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); if ($row['tip'] != 24) { $sprIds[] = $row['id']; } else { $sqlSub = sisplet_query("SELECT s.id FROM srv_spremenljivka AS s JOIN srv_grid_multiple AS sgm ON (s.id = sgm.spr_id) WHERE sgm.parent = '$row[id]' ORDER BY sgm.vrstni_red"); while (list($subSprId) = mysqli_fetch_row($sqlSub)) { $sprIds[] = $subSprId; } } } if (count($sprIds) > 0) { $this->_str_questions = implode(',',$sprIds); } } } } /** * @desc vrne qry z vsemi userji * ko prvič pokličemo naredimo query */ private function create_qry_users() { if ($this->_qry_users === null ) { if ((int)$this->data_file_time > 0 && file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { # delamo inkremental $inkremental_user_limit = " AND u.time_edit > FROM_UNIXTIME('".(int)$this->data_file_time."') "; } else { # lovimo vse userje - datoteko generiramo na novo $inkremental_user_limit = ''; } $str_qry_cnt = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$inkremental_user_limit .$this->is_valid_user_limit; $_qry_cnt = sisplet_query($str_qry_cnt); $_allUsers_count = mysqli_fetch_row($_qry_cnt); $this->_cnt_all_users = 0; $c = 0; # naredimo array querijev za userje, limitirano po max vrednosti userjev na loop (MAX_USER_PER_LOOP) do { # če ne lovimo meta nardimo manjši query if ($this->collect_full_meta) { $str_qry = "SELECT u.id AS usr_id, u.cookie, u.recnum, u.last_status as status, u.pass, u.testdata, u.lurker, u.unsubscribed, UNIX_TIMESTAMP(u.time_insert) AS unx_ins_date, UNIX_TIMESTAMP(u.time_edit) AS unx_edt_date, u.user_id, u.inv_res_id". ", u.time_insert, u.time_edit, u.ip, u.javascript, REPLACE(u.useragent,'|',' ') as useragent, u.browser, u.os, u.device, REPLACE(u.referer,'|',' ') as referer, language FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$inkremental_user_limit.$this->is_valid_user_limit.$this->getRecOrderString().' LIMIT '.($c * MAX_USER_PER_LOOP).','.MAX_USER_PER_LOOP; } else { $str_qry = "SELECT u.id AS usr_id, u.cookie, u.recnum, u.last_status as status, u.testdata, u.lurker, u.unsubscribed, UNIX_TIMESTAMP(u.time_insert) AS unx_ins_date, UNIX_TIMESTAMP(u.time_edit) AS unx_edt_date, u.user_id, u.inv_res_id FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$inkremental_user_limit.$this->is_valid_user_limit.$this->getRecOrderString().' LIMIT '.($c * MAX_USER_PER_LOOP).','.MAX_USER_PER_LOOP; } $this->_qry_users[$c] = sisplet_query($str_qry); if (!$this->_qry_users[$c]) { $this->trigerError('create_qry_users', 'MYSQL ERROR in qry: '.$str_qry . " ".mysqli_error($GLOBALS['connect_db'])); } #naredimo še string z id userjev za večkratno uporabo $str = ''; if (mysqli_num_rows($this->_qry_users[$c]) > 0) { $prefix =''; while ($row = mysqli_fetch_assoc($this->_qry_users[$c])) { $str.=$prefix.$row['usr_id']; $prefix = ','; } $this->_str_users[$c] = ' AND usr_id IN ('.$str.') '; } $this->_cnt_all_users += mysqli_num_rows($this->_qry_users[$c]); $c ++; } while ($c * MAX_USER_PER_LOOP <= $_allUsers_count['0']); } session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['total'] = $this->_cnt_all_users; session_commit(); } /** Skreiramo pointer do arraya z vrednostmi */ private function create_array_vrednosti() { # ce ne ce obstaja qry if ($this->_qry_vrednosti !== null) { return $this->_qry_vrednosti; } else { if ($this->_str_questions != '') { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 4; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); $str_qry = "SELECT id, spr_id, REPLACE(REPLACE(REPLACE(naslov,'\n',' '),'\r','
'),'|',' ') as naslov, REPLACE(REPLACE(REPLACE(naslov2,'\n',' '),'\r','
'),'|',' ') as naslov2, variable, vrstni_red, other, REPLACE(REPLACE(REPLACE(naslov_graf,'\n',' '),'\r','
'),'|',' ') as naslov_graf FROM srv_vrednost WHERE spr_id IN (".$this->_str_questions.") order by spr_id, vrstni_red"; //$str_qry = "SELECT id, spr_id, REPLACE(REPLACE(REPLACE(naslov,'\n',' '),'\r','
'),'|',' ') as naslov, variable, vrstni_red, other FROM srv_vrednost WHERE spr_id IN (".$this->_str_questions.") order by spr_id, vrstni_red"; $this->_qry_vrednosti = sisplet_query($str_qry); if (!$this->_qry_vrednosti) { $this->trigerError('create_array_vrednosti', 'MYSQL ERROR in qry: '.$str_qry . " ".mysqli_error($GLOBALS['connect_db'])); } $this->_cnt_vrednosti = mysqli_num_rows($this->_qry_vrednosti); } } } /** * @desc vrne array z vrednostm za posamezno spremenljivko (spr_id) * ko prvič pokličemo naredimo query in napolnimo array */ public function get_array_vrednosti($spid=null) { if ($spid != null && (int)$spid > 0 ) { # če že imamo podatek in iščemo za posamezno spremenljivko if (isset($this->_array_vrednosti[$spid])) return $this->_array_vrednosti[$spid]; } else { # vrenmo celoten array if ($this->_array_vrednosti !== null) { return $this->_array_vrednosti; } } # ce ne ce obstaja qry if ($this->_qry_vrednosti === null) { $this->create_array_vrednosti(); } session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 4; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $this->_cnt_vrednosti; session_commit(); $cnt=0; if ($this->_cnt_vrednosti > 0) { mysqli_data_seek($this->_qry_vrednosti, 0); while ( list($id, $spr_id, $naslov, $naslov2, $variable, $vrstni_red, $other, $naslov_graf) = mysqli_fetch_row($this->_qry_vrednosti)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_vrednosti[(int)$spr_id][(int)$id] = array('id'=>(int)$id, 'naslov'=>strip_tags($naslov), 'naslov2'=>strip_tags($naslov2), 'variable'=>$variable, 'vrstni_red'=>(int)$vrstni_red, 'other'=>(int)$other, 'naslov_graf'=>strip_tags($naslov_graf) ); } } if ($spid != null && (int)$spid > 0 ) { return $this->_array_vrednosti[$spid]; } else { return $this->_array_vrednosti; } } /** Skreiramo pointer do arraya z gridi */ private function create_array_gridi() { # ce ne ce obstaja qry if ($this->_qry_gridi !== null) { return $this->_qry_gridi; } else { if ($this->_str_questions != '') { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 5; $_SESSION['incrementalProgressBar'][$this->sid]['ha'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hc'] = 0; session_commit(); $str_qry = "SELECT id, spr_id, REPLACE(REPLACE(REPLACE(naslov,'\n',' '),'\r','
'),'|',' ') as naslov, variable, other, part, REPLACE(REPLACE(REPLACE(naslov_graf,'\n',' '),'\r','
'),'|',' ') as naslov_graf, vrstni_red FROM srv_grid WHERE spr_id IN (".$this->_str_questions.") ORDER BY spr_id, vrstni_red"; //$str_qry = "SELECT id, spr_id, REPLACE(REPLACE(REPLACE(naslov,'\n',' '),'\r','
'),'|',' ') as naslov, variable, other, part, vrstni_red FROM srv_grid WHERE spr_id IN (".$this->_str_questions.") ORDER BY spr_id, vrstni_red"; $this->_qry_gridi = sisplet_query($str_qry); if (!$this->_qry_gridi) { $this->trigerError('create_array_gridi', 'MYSQL ERROR in qry: '.$str_qry . " ".mysqli_error($GLOBALS['connect_db'])); } $this->_cnt_gridi = mysqli_num_rows($this->_qry_gridi); } } } /** * @desc vrne array z vrednostm za posamezno spremenljivko (spr_id) * ko prvič pokličemo naredimo query in napolnimo array */ private function get_array_gridi($grid=null) { if ($grid != null && (int)$grid > 0 ) { # če že imamo podatek in iščemo za posamezno spremenljivko if (isset($this->_array_gridi[$grid])) return $this->_array_gridi[$grid]; } else { # vrenmo celoten array if ($this->_array_gridi !== null) { return $this->_array_gridi; } } # ce ne ce obstaja qry if ($this->_qry_gridi === null) { $this->create_array_gridi(); } session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $this->_cnt_gridi; session_commit(); $cnt=0; if ($this->_cnt_gridi > 0) { mysqli_data_seek($this->_qry_gridi, 0); while ( list($id, $spr_id, $naslov, $variable, $other, $part, $naslov_graf) = mysqli_fetch_row($this->_qry_gridi)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_gridi[(int)$spr_id][(int)$id] = array('id'=>(int)$id, 'naslov'=>strip_tags($naslov), 'variable'=>$variable, 'other'=>(int)$other, 'part'=>(int)$part, 'naslov_graf'=>strip_tags($naslov_graf)); } } if ($grid != null && (int)$grid > 0 ) { return $this->_array_gridi[$grid]; } else { return $this->_array_gridi; } } /** * @desc vrne id strani do katere je prišel uporabnik * */ private function create_array_user_grupa($string_user) { if ($this->_str_groups != '') { $qry_string = 'SELECT gru_id, usr_id, time_edit, preskocena FROM srv_user_grupa'.$this->db_table.' WHERE gru_id IN ('.$this->_str_groups.')'.$string_user; $qry = sisplet_query($qry_string); if (!$qry) { $this->trigerError('create_array_user_grupa', 'MYSQL ERROR in qry: '.$qry_string . " ".mysqli_error($GLOBALS['connect_db'])); } $this->_array_user_grupa = array(); while ($row = mysqli_fetch_assoc($qry)) { $this->_array_user_grupa[(int)$row['usr_id']][(int)$row['gru_id']] = $row['time_edit']; } } } private function create_array_SPSS() { if ($this->_array_SPSS === null) { if ($this->_str_questions != '') { //$str_query = 'SELECT spr_id, max(LENGTH(text)) AS length, max(LENGTH(text2)) AS length2 FROM srv_data_text'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.') GROUP BY spr_id'; $str_query = 'SELECT dt.spr_id, MAX(LENGTH(dt.text)) AS length, MAX(LENGTH(dt.text2)) AS length2 FROM srv_data_text'.$this->db_table.' dt, srv_grupa g, srv_spremenljivka s WHERE dt.spr_id = s.id AND s.gru_id=g.id AND g.ank_id='.$this->sid.' GROUP BY dt.spr_id'; $_qry_SPSS = sisplet_query($str_query); $str_query = 'SELECT spr_id, max(LENGTH(text)) AS length FROM srv_data_textgrid'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.') GROUP BY spr_id'; $_qry_SPSS1 = sisplet_query($str_query); # polovimo še max vrednosti za variable $str_query = 'SELECT spr_id, max(LENGTH(vrstni_red)) AS length FROM srv_vrednost WHERE spr_id IN ('.$this->_str_questions.') GROUP BY spr_id order by spr_id, vrstni_red'; $tmp_qry_SPSS = sisplet_query($str_query); $this->_array_SPSS = array(); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 6; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = (int)mysqli_num_rows($_qry_SPSS)+(int)mysqli_num_rows($_qry_SPSS1)+(int)mysqli_num_rows($tmp_qry_SPSS); session_commit(); $cnt=0; while (list($spr_id,$text,$text2) = mysqli_fetch_row($_qry_SPSS)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_SPSS[$spr_id] = array('text'=>(int)$text, 'text2'=>(int)$text2); } while (list($spr_id,$text) = mysqli_fetch_row($_qry_SPSS1)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); #$this->_array_SPSS[$spr_id]['text2'] = ((int)$text < $this->MISSING_MAX_LENGTH ? $this->MISSING_MAX_LENGTH :$text); $this->_array_SPSS[$spr_id]['text2'] = $text; } # polovimo še max vrednosti za variable while (list($spr_id,$vrstni_red) = mysqli_fetch_row($tmp_qry_SPSS)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); #$this->_array_SPSS[$spr_id]['vrednost'] = ((int)$vrstni_red < $this->MISSING_MAX_LENGTH ? $this->MISSING_MAX_LENGTH : $vrstni_red); $this->_array_SPSS[$spr_id]['vrednost'] = $vrstni_red; } } } return $this->_array_SPSS; } /** * @desc vrne array z vsemi bloki in vprasanji, ki imajo vklopljeno randomizacijo * ko prvič pokličemo naredimo query */ private function get_array_random () { # ce smo ze zakesirali vrednosti if ($this->_array_random_cached) { return $this->_array_random; } $this->_array_random = array(); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 2; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); // Preberemo vsa VPRASANJA ki imajo vklopljeno randomizacijo $str_qry_random_spr = "SELECT s.id, s.variable FROM srv_spremenljivka s, srv_grupa g WHERE g.ank_id='".$this->sid."' AND s.gru_id=g.id AND s.random='1' ORDER BY s.vrstni_red"; $_qry_random_spr = sisplet_query($str_qry_random_spr); if (!$_qry_random_spr) { $this->trigerError('get_array_random', 'MYSQL ERROR in qry: '.$str_qry_random_spr . " ".mysqli_error($GLOBALS['connect_db'])); } # koliko zapicov $cnt_rows = mysqli_num_rows($_qry_random_spr); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $cnt_rows; session_commit(); // Napolnimo array z randomiziranimi vprasanji $cnt = 0; if ($cnt_rows > 0) { while ($row = mysqli_fetch_array($_qry_random_spr)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_random[$row['id']]['id'] = $row['id']; $this->_array_random[$row['id']]['variable'] = $row['variable']; $this->_array_random[$row['id']]['type'] = 'spr'; } } session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 2; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); // Preberemo vse BLOKE ki imajo vklopljeno randomizacijo $str_qry_random_blok = "SELECT i.id, i.random, i.label, i.number FROM srv_if i, srv_branching b WHERE b.ank_id='".$this->sid."' AND b.element_if=i.id AND (i.random>=0 OR i.random=-2) AND i.tip='1'"; $_qry_random_blok = sisplet_query($str_qry_random_blok); if (!$_qry_random_blok) { $this->trigerError('get_array_random', 'MYSQL ERROR in qry: '.$str_qry_random_blok . " ".mysqli_error($GLOBALS['connect_db'])); } # koliko zapicov $cnt_rows = mysqli_num_rows($_qry_random_blok); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = $cnt; session_commit(); // Napolnimo array z randomiziranimi bloki $cnt = 0; if ($cnt_rows > 0) { while ($row = mysqli_fetch_array($_qry_random_blok)) { $cnt++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cnt; session_commit(); $this->_array_random[$row['id']]['id'] = $row['id']; $this->_array_random[$row['id']]['variable'] = $row['label']; $this->_array_random[$row['id']]['number'] = $row['number']; // Blok ima randomizirane bloke if($row['random'] == -2){ $this->_array_random[$row['id']]['type'] = 'blok_blok'; } // Blok ima randomizirana vprasanja else{ $this->_array_random[$row['id']]['type'] = 'blok_spr'; } } } // Oznacimo da smo izvedli kesiranje $this->_array_random_cached = true; return $this->_array_random; } # FUNKCIJE ZA PODATKE /** srv_data_vrednost * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_vrednost ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); //$str_query = 'SELECT spr_id, vre_id, usr_id FROM srv_data_vrednost'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.') '.$string_user; $str_query = 'SELECT spr_id, vre_id, usr_id, loop_id FROM srv_data_vrednost'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.')' . $string_user; $this->_qry_data_vrednost = sisplet_query($str_query); if (!$this->_qry_data_vrednost) { $this->trigerError('create_array_data_vrednost', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_vrednost * srv_data_vrednost * @param $uid * @param $spr_id */ private function get_array_data_vrednost ($uid, $spid) { if (isset($this->_array_data_vrednost[$uid][$spid])) { return $this->_array_data_vrednost[$uid][$spid]; } if ($this->_array_data_vrednost === null) { if ($this->_qry_data_vrednost === null) { return array(); } if (mysqli_num_rows($this->_qry_data_vrednost)) { mysqli_data_seek($this->_qry_data_vrednost, 0); while ( list($spr_id, $vre_id, $usr_id,$loop_id) = mysqli_fetch_row($this->_qry_data_vrednost)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_vrednost[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id] = (int)$vre_id; } } if (isset($this->_array_data_vrednost[$uid][$spid])) { return $this->_array_data_vrednost[$uid][$spid]; } else { return array(); } } else { return array(); } } /** srv_data_text * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_text ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); //$str_query = "SELECT spr_id, vre_id, usr_id, REPLACE(text,'\n',' ') as text, REPLACE(text2,'\n',' ') as text2 FROM srv_data_text".$this->db_table." WHERE spr_id IN (".$this->_str_questions.")".$string_user; $str_query = "SELECT spr_id, vre_id, usr_id, REPLACE(REPLACE(REPLACE(text,'\n',' '),'\r',' '),'|',' ') as text, REPLACE(REPLACE(REPLACE(text2,'\n',' '),'\r',' '),'|',' ') as text2, loop_id FROM srv_data_text".$this->db_table." WHERE spr_id IN (".$this->_str_questions.') ' //'AND usr_id BETWEEN '.substr($string_user, strpos($string_user, '(')+1, strpos($string_user, ',')-strpos($string_user, '(')-1)." AND ".substr($string_user, strrpos($string_user, ',')+1, strrpos($string_user, ')')-strrpos($string_user, ',')-1); .$string_user; $this->_qry_data_text = sisplet_query($str_query); if (!$this->_qry_data_text) { $this->trigerError('create_array_data_text', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_text * * @param $uid * @param $spr_id */ private function get_array_data_text ($uid, $spid) { if (isset($this->_array_data_text[$uid][$spid])) { return $this->_array_data_text[$uid][$spid]; } if ($this->_array_data_text === null ) { if ($this->_qry_data_text === null) { return array(); } if (mysqli_num_rows($this->_qry_data_text)) { mysqli_data_seek($this->_qry_data_text, 0); while ( list($spr_id, $vre_id, $usr_id, $text, $text2, $loop_id) = mysqli_fetch_row($this->_qry_data_text)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; # adslashes je potreben za analize $this->_array_data_text[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id] = array('text'=>trim(addslashes(strip_tags($text))), 'text2'=>trim(addslashes(strip_tags($text2)))); } } if (isset($this->_array_data_text[$uid][$spid])) { return $this->_array_data_text[$uid][$spid]; } else { return array(); } } else { return array(); } } /** srv_data_map * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_map ($string_user) { // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['26']) && $this->_cnt_questions_types['26'] > 0)) return; if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); //$str_query = "SELECT spr_id, vre_id, usr_id, REPLACE(text,'\n',' ') as text, REPLACE(text2,'\n',' ') as text2 FROM srv_data_text".$this->db_table." WHERE spr_id IN (".$this->_str_questions.")".$string_user; $str_query = "SELECT spr_id, usr_id, REPLACE(REPLACE(REPLACE(address,'\n',' '),'\r',' '),'|',' ') as address, " . "REPLACE(REPLACE(REPLACE(text,'\n',' '),'\r',' '),'|',' ') as text, lat, lng, " . "loop_id FROM srv_data_map WHERE spr_id IN (".$this->_str_questions.') ' //'AND usr_id BETWEEN '.substr($string_user, strpos($string_user, '(')+1, strpos($string_user, ',')-strpos($string_user, '(')-1)." AND ".substr($string_user, strrpos($string_user, ',')+1, strrpos($string_user, ')')-strrpos($string_user, ',')-1); .$string_user; $this->_qry_data_map = sisplet_query($str_query); if (!$this->_qry_data_map) { $this->trigerError('create_array_data_map', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** srv_data_heatmap * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_heatmap ($string_user) { // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['27']) && $this->_cnt_questions_types['27'] > 0)) return; if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); //$str_query = "SELECT spr_id, vre_id, usr_id, REPLACE(text,'\n',' ') as text, REPLACE(text2,'\n',' ') as text2 FROM srv_data_text".$this->db_table." WHERE spr_id IN (".$this->_str_questions.")".$string_user; $str_query = "SELECT spr_id, usr_id, REPLACE(REPLACE(REPLACE(address,'\n',' '),'\r',' '),'|',' ') as address, " . "REPLACE(REPLACE(REPLACE(text,'\n',' '),'\r',' '),'|',' ') as text, lat, lng, " . "loop_id FROM srv_data_heatmap WHERE spr_id IN (".$this->_str_questions.') ' //'AND usr_id BETWEEN '.substr($string_user, strpos($string_user, '(')+1, strpos($string_user, ',')-strpos($string_user, '(')-1)." AND ".substr($string_user, strrpos($string_user, ',')+1, strrpos($string_user, ')')-strrpos($string_user, ',')-1); .$string_user; $this->_qry_data_heatmap = sisplet_query($str_query); if (!$this->_qry_data_heatmap) { $this->trigerError('create_array_data_heatmap', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } private function create_array_data_heatmap_regions ($string_user) { // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['27']) && $this->_cnt_questions_types['27'] > 0)) return; if ($this->_str_questions != '') { /* $str_query_regions = "SELECT id, vre_id, spr_id, region_name, region_coords FROM srv_hotspot_regions WHERE spr_id =".$this->_str_questions.' '; echo ''; $this->_qry_data_heatmap_regions = sisplet_query($str_query_regions); */ $spremenljivke_id = explode(",", $this->_str_questions); $this->_qry_data_heatmap_regions = array(); //polje s SQL stavki foreach ($spremenljivke_id AS $val) { //echo ''; $str_query_regions = "SELECT id, vre_id, spr_id, region_name, region_coords FROM srv_hotspot_regions WHERE spr_id =".$val.' '; array_push($this->_qry_data_heatmap_regions, $str_query_regions); } /* foreach ($this->_qry_data_heatmap_regions AS $query){ echo ''; } */ } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_map * * @param $uid * @param $spr_id */ private function get_array_data_map ($uid, $spid) { if (isset($this->_array_data_map[$uid][$spid])) { return $this->_array_data_map[$uid][$spid]; } // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['26']) && $this->_cnt_questions_types['26'] > 0)) return array(); if ($this->_array_data_map === null ) { if ($this->_qry_data_map === null) { return array(); } $i=0; if (mysqli_num_rows($this->_qry_data_map)) { mysqli_data_seek($this->_qry_data_map, 0); while ( list($spr_id, $usr_id, $address, $text, $lat, $lng, $loop_id) = mysqli_fetch_row($this->_qry_data_map)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; //ce respondent ni vnesel vrednosti v infowindow if($text == '' || $text == null) $text = '-1'; # adslashes je potreben za analize if($this->_array_data_map[(int)$usr_id][$spr_id.'_'.$loop_id]){ $this->_array_data_map[(int)$usr_id][$spr_id.'_'.$loop_id]['izpis'][$i] = array('address'=>addslashes(strip_tags($address)), 'vrednost'=>addslashes(strip_tags($text)), 'koordinate'=> $lat . ', ' . $lng); /*$this->_array_data_map[(int)$usr_id][$spr_id.'_'.$loop_id]['map_data'][$i] = array('address'=>addslashes(strip_tags($address)), 'text'=> $text ? addslashes(strip_tags($text)) : '', 'lat'=>$lat, 'lng'=> $lng);*/ } else{ $this->_array_data_map[(int)$usr_id][$spr_id.'_'.$loop_id] = array('izpis'=>array(array('address'=>addslashes(strip_tags($address)), 'vrednost'=>addslashes(strip_tags($text)), 'koordinate'=>$lat . ', ' . $lng)), 'spr_id' => $spr_id, 'usr_id' => $usr_id, 'loop_id' => $loop_id/* 'map_data'=> array(array('address'=>addslashes(strip_tags($address)), 'text'=> $text ? addslashes(strip_tags($text)) : '', 'lat'=>$lat, 'lng'=> $lng))*/); } $i++; } } if (isset($this->_array_data_map[$uid][$spid])) { return $this->_array_data_map[$uid][$spid]; } else { return array(); } } else { return array(); } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_heatmap * * @param $uid * @param $spr_id */ private function get_array_data_heatmap ($uid, $spid) { if (isset($this->_array_data_heatmap[$uid][$spid])) { return $this->_array_data_heatmap[$uid][$spid]; } // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['27']) && $this->_cnt_questions_types['27'] > 0)) return array(); if ($this->_array_data_heatmap === null ) { if ($this->_qry_data_heatmap === null) { return array(); } $i=0; if (mysqli_num_rows($this->_qry_data_heatmap)) { mysqli_data_seek($this->_qry_data_heatmap, 0); while ( list($spr_id, $usr_id, $address, $text, $lat, $lng, $loop_id) = mysqli_fetch_row($this->_qry_data_heatmap)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; //ce respondent ni vnesel vrednosti v infowindow if($text == '' || $text == null) $text = '-1'; # adslashes je potreben za analize if($this->_array_data_heatmap[(int)$usr_id][$spr_id.'_'.$loop_id]){ $this->_array_data_heatmap[(int)$usr_id][$spr_id.'_'.$loop_id]['izpis'][$i] = array('address'=>addslashes(strip_tags($address)), 'vrednost'=>addslashes(strip_tags($text)), 'koordinate'=> $lat . ', ' . $lng); /*$this->_array_data_map[(int)$usr_id][$spr_id.'_'.$loop_id]['map_data'][$i] = array('address'=>addslashes(strip_tags($address)), 'text'=> $text ? addslashes(strip_tags($text)) : '', 'lat'=>$lat, 'lng'=> $lng);*/ } else{ $this->_array_data_heatmap[(int)$usr_id][$spr_id.'_'.$loop_id] = array('izpis'=>array(array('address'=>addslashes(strip_tags($address)), 'vrednost'=>addslashes(strip_tags($text)), 'koordinate'=>$lat . ', ' . $lng)), 'spr_id' => $spr_id, 'usr_id' => $usr_id, 'loop_id' => $loop_id/* 'map_data'=> array(array('address'=>addslashes(strip_tags($address)), 'text'=> $text ? addslashes(strip_tags($text)) : '', 'lat'=>$lat, 'lng'=> $lng))*/); } $i++; } } if (isset($this->_array_data_heatmap[$uid][$spid])) { return $this->_array_data_heatmap[$uid][$spid]; } else { return array(); } } else { return array(); } } private function get_array_data_heatmap_regions ($uid, $spid) { if (isset($this->_array_data_heatmap_regions[$uid][$spid])) { return $this->_array_data_heatmap_regions[$uid][$spid]; } // Ce ni nobenega vprasanja tega tipa v anketi, ne rabimo tega izvajat if(!(isset($this->_cnt_questions_types['27']) && $this->_cnt_questions_types['27'] > 0)) return array(); if ($this->_array_data_heatmap_regions[$uid][$spid] === null) { foreach($this->_qry_data_heatmap_regions as $query){ //echo ''; $regionsQuery = sisplet_query($query); if ($regionsQuery === null) { # napaka return array(); } //echo ''; $i=0; if (mysqli_num_rows($regionsQuery)) { //mysqli_data_seek($this->_qry_data_heatmap_regions, 0); while ( list($region_id, $vre_id, $spr_id, $region_name, $region_coords) = mysqli_fetch_row($regionsQuery) ) { # adslashes je potreben za analize $this->_array_data_heatmap_regions[(int)$spr_id][$i] = array('region_name'=>addslashes(strip_tags($region_name)), 'region_coords'=>$region_coords); $i++; } } } if (isset($this->_array_data_heatmap_regions[(int)$spr_id])) { return $this->_array_data_heatmap_regions[(int)$spr_id]; } else { return array(); } } else { return array(); } } /** srv__data_vrednost_cond * @desc vrne array z vrednostmi kateri imajo -2 za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_vrednost_cond ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = "SELECT spr_id, vre_id, usr_id, text, loop_id FROM srv_data_vrednost_cond WHERE spr_id IN (".$this->_str_questions.') ' .$string_user; $this->_qry_data_vrednost_cond = sisplet_query($str_query); if (!$this->_qry_data_vrednost_cond) { $this->trigerError('create_array_data_vrednost_cond', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_vrednost_cond * * @param $uid * @param $spr_id */ private function get_array_data_vrednost_cond ($uid, $spid) { if (isset($this->_array_data_vrednost_cond[$uid][$spid])) { return $this->_array_data_vrednost_cond[$uid][$spid]; } if ($this->_array_data_vrednost_cond === null ) { if ($this->_qry_data_vrednost_cond === null) { # napaka return array(); } if (mysqli_num_rows($this->_qry_data_vrednost_cond)) { mysqli_data_seek($this->_qry_data_vrednost_cond, 0); while ( list($spr_id, $vre_id, $usr_id, $text, $loop_id) = mysqli_fetch_row($this->_qry_data_vrednost_cond)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; # adslashes je potreben za analize $this->_array_data_vrednost_cond[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id] = addslashes(strip_tags($text)); } } if (isset($this->_array_data_vrednost_cond[$uid][$spid])) { return $this->_array_data_vrednost_cond[$uid][$spid]; } else { return array(); } } else { return array(); } } /** srv_data_grid (active) * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_grids ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); //$str_query = 'SELECT spr_id, vre_id, usr_id, grd_id FROM srv_data_grid'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.') '.$string_user; $str_query = 'SELECT spr_id, vre_id, usr_id, grd_id, loop_id FROM srv_data_grid'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.')'.$string_user; //' AND usr_id BETWEEN '.substr($string_user, strpos($string_user, '(')+1, strpos($string_user, ',')-strpos($string_user, '(')-1)." AND ".substr($string_user, strrpos($string_user, ',')+1, strrpos($string_user, ')')-strrpos($string_user, ',')-1); $this->_qry_data_grids = sisplet_query($str_query); if (!$this->_qry_data_grids) { $this->trigerError('create_array_data_grids', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_grids * * @param $uid * @param $spr_id */ private function get_array_data_grids ($uid, $spid) { if (isset($this->_array_data_grids[$uid][$spid])) { return $this->_array_data_grids[$uid][$spid]; } if ($this->_array_data_grids === null) { if ($this->_qry_data_grids === null) { # napaka return array(); } if (mysqli_num_rows($this->_qry_data_grids)) { mysqli_data_seek($this->_qry_data_grids, 0); while (list($spr_id, $vre_id, $usr_id, $grd_id, $loop_id)= mysqli_fetch_row($this->_qry_data_grids)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_grids[(int)$usr_id][$spr_id.'_'.$loop_id ][(int)$vre_id] = (int)$grd_id; } } } if (isset($this->_array_data_grids[$uid][$spid])) { return $this->_array_data_grids[$uid][$spid]; } else { return array(); } } /** srv_data_checkgrid * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_check_grids ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = 'SELECT spr_id, vre_id, usr_id, grd_id, loop_id FROM srv_data_checkgrid'.$this->db_table.' WHERE spr_id IN ('.$this->_str_questions.') '.$string_user; $this->_qry_data_check_grids = sisplet_query($str_query); if (!$this->_qry_data_check_grids) { $this->trigerError('create_array_data_check_grids', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_checkgrid * * @param $uid * @param $spr_id */ private function get_array_data_check_grids ($uid, $spid) { if (isset($this->_array_data_check_grids[$uid][$spid])) { return $this->_array_data_check_grids[$uid][$spid]; } if ($this->_array_data_check_grids === null) { if ($this->_qry_data_check_grids === null) { return array(); } if (mysqli_num_rows($this->_qry_data_check_grids)) { mysqli_data_seek($this->_qry_data_check_grids, 0); while ( list($spr_id, $vre_id, $usr_id, $grd_id, $loop_id) = mysqli_fetch_row($this->_qry_data_check_grids)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_check_grids[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id][(int)$grd_id] = (int)$grd_id; } } if (isset($this->_array_data_check_grids[$uid][$spid])) return $this->_array_data_check_grids[$uid][$spid]; else return array(); } else { return array(); } } /** srv_data_number * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_number ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = "SELECT spr_id, vre_id, usr_id, REPLACE(text,'\n',' ') as text, REPLACE(text2,'\n',' ') as text2, loop_id FROM srv_data_number WHERE spr_id IN (".$this->_str_questions.') '.$string_user; $this->_qry_data_number = sisplet_query($str_query); if (!$this->_qry_data_number) { $this->trigerError('create_array_data_number', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_number * * @param $uid * @param $spr_id */ private function get_array_data_number ($uid, $spid) { if (isset($this->_array_data_number[$uid][$spid])) { return $this->_array_data_number[$uid][$spid]; } if ($this->_array_data_number === null) { if ($this->_qry_data_number === null) { return array(); } if (mysqli_num_rows($this->_qry_data_number)) { mysqli_data_seek($this->_qry_data_number, 0); while ( list($spr_id, $vre_id, $usr_id, $text, $text2, $loop_id) = mysqli_fetch_row($this->_qry_data_number)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_number[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id] = array('text'=>strip_tags($text),'text2'=>strip_tags($text2)) ; } } if (isset($this->_array_data_number[$uid][$spid])) return $this->_array_data_number[$uid][$spid]; else return array(); } else { return array(); } } /** srv_data_rating * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_rating ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = 'SELECT spr_id, vre_id, usr_id, vrstni_red, loop_id FROM srv_data_rating WHERE spr_id IN ('.$this->_str_questions.') '.$string_user; $this->_qry_data_rating = sisplet_query($str_query); if (!$this->_qry_data_rating) { $this->trigerError('create_array_data_rating', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_rating * * @param $uid * @param $spr_id */ private function get_array_data_rating ($uid, $spid) { if (isset($this->_array_data_rating[$uid][$spid])) { return $this->_array_data_rating[$uid][$spid]; } if ($this->_array_data_rating === null) { if ($this->_qry_data_rating === null) { return array(); } if (mysqli_num_rows($this->_qry_data_rating)) { mysqli_data_seek($this->_qry_data_rating, 0); while ( list($spr_id, $vre_id, $usr_id, $vrstni_red, $loop_id) = mysqli_fetch_row($this->_qry_data_rating)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_rating[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id] = (int)$vrstni_red; } } if (isset($this->_array_data_rating[$uid][$spid])) return $this->_array_data_rating[$uid][$spid]; else return array(); } else { return array(); } } /** srv_data_textgrid * @desc vrne array z gridi za posameznega userja in spremenljivko * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_text_grid ($string_user) { if ($this->_str_questions != '') { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = "SELECT spr_id, vre_id, usr_id, grd_id, REPLACE(REPLACE(REPLACE(REPLACE(text, '\\\\', '/'),'\n',' '),'\r','
'),'|',' ') as text, loop_id FROM srv_data_textgrid".$this->db_table." WHERE spr_id IN (".$this->_str_questions.') '.$string_user; $this->_qry_data_text_grid = sisplet_query($str_query); if (!$this->_qry_data_text_grid) { $this->trigerError('create_array_data_text_grid', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } } /** Vrnemo vrednost za uid in spr_id za tabelo srv_data_textgrid * srv_data_textgrid * @param $uid * @param $spr_id */ private function get_array_data_text_grid ($uid, $spid) { if (isset($this->_array_data_text_grid[$uid][$spid])) { return $this->_array_data_text_grid[$uid][$spid]; } if ($this->_array_data_text_grid === null) { if ($this->_qry_data_text_grid === null) { return array(); } if (mysqli_num_rows($this->_qry_data_text_grid)) { mysqli_data_seek($this->_qry_data_text_grid, 0); while ( list($spr_id, $vre_id, $usr_id, $grd_id, $text, $loop_id) = mysqli_fetch_row($this->_qry_data_text_grid)) { $loop_id = ($loop_id == null || $loop_id == '') ? 0 : $loop_id; $this->_array_data_text_grid[(int)$usr_id][$spr_id.'_'.$loop_id][(int)$vre_id][(int)$grd_id] = trim(strip_tags($text)); } } if (isset($this->_array_data_text_grid[$uid][$spid])) return $this->_array_data_text_grid[$uid][$spid]; else return array(); } else { return array(); } } /** srv_data_upload * @desc vrne array z imeni datotek za upload polja * ko prvič pokličemo naredimo query in napolnimo array */ private function create_array_data_text_upload ($string_user) { # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' AND usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); $str_query = "SELECT usr_id, code, filename FROM srv_data_upload WHERE ank_id = '" . $this->sid . "'".$string_user; $this->_qry_data_text_upload = sisplet_query($str_query); if (!$this->_qry_data_text_upload) { $this->trigerError('create_array_data_text_upload', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } } /** Vrnemo vrednost za filename za posamezen code za tabelo srv_data_upload * srv_data_upload * @param $code */ private function get_array_data_text_upload ($_code) { if (isset($this->_array_data_text_upload[$_code])) { return $this->_array_data_text_upload[$_code]; } if ($this->_array_data_text_upload === null) { if (mysqli_num_rows($this->_qry_data_text_upload)) { mysqli_data_seek($this->_qry_data_text_upload, 0); while ( list($usr_id, $code, $filename) = mysqli_fetch_row($this->_qry_data_text_upload)) { $this->_array_data_text_upload[$code] = strip_tags($filename); } } if(isset($this->_array_data_text_upload[$_code])) return $this->_array_data_text_upload[$_code]; else return 'Download'; } else { return 'Download'; } } /** * Ustvarimo array z vrstnimi redi v randomizaciji (vprasanje ali blok) */ private function create_array_data_random ($string_user) { // Ce smo ze zakesirali ne rabimo naprej if ($this->_array_data_random_cached){ return; } # popravimo string za omejevanje userjev $_string_user = str_replace(array(' AND usr_id IN (', ')'), '', $string_user); $_string_user = explode(',',$_string_user); $string_user = ' usr_id BETWEEN '.$_string_user[0].' AND '.end($_string_user); // Najprej dobimo random podatke za randomizacijo znotraj vprasanj $str_query = 'SELECT spr_id, usr_id, vrstni_red FROM srv_data_random_spremenljivkaContent WHERE '.$string_user; $_qry_data_random = sisplet_query($str_query); if (!$_qry_data_random) { $this->trigerError('create_array_data_random', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } if (mysqli_num_rows($_qry_data_random)) { while($row1 = mysqli_fetch_array($_qry_data_random)){ $this->_array_data_random[$row1['usr_id']]['spr'][$row1['spr_id']] = $row1['vrstni_red']; } } // Dobimo se random podatke za randomizacijo znotraj blokov $str_query = 'SELECT block_id, usr_id, vrstni_red FROM srv_data_random_blockContent WHERE '.$string_user; $_qry_data_random = sisplet_query($str_query); if (!$_qry_data_random) { $this->trigerError('create_array_data_random', 'MYSQL ERROR in qry: '.$str_query . " ".mysqli_error($GLOBALS['connect_db'])); } if (mysqli_num_rows($_qry_data_random)) { while($row2 = mysqli_fetch_array($_qry_data_random)){ // Zgradimo string z labelami vprasanj za prikaz v podatkih $vrstni_red_string = ''; // Spremenljivke v blokih if($this->_array_random[$row2['block_id']]['type'] == 'blok_spr'){ // Pridobimo imena vprasanj za izpis $sqlLabele1 = sisplet_query("SELECT variable FROM srv_spremenljivka WHERE id IN (".$row2['vrstni_red'].") ORDER BY FIND_IN_SET(id, '".$row2['vrstni_red']."') "); while($rowLabele1 = mysqli_fetch_array($sqlLabele1)){ $vrstni_red_string .= $rowLabele1['variable'].','; } } // Bloki v blokih else{ // Pridobimo imena blokov za izpis $sqlLabele2 = sisplet_query("SELECT number FROM srv_if WHERE id IN (".$row2['vrstni_red'].") ORDER BY FIND_IN_SET(id, '".$row2['vrstni_red']."') "); if($sqlLabele2){ while($rowLabele2 = mysqli_fetch_array($sqlLabele2)){ $vrstni_red_string .= 'B'.$rowLabele2['number'].','; } } } $vrstni_red_string = substr($vrstni_red_string, 0, -1); $this->_array_data_random[$row2['usr_id']]['block'][$row2['block_id']] = $vrstni_red_string; } } // Oznacimo da smo opravili kesiranje $this->_array_data_random_cached = true; } /** * Vrnemo podatke vrstnega reda za userja in element (vprasanje ali blok) */ private function get_array_data_random ($uid, $el_id, $el_type) { // Ce imamo vrednost jo vrnemo if (isset($this->_array_data_random[$uid][$el_type][$el_id])) { return $this->_array_data_random[$uid][$el_type][$el_id]; } else { return ''; } } public function trigerError($what, $error) { # trigger_error("Could not perform action. " . $error, E_USER_WARNING); $this->noErrors = false; $this->logError[][$what] = $error; return; } public function getLog() { return array('error'=>$this->logError); } /** * @desc izracuna razliko med dvema datuma (za cas odgovarjanja na eno stran) */ private function date_diff($d1, $d2){ $d1 = (is_string($d1) ? strtotime($d1) : $d1); $d2 = (is_string($d2) ? strtotime($d2) : $d2); $diff_secs = abs($d1 - $d2); $base_year = min(date("Y", $d1), date("Y", $d2)); $diff = mktime(0, 0, $diff_secs, 1, 1, $base_year); $days_total = floor($diff_secs / (3600 * 24)); $hours_total = floor($diff_secs / 3600); // total hours if ($hours_total < 24) return date("H:i:s", $diff); else return $hours_total.':'.date("i:s", $diff); /* alternativni prikaz, ki izpise stevilo dni namesto ur // total days if ($days_total == 0) return date("H:i:s", $diff); else return $days_total.' days '.date("H:i:s", $diff); */ } public function collectLoop() { # ali smo za to anketo že lovili loope, da se ne podvajamo if ($this->_loop_collected == false) { session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hs'] = 3; $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = 0; session_commit(); # na katero spremenljivko se veže loop $this->_array_loop_on_spr = array(); $this->_array_loop_parent = array(); $loop_spr_select = "select l.if_id, l.spr_id FROM srv_branching AS b, srv_loop AS l WHERE b.ank_id = '".$this->sid."' AND b.element_if = l.if_id;"; $qryLoop_spr_select = sisplet_query($loop_spr_select); while (list($loop_id,$spr_id) = mysqli_fetch_row($qryLoop_spr_select)) { $this->_array_loop_parent[$spr_id] = $loop_id; $this->_array_loop_on_spr[$loop_id] = $spr_id; $_cnt_loop++; } #katere vrednosti uporablja posamezen loop ( kolikokrat se loop zavrti) $this->_array_vre_on_loop = array(); $this->_array_vrednosti_in_loops = array(); $vre_on_loop_select = "select ld.id, ld.if_id, ld.vre_id FROM srv_loop_data AS ld WHERE ld.if_id IN (select l.if_id FROM srv_branching AS b, srv_loop AS l WHERE b.ank_id = '".$this->sid."' AND b.element_if = l.if_id) ORDER BY if_id, ld.vre_id, ld.id;"; $qry_vre_on_loop_select = sisplet_query($vre_on_loop_select); while (list($id, $loop_id,$vre_id) = mysqli_fetch_row($qry_vre_on_loop_select)) { # če imamp SN -imena in je loop na SN - imena ne loopamo po vseh vrednostih, ampak samo po max vnosih $this->_array_vre_on_loop[$loop_id][$id] = $vre_id; $this->_array_vrednosti_in_loops[] = $vre_id; // Posebej nastavimo ce gre za loop po numeric vprasanju if($vre_id == null){ $this->_array_vre_on_loop[$loop_id][$id] = 'num_loop'; $this->_array_vrednosti_in_loops[] = 'num_loop'; } } #preverimo katere spremenljvke so v katerem loopu $this->_array_spr_in_loop = array(); $this->_array_loop_has_spr = array(); $b = new Branching ($this->sid); $_loops = $b->spremenljivke_in_loop(); session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsa'] = count($_loops); session_commit(); $cntHs=0; if (count($_loops) > 0 ) { foreach ($_loops AS $lkey => $spr_ids) { $cntHs++; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['hsc'] = $cntHs; session_commit(); if (count($spr_ids) > 0 ) { $this->_array_loop_has_spr[$lkey] = array(); foreach ($spr_ids AS $spr_id) { $this->_array_spr_in_loop[$spr_id] = $lkey; $this->_array_loop_has_spr[$lkey][] = $spr_id; } } } } $this->_loop_collected = true; } } public function createAllQuestionsOrder() { # delamo samo 1x if ( $this->AllQuestionsData !==null && $this->AllQuestionsOrder != null) { return array('AllQuestionsData'=>$this->AllQuestionsData, 'AllQuestionsOrder'=>$this->AllQuestionsOrder); } # polovimo spremenljivke za survey Grid Multiple - kombinirana vprašanja $sgmMap = array(); $sqlSgmMap = sisplet_query("SELECT sgm.parent AS sgm_parrent, s.id, s.tip, s.variable, REPLACE(REPLACE(REPLACE(s.naslov,'\n',' '),'\r','
'),'|','
') as naslov, s.gru_id, s.size, s.random, s.cela, s.decimalna, s.skala, s.enota, s.sistem, s.upload, s.signature, s.grid_subtitle1, s.grid_subtitle2, s.inline_edit, REPLACE(REPLACE(REPLACE(s.naslov_graf,'\n',' '),'\r','
'),'|','
') as naslov_graf, s.edit_graf, s.wide_graf, s.antonucci, s.visible, s.dostop". " FROM srv_spremenljivka AS s JOIN srv_grid_multiple AS sgm ON (s.id = sgm.spr_id) WHERE sgm.ank_id = '$this->sid' ORDER BY sgm.vrstni_red"); while ($sgmRow = mysqli_fetch_assoc($sqlSgmMap)) { $sgmMap[$sgmRow['sgm_parrent']][] = $sgmRow; } #peverimo ali so bili skreirani loopi if ($this->_array_loop_on_spr == null || $this->_array_spr_in_loop == null) { $this->collectLoop(); } $this->AllQuestionsData = array(); $this->AllQuestionsOrder = array(); $star_loop_id = null; # za SN - imena if(SurveyInfo::getInstance()->checkSurveyModule('social_network')){ $sn_loop_variables = $this->getSNVariablesForSpr(); } if ($this->_cnt_questions > 0) { mysqli_data_seek($this->_qry_questions, 0); while ($rowMainVprasanje = mysqli_fetch_assoc($this->_qry_questions)) { $rowVprasanja = array(); if (!is_countable($sgmMap[$rowMainVprasanje['id']]) || count($sgmMap[$rowMainVprasanje['id']]) == 0) { $rowVprasanja[] = $rowMainVprasanje; } else { # preverimo parent tip. mora biti 24 if ((int)$rowMainVprasanje['tip'] == 24){ # imamo kombinirano vprašanje foreach ($sgmMap[$rowMainVprasanje['id']] AS $sgmRow) { $tmpVprasanje = $sgmRow; # popravimo variablo in besedilo $tmpVprasanje['sgm_parrent'] = $rowMainVprasanje['id']; $tmpVprasanje['variable'] = $rowMainVprasanje['variable'].'_'.$sgmRow['variable']; $tmpVprasanje['naslov'] = $rowMainVprasanje['naslov']; $rowVprasanja[] = $tmpVprasanje; } } else { # če ne ni kombinirana tabela $rowVprasanja[] = $rowMainVprasanje; } } if (count($rowVprasanja) > 0) { foreach ($rowVprasanja AS $rowVprasanje) { $spr_id = $rowVprasanje['id']; $this->AllQuestionsData[$rowVprasanje['id']] = array( 'id' => $rowVprasanje['id'], 'spr_id' => $spr_id, 'sgm_parrent'=> $rowVprasanje['sgm_parrent'], 'tip' => $rowVprasanje['tip'], 'gru_id' => $rowVprasanje['gru_id'], 'variable' => strip_tags($rowVprasanje['variable']), 'naslov' => strip_tags($rowVprasanje['naslov']), 'label' => strip_tags($rowVprasanje['label']), 'size' => $rowVprasanje['size'], 'cela' => $rowVprasanje['cela'], 'grid_subtitle1' => $rowVprasanje['grid_subtitle1'], 'grid_subtitle2' => $rowVprasanje['grid_subtitle2'], 'decimalna' => $rowVprasanje['decimalna'], 'skala' => $rowVprasanje['skala'], 'sistem' => $rowVprasanje['sistem'], 'enota' => $rowVprasanje['enota'], 'if_id' => (isset($this->_array_spr_in_loop[$spr_id]) ? $this->_array_spr_in_loop[$spr_id] : 0), 'upload' => $rowVprasanje['upload'], 'signature' => $rowVprasanje['signature'], 'naslov_graf' => $rowVprasanje['naslov_graf'], 'edit_graf' => $rowVprasanje['edit_graf'], 'wide_graf' => $rowVprasanje['wide_graf'], 'antonucci' => $rowVprasanje['antonucci'], 'visible' => $rowVprasanje['visible'], 'dostop' => $rowVprasanje['dostop'], 'random' => $rowVprasanje['random'] ); if ($rowVprasanje['inline_edit'] != 0) { $this->AllQuestionsData[$rowVprasanje['id']]['inline_edit'] = $rowVprasanje['inline_edit']; } // Zabelezimo stevilo vprasanj po tipu $this->_cnt_questions_types[$rowVprasanje['tip']] = (isset($this->_cnt_questions_types[$rowVprasanje['tip']])) ? $this->_cnt_questions_types[$rowVprasanje['tip']]+1 : 1; # če je spremenljivka parent od loopa jo dodamo if (isset($this->_array_loop_parent[$spr_id]) && $this->_array_loop_parent[$spr_id] > 0) { $this->AllQuestionsData[$rowVprasanje['id']]['loop_parent'] = $this->_array_loop_parent[$spr_id]; $this->AllQuestionsData[$rowVprasanje['id']]['antonucci'] = $rowVprasanje['antonucci']; } # dodamo vprašanje v vrstni red, če je vprašanje v loopu dodamo loop if (!isset($this->_array_spr_in_loop[$spr_id])) { # vprašanje ni v loopu $this->AllQuestionsOrder[] = array('id'=>$spr_id,'loop_id'=>0); $star_loop_id = null; # nismo v loopu } else { # vprašanje je v lopu $trenutni_loop_id = $this->_array_spr_in_loop[$spr_id]; # id loopa v katerem se nahaja spremenljivk # na katero spremenljivko se dela loop $loop_on_spr = $this->_array_loop_on_spr[$trenutni_loop_id]; # če ta loop in pripadajoča vprašanja še niso bila dodana v vrstni red, jih dodamoše ni bil if ($trenutni_loop_id != $star_loop_id) { # loop še ni bil sprocesiran; $_vrednosti_v_loopu = $this->_array_vre_on_loop[$trenutni_loop_id]; # preverimo ali smo v navadnem loopu ali v SN loopu if (isset($this->SNVariablesForSpr[$loop_on_spr]) == false) { # smo v navadnem loopu # kolikokrat moramo iti skozi loop if (count($_vrednosti_v_loopu)) { foreach ($_vrednosti_v_loopu AS $li_id => $vrednost) { # dodamo vprašanja ki so v posameznemm loopu. if (count($this->_array_loop_has_spr[$trenutni_loop_id])) { foreach($this->_array_loop_has_spr[$trenutni_loop_id] AS $vprasanje) { $this->AllQuestionsOrder[] = array('id'=>$vprasanje,'loop_id'=>$li_id,'vre_id'=>$vrednost, 'parent_loop_id'=>$trenutni_loop_id); } } } } } else { # smo v SN loopu - skozi loop gremo samo za vrednosti ki so dodane kot sn imena if (count($_vrednosti_v_loopu)) { foreach ($_vrednosti_v_loopu AS $li_id => $vrednost) { if (in_array($vrednost,$this->SNVariablesForSpr[$loop_on_spr])) { # dodamo vprašanja ki so v posameznemm loopu. if (count($this->_array_loop_has_spr[$trenutni_loop_id])) { foreach($this->_array_loop_has_spr[$trenutni_loop_id] AS $vprasanje) { $this->AllQuestionsOrder[] = array('id'=>$vprasanje,'loop_id'=>$li_id,'vre_id'=>$vrednost, 'parent_loop_id'=>$trenutni_loop_id); } } } } } } # priredimo kateri loop smo že obdelali, da ne bomo 2x $star_loop_id = $trenutni_loop_id; } else { # loop je že bil sprocesiran, ne naredimo nič } } } } } } return array('AllQuestionsData'=>$this->AllQuestionsData, 'AllQuestionsOrder'=>$this->AllQuestionsOrder); } /* public function getVariableLabelsForLoop() { $result = array(); if (count($this->_array_vrednosti_in_loops) > 0) { $sql_vrednosti = sisplet_query('select id, naslov, variable from srv_vrednost where id IN ('.implode(",",$this->_array_vrednosti_in_loops).') order by spr_id, vrstni_red'); while (list($id, $naslov, $variabla) = mysqli_fetch_row($sql_vrednosti)) { $result[$id] = array('naslov'=>$naslov, 'variabla'=>$variabla); } } return $result; } */ public function getArrayLoopOnSpremenljvika() { return $this->_array_loop_on_spr; } public function getArrayVrednostOnLoop() { return $this->_array_vre_on_loop; } public function getSNVariablesForSpr() { $_result = array(); if ($this->_cnt_questions > 0) { mysqli_data_seek($this->_qry_questions, 0); while ($rowVprasanje = mysqli_fetch_assoc($this->_qry_questions)) { if($rowVprasanje['tip'] == 9) { $_result[] = $rowVprasanje['id']; } } } if (count($_result) > 0) { foreach ($_result AS $spr_id) { $string = "SELECT vre_id FROM srv_data_text".$this->db_table." WHERE spr_id = '".$spr_id."' GROUP BY vre_id"; $qry = sisplet_query($string); while ( $row = mysqli_fetch_assoc($qry)) { if ( $row['vre_id'] > 0 ) { $this->SNVariablesForSpr[$spr_id][$row['vre_id']] = $row['vre_id']; } } } } return $this->SNVariablesForSpr; } public function get_user_CMS_email($user_from_cms_id) { # če še niammo arraya z e-maili if ($this->_array_users_from_CMS == null) { # polovimo emaile uporrabnikov iz CMS $this->_array_users_from_CMS = array(); $string = "SELECT su.user_id, u.email FROM srv_user AS su JOIN users AS u ON su.user_id = u.id WHERE su.ank_id = '".$this->sid."' AND su.preview='0' AND su.deleted='0' AND su.user_id > 0"; $qry = sisplet_query($string); while ( $row = mysqli_fetch_assoc($qry)) { $this->_array_users_from_CMS[$row['user_id']] = $row['email']; } } #ko smo že polovili e-maile if (is_array($this->_array_users_from_CMS) && isset($this->_array_users_from_CMS[$user_from_cms_id])) { return $this->_array_users_from_CMS[$user_from_cms_id]; } else { return ''; } } private function recode_answer($spr_id, $answer, $uid) { $this->addUserSprAnswerCount($spr_id, $answer, $uid); # najprej preverimo ali imamo mapping za sistemske missige $answer = isset($this->sysMissingMap[$answer]) && $this->sysMissingMap[$answer] != null ? $this->sysMissingMap[$answer] : $answer; $_recoded = $answer; if ( $this->_array_recode === null) { $this->_array_recode = array(); # polovimo vse spremenljivke za katere moramo rekodirat $strSelect = "SELECT spr_id, search, value, operator FROM srv_recode WHERE ank_id = '".$this->sid."' AND enabled='1' ORDER BY vrstni_red"; $sqlSelect = sisplet_query($strSelect); if (!$sqlSelect) { #echo mysqli_error($GLOBALS['connect_db']); } if (mysqli_num_rows($sqlSelect)) { while ($rowSelect = mysqli_fetch_assoc($sqlSelect)) { $this->_array_recode[$rowSelect['spr_id']][] = array('s'=>$rowSelect['search'],'v'=>$rowSelect['value'],'o'=>$rowSelect['operator']); } } } if (isset($this->_array_recode[$spr_id])) { $recoded = false; if (isset($this->_array_recoded[$spr_id][$answer])) { return $this->_array_recoded[$spr_id][$answer]; } else if (count($this->_array_recode[$spr_id]) > 0 && $recoded == false) { foreach ($this->_array_recode[$spr_id] AS $k => $do_recode) { if ( $answer == $do_recode['s'] || (int)$do_recode['o'] > 0 && $recoded == false) { $original = $_recoded; $_recoded = $this->check_recode($_recoded,$do_recode['s'],$do_recode['v'],$do_recode['o']); if ($original != $_recoded) { $recoded = true; } } } $this->_array_recoded[$spr_id][$answer] = $_recoded; } } #vrnemo rezultat return $_recoded; } function check_recode ($answer,$search,$value,$operand) { $_recoded = $answer; switch ($operand) { case 0: # == $_recoded = $answer == $search ? $value : $answer; break; case 1: # <> $_recoded = $answer != $search ? $value : $answer; break; case 2: # < $_recoded = $answer < $search ? $value : $answer; break; case 3: # > $_recoded = $answer > $search ? $value : $answer; break; case 4: # <= $_recoded = $answer <= $search ? $value : $answer; break; case 5: # >= $_recoded = $answer >= $search ? $value : $answer; break; case 6: # >= $search = explode(',',$search); $s1 = (int)$search[0]; $s2 = (int)$search[1]; $_recoded = (int)$answer >= $s1 && (int)$answer <= $s2 ? $value : $answer; break; } return $_recoded; } function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } public function getFileStatus() { return $this->fileStatus; } public function getFileUpdated() { return $this->last_update; } public function getHeadFileName() { if (file_exists($this->folder . 'export_header_'.$this->sid.'.dat')) { return $this->folder . 'export_header_'.$this->sid.'.dat'; } else { return null; } } public function getDataFileName() { if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { return $this->folder . 'export_data_'.$this->sid.'.dat'; } else { return null; } } public function getAutoCreatingFile () { return $this->autoCreatingFile; } public function getSurveyVariables($filterTip = NULL) { $result = array(); if (!isset($this->_HEADER) || $this->_HEADER == null) { $this->_HEADER = unserialize(file_get_contents($this->getHeadFileName())); } if ($this->getHeadFileName() != null ) { foreach ($this->_HEADER AS $_vkey => $variable) { # dodamo samo tiste variable, ki imajo numerični tip (navadne spremenljvke) if (is_numeric($variable['tip'] ) # ne dodamo sistemskih email, telefon, ime, priimek, naziv && !( (int)$variable['hide_system'] == 1 && in_array($variable['variable'],unserialize (SYSTEM_VARIABLES)) )# unserialize (SYSTEM_VARIABLES) -> definition.php = array('email','telefon','ime','priimek','naziv','drugo') ) { # če filter ni setiran dodamo vse variable if ( $filterTip == NULL ) { $result[$_vkey] = $variable['sequences']; } else if ( is_array($filterTip) && in_array($variable['tip'],$filterTip) ) { $result[$_vkey] = $variable['sequences']; } else if ( is_string($filterTip) && (string)$variable['tip'] == (string)$filterTip ) { $result[$_vkey] = $variable['sequences']; }else if ( is_numeric($filterTip) && (int)$variable['tip'] == (int)$filterTip ) { $result[$_vkey] = $variable['sequences']; } } } } return $result; } public function getVariableName($variable) { if (!isset($this->_HEADER) || $this->_HEADER == null) { $this->_HEADER = unserialize(file_get_contents($this->getHeadFileName())); } $result = ''; if (isset($this->_HEADER[$variable])) { $result = '(' . $this->_HEADER[$variable]['variable'] .') - '.$this->_HEADER[$variable]['naslov']; } return $result; } public function getHeaderVariable($variable) { if (!isset($this->_HEADER) || $this->_HEADER == null) { if (trim($this->getHeadFileName()) != '') { $this->_HEADER = unserialize(file_get_contents($this->getHeadFileName())); } } return $this->_HEADER[$variable]; } public function setSkipCreate($skipCreate = false) { $this->skipCreate = $skipCreate; } public function getDataFileInfo() { global $admin_type, $lang; $result = null; if ($admin_type == '0') { if ($this->fileStatus != FILE_STATUS_NO_FILE && (int)$this->data_file_time > 0 && file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { # delamo inkremental $inkremental_user_limit = " AND u.time_edit > FROM_UNIXTIME('".(int)$this->data_file_time."') "; } else { # lovimo vse userje - datoteko generiramo na novo $inkremental_user_limit = ''; } $str_qry_usr_cnt = "SELECT count(u.id) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' ".$this->is_valid_user_limit.$inkremental_user_limit; $qry_usr_cnt = sisplet_query($str_qry_usr_cnt); list($user_cnt) = mysqli_fetch_row($qry_usr_cnt); // Preverimo ce imamo izklopljeno belezenje parapodatka datum - potem moramo vedno generirati datoteko $no_paradata_date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date'); $result = '  '; if ($this->fileStatus == FILE_STATUS_NO_DATA) { $result .= $lang['srv_dashboard_no_data']; } else if ($this->fileStatus == FILE_STATUS_NO_FILE) { $result .= $lang['srv_dashboard_no_file'].$lang['srv_dashboard_new_units'].(int)$user_cnt; } else if ($this->fileStatus == FILE_STATUS_OLD && $no_paradata_date == 0) { $result .= $lang['srv_dashboard_not_up_to_date'].'('.$this->last_update.')'; $result .= $lang['srv_dashboard_new_units'].(int) $user_cnt; } else if ($this->fileStatus == FILE_STATUS_OLD && $no_paradata_date == 1) { $result .= $lang['srv_dashboard_up_to_date'].' ('.$this->last_update.')'; } else if ($this->fileStatus == FILE_STATUS_OK) { $result .= $lang['srv_dashboard_up_to_date'].' ('.$this->last_update.')'; } } return $result; } function cleanup() { # resetiramo vse pointerje $this->noErrors = true; $this->_HEADER = null; $this->_qry_groups = null; # cache query za strani $this->_str_groups = null; # cache string za strani $this->_cnt_groups = 0; # cache število za strani $this->_qry_questions = null; # cache query za vprašanja $this->_str_questions = null; # cache string za vprašanja $this->_cnt_questions = 0; # cache za število vprašanj $this->_qry_users = null; # cache query za vprašanja $this->_str_users = null; # cache string za user_id ji $this->_cnt_all_users = 0; # cache za število userjev $this->_qry_vrednosti = null; # cache query za vrednosti $this->_array_vrednosti = null; # cache array z vrednostmi $this->_cnt_vrednosti = 0; # cache za število vseh vrednosti $this->_qry_gridi = null; # cache query za gride $this->_array_gridi = null; # cache array z gridi $this->_cnt_gridi = 0; # cache za število vseh gridov $this->_qry_rand_blocks = null; # cache query za random bloke $this->_qry_data_vrednost = null; $this->_array_data_vrednost = null; $this->_qry_data_text = null; $this->_array_data_text = null; $this->_qry_data_grids = null; $this->_array_data_grids = null; $this->_qry_data_check_grids = null; $this->_array_data_check_grids = null; $this->_qry_data_number = null; $this->_array_data_number = null; $this->_qry_data_rating = null; $this->_array_data_rating = null; $this->_qry_data_text_grid = null; $this->_array_data_text_grid = null; $this->_array_SPSS = null; # zakeširamo array usergrup za uporabnika $this->_array_user_grupa = null; # zakeširamo array usergrup za uporabnika $this->_array_users_from_CMS = null; $this->_loop_collected = false; # Ali smo že zakeširali loop } function skipCreateIfInProgress() { $qstr = "SELECT updateInProgress, updateStartTime, TIME_TO_SEC(TIMEDIFF(now(), updateStartTime)) as diference FROM srv_data_files WHERE sid = '".$this->sid."'"; $qqry = sisplet_query($qstr); list($updateInProgress, $updateStartTime, $diference) = mysqli_fetch_row($qqry); if ((int)$updateInProgress == 0) { return false; } else { # v teku je kreacija datoteke preverimo da ni slučajno od te instance if ($this->updateStartTime == $updateStartTime) { #generacijo smo zagnali iz te instance return false; } else if ((int)$diference > (int)INCREMENTAL_LOCK_TIMEOUT) { # preverimo še čas zaklepanja, če je većji kot INCREMENTAL_LOCK_TIMEOUT = 20 minut, pomeni da je nekaj šlo narove in pustimo ponovno generacijo datoteke return false; } else { #echo 'Kreacija datoteke je že v teku!'; # generacija je že v teku in od zagona še ni minil 20 minut return true; } } } function setStartInProgress() { if ($this->updnateStartTime == null) { SurveyTrackIncremental::write($this->sid,'setStartInProgress() =>'.implode(',',func_get_args())); $str_qry_update = "INSERT INTO srv_data_files (sid, updateInProgress, updateStartTime) VALUES ('".$this->sid."','1', NOW()) ON DUPLICATE KEY UPDATE updateInProgress = '1', updateStartTime = NOW()"; $updated = sisplet_query($str_qry_update); sisplet_query('COMMIT'); $qstr = "SELECT updateInProgress, updateStartTime FROM srv_data_files WHERE sid = '".$this->sid."'"; $qqry = sisplet_query($qstr); list($updateInProgress, $updateStartTime) = mysqli_fetch_row($qqry); $this->updateStartTime = $updateStartTime; session_start(); $_SESSION['incrementalProgressBar'][$this->sid]['current'] = 0; $_SESSION['incrementalProgressBar'][$this->sid]['total'] = $this->_cnt_all_users; $_SESSION['incrementalProgressBar'][$this->sid]['status'] = 1; session_commit(); } } function setStopInProgress() { if ($this->updateStartTime != null) { SurveyTrackIncremental::write($this->sid,'setStopInProgress() =>'.implode(',',func_get_args())); $qstr = "SELECT updateInProgress, updateStartTime FROM srv_data_files WHERE sid = '".$this->sid."'"; $qqry = sisplet_query($qstr); list($updateInProgress, $updateStartTime) = mysqli_fetch_row($qqry); if ($this->updateStartTime == $updateStartTime ) { $str_qry_update = "INSERT INTO srv_data_files (sid, updateInProgress, updateStartTime) VALUES ('".$this->sid."','0', '0000-00-00') ON DUPLICATE KEY UPDATE updateInProgress = '0', updateStartTime = '0000-00-00'"; $updated = sisplet_query($str_qry_update); sisplet_query('COMMIT'); $this->updateStartTime = null; } } } function setSurveyMissingValues() { $smv = new SurveyMissingValues($sid); $smv -> Init(); $_sys_missings = $smv->GetSurveyMissingValues(); if (is_array($_sys_missings) && count($_sys_missings) > 0) foreach ($_sys_missings[1] AS $_sys_missing) { #nastavimo mapping za rekodiranje sistemskih vrednosti $this->sysMissingMap[$_sys_missing['defSysVal']] = $_sys_missing['value']; } } function clearSurveyDataFiles($filename=null) { if ($filename !== null && trim($filename)!='') { # brišemo specifično datoteko if (file_exists($filename)) { unlink($filename); } } else { #pobrišemo header datoteke if (file_exists($this->folder . 'export_header_'.$this->sid.'.dat')) { unlink($this->folder . 'export_header_'.$this->sid.'.dat'); } #pobrišemo data datoteko if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat')) { unlink($this->folder . 'export_data_'.$this->sid.'.dat'); } # pobrišemo tmp file if (file_exists($this->folder . 'export_data_'.$this->sid.'.tmp')) { unlink($this->folder . 'export_data_'.$this->sid.'.tmp'); } if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat_data1.tmp')) { unlink($this->folder . 'export_data_'.$this->sid.'.dat_data1.tmp'); } if (file_exists($this->folder . 'export_data_'.$this->sid.'.dat_data1_1.tmp')) { unlink($this->folder . 'export_data_'.$this->sid.'.dat_data1_1.tmp'); } # odstranimo morebitne SN datoteke - header $files = glob($this->folder.'export_sn_header_'.$this->sid.'_*.dat'); if(count($files ) > 0) { foreach ($files AS $file) { unlink($file); } } # odstranimo morebitne SN datoteke - data $files = glob($this->folder.'export_sn_data_'.$this->sid.'_*.dat'); if(count($files ) > 0) { foreach ($files AS $file) { unlink($file); } } } } public function checkRealFile() { #preštejemo enote iz datoteke if (IS_WINDOWS) { $command = 'awk "NF != 0 {++count} END {print count}" '.$this->data_file_name; } else { $command = 'awk \'NF != 0 {++count} END {print count}\' '.$this->data_file_name; } $lines = (int)shell_exec($command); #preštejemo userje iz baze if ((int)$this->collect_all_status == 1) { # vse statuse $str_qry_cnt = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0'"; $qryqry_cnt = sisplet_query($str_qry_cnt); list($cnt) = mysqli_fetch_row($qryqry_cnt); } else { # samo ustrezne $str_qry_cnt = "SELECT count(*) FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' AND u.preview='0' AND u.deleted='0' AND u.last_status IN (5,6)"; $qryqry_cnt = sisplet_query($str_qry_cnt); list($cnt) = mysqli_fetch_row($qryqry_cnt); } #vsi statusi $result = array('result'=>((int)$lines == (int)$cnt ? true : false), 'file'=>(int)$lines, 'db'=>$cnt); return $result; } function deleteUsers() { # če fajl sploh obstaja #datoteka s podatki $f1 = $this->data_file_name; #datoteka kam zapišemo user id-je ki jih je potrebno pobrisat $f2 = $this->data_file_name.'.todel'; # datoteka kamor začasno shranimo original $f3 = $this->data_file_name.'_'.time().'.orig'; if ((int)$this->sid > 0 && file_exists($f1)) { # zaklenemo izvajanje $lock = new ExclusiveLock( "survey_lock_".$this->sid, FALSE); if( $lock->lock( ) == FALSE ) { SurveyTrackIncremental::write($this->sid,'deleteUsers(); LOCK: alreadyLocked for survey: '.$this->sid); #error("Locking failed"); } else { try { if ((int)$this->data_file_time > 0) { # preberemo max time iz datoteke in uporabimo manjšega if (IS_WINDOWS) { $command = 'awk -F"|" "BEGIN {max = 0} {if ('.TIME_FIELD.' > max && '.TIME_FIELD.' > 0) max='.TIME_FIELD.' } END {print max}" '.$f1; } else { $command = 'awk -F\'|\' \'BEGIN {max = 0} {if ('.TIME_FIELD.' > max && '.TIME_FIELD.' > 0) max='.TIME_FIELD.' } END {print max}\' '.$f1; } $user_time_from_file = shell_exec($command); # delamo inkremental $inkremental_user_limit = " AND u.time_edit > FROM_UNIXTIME('".max((int)$this->data_file_time,(int)$user_time_from_file)."') "; } else { # lovimo vse userje - datoteko generiramo na novo $inkremental_user_limit = ''; } # za inkrementalno brisanje datotek $str_qry_deleted = "SELECT u.id AS usr_id FROM srv_user AS u WHERE u.ank_id = '".$this->sid."' ".$inkremental_user_limit; $qry_users_deleted = sisplet_query($str_qry_deleted); if (!$qry_users_deleted) { $this->trigerError('create_qry_users', 'MYSQL ERROR in qry: '.$str_qry . " ".mysqli_error($GLOBALS['connect_db'])); } if (mysqli_num_rows($qry_users_deleted) > 0) { # zapišemo v datoteko idje katere brišemo $file = fopen($f2, 'w'); while (list($usr_id) = mysqli_fetch_row($qry_users_deleted)) { fwrite($file, $usr_id . "\n"); } fclose($file); if (IS_WINDOWS) { $cmd = 'cp '.$f1.' '.$f3.' && awk -F"|" "NR==FNR {++a[$0]; next} { f = $1; if (!a[$1]) print $0}" '.$f2.' '.$f3.' > '.$f1; } else { $cmd = 'cp '.$f1.' '.$f3.' && awk -F\'|\' \'NR==FNR {++a[$0]; next} { f = $1; if (!a[$1]) print $0}\' '.$f2.' '.$f3.' > '.$f1; } SurveyTrackIncremental::write($this->sid,'deleteUsers() Command:'.mysqli_real_escape_string($GLOBALS['connect_db'], $cmd)); $out_command = shell_exec($cmd); } #če je vse ok, pobrišemo datoteke if (file_exists($f1)) { # pobrišemo datoteko z userji katere smo brisali if (file_exists($f2)) { unlink($f2); } # pobrišemo backup datoteko if (file_exists($f3)) { unlink($f3); } } } catch (Exception $e) { if ($logClass != null) { SurveyTrackIncremental::write($this->sid,'deleteUsers() Exception:'.$e->getMessage()); } } } $lock->unlock(); } } function writeLockMessage($lockDate) { global $lang; echo '
'; echo $lang['srv_incremental_lock_message']; echo '
'; # na 15 sekund refreshamo stran echo ''; } function getLinesCnt() { if (IS_WINDOWS) { $command = 'awk "NF != 0 {++count} END {print count}" '.$this->data_file_name; } else { $command = 'awk \'NF != 0 {++count} END {print count}\' '.$this->data_file_name; } $lines = shell_exec($command); return (int)$lines; } private function addUserSprAnswerCount($spr, $answer, $uid) { # štejemo zadnji veljaven odgovor $this->_user_spr_answer_count['cnt']++; if ($answer != -1 && $answer != -4 && $answer !== '-2d') { // sistemskih in skritih ne upoštevamo if ($this->AllQuestionsData[$spr]['sistem'] == 1 || $this->AllQuestionsData[$spr]['visible'] == 0) { // preskočimo } else { $this->_user_spr_answer_count['last'] = $this->_user_spr_answer_count['cnt']; $this->_user_spr_answer_count['last_seen'] = $this->_user_spr_answer_count['cnt']; } } // Pogledamo se ce je respondent videl vprasanje (tudi ce je -1, ker ga potem ne smemo spremenit v -3) if ($answer == -1 || $answer === '-2d') { if (is_array($this->_array_user_grupa[$uid]) && array_key_exists($this->AllQuestionsData[$spr]['gru_id'], $this->_array_user_grupa[$uid])) { $this->_user_spr_answer_count['last_seen'] = $this->_user_spr_answer_count['cnt'] - 1; } } if (!isset($this->_user_spr_answer_count['spremenljivke'][$spr])) { $this->_user_spr_answer_count['spremenljivke'][$spr] = 0; } $this->_user_spr_answer_count['spremenljivke'][$spr]++; } private function calculateValuesToChange($uid) { $result = 0; if (count($this->_user_spr_answer_count['spremenljivke']) == 0) { return $result; } //if ($this->_user_spr_answer_count['last'] == $this->_user_spr_answer_count['cnt']) { if ($this->_user_spr_answer_count['last_seen'] == $this->_user_spr_answer_count['cnt']) { return $result; } if (count($this->_user_spr_answer_count['spremenljivke']) == 0) { return $result; } foreach ($this->_user_spr_answer_count['spremenljivke'] AS $cnt) { //if ($this->_user_spr_answer_count['last'] > $result) { if ($this->_user_spr_answer_count['last_seen'] > $result) { $result += $cnt; } } return $this->_user_spr_answer_count['cnt'] - $result; } private function convertPolyString($polypoints){ $poly = array(); $polyObjectArray = array(); $j = 0; $poly = explode(',',$polypoints); for($i = 0; $i $pointy) != ($poly[$j]["y"] > $pointy)) && ($pointx < ($poly[$j]["x"]-$poly[$i]["x"]) * ($pointy-$poly[$i]["y"]) / ($poly[$j]["y"]-$poly[$i]["y"]) + $poly[$i]["x"]) ) $inside = !$inside; } return $inside; } private function preparePointCoords($answerKoo, $returnPointx, $returnPointy){ $coordsWithComma = explode('
',$answerKoo); $pointx = array(); $pointy = array(); for($i = 1; $i