summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyBaseSetting.php
blob: 8f107db9323bf671dfedb5471d5ddcb271c24301 (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
<?php
/** Class ki skrbi za osnovne nastavitve ankete - tabela srv_survey
 *  November 2011
 * 
 * 
 * Enter description here ...
 * @author Gorazd_Veselic
 *
 */
class SurveyBaseSetting
{
	private $sid;
	private $return = array('error' => 1, 'msg'=>'','action'=>'0');
	
	function __construct($sid) {
		if ((int)$sid > 0) {
			$this->sid = $sid;
			$this->return['msg'] = 'Napaka!'; # osnovno sporočilo o napaki
		} else {
			echo json_encode(array('error' => 1, 'msg'=>'Invalid Survey ID!'));
			exit();
		}
	}
	
	function ajax() {
		switch ($_GET['a']) {
			case 'radio':
				$this->saveSettingRadio();
			break;

			case 'text':
				$this->saveSettingText();
			break;
			
			default:
				;
			break;
		}
		echo json_encode($this->return);
		exit();
	}
	
	function saveSettingRadio() {
		if (isset($_POST['what']) && isset($_POST['value'])) {
			$what = trim($_POST['what']);
			$value = trim($_POST['value']);
			
			# ali refreshamo timestamp, da vsilimo refresh podatkov, oziroma ponastavimo še kakšne druge stvari
			switch ($what) {
				case 'show_email':
					global $global_user_id;
					$sql = sisplet_query("UPDATE srv_anketa SET edit_uid = '$global_user_id', edit_time=NOW() WHERE id='".$this->sid."'");
				break;
				# če nastavimo individualiziran url nazaj na 1 (=DA) potem obvezno vklopimo prikazovanje uvoda
				case 'individual_invitation':
					if ((int)$value > 0) {
						$sql = sisplet_query("UPDATE srv_anketa SET show_intro = '1' WHERE id='".$this->sid."'");
					}
				default:
					;
				break;
			} 
			
			$updateString = "UPDATE srv_anketa SET ".$what."='".$value."' WHERE id='".$this->sid."'";
			$update = sisplet_query($updateString);
			sisplet_query("COMMIT");
			$this->return['msg'] = 'Updated:'.$update;		
			$this->return['error'] = 0;		
		}
	}
	
	function saveSettingText() {
		if (isset($_POST['what']) && isset($_POST['value'])) {
			$what = trim($_POST['what']);
			$value = trim($_POST['value']);
			$updateString = "UPDATE srv_anketa SET ".$what."='".$value."' WHERE id='".$this->sid."'";
			$update = sisplet_query($updateString);
			sisplet_query("COMMIT");
			$this->return['msg'] = 'Updated:'.$update;		
			$this->return['error'] = 0;		
		}
	}
	
}