library pri datotekah, 0 -> glasovanje, 1 -> forma, 2 -> ankata na več straneh, 3 -> ifi var $skin = 0; private $isSearch = 0; // ali izvajamo search po anektah private $searchString = ''; // geslo po katerem iscemo po anketah private $searchStringProcessed = array(); // geslo po katerem iscemo po anketah, obdelano (skrajsano da isce tudi po drugih sklanjatvah) private $searchSettings = array(); // nastavitve searcha /** * @desc konstruktor */ function __construct ($_options = array()) { global $surveySkin; if (isset($surveySkin)) $this->skin = $surveySkin; $this->SurveyAdmin = new SurveyAdmin(1, -1); $this->Branching = new Branching($this->SurveyAdmin->anketa); if (isset($_options['tab'])) { $this->tab = $_options['tab']; } else if (isset($_POST['tab'])) { $this->tab = ($_POST['tab'] == 0 || $_POST['tab'] == 'undefined') ? 0 : $_POST['tab']; } else { $this->tab = 0; } if (isset($_GET['tab'])) $this->tab = (int)$_GET['tab']; // nastavimo mode v odvisnosti od survey_type ( če nismo v anketi je -1) if (isset($this->SurveyAdmin->anketa) && $this->SurveyAdmin->anketa > 0) { $_st = $this->SurveyAdmin->getSurvey_type($this->SurveyAdmin->anketa); if ($_st > -1) $this->mode = $_st; } $this->repareTabs(); // Preverimo ce gre za search po anketah if(isset($_GET['search']) && $_GET['search'] != ''){ $this->isSearch = 1; $this->searchString = str_replace("\\", "", trim($_GET['search'])); } // Iscemo po naslovu ali vsebini $this->searchSettings['stype'] = (isset($_GET['stype'])) ? $_GET['stype'] : '0'; } function display_folders () { global $global_user_id; global $lang; echo ''; // Na prvi strani imamo search if($this->isSearch == 1){ echo '
'.($this->tab == '3' ? $lang['srv_library_title_search_my'] : $lang['srv_library_title_search_public']).'
'; $this->display_contentfolders_searchList(); } else{ echo '
'.($this->tab == '3' ? $lang['srv_library_title_my'] : $lang['srv_library_title_public']).'
'; $this->display_contentfolders(); } // Klik izven "Vec" - zapremo okno echo ''; } /** * @desc prikaze folderje v knjiznici */ function display_contentfolders ($parent = 0, $uid = -1) { global $lang; global $admin_type; global $global_user_id; global $site_url; $language = ""; if ($uid == -1) { if ($this->tab == 0 || $this->tab == 2) { $uid = 0; } else { $uid = $global_user_id; } } if ($parent == 0 && $uid == 0) { $language = " AND lang='$lang[id]' "; } $cookie = isset($_COOKIE['library_folders']) ? $_COOKIE['library_folders'] : ''; // da se v url lahko doda odprte folderje: &libfolder=131-147 (more vkljucevat tudi parente) if (isset($_GET['libfolder'])) $cookie .= '-'.$_GET['libfolder'].'-'; if ($parent == 0) { // v skrite html elemente shranimo tab echo 'tab").'">'; echo ''."\n"; } if ( $parent == 0 ) { ?> tab == 2) $uid = 0; else $uid = $global_user_id; if ($uid == 0) $language = " AND lang='$lang[id]' "; // v skrite html elemente shranimo tab echo ''; echo ''."\n"; echo ' '."\n"; if ($parent == 0) { echo ''."\n"; } if ( $parent == 0 ) { ?> '; // Hidden polja za knjiznico echo ''; if($this->tab == '3') echo ''; // Zgornja vrstica z geslom in gumbom za iskanje echo '
'; // Iskano geslo echo '
'; echo ' '; echo '
'; // Iskanje po naslovu ali avtorju ali besedilu echo '
'; echo ' '; echo '
'; // Gumb isci echo '
'; echo ' '; echo '
'; echo '
'; // Gumba za napredne nastavitve echo '
'; // Gumb nazaj na moje ankete echo ' '; echo '
'; echo ''; echo ''; } // vrne sql string za search po anketah glede na nastavitve searcha private function getSearchString(){ $search_text = mysqli_real_escape_string($GLOBALS['connect_db'], $this->searchString); // Vse gre v lowerstring $search_text = strtolower($search_text); // Sklanjamo po search besedi $search_text = explode (" ", $search_text); for ($a=0; $a 5) $search_text[$a] = substr ($search_text[$a], 0, -2); elseif (strlen ($search_text[$a]) > 2) $search_text[$a] = substr ($search_text[$a], 0, -1); else $search_text[$a] = $search_text[$a]; $this->searchStringProcessed[$a] = $search_text[$a]; $search_text[$a] = '%'.$search_text[$a].'%'; } $search_text = implode (" ", $search_text); // Search po kljucnih besedah znotraj vprasanj (naslovi vprasanj in vrednosti) if($this->searchSettings['stype'] == '1') $result = " AND (LOWER(sa.introduction) LIKE LOWER('".$search_text."') OR LOWER(sa.conclusion) LIKE LOWER('".$search_text."') OR LOWER(ss.naslov) LIKE LOWER('".$search_text."') OR LOWER(sv.naslov) LIKE LOWER('".$search_text."'))"; // Search po naslovu else $result = " AND (LOWER(sa.naslov) LIKE LOWER('".$search_text."') OR LOWER(sa.akronim) LIKE LOWER('".$search_text."'))"; return $result; } /** * @desc pohendla ajax klice */ function ajax () { if (isset($_POST['tab'])) $this->tab = (int)$_POST['tab']; else if (isset($_GET['tab'])) $this->tab = (int)$_GET['tab']; if ($this->tab == 'undefined') $this->tab = 0; if ($_GET['a'] == 'display_knjiznica') { $this->ajax_display_knjiznica(); } elseif ($_GET['a'] == 'library_add') { $this->ajax_library_add(); } elseif ($_GET['a'] == 'spr_dropped') { $this->ajax_spr_dropped(); } elseif ($_GET['a'] == 'if_dropped') { $this->ajax_if_dropped(); } elseif ($_GET['a'] == 'folder_dropped') { $this->ajax_folder_dropped(); } elseif ($_GET['a'] == 'folder_rename') { $this->ajax_folder_rename(); } elseif ($_GET['a'] == 'folder_newname') { $this->ajax_folder_newname(); } elseif ($_GET['a'] == 'new_folder') { $this->ajax_new_folder(); } elseif ($_GET['a'] == 'delete_folder') { $this->ajax_delete_folder(); } elseif ($_GET['a'] == 'folder_collapsed') { $this->ajax_folder_collapsed(); } elseif ($_GET['a'] == 'library_del_anketa') { $this->ajax_library_del_anketa(); } elseif ($_GET['a'] == 'library_del_myanketa') { $this->ajax_library_del_myanketa(); } elseif ($_GET['a'] == 'library_add_myanketa') { $this->ajax_library_add_myanketa(); } elseif ($_GET['a'] == 'anketa_copy') { $this->ajax_anketa_copy(); } elseif ($_GET['a'] == 'anketa_copy_new') { $this->ajax_anketa_copy_new(); } elseif ($_GET['a'] == 'if_remove') { $this->ajax_if_remove(); } elseif ($_GET['a'] == 'brisi_spremenljivko') { $this->ajax_brisi_spremenljivko(); } elseif ($_GET['a'] == 'alert_copy_anketa') { $this->ajax_alert_copy_anketa(); } elseif ($_GET['a'] == 'anketa_archive_and_copy') { $this->ajax_anketa_archive_and_copy(); } } function ajax_display_knjiznica () { $this->display(); } function ajax_library_add () { global $lang; $data = array(); ob_start(); $this->display_folders(); $data['folders'] = ob_get_clean(); echo json_encode($data); } function ajax_spr_dropped() { global $global_user_id; $spremenljivka = $_POST['spremenljivka']; $folder = $_POST['folder']; if ($this->tab == 0 or $this->tab == 2) $uid = 0; elseif ($this->tab == 1 or $this->tab == 3) $uid = $global_user_id; sisplet_query("UPDATE srv_library_anketa SET folder='$folder' WHERE ank_id='$spremenljivka' AND uid='$uid'"); $this->display_folders(); } function ajax_if_dropped() { global $global_user_id; $if = $_POST['if']; $folder = $_POST['folder']; sisplet_query("UPDATE srv_if SET folder = '$folder' WHERE id = '$if'"); //$this->display(); $this->display_folders(); } function ajax_folder_dropped() { $drop = $_POST['drop']; $folder = $_POST['folder']; if ($drop != $folder) sisplet_query("UPDATE srv_library_folder SET parent = '$folder' WHERE id = '$drop' AND tip='1'"); $this->display_folders(); } function ajax_folder_rename () { $folder = $_POST['folder']; $sql = sisplet_query("SELECT naslov FROM srv_library_folder WHERE id = '$folder'"); $row = mysqli_fetch_array($sql); echo '
'; echo ' '. ''; echo '
'; } function ajax_folder_newname () { $folder = $_POST['folder']; $naslov = $_POST['naslov']; sisplet_query("UPDATE srv_library_folder SET naslov='$naslov' WHERE id ='$folder'"); //$this->display(); $this->display_folders(); } function ajax_new_folder () { global $lang; global $global_user_id; $folder = $_POST['folder']; if ($this->tab == 0 or $this->tab == 2) $uid = 0; elseif ($this->tab == 1 or $this->tab == 3) $uid = $global_user_id; $uid = $_POST['uid']; $s = sisplet_query("INSERT INTO srv_library_folder (uid, tip, naslov, parent) VALUES ('$uid', '1', '$lang[srv_newfolder]', '$folder')"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); $insert_id = mysqli_insert_id($GLOBALS['connect_db']); // $_COOKIE popravimo, da bo sprememba vidna tudi v display_folders() if(isset($_COOKIE['library_folders'])) $_COOKIE['library_folders'] .= '-'.$insert_id.'-'; else $_COOKIE['library_folders'] = '-'.$insert_id.'-'; setcookie('library_folders', $_COOKIE['library_folders'], time()+2500000); $this->display_folders(); } function ajax_delete_folder () { global $lang; $folder = $_POST['folder']; $sql = sisplet_query("SELECT parent FROM srv_library_folder WHERE id = '$folder'"); $row = mysqli_fetch_array($sql); sisplet_query("UPDATE srv_library_anketa SET folder = '$row[parent]' WHERE folder = '$folder'"); sisplet_query("UPDATE srv_library_folder SET parent = '$row[parent]' WHERE parent = '$folder'"); sisplet_query("DELETE FROM srv_library_folder WHERE id = '$folder'"); //$this->display(); $this->display_folders(); } function ajax_folder_collapsed () { $folder = $_POST['folder']; $collapsed = $_POST['collapsed']; $cookie = $_COOKIE['library_folders']; if ($collapsed == 0) { $cookie .= '-'.$folder.'-'; } else { $cookie = str_replace('-'.$folder.'-', '', $cookie); } setcookie('library_folders', $cookie, time()+2500000); } function ajax_library_del_anketa () { $anketa = $_POST['anketa']; sisplet_query("DELETE FROM srv_library_anketa WHERE ank_id='$anketa' AND uid='0'"); $this->display_folders(); } function ajax_library_del_myanketa () { global $global_user_id; $anketa = $_POST['anketa']; sisplet_query("DELETE FROM srv_library_anketa WHERE ank_id='$anketa' AND uid='$global_user_id'"); $this->display_folders(); } function ajax_library_add_myanketa () { global $global_user_id; $anketa = $_POST['anketa']; $sql1 = sisplet_query("SELECT id FROM srv_library_folder WHERE uid='$global_user_id' AND tip='1' AND parent='0'"); $row1 = mysqli_fetch_array($sql1); sisplet_query("INSERT INTO srv_library_anketa (ank_id, uid, folder) VALUES ('$anketa', '$global_user_id', '$row1[id]')"); } /** * skopira anketo cez neko ze obstojeco anketo * */ function ajax_anketa_copy () { global $global_user_id; global $lang; global $site_url; $anketa = $_POST['anketa']; // nasa anketa (jo povozimo) $ank_id = $_POST['ank_id']; // anketa, ki jo uporabimo za predlogo $hierarhija = (empty($_POST['hierarhija']) ? false : true); if($hierarhija && $ank_id == 'privzeta'){ $ank_id = AppSettings::getInstance()->getSetting('hierarhija-default_id'); } if ($anketa > 0) { // preberemo osnovne podatke obstojece ankete (naslov.....) $sql = sisplet_query("SELECT naslov, dostop FROM srv_anketa WHERE id = '$anketa'"); $row = mysqli_fetch_array($sql); $sql2 = sisplet_query("SELECT naslov FROM srv_anketa WHERE id = '$ank_id'"); $row2 = mysqli_fetch_array($sql2); $sqls = sisplet_query("SELECT ank_id, uid FROM srv_dostop WHERE ank_id='$anketa'"); $this->SurveyAdmin->anketa_delete($anketa); } else { $sql = sisplet_query("SELECT naslov, dostop FROM srv_anketa WHERE id = '$ank_id'"); $row = mysqli_fetch_array($sql); $sqls = sisplet_query("SELECT ank_id, uid FROM srv_dostop WHERE ank_id='$ank_id'"); } $naslov = " naslov='".(isset($_POST['naslov']) ? $_POST['naslov'] : $row['naslov'])."',"; $intro_opomba = " intro_opomba='".(addslashes($lang['srv_library_copy_of_note'].''.$row2['naslov'].''))."',"; $sas = new SurveyAdminSettings(); $new_id = $sas->anketa_copy($ank_id); // popravimo naslov, opombo, dostop, in novega avtorja sisplet_query("UPDATE srv_anketa SET $naslov $intro_opomba dostop='$row[dostop]', insert_uid='$global_user_id', edit_uid='$global_user_id' WHERE id='$new_id'"); // vsilimo refresh podatkov SurveyInfo :: getInstance()->resetSurveyData(); // dostop uporabimo od stare ankete in ne od skopirane (trnutno ne kopira pravic od prej, če ustvarjamo novo anketo) // TODO: po kakšni logiki ohranimo dostop od stare ankete?? Če jo jaz ustvarim je prav, v kolikor kopirma iz knjižnice pa tole ni ok! if(!empty($anketa)) { sisplet_query("DELETE FROM srv_dostop WHERE ank_id = '$new_id'"); while ($rows = mysqli_fetch_array($sqls)) { sisplet_query("INSERT INTO srv_dostop (ank_id, uid) VALUES ('$new_id', '$rows[uid]')"); } } // Vrnemo samo ID ankete if($hierarhija) { sisplet_query("INSERT INTO srv_anketa_module (ank_id, modul) VALUES ('".$new_id."', 'hierarhija')"); sisplet_query("INSERT INTO srv_hierarhija_users (user_id, anketa_id, type) VALUES ('".$global_user_id."', '".$new_id."', 1)"); // Določimo vlogo (new \Hierarhija\Hierarhija($new_id))->izrisisSistemskoVprsanjeVloga(); echo $new_id; } else{ echo 'index.php?anketa='.$new_id.'&a=branching'; } } /** * ustvari novo kopijo ankete * @param ank_id samo za API - prekrije tudi vse echo */ function ajax_anketa_copy_new ($ank_id = null) { global $global_user_id, $lang, $site_url; $API_call = false; if($ank_id == null) { $ank_id = $_POST['ank_id']; // anketa, ki jo uporabimo za predlogo // Če imamo hierarhijo in je privzeta anketa potem preverimo v settings_optional.php if(!empty($_POST['hierarhija']) && $ank_id == 'privzeta'){ $ank_id = AppSettings::getInstance()->getSetting('hierarhija-default_id'); } } else { $API_call = true; } $sql = sisplet_query("SELECT naslov, dostop FROM srv_anketa WHERE id = '$ank_id'"); $row = mysqli_fetch_array($sql); // Nastavimo naslov if(isset($_POST['naslov']) && $_POST['naslov'] != '' && $_POST['naslov'] != $lang['srv_naslov'] && $_POST['naslov'] != $lang['srv_novaanketa_polnoime'] && trim($_POST['naslov']) != "") $naslov = " naslov='".$_POST['naslov']."',"; else $naslov = " naslov='".addslashes($lang['srv_library_copy_of'].$row['naslov'])."',"; // Nastavimo akronim, ce ga imamo $akronim = ""; if(isset($_POST['akronim']) && $_POST['akronim'] != '' && $_POST['akronim'] != $lang['srv_naslov'] && $_POST['akronim'] != $lang['srv_novaanketa_ime_respondenti'] && trim($_POST['akronim']) != "") $akronim = " akronim='".$_POST['akronim']."',"; $intro_opomba = " intro_opomba='".(addslashes($lang['srv_library_copy_of_note'].''.$row['naslov'].''))."',"; //$new_id = $this->SurveyAdmin->anketa_copy($ank_id); $sas = new SurveyAdminSettings(); $new_id = $sas->anketa_copy($ank_id); // popravimo naslov, opombo, dostop, in novega avtorja in ugasnemo email vabila sisplet_query("UPDATE srv_anketa SET $naslov $akronim $intro_opomba dostop='$row[dostop]', insert_uid='$global_user_id', edit_uid='$global_user_id', user_base='0' WHERE id='$new_id'"); // vsilimo refresh podatkov SurveyInfo :: getInstance()->resetSurveyData(); // dostop od stare ankete odstranimo sisplet_query("DELETE FROM srv_dostop WHERE ank_id = '$new_id'"); //dostop dodamo uporabniku, ki si kopira anketo sisplet_query("INSERT INTO srv_dostop (ank_id, uid) VALUES ('$new_id', '$global_user_id')"); // Ce imamo pri ustvarjanju doloceno tudi mapo, anketo vstavimo v njo if(isset($_POST['folder']) && $_POST['folder'] > 0){ // Razpremo folder v akterega uvrscamo anketo $sql = sisplet_query("UPDATE srv_mysurvey_folder SET open='1' WHERE id='".$_POST['folder']."' AND usr_id='".$global_user_id."'"); // Vstavimo anketo $sql = sisplet_query("INSERT INTO srv_mysurvey_anketa (ank_id, usr_id, folder) VALUES ('".$new_id."', '".$global_user_id."', '".$_POST['folder']."')"); } // popravimo branching, ce kopiramo staro anketo, ki ima lahko pokvarjenega $b = new Branching($new_id); $b->repare_branching(); // v kolikor je vkloplje modul evalvacija v šolah - hierarhija potem modul vključimo tudi v izbrani anketi if(SurveyInfo::checkSurveyModule('hierarhija', $ank_id) || !empty($_POST['novaHierarhjia'])){ sisplet_query("INSERT INTO srv_anketa_module (ank_id, modul) VALUES ('".$new_id."', 'hierarhija')"); sisplet_query("INSERT INTO srv_hierarhija_users (user_id, anketa_id, type) VALUES ('".$global_user_id."', '".$new_id."', 1)"); // Določimo vlogo (new \Hierarhija\Hierarhija($new_id))->izrisisSistemskoVprsanjeVloga(); // Omenjeno funkcijo kopije strukture in preusmeritev uporabimo, kadar kopiramo obstoječe anketo skupaj s strukturo if($_POST['hierarhija'] == 1 && empty($_POST['novaHierarhjia'])){ // $new_id je ID nove ankete, ki je bila skopirana // $ank_id pa je ID naše trenutne ankete \Hierarhija\HierarhijaKopiranjeClass::getInstance($new_id)->kopirajCelotroStrukturoKNoviAnketi($ank_id); } if(empty($_POST['novaHierarhjia'])){ echo 'index.php?anketa=' . $new_id .'&a='.A_HIERARHIJA_SUPERADMIN.'&m='.M_ADMIN_UREDI_SIFRANTE; }else{ echo $new_id; } }else { if(!$API_call) echo 'index.php?anketa=' . $new_id; } //vrrni id nove ankete za API return $new_id; } function ajax_if_remove () { $if = $_POST['if']; $this->anketa = $_POST['anketa']; $BranchingAjax = new BranchingAjax($this->anketa); // ne bomo izpisal kar izpisuje ta funkcija ob_start(); $BranchingAjax->ajax_if_remove($if); ob_end_clean(); //$this->display(); $this->display_folders(); } function ajax_brisi_spremenljivko () { $spremenljivka = $_POST['spremenljivka']; $this->SurveyAdmin->brisi_spremenljivko($spremenljivka); //$this->display(); $this->display_folders(); } function ajax_alert_copy_anketa () { global $lang; // preverimo stevilo trenutno dodanih vprasanj ce jih ni, ni potrebno arhivirat $sql = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='".$_POST['anketa']."'"); if (mysqli_num_rows($sql) > 0) { ?>


