Init(self::$surveyId, self::$uId); # preverimo ali ima uporabnik nastavljen privzet profil $dsp = SurveyUserSetting :: getInstance()->getSettings('default_time_profile'); if ( $dsp == null ) { # nastavimo privzet profil v clas $dsp = 0; } #dodamo profil iz seje if ( (int)$dsp == -1 ) { if ( isset($_SESSION['time_profile'][self::$surveyId])) { #dodamo profil iz seje self::$profiles['-1'] = array('id'=>'-1', 'name'=>$lang['srv_temp_profile'], 'type'=>$_SESSION['time_profile'][self::$surveyId]['type'], 'starts'=>(isset($_SESSION['time_profile'][self::$surveyId]['starts']) ? $_SESSION['time_profile'][self::$surveyId]['starts'] : null), 'ends'=>(isset($_SESSION['time_profile'][self::$surveyId]['ends']) ? $_SESSION['time_profile'][self::$surveyId]['ends'] : null), 'interval_txt'=>(isset($_SESSION['time_profile'][self::$surveyId]['interval_txt']) ? $_SESSION['time_profile'][self::$surveyId]['interval_txt'] : null)); $dsp = -1; } else { // ni v seji, naredimo privzetega $dsp = 0; } } # če mamo spremembo shranimo self::SetDefaultProfileId((int)$dsp); #dodamo privzet profil # datum od, "ce ni podan vzamemo kreacijo ankete SurveyInfo :: getInstance()->SurveyInit(self::getSurveyId()); self::$start_date = date(STP_DATE_FORMAT, strtotime(SurveyInfo::getInstance()->getSurveyInsertDate())); # datum do, "ce ni podan vzamemo danasnji dan self::$end_date = date(STP_DATE_FORMAT);// ce ne, # dodamo sistemski profil self::$profiles['0'] = array( 'id'=>0, 'type'=>0, 'name'=>$lang['srv_default_profile'], 'starts'=>self::$start_date, 'ends'=>self::$end_date, 'interval_txt'=>''); # poiščemo še seznam vseh ostalih profilov uporabnika $stringSelect = "SELECT id, name, type, DATE_FORMAT(starts,'".STP_CALENDAR_DATE_FORMAT."') AS starts, DATE_FORMAT(ends,'".STP_CALENDAR_DATE_FORMAT."') AS ends, interval_txt FROM srv_time_profile WHERE uid = '".self::getGlobalUserId()."' || uid = '0' ORDER BY id"; $querySelect = sisplet_query($stringSelect); while ( $rowSelect = mysqli_fetch_assoc($querySelect) ) { self::$profiles[$rowSelect['id']] = array( 'id'=>$rowSelect['id'], 'name'=>$rowSelect['name'], 'type'=>$rowSelect['type'], 'starts'=>$rowSelect['starts'], 'ends'=>$rowSelect['ends'], 'interval_txt'=>$rowSelect['interval_txt']); } # nastavimo id profil klassa na izbran self::$currentProfileId = (int)$dsp; return true; } else { return false; } } static function getSystemDefaultProfile() { return (int)STP_DEFAULT_PROFILE; } /** Vrne podatke trenutno izbranega profofila * */ static function GetCurentProfileData() { return self::$profiles[self::$currentProfileId]; } /** Vrne podatke podanega profofila * */ static function GetProfileData($pid) { return self::$profiles[$pid]; } public function getProfileName($pid) { return self::$profiles[$pid]['name']; } /** Vrne array z start date in end date * */ static function GetDates($forceDefaultFilter = false) { if ($forceDefaultFilter == false) { $_profile_data = self :: GetCurentProfileData(); # ali imam o privzete datume filtra $is_default_dates = ((int)$_profile_data['id'] == 0 ? true : false); } else { # zaradi možnosti masovnega zbiranja vsilimo privzet datum $_profile_data = self::$profiles[0]; # ali imam o privzete datume filtra $is_default_dates = true; } # nastavimo start date in end date if ($_profile_data['interval_txt'] != '') { # ce imamo nastavljen datum preko intervala $end_date = date(STP_OUTPUT_DATE_FORMAT); $start_date = date(STP_OUTPUT_DATE_FORMAT,strtotime(date(STP_OUTPUT_DATE_FORMAT, strtotime($end_date)) . ' - '.$_profile_data['interval_txt'])); } else if ($_profile_data['starts'] != '' && $_profile_data['ends'] != '') { # imamo podana oba datuma $start_date = date(STP_OUTPUT_DATE_FORMAT,strtotime($_profile_data['starts'])); $end_date = date(STP_OUTPUT_DATE_FORMAT,strtotime($_profile_data['ends'])); } else { # napaka vzamemo datum kreacije ankete in današnji datum $start_date = date(STP_OUTPUT_DATE_FORMAT,strtotime(SurveyInfo::getInstance()->getSurveyInsertDate())); $end_date = date(STP_OUTPUT_DATE_FORMAT);; } # končni datum po potrebi zmanjšamo na današnji datum if (strtotime($end_date) > strtotime(date(STP_OUTPUT_DATE_FORMAT))) { $end_date = date(STP_OUTPUT_DATE_FORMAT); } return array('start_date'=>$start_date, 'end_date'=>$end_date, 'is_default_dates' => $is_default_dates); } /** Pridobimo seznam vseh list uporabnika * v obliki arraya */ static function getProfiles() { return self::$profiles; } /* Vrne ID in ime trenutno izbranega profila * */ function getCurentProfile() { return array('id'=>self::$currentProfileId,'name'=>self::$profiles[self::$currentProfileId]['name']); } /** Ponastavi id privzetega profila * */ static function SetDefaultProfile($pid) { self::SetDefaultProfileId($pid); } static function SetDefaultProfileId($pid) { self::$currentProfileId = (int)$pid; $saved = SurveyUserSetting :: getInstance()->saveSettings('default_time_profile',(int)$pid); } static function ChooseProfile($pid) { # če smo izbrali drug profil resetiramo še profil profilov na trenutne nastavitve SurveyUserSetting :: getInstance()->saveSettings('default_profileManager_pid', '0'); self::SetDefaultProfileId((int)$pid); self::$currentProfileId = (int)$pid; } /** * */ static function SaveProfile($pid,$type,$startDate,$endDate,$stat_interval) { global $lang; if ((int)$pid == 0 ) { # imamo privzet profil self :: ChooseProfile((int)$pid); $updated = true; } else if ((int)$pid > 0) { # shranimo v bazo if ((int)$type == 0) { # $type = '0'; # shranjujemo od - do $stat_interval = ''; $_startDate = date(STP_OUTPUT_DATE_FORMAT, strtotime($startDate)); $_endDate = date(STP_OUTPUT_DATE_FORMAT, strtotime($endDate)); $update = "UPDATE srv_time_profile SET starts = '".$_startDate."', ends='".$_endDate."', type='".$type."', interval_txt = '' WHERE id = '".$pid."'"; } else { # $type = '1'; # shranjujemo interval $startDate = ''; $endDate = ''; $type = '1'; $update = "UPDATE srv_time_profile SET starts = '0000-00-00 00:00:00', ends='0000-00-00 00:00:00', type='".$type."', interval_txt = '".$stat_interval."' WHERE id = '".$pid."'"; } $updated = sisplet_query($update); # ce je bili updejt ok posodobimo se vrednost v profilu if ($updated) { self::$profiles[$pid]['type'] = $type; self::$profiles[$pid]['starts'] = $startDate; self::$profiles[$pid]['ends'] = $endDate; self::$profiles[$pid]['interval_txt'] = $stat_interval; } # nastavimo privzet profil na trenutnega self :: ChooseProfile((int)$pid); } else { # shranjujenmo v sejo $_SESSION['time_profile'][self::$surveyId] = array('id'=>'-1', 'name'=>$lang['srv_temp_profile']); if ((int)$type == 0) { # $type = '0'; # shranjujemo od - do $_SESSION['time_profile'][self::$surveyId]['type'] = '0'; $_SESSION['time_profile'][self::$surveyId]['starts'] = date(STP_OUTPUT_DATE_FORMAT, strtotime($startDate)); $_SESSION['time_profile'][self::$surveyId]['ends'] = date(STP_OUTPUT_DATE_FORMAT, strtotime($endDate)); unset($_SESSION['time_profile'][self::$surveyId]['interval_txt']); } else { $_SESSION['time_profile'][self::$surveyId]['type'] = '1'; $_SESSION['time_profile'][self::$surveyId]['interval_txt'] = $stat_interval; unset($_SESSION['time_profile'][self::$surveyId]['starts']); unset($_SESSION['time_profile'][self::$surveyId]['ends']); } self::$profiles[$pid] = $_SESSION['time_profile'][self::$surveyId]; $updated = true; self :: ChooseProfile((int)$pid); } return $updated; } static function RenameProfile($pid, $name) { if (isset($pid) && $pid > 0 && isset($name) && trim($name) != "") { // popravimo podatek za variables $stringUpdate = "UPDATE srv_time_profile SET name = '".$name."' WHERE id = '".$pid."'"; $updated = sisplet_query($stringUpdate); return $updated; } else { return -1; } } static function DeleteProfile($pid = 0) { if (isset($pid) && $pid == -1) { unset($_SESSION['time_profile'][self::$surveyId] ); } else if (isset($pid) && $pid > 0) { // Izbrišemo profil in nastavimo privzetega $stringUpdate = "DELETE FROM srv_time_profile WHERE id = '".$pid."'"; $updated = sisplet_query($stringUpdate); } # nastavimo privzet profil self::ChooseProfile('0'); } /** Funkcija kreira nov profil * */ function createProfile($type,$startDate,$endDate,$stat_interval,$name=null) { global $lang; if ($name == null || trim($name) == '' ) { $name = $lang['srv_new_profile']; } if ($type == '0') { # shranjujemo od - do $startDate = date(STP_OUTPUT_DATE_FORMAT, strtotime($startDate)); $endDate = date(STP_OUTPUT_DATE_FORMAT, strtotime($endDate)); $stat_interval = ''; } else { # shranjujemo interval $startDate = '0000-00-00'; $endDate = '0000-00-00'; $type = '1'; } $iStr = "INSERT INTO srv_time_profile (id,uid,name,type,starts,ends,interval_txt)". " VALUES (NULL, '".self::$uId."', '".$name."', '".$type."', '".$startDate."', '".$endDate."', '".$stat_interval."')"; $ins = sisplet_query($iStr); $id = mysqli_insert_id($GLOBALS['connect_db']); if ($id > 0) { self :: ChooseProfile($id); } else { self :: ChooseProfile(0); } return; } /** prikažemo dropdown z izbranim profilom in link do nastavitev profila * * */ static function DisplayLink($hideAdvanced = true, $showseperator = true) { global $lang; $profiles = self :: getProfiles(); $izbranProfil = self :: getCurentProfileId(); $css = ($izbranProfil == STP_DEFAULT_PROFILE ? ' gray' : ''); if ($hideAdvanced == false || $izbranProfil != STP_DEFAULT_PROFILE) { echo '
' . $lang['srv_time_profile_time'] . '
'; echo '"); print_r($_POST); print_r($_GET); break; } } /** Kreira nov profil z datumom od začetka ankete do danes * */ public static function createNewProfile() { global $lang; if ($_POST['profileName'] == null || trim($_POST['profileName']) == '' ) { $_POST['profileName'] = $lang['srv_new_profile']; } $type = '0';; $stat_interval = ''; $startdate = date(STP_OUTPUT_DATE_FORMAT, strtotime(self::$start_date)); $enddate = date(STP_OUTPUT_DATE_FORMAT, strtotime(self::$end_date)); $iStr = "INSERT INTO srv_time_profile (id,uid,name,type,starts,ends,interval_txt)". " VALUES (NULL, '".self::getGlobalUserId()."', '".$_POST['profileName']."', '".$type."', '".$startdate."', '".$enddate."', '".$stat_interval."')"; $ins = sisplet_query($iStr); $id = mysqli_insert_id($GLOBALS['connect_db']); if ($id > 0) { self::ChooseProfile($id); } else { $id = 0; self::ChooseProfile($id); } return $id; } /** Vrne filter v obliki stringa primernega za uporabo filtriranja z AWK * */ public static function getFilterForAWK ($sequenca = null) { # če manjka sekvenca mamo napako in ne delamo filtra if ($sequenca == null || $sequenca == '') { return ''; } $_profile = self::GetCurentProfileData(); #za privzet porfil id = 0 ne delamo časovnih omejitev if ($_profile['id'] == '0') { return ''; } else { # odvisno od tipa profila pripravimo omejitve datuma $set=false; if ($_profile['type'] == '0') { $result = '('; $prefix = ''; # imamo range od - do # spremenimo oba datuma v unixtime $startUnixDate = date("U", strtotime($_profile['starts'])); $endUnixDate = date("U", strtotime($_profile['ends'])); if ((int)$startUnixDate > 0 ) { $result .= '$'.$sequenca. ' > ' . $startUnixDate; $prefix = ' && '; $set=true; } if ((int)$endUnixDate > 0 ) { # + 86 400 seconds = one day $result .= $prefix. '$'.$sequenca. ' < ' . ($endUnixDate+ 86400) ; $set=true; } $result .= ')'; } else { #imamo interval zadnjih XXX dni $date = date("Y-m-d");// current date $unix_date = strtotime(date("Y-m-d", strtotime($date)) . " -".$_profile['interval_txt']); if ((int)$unix_date > 0 && $_profile['interval_txt'] != null && $_profile['interval_txt'] =! '') { $result = '($'.$sequenca. ' > ' . $unix_date.')'; $set=true; } } if ($set == true) { return $result; } } } /** Izpišemo opozorilo če ni privzet profil * */ static function printIsDefaultProfile() { global $lang; if (self::$currentProfileId != 0) { $cp_data = self::GetCurentProfileData(); echo ''; echo ''; return true; } else { return false; } } /** 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; } } ?>'; # odvisno od tipa profila izpišemo ali obdobje ali interval if ($cp_data['type'] == 0) { # obdobje: od - do echo ''.$lang['obdobje_od'].': '.date(STP_DATE_FORMAT, strtotime($cp_data['starts'])); echo ' '.$lang['obdobje_do'].': '.date(STP_DATE_FORMAT, strtotime($cp_data['ends'])); } else { # interval: zadnjih x dni echo ''.$lang['srv_time_profile_filter_period'].': '.($lang['srv_diagnostics_'.$cp_data['interval_txt']]); } echo ''; echo ''; echo ' '; echo ' '; echo ''; echo '