diff options
Diffstat (limited to 'admin/survey/classes/class.SurveyInfo.php')
-rw-r--r-- | admin/survey/classes/class.SurveyInfo.php | 216 |
1 files changed, 160 insertions, 56 deletions
diff --git a/admin/survey/classes/class.SurveyInfo.php b/admin/survey/classes/class.SurveyInfo.php index 5e24766..49a2e7e 100644 --- a/admin/survey/classes/class.SurveyInfo.php +++ b/admin/survey/classes/class.SurveyInfo.php @@ -37,7 +37,7 @@ class SurveyInfo protected function __construct() {}
- final private function __clone() {}
+ private function __clone() {}
/** Poskrbimo za samo eno instanco razreda
*
@@ -100,13 +100,17 @@ class SurveyInfo */
static function getSurveyColumn ($key) {
$row = self::getSurveyRow();
- return $row[$key];
+ return $row != null ? $row[$key] : null;
}
static function getSurveyRow () {
if (!self::$rowSurveyInit) {
$querySurveyInit = sisplet_query("SELECT * FROM srv_anketa WHERE id = '".self::$surveyId."'");
self::$rowSurveyInit = mysqli_fetch_assoc($querySurveyInit);
+
+ // Dodatno ciscenje texta naslova ankete - ne smemo imeti nobenih tag-ov
+ self::$rowSurveyInit['naslov'] = strip_tags(self::$rowSurveyInit['naslov']);
+ self::$rowSurveyInit['akronim'] = strip_tags(self::$rowSurveyInit['akronim']);
}
return self::$rowSurveyInit;
@@ -159,8 +163,9 @@ class SurveyInfo // te funkcije ohranimo, da se obdrzi kompatibilnost za nazaj. Za naprej se lahko uporabi kar direktno getSurveyColumn (v primerih kjer se lahko)
static function getSurveyId() { return self::$surveyId; }
- static function getSurveyTitle() { return strip_tags(self::getSurveyColumn('naslov')); }
- static function getSurveyAkronim() { return strip_tags(self::getSurveyColumn('akronim')); }
+ static function getSurveyHash() { return self::getSurveyColumn('hash'); }
+ static function getSurveyTitle() { return strip_tags(is_string(self::getSurveyColumn('naslov')) ? self::getSurveyColumn('naslov') : ''); }
+ static function getSurveyAkronim() { return strip_tags(is_string(self::getSurveyColumn('akronim')) ? self::getSurveyColumn('akronim') : ''); }
static function getSurveyActive() { return self::getSurveyColumn('active'); }
static function getSurveyFolder() { return self::getSurveyColumn('folder'); }
static function getSurveyInfo() { return self::getSurveyColumn('intro_opomba'); }
@@ -168,8 +173,8 @@ class SurveyInfo static function getSurveyShowIntro() { return self::getSurveyColumn('show_intro'); }
static function getSurveyShowConcl() { return self::getSurveyColumn('show_concl'); }
- static function getSurveyIntro() { return strip_tags(self::getSurveyColumn('introduction')); }
- static function getSurveyConcl() { return strip_tags(self::getSurveyColumn('conclusion')); }
+ static function getSurveyIntro() { return strip_tags(is_string(self::getSurveyColumn('introduction')) ? self::getSurveyColumn('introduction') : ''); }
+ static function getSurveyConcl() { return strip_tags(is_string(self::getSurveyColumn('conclusion')) ? self::getSurveyColumn('conclusion') : ''); }
static function getSurveyCountType() { return self::getSurveyColumn('countType'); }
static function getSurveyInsertUid() { return self::getSurveyColumn('insert_uid'); }
static function getSurveyInsertName() {
@@ -193,7 +198,7 @@ class SurveyInfo }
}
static function getSurveyInsertDate() { $insertDateTime = explode(" ", self::getSurveyColumn('insert_time')); $tmpDate = explode('-',$insertDateTime[0]); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
- static function getSurveyInsertTime() { $insertDateTime = explode(" ", self::getSurveyColumn('insert_time')); return $insertDateTime[1]; }
+ static function getSurveyInsertTime() { $insertDateTime = explode(" ", (self::getSurveyColumn('insert_time'))); return $insertDateTime[1]; }
static function getSurveyEditUid() { return self::getSurveyColumn('edit_uid'); }
static function getSurveyEditName() {
if (trim(self::getUserEditInfo('name')) || trim(self::getUserEditInfo('surname'))) {
@@ -214,10 +219,10 @@ class SurveyInfo return $lang['srv_anonymous'];
}
}
- static function getSurveyEditDate() { $editDateTime = explode(" ", self::getSurveyColumn('edit_time')); $tmpDate = explode('-',$editDateTime[0]); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
- static function getSurveyEditTime() { $editDateTime = explode(" ", self::getSurveyColumn('edit_time')); return $edit_time = $editDateTime[1]; }
- static function getSurveyStartsDate() { $tmpDate = explode('-',self::getSurveyColumn('starts')); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
- static function getSurveyExpireDate() { $tmpDate = explode('-',self::getSurveyColumn('expire')); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
+ static function getSurveyEditDate() { $editDateTime = explode(" ", (self::getSurveyColumn('edit_time'))); $tmpDate = explode('-',$editDateTime[0]); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
+ static function getSurveyEditTime() { $editDateTime = explode(" ", (self::getSurveyColumn('edit_time'))); return $edit_time = $editDateTime[1]; }
+ static function getSurveyStartsDate() { $tmpDate = explode('-',(self::getSurveyColumn('starts'))); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
+ static function getSurveyExpireDate() { $tmpDate = explode('-',(self::getSurveyColumn('expire'))); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0]; }
static function getSurveyFirstEntryDate() {
if (self::getFirstLast('frst') == '0000-00-00 00:00:00' || self::getFirstLast('frst') == null)
@@ -230,8 +235,27 @@ class SurveyInfo $lastDateTime = explode(" ", self::getFirstLast('lst')); $tmpDate = explode('-',$lastDateTime[0]); return $tmpDate[2].".".$tmpDate[1].".".$tmpDate[0];
}
- static function getSurveyFirstEntryTime() { $firstDateTime = explode(" ", self::getFirstLast('frst')); $tmpDate = explode(':',$firstDateTime[1]); return $tmpDate[0].":".$tmpDate[1].":".$tmpDate[2]; }
- static function getSurveyLastEntryTime() { $lastDateTime = explode(" ", self::getFirstLast('lst')); $tmpDate = explode(':',$lastDateTime[1]); return $tmpDate[0].":".$tmpDate[1].":".$tmpDate[2]; }
+ static function getSurveyFirstEntryTime() {
+
+ if(!is_string(self::getFirstLast('frst')))
+ return '';
+
+ $firstDateTime = explode(" ", self::getFirstLast('frst'));
+ $tmpDate = explode(':',$firstDateTime[1]);
+
+ return $tmpDate[0].":".$tmpDate[1].":".$tmpDate[2];
+ }
+
+ static function getSurveyLastEntryTime() {
+
+ if(!is_string(self::getFirstLast('lst')))
+ return '';
+
+ $lastDateTime = explode(" ", self::getFirstLast('lst'));
+ $tmpDate = explode(':',$lastDateTime[1]);
+
+ return $tmpDate[0].":".$tmpDate[1].":".$tmpDate[2];
+ }
static function getSurveyGroupCount() {
if (!self::$cntGroups) {
@@ -361,34 +385,20 @@ class SurveyInfo return self::$access_users;
}
- /** Polovimo vse datume aktivnosti ankete
+ /** Polovimo datume prvega aktiviranja in zadnjega deaktiviranja ankete
*
* @return unknown_type
*/
static function getSurveyActivity() {
$activity = array();
- if ( self::getSurveyColumn('active') == 1 ) {
- $_starts = self::getSurveyColumn('starts');
- $_expire = self::getSurveyColumn('expire');
-
- // izberemo samo unikatne zapise ki niso enaki trenutni aktivnosti
- $str = "SELECT DISTINCT starts, expire FROM srv_activity WHERE not(starts = '".$_starts."' AND expire = '".$_expire."') AND sid = '".self::getSurveyId()."'";
- $qry = sisplet_query($str);
- while ($row = mysqli_fetch_assoc($qry)) {
- $activity[] = array('starts'=>$row['starts'],'expire'=>$row['expire']);
- }
- // dodamo trenutno nastavljeno aktivnost
- $activity[] = array('starts'=>$_starts,'expire'=>$_expire);
-
- } else {
- // anketa ni aktivna, preberemo samo iz tabele aktivnosti
- $str = "SELECT DISTINCT starts, expire FROM srv_activity WHERE sid = '".self::getSurveyId()."'";
- $qry = sisplet_query($str);
- while ($row = mysqli_fetch_assoc($qry)) {
- $activity[] = array('starts'=>$row['starts'],'expire'=>$row['expire']);
- }
-
+
+ $sql = sisplet_query("SELECT starts, expire FROM srv_activity WHERE sid='".self::getSurveyId()."'");
+
+ if(mysqli_num_rows($sql) > 0){
+ $row = mysqli_fetch_assoc($sql);
+ $activity[] = array('starts'=>$row['starts'],'expire'=>$row['expire']);
}
+
return $activity;
}
@@ -468,7 +478,7 @@ class SurveyInfo echo ($showIcons ? '<span class="sprites clock_play" title="'.$lang['srv_info_activity'].'"></span> ' : '');
echo $lang['srv_info_activity']. ': </span>';
$activity = self:: getSurveyActivity();
- if ( count($activity) > 0 ) {
+ if (is_countable($activity) && count($activity) > 0 ) {
$prefix = '';
foreach ($activity as $active) {
$_starts = explode('-',$active['starts']);
@@ -477,7 +487,8 @@ class SurveyInfo echo $prefix.$_starts[2].'.'.$_starts[1].'.'.$_starts[0].'-'.$_expire[2].'.'.$_expire[1].'.'.$_expire[0];
$prefix = '; ';
}
- } else {
+ }
+ else {
echo $lang['srv_anketa_noactive2'].'!';
}
echo "<br />";
@@ -510,14 +521,18 @@ class SurveyInfo }
}
- static function doVariablesCount($query) {
+ static function doVariablesCount($query){
+
// zloopamo skozi vprašanja in za vsako vprašan je preberemo št variabel
$cnt= 0;
while ($rowVprasanje = mysqli_fetch_assoc($query)) {
$spr_id= $rowVprasanje['id'];
- switch ( $rowVprasanje['tip'] ) { // v odvisnosti od tipa vprašanja pohandlamo podatke
+
+ // v odvisnosti od tipa vprašanja pohandlamo podatke
+ switch ( $rowVprasanje['tip'] ) {
+
case 1: // radio
case 3: // dropdown
$cnt++; // za sam header
@@ -529,12 +544,12 @@ class SurveyInfo }
}
break;
+
case 2: // checkbox
case 6: // multigrid
case 18: // vsota
case 17: // ranking
case 21: // text*
-// $cnt++; // za sam header
$sqlSrvVred = self::select_sql_vrednost($rowVprasanje['id']);
while ( $rowSrvVred = mysqli_fetch_assoc($sqlSrvVred) ) {
$cnt++; // za vsako variablo
@@ -543,6 +558,7 @@ class SurveyInfo }
}
break;
+
case 4: // text
case 8: // datum
case 7: // number
@@ -553,6 +569,7 @@ class SurveyInfo $cnt+=2;
}
break;
+
case 16: // multicheckbox
case 19: // multitext
case 20: // multinumber
@@ -570,17 +587,21 @@ class SurveyInfo }
}
break;
- case 26: // lokacija
- if($rowVprasanje['enota'] == 3){
- $sqlSrvVred = self::select_sql_vrednost($rowVprasanje['id']);
- while ( $rowSrvVred = mysqli_fetch_assoc($sqlSrvVred) ) {
- $cnt++; // za vsako variablo
- }
- }
- else
- $cnt++; // moja lokacija in multilokacija je 1
+
+ // lokacija
+ case 26:
+ if($rowVprasanje['enota'] == 3){
+ $sqlSrvVred = self::select_sql_vrednost($rowVprasanje['id']);
+ while ( $rowSrvVred = mysqli_fetch_assoc($sqlSrvVred) ) {
+ $cnt++; // za vsako variablo
+ }
+ }
+ else
+ $cnt++; // moja lokacija in multilokacija je 1
break;
- case 27: // heatmap
+
+ // heatmap
+ case 27:
$cnt++; // za koordinate
$sqlSrvVred = self::select_sql_vrednost($rowVprasanje['id']);
while ( $rowSrvVred = mysqli_fetch_assoc($sqlSrvVred) ) { //za morebitna obmocja
@@ -642,10 +663,9 @@ class SurveyInfo if ($anketa == false)
$anketa = self::$surveyId;
-
- // V get-u ni vec id ankete ampak string (zaradi zascite, da en more kdorkoli dostopati do vseh anket)
- $anketa_string = Common::encryptAnketaID($anketa);
-
+
+ $anketa_string = self::getSurveyHash();
+
if ( ! isset( self::$surveyLink[$anketa_string] ) ) {
$sqll = sisplet_query("SELECT link FROM srv_nice_links WHERE ank_id = '".$anketa."' ORDER BY id ASC LIMIT 1");
@@ -656,7 +676,7 @@ class SurveyInfo }
else {
if (self::checkSurveyModule('uporabnost') && $uporabnost == true) // na redirectih pa v form action ne sme it na uporabnost (ker se odpira znotraj frama)
- $link = $site_url.'main/survey/uporabnost.php?anketa=' . $anketa_string ;
+ $link = $site_url.'main/survey/uporabnost.php?anketa=' . $anketa_string;
else
$link = $site_url.'a/' . $anketa_string ;
}
@@ -666,6 +686,17 @@ class SurveyInfo return self::$surveyLink[$anketa_string];
}
+
+ static function getRawSurveyLink ($uporabnost = true) {
+ global $site_url;
+
+ $anketa_string = self::getSurveyHash();
+
+ if (self::checkSurveyModule('uporabnost') && $uporabnost == true) // na redirectih pa v form action ne sme it na uporabnost (ker se odpira znotraj frama)
+ return $site_url.'main/survey/uporabnost.php?anketa=' . $anketa_string;
+ else
+ return $site_url.'a/' . $anketa_string ;
+ }
static function getRespondentLanguage() {
global $lang;
@@ -838,7 +869,7 @@ class SurveyInfo return false;
}
else{
- if(self::$surveyModules[$module] > 0)
+ if(isset(self::$surveyModules[$module]) && self::$surveyModules[$module] > 0)
return true;
else
return false;
@@ -847,5 +878,78 @@ class SurveyInfo else
return false;
}
+
+
+ // Vrnemo pripeto ime tabele s podatki ce gre za arhivsko ali aktivno anketo (_active, archive1, archive2...)
+ public static function getSurveyArchiveDBString() {
+
+ $db_table = self::getSurveyColumn('db_table');
+
+ switch($db_table){
+
+ // Arhivska 1
+ case '0':
+ $db_table_string = '_archive1';
+ break;
+
+ // Arhivska 2
+ case '2':
+ $db_table_string = '_archive2';
+ break;
+
+ // Arhivska 3
+ case '3':
+ $db_table_string = '_archive3';
+ break;
+
+ // Aktivna anketa
+ case '1':
+ default:
+ $db_table_string = '_active';
+ break;
+ }
+
+ return $db_table_string;
+ }
+
+
+ // Preverimo, ce je anketa ze potekla oz. bi se morala avtomatsko aktivirati
+ public static function checkSurveyActive(){
+
+ $anketa = self::$surveyId;
+ $active = self::getSurveyActive();
+
+ $starts = self::getSurveyStartsDate();
+ $expire = self::getSurveyExpireDate();
+
+ $currentDate = new DateTime();
+ $startDateTime = new DateTime($starts . ' 00:00:00');
+ $endDateTime = new DateTime($expire . ' 23:59:59');
+
+ // Anketa je aktivna - pogledamo, ce jo moramo deaktivirati
+ if($active == '1' && ($currentDate < $startDateTime || $currentDate > $endDateTime)){
+ // pretecena anketa, kontroliramo datum na: starts in expire
+ sisplet_query("UPDATE srv_anketa SET active='0' WHERE id='".$anketa."'");
+
+ SurveyInfo:: getInstance()->SurveyInit($anketa);
+ // vsilimo refresh podatkov
+ SurveyInfo:: getInstance()->resetSurveyData();
+
+ $active = '0';
+ }
+ // Anketa ni aktivna - pogledamo, ce jo moramo aktivirati
+ /*elseif($active == '0' && $currentDate >= $startDateTime && $currentDate <= $endDateTime){
+ // neaktivna anketa, kontroliramo datum na: starts in expire
+ sisplet_query("UPDATE srv_anketa SET active='1' WHERE id='".$anketa."'");
+
+ SurveyInfo:: getInstance()->SurveyInit($anketa);
+ // vsilimo refresh podatkov
+ SurveyInfo:: getInstance()->resetSurveyData();
+
+ $active = '1';
+ }*/
+
+ return $active;
+ }
}
?>
\ No newline at end of file |