summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyUserSetting.php
blob: f93782eb69bd987535f965d244edd2bb0a45fdb4 (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
<?php
/**
 * Created on 4.5.2009
 *
 * @author: GOrazd Vesleič
 *
 * @desc: za nastavitve uporabnikov, za vsako anketo posebej
 */

 class SurveyUserSetting
{
	static private $instance;

	static private $surveyId = null;
	static private $userId = null;
	static private $inited = false;
	 static private $rowUserInit = null;

	protected function __construct() {}

	private function __clone() {}

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

	/** napolnimo podatke
	 *
	 */
	static function Init($_surveyId, $_userId)
	{
		if ($_surveyId && $_userId)
		{
			self::$surveyId = $_surveyId;
			self::$userId = $_userId;
			
			self::$inited=true;
			return true;
		}
		else
			return false;
	}

	static function getSurveyId()			{ return self::$surveyId; }
	static function getUserId()				{ return self::$userId; }

	static function useIfinReport()			{ // stara funkcija
		$use_if_in_report = self::getSettings('use_if_in_report');
		if ($use_if_in_report == null)
			$use_if_in_report = 1;
		return $use_if_in_report; }

	static function setShowPdfIf($set)		{ // stara funkcija
		$value = $set?1:0;
		self::saveSettings('use_if_in_report', $value);
	}


	static function getSettings($what) {

		$selectSql = "SELECT value FROM srv_user_setting_for_survey WHERE sid = '".(!is_array(self::$surveyId)?self::$surveyId:self::$surveyId['id'])."' AND uid = '".self::$userId."' AND what = '".$what."'";
		$sqlUserSetting = sisplet_query($selectSql);
		$rowUserSetting = mysqli_fetch_assoc($sqlUserSetting);

		return $rowUserSetting['value'] ?? null;
	}
	
	static function getAll() {
		$result = array();
		$selectSql = "SELECT what, value FROM srv_user_setting_for_survey WHERE sid = '".self::$surveyId."' AND uid = '".self::$userId."'";
		$sqlUserSetting = sisplet_query($selectSql);
        while (list($what,$value) =mysqli_fetch_row($sqlUserSetting))
        {
        	$result[] = array('what'=>$what,'value'=>$value);
        }
		return $result;
	}

	static function saveSettings($what, $value) {

		if ($what != null) {
	    	$insertString = "INSERT INTO srv_user_setting_for_survey  (sid, uid, what, value) VALUES " .
	    		"('".self::$surveyId."', '".self::$userId."', '".$what."', '".$value."') " .
	    		"ON DUPLICATE KEY UPDATE value='".$value."'";
	    	$insert = sisplet_query($insertString);
	    	sisplet_query('COMMIT');
		}

		return $insert;
	}
	static function removeSettings($what) {
		if ($what != null) {
	    	$deleteString = "DELETE FROM srv_user_setting_for_survey WHERE sid = '".self::$surveyId."' AND uid = '".self::$userId."' AND what = '".$what."'";
	    	$delete = sisplet_query($deleteString);
		}

		return $delete;
	}

	 static function getUserRow () {
		 global $global_user_id;

		 if (!self::$rowUserInit) {
			 $queryUserInit = sisplet_query("SELECT * FROM users WHERE id = '".$global_user_id."'");
			 self::$rowUserInit = mysqli_fetch_assoc($queryUserInit);
		 }

		 return self::$rowUserInit;
	 }

}
?>