summaryrefslogtreecommitdiffstats
path: root/admin/survey/modules/mod_hierarhija/class/Ajax/AjaxHierarhijaDostopUporabnikovClass.php
blob: 652cfa96b12513b1f041073b81b44a999cefcb9c (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
<?php
/***************************************
 * Description: Omogočanje dostopa za SA modul
 * Autor: Robert Šmalc
 * Created date: 28.09.2017
 *****************************************/

namespace Hierarhija\Ajax;


class AjaxHierarhijaDostopUporabnikovClass {

	public function __construct()
	{
		global $admin_type;

		if($admin_type != 0)
			return false;

		if (!$this->isAjax())
			return redirect('/admin/survey/');
	}

	public function popupNew($id = null){
		$user = null;

		if(!empty($id)) {
			$user = sisplet_query("SELECT id, u.name, u.surname, u.email, d.ustanova, d.aai_email FROM srv_hierarhija_dostop AS d LEFT JOIN users AS u ON u.id=d.user_id WHERE id='".$id."'", "obj");

			if(empty($user->email))
				$user = null;
		}

		global $lang;
		echo '<div class="sa-modul">';

		echo '<div>';
		if(!empty($user)){
			echo '<h2> Urejanje uporabnika <span class="red">'.$user->name.' ' .$user->surname.'</span> za dostop do SA modula</h2>';
		}else {
			echo '<h2> Vpiši uporabnika za dostop do SA modula</h2>';
		}
		echo '<div>';

		// EMAIL
		echo '<div style="width: 100%;">';
		echo '<label>Elektronski naslov</label><br/>';
			if(!empty($user)){
				echo '<input type="email" value="'.$user->email .'" disabled="disabled" style="width: 80%; padding: 4px; margin: 2px 0;"/>';
			}else{
				echo '<input type="email" 
	                        value="" 
	                        placeholder="janez.novak@sola.si" 
	                        id="sa-email" 
	                        onblur="preveriVpisanEmailZaSAdostop()"
	                        required="required" 
	                        style="width: 80%; padding: 4px; margin: 2px 0;"/>';
				echo '<input type="hidden" value="" id="sa-id" "/>';
				echo '<span id="sa-email-sporocilo"></span>';
			}
		echo '</div>';

		// Organizzacija
		echo '<div style="padding:15px 0;width: 100%;">';
		echo '<label>Šola oz. javni zavod</label><br/>';
		echo '<input type="text" value="'.(!empty($user) ? $user->ustanova : NULL).'" placeholder="Srednja šola" id="sa-ustanova" required="required" style="width: 80%; padding: 4px; margin: 2px 0;"/>';
		echo '</div>';

		// Email za AAI dostop
		echo '<div style="padding-bottom:15px; width: 100%;">';
		echo '<label>Elektronski naaslov za AAI dostop (v kolikor je primarni email drugačen od AAI dostopa)</label><br/>';
		echo '<input type="email" value="'.(!empty($user) ? $user->aai_email : NULL).'" placeholder="janez.novak@guest.arnes.si" id="sa-aai" style="width: 80%; padding: 4px; margin: 2px 0;"/>';
		echo '</div>';

		echo '</div>';
		echo '</div>';

		// Gumb za zapret popup in potrdit
		echo '<div class="sa-modul">';
		echo '<div class="buttonwrapper spaceRight floatLeft">';
		if(!empty($user)) {
			echo '<a class="ovalbutton ovalbutton_orange sa-potrdi" href="#" onclick="posodobiSAuporabnika(\'' . $user->id . '\')"; return false;"><span>' . $lang['srv_potrdi'] . '</span></a>' . "\n\r";
		}else {
			echo '<a class="ovalbutton ovalbutton_orange sa-potrdi" href="#" onclick="shraniSAuporabnika()"; return false;"><span>' . $lang['srv_potrdi'] . '</span></a>' . "\n\r";
		}
		echo '</div>';

		echo '<div class="buttonwrapper spaceRight floatLeft">';
		echo '<a class="ovalbutton ovalbutton_gray" href="#" onclick="vrednost_cancel(); return false;"><span>' . $lang['srv_close_profile'] . '</span></a>' . "\n\r";
		echo '</div>';
		echo '</div>';

		echo '</div>';

	}

	public function save(){
		$email = (!empty($_POST['email']) ? $_POST['email'] : null);
		$user_id = (!empty($_POST['id']) ? $_POST['id'] : null);
		$ustanova = (!empty($_POST['ustanova']) ? $_POST['ustanova'] : null);
		$aai_email = (!empty($_POST['aai']) ? $_POST['aai'] : null);

		$uporabnik = sisplet_query("SELECT id, email FROM users WHERE email='".$email."'", "obj");
		if($uporabnik->id != $user_id)
			return false;

		sisplet_query("INSERT INTO srv_hierarhija_dostop (user_id, dostop, ustanova, aai_email) VALUES ('".$uporabnik->id."', '1', '".$ustanova."', '".$aai_email."')");

		echo 'success';
	}

	public function update(){
		$user_id = (!empty($_POST['id']) ? $_POST['id'] : null);
		$ustanova = (!empty($_POST['ustanova']) ? $_POST['ustanova'] : null);
		$aai_email = (!empty($_POST['aai']) ? $_POST['aai'] : null);

		sisplet_query("UPDATE srv_hierarhija_dostop SET ustanova='".$ustanova."' , aai_email='".$aai_email."' WHERE user_id='".$user_id."'");

		echo 'success';
	}

	public function delete(){
		$user_id = (!empty($_POST['id']) ? $_POST['id'] : null);

		sisplet_query("DELETE FROM srv_hierarhija_dostop WHERE user_id='".$user_id."'");
	}

	public function checkUserEmail(){
		$email = (!empty($_POST['email']) ? $_POST['email'] : null);

		if(!validEmail($email)) {
			echo json_encode([
				                 'tip' => 'error',
				                 'sporocilo' => 'Napačen email.'
			                 ]);

			return FALSE;
		}

		$uporabnik = sisplet_query("SELECT id, email FROM users WHERE email='".$email."'", "obj");

		if(empty($uporabnik)) {
			echo json_encode([
				                 'tip' => 'error',
				                 'sporocilo' => 'Uporabnika z omenjenim emailom ni v bazi.'
			                 ]);

			return FALSE;
		}

		echo json_encode([
			                 'tip' => 'success',
			                 'sporocilo' => 'Email pravilen, ker uporabnik obstaja v bazi.',
			                 'id' => $uporabnik->id
		                 ]);
	}

	public function show(){
		global $lang;
		global $global_user_id;
		global $admin_type;

		$user_id = (!empty($_POST['id']) ? $_POST['id'] : null);

		if(is_null($user_id))
			return false;


		echo '<div style="float: right; width: 250px; max-height: 345px; overflow-y: auto">';
		echo '<h3><strong>'.$lang['srv_ankete'].'</strong></h3>';

		echo '<ul>';
		$sql = sisplet_query("SELECT srv_anketa.id, srv_anketa.naslov FROM srv_dostop, srv_anketa WHERE srv_dostop.uid='$user_id' AND srv_dostop.ank_id=srv_anketa.id ORDER BY srv_anketa.edit_time DESC");
		while ($row = mysqli_fetch_array($sql)) {
			echo '<li><a href="#" onclick="anketa_user_dostop(\''.$uid.'\', \''.$row['id'].'\'); return false;">'.$row['naslov'].'</a></li>';
		}

		echo '</ul>';
		echo '</div>';

		$user = sisplet_query("SELECT id, u.name, u.surname, u.email, d.ustanova, d.aai_email, u.type, u.status, DATE_FORMAT(d.created_at, '%d.%m.%Y - %H:%i') AS created, DATE_FORMAT(d.updated_at, '%d.%m.%Y - %H:%i') AS updated FROM srv_hierarhija_dostop AS d LEFT JOIN users AS u ON u.id=d.user_id WHERE user_id='".$user_id."'", "obj");

		echo '<div class="sa-modul">';
		echo '<h3><strong>'.$lang['user2'].'</strong></h3>';
		echo '<p><label for="type">'.$lang['admin_type'].':</label>';
			switch ($user->type){
				case 0:
					echo $lang['admin_manager'];
					break;
				case 1:
					 echo $lang['admin_manager'];
					 break;
				case 2:
					echo $lang['admin_clan'];
					break;
				default:
					echo $lang['admin_narocnik'];
			}
		echo '</p>';
		echo '<p><label for="status">'.$lang['status'].':</label>';
		switch ($user->status){
			case 0:
				echo $lang['srv_user_banned'];
				break;
			case 1:
				echo $lang['srv_user_notbanned'];
				break;
		}
		echo '</p>';
		echo '<p><label for="email">'.$lang['email'].':</label>'.$user->email.'</p>';
		echo '<p><label for="name">'.$lang['name'].':</label>'.$user->name.'</p>';
		echo '<p><label for="surname">'.$lang['surname'].':</label>'.$user->surname.'</p>';
		echo '<p><label for="ustanova">'.$lang['srv_hierarchy_users_organization'].':</label>'.$user->ustanova.'</p>';
		echo '<p><label for="aai_uporabnik">'.$lang['srv_hierarchy_users_aai'].':</label>'.$user->aai_email.'</p>';
		echo '<p><label for="created">'.$lang['srv_hierarchy_users_created'].':</label>'.$user->created.'</p>';
		echo '<p><label for="updatetd">'.$lang['srv_hierarchy_users_updated'].':</label>'.$user->updated.'</p>';

		// Gumb za zapret popup in potrdit
		echo '<div style="    display: block;">';
			echo '<div class="buttonwrapper spaceRight floatLeft">';
			echo '<a class="ovalbutton ovalbutton_gray" href="#" onclick="vrednost_cancel(); return false;"><span>' . $lang['srv_close_profile'] . '</span></a>' . "\n\r";
			echo '</div>';
		echo '</div>';
		echo '</div>';


	}


	/**
	 * Preverimo, če je ajax request
	 *
	 * @return boolean
	 */
	private function isAjax()
	{
		if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
			return true;

		return false;
	}

}