summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.Setting.php
blob: ff39cfba44133ab534792f7efcee2a6541f8bdc2 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
// star class. Nasomesti ga class.SurveyMissingValues

/*
 * Created on 20.5.2009
 *
 */

class Setting
{
	static private $instance;

	// nastavitve sistema
	static private $sysSetting = array();

	// nastavitve ankete
	static private $srvSetting = array();

	// nastavitve uporabnika
	static private $usrSetting = array();

	// userId
	static private $uid = null;

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

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

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

	/** inicializacija */

	static function Init( $_userId = null )
	{
		if ( $_userId )
			{ self::$uid = $_userId; }
		self::refreshData();
	}


	// nastavimo nov User Id
	static function setUID( $_userId )
	{
		if ( $_userId )
			{ self::$uid = $_userId; }
		$this->refreshData();
	}

	// osvežimo podatke nastavitev
	static function refreshData()
	{
		// nastavitve sistema
		self::getSystemSetting();
		// nastavitve ankete

		// nastavitve uporabika
	}

	static function getSystemSetting()
	{
		//$stringSystemSetting =  "SELECT * FROM srv_settng "

	}

	/** @desc: polovi sistemske filtre */
	private static $_systemFilters = array();
	private static $_systemFiltersArray;
	static function GetSystemFilters($filter=null)
	{
		if (!$filter) {
			if (isset(self::$_systemFiltersArray)) {
				return self::$_systemFiltersArray;
			}
			else {
				$result = array();
				$stringSystemSetting_filters =  "SELECT * FROM srv_sys_filters ORDER BY type, filter ASC";
				$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
			    while ( $rowSystemSetting_filters = mysqli_fetch_assoc($sqlSystemSetting_filters) )
			    {
			    	$result[] = $rowSystemSetting_filters;
			    }
			    	self::$_systemFiltersArray = $result;
				return self::$_systemFiltersArray;
			}
		}
		else {
			if (isset(self::$_systemFilters[$filter]))
				return self::$_systemFilters[$filter];
			else
			{
				$stringSystemSetting_filters =  "SELECT * FROM srv_sys_filters where filter = '".$filter."'";
				$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
			    $result = mysqli_fetch_assoc($sqlSystemSetting_filters);
				self::$_systemFilters[$filter] = $result;
				return $result;
			}
		}
	}

	// vrne array z sistemskimi filtri
	private static $_systemFiltersValues;
	static function GetSystemFiltersValues()
	{
		if (isset(self::$_systemFiltersValues)) {
			return self::$_systemFiltersValues;
		}
		else {
			$result = array();
			$stringSystemSetting_filters =  "SELECT filter FROM srv_sys_filters ORDER BY type, filter ASC";
			$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
		    while ( $rowSystemSetting_filters = mysqli_fetch_assoc($sqlSystemSetting_filters) )
		    {
		    	$result[$rowSystemSetting_filters['filter']] = $rowSystemSetting_filters['filter'];
		    }
		    self::$_systemFiltersValues = $result;
			return self::$_systemFiltersValues;
		}
	}

	private static $_systemFiltersByType = array();
	static function GetSystemFlterByType($type)
	{
		if (isset(self::$_systemFiltersByType[$type]))
			return self::$_systemFiltersByType[$type];
		else {
			$result = array();
			$stringSystemSetting_filters =  "SELECT * FROM srv_sys_filters WHERE type = '".$type."' ORDER BY filter ASC";
			$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
		    while ( $rowSystemSetting_filters = mysqli_fetch_assoc($sqlSystemSetting_filters) )
		    {
		    	$result[] = $rowSystemSetting_filters;
		    }
		    self::$_systemFiltersByType[$type] = $result;
			return self::$_systemFiltersByType[$type];
		}
	}

