init($sid); #polovimo vse profile self::getProfiles(); #inicaliziramo nastavitve uporabnika SurveyUserSetting :: getInstance()->Init($sid, $global_user_id); self::$currentId = self:: getCurentProfileId(); } static function setCurrentProfileId($pid) { if (isset(self::$profiles[$pid])){ self::$currentId = $pid; } else{ self::$currentId = SVP_DEFAULT_PROFILE; } } static function getProfiles() { global $lang; # če imamo sejo preberemo iz seje if ( isset($_SESSION['variables_profile'][self::$sid])) { self::$profiles[-1] = $_SESSION['variables_profile'][self::$sid]; } #dodamo profil vse variable $svp_av = self::$SDF->getSurveyVariables(); $all_variables = array(); if (count($svp_av) > 0) { foreach($svp_av AS $v_id => $seq) { $all_variables[] = $v_id; } } $variables = serialize($all_variables); self::$profiles[SVP_DEFAULT_PROFILE] = array('id'=>SVP_DEFAULT_PROFILE, 'name'=>$lang['srv_all_vars'].' *', 'variables'=>$variables); # preberemo še profile iz baze $stringSelect = "SELECT id, name, variables FROM srv_variable_profiles WHERE sid = '".self::$sid."'"; $sqlQuery = sisplet_query($stringSelect); while (list($id,$name,$variables) = mysqli_fetch_row($sqlQuery)) { self::$profiles[$id] = array('id'=>$id, 'name'=>$name, 'variables'=>$variables); } } /** Trenutno izbran profil * */ static function getCurentProfileId() { # poiscemo privzet profil $_dvp = SurveyUserSetting :: getInstance()->getSettings('default_variable_profile'); self::$currentId = $_dvp; if ($_dvp == null || !isset(self::$profiles[self::$currentId])) { $_dvp = SVP_DEFAULT_PROFILE; self::$currentId = $_dvp; self::setDefaultProfile(self::$currentId); } return (int)self::$currentId; } static function getSystemDefaultProfile() { return (int)SVP_DEFAULT_PROFILE; } static function checkDefaultProfile($dvp=0) { // preverimo ali izbran privzet profil obstaja if ($dvp == -1) { //preverimo sejo if ( isset($_SESSION['variables_profile'][self::$sid]) ) { return $_SESSION['variables_profile'][self::$sid]['id']; } else { // morali bi imeti sejo pa je ni, zato nastavimo na privzetega (1) $dvp = SVP_DEFAULT_PROFILE; } } if ($dvp > 0 ) { $stringSelect = "SELECT id FROM srv_variable_profiles WHERE id = '".$dvp."'"; $sqlSelect = sisplet_query($stringSelect); if (mysqli_num_rows($sqlSelect) > 0) {// profil obstaja $rowSelect = mysqli_fetch_assoc($sqlSelect); return $rowSelect['id']; } } # ce ne izberemo osnovni profil return SVP_DEFAULT_PROFILE; } /** * * Enter description here ... * @param $pid - profil ID * @param $ignoreInspect - ce je profil inspect, in ga moramo ignorirat potem vrnemo prazn array */ static function getProfileVariables($pid = null, $ignoreInspect=false) { if ($pid === null) { $pid = self::getCurentProfileId(); } if ($ignoreInspect == true) { return array(); } # ce profil ni inspect ali ce ga ne ignoriramone vrnemo variable $variables = isset(self::$profiles[$pid]['variables']) ? unserialize(self::$profiles[$pid]['variables']) : null; if (is_array($variables)) { $result=array(); if (count($variables) > 0) { foreach ($variables AS $key => $variable) { $result[$variable] = $variable; } } return $result; } else { return array(); } return array(); } public function getProfileName($pid) { return self::$profiles[$pid]['name']; } /** * * @param $ignoreInspect - ce je profil inspect, in ga moramo ignorirat */ static function DisplayLink($ignoreInspect=false,$hideAdvanced = true) { global $lang; $izbranProfil = self::checkDefaultProfile(self::$currentId); $css = ($izbranProfil == SVP_DEFAULT_PROFILE ? ' gray' : ''); if ($hideAdvanced == false || $css != ' gray') { echo '
  • '; echo ' '.$lang['srv_filtri'].''; echo '
  • '; } } /** * @param $ignoreInspect - ce je profil inspect, in ga moramo ignorirat potem vrnemo prazn array */ static function getProfileString($ignoreInspect = false) { global $lang; $pid = self::checkDefaultProfile(self::$currentId); if ($ignoreInspect == true) { return; } $svp_pv = self::getProfileVariables($pid); $svp_av = self::$SDF->getSurveyVariables(); if (count($svp_pv) > 0 && count($svp_pv) != count($svp_av)) { $vars = array(); foreach ($svp_pv AS $vkey => $variable) { $variable_data = self::$SDF->getHeaderVariable($variable); $vars[] = $variable_data['variable']; } $variable_label = implode(', ',$vars); echo '
    '; echo '
    '; echo ' '.$lang['srv_profile_variables_is_filtred'].''; echo '
    '; echo ' '; echo ' '; echo '
    '; echo '
    '; echo '
    '; echo ' '.$variable_label.''; echo '
    '; echo '
    '; return true; } return false; } static function chooseProfile($pid){ # če smo izbrali drug profil resetiramo še profil profilov na trenutne nastavitve SurveyUserSetting :: getInstance()->saveSettings('default_profileManager_pid', '0'); if(isset(self::$profiles[$pid])) { SurveyUserSetting :: getInstance()->saveSettings('default_variable_profile', $pid); } else { SurveyUserSetting :: getInstance()->saveSettings('default_variable_profile', SVP_DEFAULT_PROFILE); } } static function ajax() { $pid = isset($_POST['pid']) ? $_POST['pid'] : null; if ($_POST['podstran'] == 'monitoring') { self::$monitoring = true; self::refreshAvailableProfiles(); }; switch ($_GET['a']) { case 'displayProfile': self::displayProfiles($pid); break; case 'changeProfile': self::displayProfiles($pid); break; case 'chooseProfile': self::chooseProfile($pid); break; case 'saveProfile': self::saveProfile(); break; case 'saveNewProfile': $new_id = self :: newProfileVariables(); break; case 'renameProfile': $updated = self::renameVariableProfile($pid,$_POST['name']); break; case 'deleteProfile': self::deleteVariableProfile($pid); break; } } static function displayProfiles ($cvp = null) { global $lang; $pid = isset($_POST['pid']) ? $_POST['pid'] : null; $popUp = new PopUp(); $popUp->setId('div_variable_profiles'); $popUp->setHeaderText($lang['srv_spremenljivke_settings']); #vsebino shranimo v buffer ob_start(); echo ''; if ($cvp == null) $cvp = self::$currentId; $svp_ap = self::$profiles; $svp_pv = self :: getProfileVariables($cvp); $svp_av = self::$SDF->getSurveyVariables(); if ( self::$currentId != SVP_DEFAULT_PROFILE ) { echo ''; } echo ''; // cover Div echo '
    '; // div za shranjevanje novega profila echo '
    '; echo '
    '; echo '
    '; echo ''; echo ''; echo '
    '; echo '
    '; echo '
    '; $button = new PopUpButton($lang['srv_cancel']); echo $button -> setFloat('right') -> addAction('onClick','variableProfileAction(\'newCancel\'); return false;'); $button = new PopUpButton($lang['srv_save_profile']); echo $button -> setFloat('right') ->setButtonColor('orange') -> addAction('onClick','variableProfileAction(\'newSave\'); return false;'); echo '
    '; echo '
    '; // div za preimenovanje echo '
    '; echo '
    '; echo '
    '; echo ''; echo ''; echo ''; echo '
    '; echo '
    '; echo '
    '; $button = new PopUpButton($lang['srv_cancel']); echo $button -> setFloat('right') -> addAction('onClick','variableProfileAction(\'renameCancel\'); return false;'); $button = new PopUpButton($lang['srv_rename_profile_yes']); echo $button -> setFloat('right') ->setButtonColor('orange') -> addAction('onClick','variableProfileAction(\'renameProfile\'); return false;'); echo '
    '; echo '
    '; // div za brisanje echo '
    '; echo $lang['srv_missing_profile_delete_confirm'].': '.$svp_ap[$cvp]['name'].'?'; echo ''; echo '
    '; $button = new PopUpButton($lang['srv_cancel']); echo $button -> setFloat('right') -> addAction('onClick','variableProfileAction(\'deleteCancel\'); return false;'); $button = new PopUpButton($lang['srv_delete_profile_yes']); echo $button -> setFloat('right') ->setButtonColor('orange') -> addAction('onClick','variableProfileAction(\'deleteConfirm\'); return false;'); echo '
    '; echo '
    '; $content = ob_get_clean(); #dodamo vsebino $popUp->setContent($content); # dodamo gumb Preklici $button = new PopUpCancelButton(); $popUp->addButton($button); # gumb shrani if ((int)$cvp != 0){ $button = new PopUpButton($lang['srv_save_profile']); $button->addAction('onClick','variableProfileAction(\'save\'); return false;'); $popUp->addButton($button); } # gumb shrani kot now $button = new PopUpButton($lang['srv_new_profile_name']); $button->addAction('onClick','variableProfileAction(\'newName\'); return false;'); $popUp->addButton($button); # gumb izberi $button = new PopUpButton($lang['srv_choose_profile']); $button -> setFloat('right') ->setButtonColor('orange') -> addAction('onClick','variableProfileAction(\'choose\'); return false;'); $popUp->addButton($button); echo $popUp; } static function setProfileVariables($pid, $variables) { global $lang; # če je pid < 1 ga shranimo v sejo if ($pid < 1) { $pid = -1; session_start(); # nastavimo kot sejo $_SESSION['variables_profile'][self::$sid] = array( 'id' => "$pid", 'name' => $lang['srv_missing_profile_temp'], 'variables' => $variables); self::$profiles[$pid] = $_SESSION['variables_profile'][self::$sid]; session_commit(); } else { $updateString = "UPDATE srv_variable_profiles SET variables = '".$variables."' WHERE id='".$pid."' AND sid = '". self::$sid."'"; $sqlupdate = sisplet_query($updateString) or die(mysqli_error($GLOBALS['connect_db'])); self::$profiles[$pid]['variables'] = $variables; } //echo $pid; return $pid; } static function saveProfile() { global $lang; $pid = $_POST['pid']; $strArray = explode("&",$_POST['vp_list_li']); $variables = array(); foreach ($strArray as $item) { $array = explode("=", $item); $variables[] = $array[1]; } $variables = serialize($variables); return self::setProfileVariables($pid, $variables); } static function newProfileVariables() { global $lang; $profileId = -1; $numrows = -1; $profileName = $_POST['name']; if (empty($profileName)) { $profileName = $lang['srv_new_profile_name']; } # ime profila preverima ali obstaja do { # preverimo ali ime že obstaja $selectSqlProfile = "SELECT id FROM srv_variable_profiles WHERE name = '".$profileName."' AND sid = '".self::$sid."'"; $sqlProfileSetting = sisplet_query($selectSqlProfile); $numrows = mysqli_num_rows($sqlProfileSetting); if ($numrows != 0) { # ime že obstaja zgeneriramo novo srand(time()); $profileName .= rand(0, 9); } } while ($numrows != 0); $strArray = explode("&",$_POST['vp_list_li']); $variables = array(); foreach ($strArray as $item) { $array = explode("=", $item); $variables[] = $array[1]; } $variables = serialize($variables); $stringInsert = "INSERT INTO srv_variable_profiles (sid,name,variables) " . "VALUES ('".self::$sid."','".$profileName."','".$variables."')"; sisplet_query($stringInsert); $insertId = mysqli_insert_id($GLOBALS['connect_db']); # osvežimo profile self::getProfiles(); #nastavimo privzetega self::chooseProfile($insertId); echo $insertId; return $insertId; } function deleteVariableProfile($pid) { if ($pid < 0 ) { // seja - session_start(); unset($_SESSION['variables_profile'][self::$sid]); unset(self::$profiles[$pid]); session_commit(); } else if( $pid > 0) { $deleteString = "DELETE FROM srv_variable_profiles WHERE id='".$pid."' AND sid = '". self::$sid."'"; $sqlDelete = sisplet_query($deleteString); unset(self::$profiles[$pid]); } $pid = SVP_DEFAULT_PROFILE; return self::chooseProfile($pid); } function renameVariableProfile($profileId, $newProfileName) { global $lang; $sqlInsert = -1; if ( !empty($profileId) && (int)$profileId > 0) { if ( $newProfileName == null || $newProfileName == "" ) { $newProfileName = $lang['srv_new_profile_name']; } $numrows = -1; do { // preverimo ali ime že obstaja $selectSqlProfile = "SELECT id FROM srv_variable_profiles WHERE name = '".$newProfileName."' AND sid = '".self::$sid."'"; $sqlProfileSetting = sisplet_query($selectSqlProfile); $numrows = mysqli_num_rows($sqlProfileSetting); if ($numrows != 0) { // ime že obstaja zgeneriramo novo srand(time()); $newProfileName .= rand(0, 9); } } while ($numrows != 0); $updateString = "UPDATE srv_variable_profiles SET name = '".$newProfileName."' WHERE id = '".$profileId."' AND sid = '".self::$sid."'"; $sqlInsert = sisplet_query($updateString); } return $sqlInsert; } /** Nastavimo profil kot zacasen inspect * * Enter description here ... * @param $variables */ function setProfileInspect($variables) { global $lang; # nastavimo kot sejo $pid = -1; if (is_array($variables)) { $variables = serialize($variables); } self::$profiles[$pid] = array('id'=>$pid, 'name'=>$lang['srv_inspect_temp_profile'], 'variables'=>$variables); session_start(); $_SESSION['variables_profile'][self::$sid] = self::$profiles[$pid]; session_commit(); # dodoamo še v class self::setDefaultProfile($pid); } /** old class compatibility **/ static function setDefaultProfile($pid) { self::chooseProfile($pid); } /** old class compatibility **/ static function setDefaultProfileId($pid) { self::chooseProfile($pid); } /** preveri obstoj profila in vrne enak id če obstaja, če ne vrne id privzetega profila * * @param unknown_type $pid * @return unknown */ function checkProfileExist($pid) { if (isset(self::$profiles[$pid])) { return true; } return false; } } function limitString($input, $limit = 100) { // Return early if the string is already shorter than the limit if(strlen($input) < $limit) { return $input; } $regex = "/(.{1,$limit})\b/"; preg_match($regex, $input, $matches); return $matches[1].'...'; } ?>