summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveySetting.php
blob: ae2aa55ea2b1440b07b991e19da35cfc9c9901e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
 * Created on 2.6.2009
 *
 */

class SurveySetting
{
	static private $instance;


	// SurveyId
	static private $sid = null;

	static private $mySqlResult = null;
	static private $mySqlErrNo = null;

	// konstrutor
	protected function __construct() {}
	// kloniranje
	private function __clone() {}

	/** Poskrbimo za samo eno instanco razreda
	 *
	 */
	static function getInstance()
	{
		if(!self::$instance)
		{
			self::$instance = new SurveySetting();
		}
		return self::$instance;
	}

	/** inicializacija */

	static function Init( $_surveyId = null)
	{
		if ( $_surveyId )
			{ self::$sid = $_surveyId; }
	}

	// nastavimo nov Survey Id
	static function setSID( $_surveyId = null )
	{
		if ( $_surveyId )
			{ self::$sid = $_surveyId; }
	}


	/**
	 * @desc polovimo nastavitev za posamezno anketo če obstaja,
	 * če ne uporabimo nastavitev sistema
	 */
	private $getSurveyMiscSetting = array();
	function getSurveyMiscSetting($what=null)
	{
		# če že imamo polovljene nastavitve iz baze jih vrnemo direkt
		if (isset($this->getSurveyMiscSetting[$what])) {
			return $this->getSurveyMiscSetting[$what];
		}
		if (is_string($what))
		{
			if(is_array(self::$sid)){
				$sid = implode('',self::$sid);
			}else{
				$sid=self::$sid;
			}
			$stringSelect = "SELECT value FROM srv_survey_misc WHERE sid='".$sid ."' AND what = '".$what."'";
			$sqlSelect = sisplet_query($stringSelect);
            if (mysqli_num_rows($sqlSelect) > 0)
            {
            	$rowSelect = mysqli_fetch_assoc($sqlSelect);
            	$result = $rowSelect['value'];
            }
            else
        	{
        		global $site_path;
        		//require_once($site_path.'admin/survey/classes/class.Setting.php');
				Setting::getInstance()->Init();
				$result = Setting::getInstance()->getSysMiscSetting($what);
        	}
		}
		
		$this->getSurveyMiscSetting[$what] = $result;
		return $this->getSurveyMiscSetting[$what];
	}
	/**
	 * @desc shranimo nastavitev survey sistema
	 */
	function setSurveyMiscSetting($what=null, $value=null)
	{
		if (self::$sid ) // rabimo sid
		{
			if ( $what )				// pustimo, da je value 0 ali prazen
			{
				if ( is_string($what) )
				{
					$stringInsert = "INSERT INTO srv_survey_misc (sid, what, value) VALUES ('".self::$sid."', '".$what."', '".$value."') ON DUPLICATE KEY UPDATE value = '".$value."'";
					$sqlInsert = sisplet_query($stringInsert);
					sisplet_query("COMMIT");
					return mysqli_affected_rows($GLOBALS['connect_db']);
				}
				else
					return false;
			}
			else
				return false;

		}
		else
			return false;
	}
	
	function removeSurveyMiscSetting ($what = null) {
		
		if (self::$sid) {	// rabimo sid
			
			if ( $what ) {				// pustimo, da je value 0 ali prazen
			
				if ( is_string($what) ) {
					
					$stringInsert = "DELETE FROM srv_survey_misc WHERE sid = '".self::$sid."' AND what = '".$what."'";
					$sqlInsert = sisplet_query($stringInsert);
					return mysqli_affected_rows($GLOBALS['connect_db']);
					
				} 
			}
		}
		
		return false;
			
	}
}

?>