	/** desc: vrnemo sistemsko privzete nastavtive filtrov
	 *  (v opisnih statistikah so vsi filtri vključeni, v frekvencah pa izključeni)
	 */
	private static $_systemFiltersDefaultValues = array();
	static function GetSystemFlterDefaultValues($fid)
	{
		if (isset(self::$_systemFiltersDefaultValues[$fid]))
			return self::$_systemFiltersDefaultValues[$fid];
		else {
	    	$result = array('means'=>false, 'crosstab'=>false, 'frequencies'=>false, 'descriptives'=>true);
		    self::$_systemFiltersByType[$fid] = $result;
			return self::$_systemFiltersByType[$fid];
		}
	}


	// vrne true če je $key v tabeli z filtri
	private static $_systemFiltersValue;
	static function isSystemFiltersValue($key)
	{
		$stringSystemSetting_filters =  "SELECT count(id) as cnt FROM srv_sys_filters where filter = '".$key."'";
		$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
	    $row = mysqli_fetch_assoc($sqlSystemSetting_filters);
	    return $row['cnt'];
	}

	static function AddSystemFilters( $filter, $text, $fid)
	{
		$insertString = "INSERT INTO srv_sys_filters (fid,filter,text,uid,type) ".
			"VALUES ('".$fid."', '".$filter."', '".$text."', '".self::$uid."', '3');";
		self::$mySqlResult = sisplet_query($insertString);
		self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
	}
	static function DeleteSystemFilters( $id)
	{
		$deleteString = "DELETE FROM srv_sys_filters WHERE id = '".$id."'";
		self::$mySqlResult = sisplet_query($deleteString);
		self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
	}
	static function SaveSystemFilters($id,$filter,$text)
	{
		$updateString = "UPDATE srv_sys_filters " .
						"SET filter = '".$filter."', text = '".$text."' ".
						"WHERE id = '".$id."'";
		self::$mySqlResult = sisplet_query($updateString);
		self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
	}

	private static $_systemSysVarFlterData = array();
	static function GetSystemSysVarFlterData($id)
	{
		if (isset(self::$_systemSysVarFlterData[$id])) {
			return self::$_systemSysVarFlterData[$id];
		}
		else {
			$stringSystemSetting_filters =  "SELECT * FROM srv_sys_filters WHERE id = '".$id."'";
			$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
		  	$result = mysqli_fetch_assoc($sqlSystemSetting_filters);
		  	self::$_systemSysVarFlterData[$id] = $result;
			return self::$_systemSysVarFlterData[$id];
		}
	}