SurveyAdmin->anketa_copy($ank_id); $sas = new SurveyAdminSettings(); $new_id = $sas->anketa_copy($ank_id); $intro_opomba = addslashes( $lang['srv_library_copy_of_note'].''.$row2['naslov'].'' ); // popravimo polja sisplet_query("UPDATE srv_anketa SET naslov='$row[naslov]', intro_opomba='$intro_opomba', dostop='$row[dostop]', insert_uid='$global_user_id', insert_time=NOW(), edit_uid='$global_user_id', edit_time=NOW() WHERE id='$new_id'"); // dostop uporabimo od stare ankete in ne od skopirane sisplet_query("DELETE FROM srv_dostop WHERE ank_id = '$new_id'"); while ($rows = mysqli_fetch_array($sqls)) { sisplet_query("INSERT INTO srv_dostop (ank_id, uid) VALUES ('$new_id', '$rows[uid]')"); } // staro anketo razglasimo kot backup(arhiv) nove sisplet_query("UPDATE srv_anketa SET backup='$new_id', active=0, edit_uid='$global_user_id', edit_time=NOW(), naslov = CONCAT( naslov, ' ', DAY(NOW()), '.', MONTH(NOW()), '.', YEAR(NOW()) ) WHERE id='$anketa'"); // vsilimo refresh podatkov SurveyInfo :: getInstance()->resetSurveyData(); // redirektamo na novo anketo echo 'index.php?anketa='.$new_id; } function repareTabs() { // popravimo tabe če smo v glasovanju ali formi if ($this->mode < 2) { // uredimo tabe if ($this->tab==0 || $this->tab==1) { $this->tab=2; } } } } ?>