summaryrefslogtreecommitdiffstats
path: root/admin/survey/modules/mod_slideshow/class.SurveySlideshow.php
blob: 17184754af11de555b8dbc9237d315252f25c146 (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
<?php
	
class SurveySlideshow {
	
	private $sid = null;
	private $settings = array();
	
	public function __construct($anketa = null) {
		if ($anketa == null) {
			die("class.SurveySlideshow -> anketa ID missing!");
		}
		
		$this->sid = $anketa;
		SurveyInfo::getInstance()->SurveyInit($anketa);
		$this->reloadSettings(); 

	}
	
	public function ajax() {
		if ($this->sid != null) {
			switch ($_GET['a']) {
				case 'reset_interval' :
					$this->ResetSlideshowInterval();
					$this->ShowSlideshowSetings();
					break;		
				case 'save_settings' :
					$this->SaveSlideshowSettings();
					break;		
				default:			
					print_r("<pre>");
					print_r($_POST);
					print_r($_GET);
					break;
			}			
			
		} else {
			die("Class Slideshow not inited!");
		}
	}
	
	/** prebere nastavitve iz baze
	 * 
	 */
	public function reloadSettings() {
		$slide_settings_qry = sisplet_query("SELECT * FROM srv_slideshow_settings WHERE ank_id='$this->sid'");
		$slide_settings = mysqli_fetch_assoc($slide_settings_qry);
		$this->settings = $slide_settings; 	

	}

	/** vrne vse nastavitve ali posamezno vrednost nastavitev za slideshow
	 * 
	 */
	public function getSettings($what = null) {
		if (!is_countable($this->settings) || !count($this->settings) > 0) {
			$this->reloadSettings();
		}
		
		if ($what == null) {
			return $this->settings;
		} else {
			return $this->settings[$what];
		}
	}
	
	/**
    * posebne opcije in navodile za anketo slideshow
    */
    public function ShowSlideshowSetings () {
    	global $lang;
    	
		$row = SurveyInfo::getInstance()->getSurveyRow();
		
		$slide_settings_qry = sisplet_query("SELECT * FROM srv_slideshow_settings WHERE ank_id='$this->sid'");
		$slide_settings = mysqli_fetch_assoc($slide_settings_qry);

		echo '<fieldset><legend>'.$lang['settings'].'</legend>';
		
		#set timer interval
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="timer" >' . $lang['srv_slideshow_set_timer'] . '&nbsp;</label></span>';
		echo '<label for="slide_fixed_interval" >' . $lang['srv_slideshow_set_fixed'] . '&nbsp;</label>';
		echo '<input type="checkbox" id="slide_fixed_interval" name="slide_fixed_interval" value="1"' . ($slide_settings['fixed_interval'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<select name="slideshow_timer" id="slideshow_timer">';
		# od 1-15 mamo za vsako sekundo
		for ($t = 1; $t < 15; $t += 1) {
			echo '<option value="' . $t . '"' . (($t == $slide_settings['timer']) ? ' selected' : '') . '>';
			echo '' . (substr(bcdiv($t, 60), 0, 4)) . '' . $lang['srv_minutes'] . ' ';
			echo '' . (bcmod($t, 60)) . '' . $lang['srv_seconds'] . '';
			echo '</option>';
		}
		#od 15 do 600 mamo na 15s 		
		for ($t = 15; $t <= 600; $t += 15) {
			echo '<option value="' . $t . '"' . (($t == $slide_settings['timer']) ? ' selected' : '') . '>';
			echo '' . (substr(bcdiv($t, 60), 0, 4)) . '' . $lang['srv_minutes'] . ' ';
			echo '' . (bcmod($t, 60)) . '' . $lang['srv_seconds'] . '';
			echo '</option>';
		}
		echo '</select>&nbsp;';
		echo '<span class="as_link" id="link_slideshow_reset_interval" title="' . $lang['srv_slideshow_link_reset_interval'] . '">' . $lang['srv_slideshow_link_reset_interval'] . '</span><br/>' . NEW_LINE;
		echo '</div>'; // slide_sett_option 

		#save entries
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="save_entries" >' . $lang['srv_slideshow_sett_save_entries_lbl'] . '&nbsp;</label></span>';
		echo '<input type="radio" id="slide_save_entries_0" name="slide_save_entries" value="0"' . ($slide_settings['save_entries'] == 0 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_save_entries_0" >' . $lang['srv_slideshow_sett_save_entries_opt_0'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_save_entries_1" name="slide_save_entries" value="1"' . ($slide_settings['save_entries'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_save_entries_1" >' . $lang['srv_slideshow_sett_save_entries_opt_1'] . '&nbsp;</label>';
		echo '</div>'; // slide_sett_option 

		#autostart
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="timer" >' . $lang['srv_slideshow_sett_autostart_lbl'] . '&nbsp;</label></span>';
		echo '<input type="radio" id="slide_autostart_0" name="slide_autostart" value="0"' . ($slide_settings['autostart'] == 0 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_autostart_0" title="' . $lang['srv_slideshow_sett_autostart_opt_0'] . '">' . $lang['srv_slideshow_sett_autostart_opt_0_short'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_autostart_1" name="slide_autostart" value="1"' . ($slide_settings['autostart'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_autostart_1" title="' . $lang['srv_slideshow_sett_autostart_opt_1'] . '">' . $lang['srv_slideshow_sett_autostart_opt_1_short'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_autostart_2" name="slide_autostart" value="2"' . ($slide_settings['autostart'] == 2 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_autostart_2" title="' . $lang['srv_slideshow_sett_autostart_opt_2'] . '">' . $lang['srv_slideshow_sett_autostart_opt_2_short'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_autostart_3" name="slide_autostart" value="3"' . ($slide_settings['autostart'] == 3 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_autostart_3" title="' . $lang['srv_slideshow_sett_autostart_opt_3'] . '">' . $lang['srv_slideshow_sett_autostart_opt_3_short'] . '&nbsp;</label>';
		echo '</div>'; // slide_sett_option 
		
		#next  button
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="next" >' . $lang['srv_slideshow_sett_next_button_lbl'] . '&nbsp;</label></span>';
		echo '<input type="radio" id="slide_next_0" name="slide_next" value="0"' . ($slide_settings['next_btn'] == 0 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_next_0" >' . $lang['srv_slideshow_sett_button_opt_0'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_next_1" name="slide_next" value="1"' . ($slide_settings['next_btn'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_next_1" >' . $lang['srv_slideshow_sett_button_opt_1'] . '&nbsp;</label>';
		echo '</div>'; // slide_sett_option 
		
		#back  button
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="back" >' . $lang['srv_slideshow_sett_back_button_lbl'] . '&nbsp;</label></span>';
		echo '<input type="radio" id="slide_back_0" name="slide_back" value="0"' . ($slide_settings['back_btn'] == 0 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_back_0" >' . $lang['srv_slideshow_sett_button_opt_0'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_back_1" name="slide_back" value="1"' . ($slide_settings['back_btn'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_back_1" >' . $lang['srv_slideshow_sett_button_opt_1'] . '&nbsp;</label>';
		echo '</div>'; // slide_sett_option 

		#pause button
		echo '<div class="slide_sett_option">';
		echo '<span class="slide_sett_option_lbl" ><label for="pause" >' . $lang['srv_slideshow_sett_pause_button_lbl'] . '&nbsp;</label></span>';
		echo '<input type="radio" id="slide_pause_0" name="slide_pause" value="0"' . ($slide_settings['pause_btn'] == 0 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_pause_0" >' . $lang['srv_slideshow_sett_button_opt_0'] . '&nbsp;</label>';
		echo '<input type="radio" id="slide_pause_1" name="slide_pause" value="1"' . ($slide_settings['pause_btn'] == 1 ? ' checked' : '') . '>&nbsp;';
		echo '<label for="slide_pause_1" >' . $lang['srv_slideshow_sett_button_opt_1'] . '&nbsp;</label>';
		echo '</div>'; // slide_sett_option 
		echo '</fieldset>';
		
		#saving
		echo '<br class="clr" />';
		echo '<span class="floatLeft spaceRight"><div class="buttonwrapper"><a class="ovalbutton ovalbutton_orange btn_savesettings" href="#" onclick="slideshow_save_settings(); return false;"><span>';
		echo $lang['edit1337'] . '</span></a></div></span>';
		echo '<div class="clr"></div>';
		echo '<div id="success_save"></div>';		
		
    }
    
    function ResetSlideshowInterval() {
    	if ((int)$_POST['timer'] > 0 && $this->sid > 0) {
    		$timer = (int)$_POST['timer'];
    		$fixed_interval = (int)$_POST['fixed_interval'];
			# shranimo v bazo
    		$sqlInsertString = "INSERT INTO srv_slideshow_settings (ank_id, fixed_interval, timer) VALUES ('$this->sid', '$fixed_interval', '$timer' ) ON DUPLICATE KEY UPDATE fixed_interval = '$fixed_interval', timer = '$timer' ";		    		
			$sqlInsertQry = sisplet_query($sqlInsertString);
			
			# ponastavimo timerje pri vprašanjih
			#zloopamo skozi vprašanja
			$_spr_ids = array();
			$sql = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->sid'");
			while($row = mysqli_fetch_assoc($sql)) {
				$_spr_ids[] = $row['id'];
			}

			if (count($_spr_ids) > 0) {
				$update_str = "UPDATE srv_spremenljivka SET timer = '".(int)$_POST['timer']."' WHERE id IN (".implode(',',$_spr_ids).")";
				$update_qry = sisplet_query($update_str);

				# spremenimo timestamp
				Common::updateEditStamp();
			}				
    	}
    }

    /**
     */
    function setSlideshowSkin() {
    	global $site_path, $site_url;
    	# ko prvič nastavimo nastavitve, nastavimo skin ankete na: slideshow, če obstaja
    	$row = SurveyInfo::getInstance()->getSurveyRow();

    	$slide_settings_qry = sisplet_query("SELECT * FROM srv_slideshow_settings WHERE ank_id='$this->sid'");
    	if (mysqli_num_rows($slide_settings_qry) ==  0 ) {
    		$prefix = '';
    		$sql_string = null;
    		
    		# skin nastavimo samo prvič, če uporabnik še ni ničesar spreminjal in če fajl fizično obstaja
    		$dir = $site_path . 'main/survey/skins/';
    		$skin_name = 'Slideshow';

    		if (file_exists($dir.$skin_name.'.css')) {
				$sql_string .= $prefix." skin='$skin_name'";
				$prefix = ',';
			}

			$sql_string .= $prefix." concl_link='1', concl_back_button='0'";
    		$prefix = ',';
    		
    		$sql_string .= $prefix." progressbar='0'";
    		$prefix = ',';
    		
    		$sql_string .= $prefix." url = '".SurveyInfo::getSurveyLink() ."?preview=on'";

    		if ($sql_string != null) {
    			$sql = sisplet_query("UPDATE srv_anketa SET".$sql_string." WHERE id='$this->sid'");
    		}
    		#vstavimo še osnovni zapis v tabelo nastavitev slideshovow
    		$slide_settings_qry = sisplet_query("INSERT INTO srv_slideshow_settings  (ank_id) VALUES ('$this->sid')");

    	}
    }
    
    /** shrani nastavitve prezentacije za posamezno anketo
     * 
     * Enter description here ...
     */
    private function SaveSlideshowSettings() {
		
		$timer = (int)$_POST['timer'];
    	$fixed_interval = (int)$_POST['fixed_interval'];
    	$save_entries = (int)$_POST['save_entries'];
    	$autostart = (int)$_POST['autostart'];
    	$next_btn = (int)$_POST['next_btn'];
    	$back_btn = (int)$_POST['back_btn'];
    	$pause_btn = (int)$_POST['pause_btn'];

    	# shranimo v bazo
    	$sqlInsertString = "INSERT INTO srv_slideshow_settings". 
    		" (ank_id, fixed_interval, timer, save_entries, autostart, next_btn, back_btn, pause_btn)".
    		" VALUES ('$this->sid', '$fixed_interval', '$timer', '$save_entries', '$autostart', '$next_btn', '$back_btn', '$pause_btn' )".
    		" ON DUPLICATE KEY UPDATE fixed_interval = '$fixed_interval', timer = '$timer', save_entries = '$save_entries', autostart = '$autostart', next_btn = '$next_btn', back_btn = '$back_btn', pause_btn = '$pause_btn' ";		    		

    	$sqlInsertQry = sisplet_query($sqlInsertString);
    }
}