	/** Hendla prikaz filtrov v nastavitvah
	 *
	 */
	static function DisplaySystemFilters($mode='normal')
	{
		global $lang;
		global $s;
		$filtri = self::GetSystemFilters();
		if ( $mode=='normal' )
		{
			echo '<a href="#" onClick="sysFilterEditMode(\'edit\'); return false;">';
			echo '<span class="faicon edit small"></span>'
					.$lang['srv_settings_filter_edit_mode']. '</a>';
			echo '<div class="clr"></div>';
				echo '<div style="clear:both; padding:5px; height:1.2em">';

				echo '<div style="width:40px; float:left; text-align:left; padding-right:15px; text-align:right">';
				echo '<i style="color:gray; text-align:right">'.$lang['srv_filter_id'].'</i>';
				echo '</div>';

				echo '<div style="width:50px; float:left; text-align:left; padding-right:15px;">';
				echo '<i style="color:gray;text-align:right">'.$lang['srv_filter_vrednost'].'</i>';
				echo '</div>';

				echo '<div class="" style="width:250px; float:left; color: gray">';
				echo '<i style="color:gray;">'.$lang['srv_filter_variabla'].'</i>';
				echo '</div>';

				echo '</div>';

			foreach ( $filtri as $key => $filter)
			{
				echo '<div id="sysfilter_div_'.$filter['id'].'" style="clear:both; padding-bottom:0px; height:1.2em;">';
					echo '<div id="sysfilter_filter_'.$filter['id'].'" class="spr_sysFilter'.$filter['type'].'" style="width:40px; float:left; text-align:left; padding-right:15px; color:gray; text-align:right;">'.$filter['fid'].'</div>';
					echo '<div id="sysfilter_filter_'.$filter['id'].'" class="spr_sysFilter'.$filter['type'].'" style="width:50px; float:left; text-align:left; padding-right:15px; text-align:right;">'.$filter['filter'].'</div>';
					echo '<div id="sysfilter_text_'.$filter['id'].'" class="spr_sysFilter'.$filter['type'].'" style="width:250px; float:left;">'.$filter['text'].'</div>';
				echo '</div>';
			}
		}
		else
		if ( $mode=='edit' || $mode=='new')
		{
			echo '<a href="/" onClick="sysFilterEditMode(\'normal\'); return false;">';
			echo '<span class="faicon mapca anketa small"></span>'
					.$lang['srv_settings_filter_view_mode']. '</a>';

				echo '<div style="clear:both; padding:5px; height:1.2em">';

				echo '<div style="width:40px; float:left; text-align:left; padding-right:15px; text-align:right">';
				echo '<i style="color:gray; text-align:right">'.$lang['srv_filter_id'].'</i>';
				echo '</div>';

				echo '<div style="width:50px; float:left; text-align:left; padding-right:15px;">';
				echo '<i style="color:gray;">'.$lang['srv_filter_vrednost'].'</i>';
				echo '</div>';

				echo '<div class="" style="width:250px; float:left; color: gray">';
				echo '<i style="color:gray;">'.$lang['srv_filter_variabla'].'</i>';
				echo '</div>';

				echo '</div>';
			foreach ( $filtri as $key => $filter)
			{

				echo '<div id="sysfilter_div_'.$filter['id'].'" style="clear:both; padding:5px; height:1.2em">';

				echo '<div id="sysfilter_filter_'.$filter['id'].'" class="" style="width:40px; float:left; text-align:left; padding-right:15px; color:gray; text-align:right;">'.$filter['fid'].'</div>';

				echo '<div id="sysfilter_filter_'.$filter['id'].'" class="" style="width:50px; float:left; text-align:left; padding-right:15px; text-align:right;">';
				echo '<input id="sysfilter_filter_input_'.$filter['id'].'" type="text" value="'.$filter['filter'].'" title="'.$filter['filter'].'" size="6" maxlength="6">';
				echo '</div>';

				echo '<div id="sysfilter_text_'.$filter['id'].'" class="" style="width:250px; float:left;">';
				echo  '<input id="sysfilter_text_input_'.$filter['id'].'" type="text" value="'.$filter['text'].'" title="'.$filter['text'].'" size="45" maxlength="100">';
				echo '</div>';

				if ( $filter['type'] == 3)
				{
					echo '<div id="sysfilter_edit_'.$filter['id'].'" class="" style="width:100px; float:left;">';
					echo '<a href="/" onClick="sysFilterDelete('.$filter['id'].'); return false;">';
					echo '<img id="sysfilter_delete_'.$filter['id'].'" src="img_'.$s->skin.'/delete_red.png" alt="'.$lang['srv_filtri_izbrisi_filter'].'" style="vertical-align:text-bottom " />';
					echo '</a>';
					echo '</div>';
				}
				echo '</div>';
				echo '<script>';
				echo '$(document).ready(function() {';
				echo '$("#sysfilter_delete_'.$filter['id'].'").click(function(e)  {});';
				echo '$("#sysfilter_filter_input_'.$filter['id'].'").blur(function(e)  {sysFilterSave('.$filter['id'].'); return false;});';
				echo '$("#sysfilter_text_input_'.$filter['id'].'").blur(function(e)  {sysFilterSave('.$filter['id'].'); return false;});';
				echo '$("#sysfilter_extra_'.$filter['id'].'").click(function(e)  {sysFilterExtraSetting('.$filter['id'].'); return false;});';

				echo '});';
				echo '</script>';
			}
			echo '<div class="clr"></div>';
			// pohendlamo error: duplicate
			if (self::$mySqlErrNo == 1062)
			{
				echo '<div id="error" class="red">';
				echo $lang['srv_duplicateEntry'];
				echo '</div>';
			}

			echo '<div id="sysfilter_new" style="padding-top:10px;">';
			if ($mode == 'new')
			{
				echo '<div id="sysfilter_div_add" style="clear:both; padding:5px; height:1.2em">';

				echo '<div id="sysfilter_filter_add" style="width:40px; float:left; text-align:left; padding-right:15px;">';
				echo '<input id="sysfilter_fid_input_add" type="text" value="'.$filter['fid'].'" title="'.$filter['fid'].'" size="6" maxlength="6">';
				echo '</div>';

				echo '<div id="sysfilter_filter_add" class="" style="width:50px; float:left; text-align:left; padding-right:15px;">';
				echo '<input id="sysfilter_filter_input_add" type="text" value="'.$filter['filter'].'" title="'.$filter['filter'].'" size="6" maxlength="6">';
				echo '</div>';

				echo '<div id="sysfilter_text_add" class="" style="width:250px; float:left;">';
				echo  '<input id="sysfilter_text_input_add" type="text" value="'.$filter['text'].'" title="'.$filter['text'].'" size="45" maxlength="100">';
				echo '</div>';

				echo '<div class="" style="width:50px; float:left;">';
				echo '<img id="sysfilter_add_img" src="icons/icons/accept.png" alt="'.$lang['srv_novfilter'].'" style="vertical-align:text-bottom " />';
				echo '</div>';
			}
			else
				echo '<img id="sysfilter_new_img" src="img_'.$s->skin.'/add.png" alt="'.$lang['srv_novfilter'].'" style="vertical-align:text-bottom " />'.$lang['srv_novfilter'];
			echo '</div>';
			echo '<script>';
			echo '$(document).ready(function() {';
			echo '$("#sysfilter_new_img").click(function(e) {sysFilterEditMode(\'new\'); return false;});';
			echo '$("#sysfilter_add_img").click(function(e) {sysFilterEditMode(\'add\'); return false;});';
			echo '});';
			echo '</script>';

		}

	}

