summaryrefslogtreecommitdiffstats
path: root/admin/survey/modules/mod_chat/class.SurveyChat.php
blob: 6afa62428906610d6eff5c464e2d1c4094548e1b (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
<?php

/*
 *  Modul za chat z respondenti
 * 
 *	Zaenkrat se uporablja storitev TAWK
 *
 */


class SurveyChat{

	var $anketa;				# id ankete

	
	function __construct($anketa){
		global $site_url;

		// Ce imamo anketo
		if ((int)$anketa > 0){
			$this->anketa = $anketa;
		}
	}
	
	
	// Nastavitve chat-a (na kateri strani se prikaze...)
	public function displaySettings(){
		global $lang;
		global $site_url;
		
		$preklici_url = ltrim(str_replace("&s=1","",$_SERVER['REQUEST_URI']),"/");
		$preklici_url = "'". $site_url . $preklici_url . "'";
    	
		$row = SurveyInfo::getInstance()->getSurveyRow();
		
		
		echo '<fieldset><legend>'.$lang['settings'].'</legend>';
			
		// Koda za embed tawk chat widgeta
		$code = '';
		$sql = sisplet_query("SELECT * FROM srv_chat_settings WHERE ank_id='".$this->anketa."'");
		if(mysqli_num_rows($sql) > 0){
			
			$row = mysqli_fetch_array($sql);
			$code = $row['code'];
		}

		echo '<p class="bottom16">'.$lang['srv_vrsta_survey_note_14_1a'].':</p>';

		echo '<div class="setting_holder">';
		echo '<p class="bold">'.$lang['srv_chat_code'].':</p>';
		echo '<textarea class="wauto" id="chat_code" name="chat_code">'.$code.'</textarea>';
		echo '</div>'; 
		
		// Prikaz vklopa chata
		echo '<p class="top16 bottom16">'.$lang['srv_vrsta_survey_note_14_1c'].'</p>';

		echo '<div class="setting_holder">';
		echo '<span class="bold setting_title">'.$lang['srv_chat_type'].':</span>';

		echo '<div class="setting_item">';
		echo '<input type="radio" name="chat_type" id="chat_type_0" value="0" '.(($row['chat_type'] == 0) ? ' checked="checked" ' : '').' />';
		echo '<label for="chat_type_0">'.$lang['srv_chat_type_0'].'</label>';
		echo '</div>';
		echo '<div class="setting_item">';
		echo '<input type="radio" name="chat_type" id="chat_type_1" value="1" '.(($row['chat_type'] == 1) ? ' checked="checked" ' : '').' />';
		echo '<label for="chat_type_1">'.$lang['srv_chat_type_1'].'</label>';	
		echo '</div>';
		echo '<div class="setting_item">';
		echo '<input type="radio" name="chat_type" id="chat_type_2" value="2" '.(($row['chat_type'] == 2) ? ' checked="checked" ' : '').' />';
		echo '<label for="chat_type_2">'.$lang['srv_chat_type_2'].'</label>';	
		echo '</div>';
					
		echo '</div>';

		echo '</fieldset>';
		
		
		// Gumb shrani
		echo '<div class="button_holder">';
		echo '<button class="medium white-blue" onClick="window.location='.$preklici_url.'; return false;">'.$lang['edit1338'].'</button>';				
		echo '<button class="medium blue" onclick="chat_save_settings(); return false;">'.$lang['edit1337'].'</button>';
		echo '</div>';

		echo '<div id="success_save"></div>';	
	}
	
	
	public function ajax() {
		
		if(isset($_GET['a']) && $_GET['a'] == 'save_settings'){
			
			$code = isset($_POST['code']) ? $_POST['code'] : '';
			$chat_type = isset($_POST['chat_type']) ? $_POST['chat_type'] : '0';
			
			$sql = sisplet_query("INSERT INTO srv_chat_settings 
									(ank_id, code, chat_type) VALUES ('".$this->anketa."', '".$code."', '".$chat_type."') 
									ON DUPLICATE KEY UPDATE code='".$code."', chat_type='".$chat_type."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
		}

	}
}