	/**
	 * @desc polovimo nastavitev survey sistema
	 */
	private static $_sysMiscSetting = array();
	function getSysMiscSetting($what=null)
	{
		if (isset(self::$_sysMiscSetting[$what])) {
			return self::$_sysMiscSetting[$what];
		}
		else
		{
			$result = null;
			if (is_string($what))
			{
				$stringSelect = "SELECT value FROM srv_misc WHERE what = '".$what."'";
				$sqlSelect = sisplet_query($stringSelect);
				$rowSelect = mysqli_fetch_array($sqlSelect);
				if (mysqli_num_rows($sqlSelect) > 0)
					$result = $rowSelect['value'];
				else
					$result = '';
			}
			if($result == ''&&$what == 'export_data_type'){
				$result = 2;
			}			
			self::$_sysMiscSetting[$what] = $result;
			return self::$_sysMiscSetting[$what];
		}
	}
	/**
	 * @desc shranimo nastavitev survey sistema
	 */
	function setSysMiscSetting($what=null, $value=null)
	{
		if ( $what && $value )
		{
			if ( is_string($what) && is_string($value) )
			{
				$stringInsert = "INSERT INTO srv_misc (what, value) VALUES ('".$what."', '".$value."') ON DUPLICATE KEY UPDATE value = '".$value."'";
				$sqlInsert = sisplet_query($stringInsert);
				return mysqli_affected_rows($GLOBALS['connect_db']);
			}
			else
				return false;
		}
		else
			return false;
	}
}
/*
function getTableNextAutoIncrement($tableName)
{
	$next_increment 	= 0;
	$qShowStatus 		= "SHOW TABLE STATUS LIKE '$tableName'";
	$qShowStatusResult 	= sisplet_query($qShowStatus) or die ( "Query failed: " . mysqli_error($GLOBALS['connect_db']) . "<br/>" . qShowStatus );


	while ($row = mysqli_fetch_assoc($qShowStatusResult)) {
		$next_increment = $row['Auto_increment'];
	}
	mysqli_free_result($qShowStatusResult);
	return $next_increment;


}
*/
?>