1 | <?php |
---|
2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
4 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
5 | |
---|
6 | class db_functions |
---|
7 | { |
---|
8 | var $db; |
---|
9 | var $user_id; |
---|
10 | var $ldap_functions; |
---|
11 | |
---|
12 | function db_functions() |
---|
13 | { |
---|
14 | if (is_array($_SESSION['phpgw_info']['expresso']['server'])) |
---|
15 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; |
---|
16 | else |
---|
17 | $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server']; |
---|
18 | |
---|
19 | $this->db = new db(); |
---|
20 | $this->db->Halt_On_Error = 'no'; |
---|
21 | $this->db->connect( |
---|
22 | $_SESSION['phpgw_info']['expresso']['server']['db_name'], |
---|
23 | $_SESSION['phpgw_info']['expresso']['server']['db_host'], |
---|
24 | $_SESSION['phpgw_info']['expresso']['server']['db_port'], |
---|
25 | $_SESSION['phpgw_info']['expresso']['server']['db_user'], |
---|
26 | $_SESSION['phpgw_info']['expresso']['server']['db_pass'], |
---|
27 | $_SESSION['phpgw_info']['expresso']['server']['db_type'] |
---|
28 | ); |
---|
29 | $this->user_id = $_SESSION['phpgw_info']['expresso']['user']['account_id']; |
---|
30 | } |
---|
31 | |
---|
32 | // BEGIN of functions. |
---|
33 | function read_acl($account_lid) |
---|
34 | { |
---|
35 | $query = "SELECT * FROM phpgw_expressoadmin WHERE manager_lid = '" . $account_lid . "'"; |
---|
36 | $this->db->query($query); |
---|
37 | while($this->db->next_record()) |
---|
38 | $result[] = $this->db->row(); |
---|
39 | return $result; |
---|
40 | } |
---|
41 | |
---|
42 | function copy_manager($params) |
---|
43 | { |
---|
44 | $manager = $params['manager']; |
---|
45 | $new_manager = $params['new_manager']; |
---|
46 | $manager_info = $this->read_acl($manager); |
---|
47 | |
---|
48 | //Escrevre no Banco a ACL do gerente |
---|
49 | $sql = "INSERT INTO phpgw_expressoadmin (manager_lid, context, acl) " |
---|
50 | . "VALUES('" . $new_manager . "','" . $manager_info[0]['context'] . "','" . $manager_info[0]['acl'] . "')"; |
---|
51 | |
---|
52 | if (!$this->db->query($sql)) |
---|
53 | { |
---|
54 | echo 'Erro em copy_manager:' . pg_last_error(); |
---|
55 | return false; |
---|
56 | } |
---|
57 | |
---|
58 | //Pesquisa no Banco e pega os valores dos apps. |
---|
59 | $sql = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $manager_info[0]['manager_lid'] . "' AND context = '" . $manager_info[0]['context'] . "'"; |
---|
60 | $this->db->query($sql); |
---|
61 | while($this->db->next_record()) |
---|
62 | { |
---|
63 | $aplications[] = $this->db->row(); |
---|
64 | } |
---|
65 | |
---|
66 | //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios. |
---|
67 | for ($i=0; $i<count($aplications); $i++) |
---|
68 | { |
---|
69 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
70 | . "VALUES('" . $new_manager . "','" . $manager_info[0]['context'] . "','" . $aplications[$i]['app'] . "')"; |
---|
71 | if (!$this->db->query($sql)) |
---|
72 | { |
---|
73 | echo 'Erro adicionando aplicacão para o novo gerente:' . pg_last_error(); |
---|
74 | return false; |
---|
75 | } |
---|
76 | } |
---|
77 | return true; |
---|
78 | } |
---|
79 | |
---|
80 | function get_next_id($type) |
---|
81 | { |
---|
82 | $return['status'] = true; |
---|
83 | |
---|
84 | $current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
85 | |
---|
86 | if ($current_config['expressoAdmin_nextid_db_host'] != '') |
---|
87 | { |
---|
88 | $this->db->disconnect(); |
---|
89 | $host = $current_config['expressoAdmin_nextid_db_host']; |
---|
90 | $port = $current_config['expressoAdmin_nextid_db_port']; |
---|
91 | $name = $current_config['expressoAdmin_nextid_db_name']; |
---|
92 | $user = $current_config['expressoAdmin_nextid_db_user']; |
---|
93 | $pass = $current_config['expressoAdmin_nextid_db_password']; |
---|
94 | |
---|
95 | $db = new db(); |
---|
96 | $db->Halt_On_Error = 'no'; |
---|
97 | $db->connect($name, $host, $port, $user, $pass, 'pgsql'); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | $db = $this->db; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | // Busco o ID dos accounts |
---|
106 | $query_accounts_nextid = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
107 | if (!$db->query($query_accounts_nextid)) |
---|
108 | { |
---|
109 | $return['status'] = false; |
---|
110 | $return['msg'] = "Problemas executando a query accounts no Banco de Dados."; |
---|
111 | $db->disconnect(); |
---|
112 | return $return; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | $accounts_nextid = $db->Query_ID->fields[0]; |
---|
117 | } |
---|
118 | |
---|
119 | // Busco o ID dos groups |
---|
120 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
121 | if (!$db->query($query_groups)) |
---|
122 | { |
---|
123 | $return['status'] = false; |
---|
124 | $return['msg'] = "Problemas executando a query groups no Banco de Dados."; |
---|
125 | $db->disconnect(); |
---|
126 | return $return; |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | $groups_nextid = $db->Query_ID->fields[0]; |
---|
131 | } |
---|
132 | |
---|
133 | //RetornO o maior dos ID's incrementado de 1 |
---|
134 | if ($accounts_nextid >= $groups_nextid) |
---|
135 | $id = $accounts_nextid; |
---|
136 | else |
---|
137 | $id = $groups_nextid; |
---|
138 | $return['id'] = (int)($id + 1); |
---|
139 | |
---|
140 | |
---|
141 | //aqui |
---|
142 | include_once(PHPGW_API_INC.'/class.ldap_functions.inc.php'); |
---|
143 | $this->ldap_functions = new ldap_functions; |
---|
144 | |
---|
145 | $searchUid = $this->ldap_functions->get_user_uidnumber($return['id']); |
---|
146 | while($searchUid) |
---|
147 | { |
---|
148 | $return['id'] += 133; |
---|
149 | $searchUid = $this->ldap_functions->get_user_uidnumber($return['id']); |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | // Atualizo o BD |
---|
154 | $query_update_id = "UPDATE phpgw_nextid set id = '" . $return['id'] . "' WHERE appname = '" . $type . "'"; |
---|
155 | if (!$db->query($query_update_id)) |
---|
156 | { |
---|
157 | $return['status'] = false; |
---|
158 | $return['msg'] = "Problemas executando a query update id no Banco de Dados."; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | $db->disconnect(); |
---|
164 | return $return; |
---|
165 | } |
---|
166 | |
---|
167 | /* |
---|
168 | function increment_id($id, $type) |
---|
169 | { |
---|
170 | $current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
171 | if ($current_config['expressoAdmin_nextid_db_host'] != '') |
---|
172 | { |
---|
173 | $this->db->disconnect(); |
---|
174 | $host = $current_config['expressoAdmin_nextid_db_host']; |
---|
175 | $port = $current_config['expressoAdmin_nextid_db_port']; |
---|
176 | $name = $current_config['expressoAdmin_nextid_db_name']; |
---|
177 | $user = $current_config['expressoAdmin_nextid_db_user']; |
---|
178 | $pass = $current_config['expressoAdmin_nextid_db_pass']; |
---|
179 | |
---|
180 | $db = new db(); |
---|
181 | $db->Halt_On_Error = 'no'; |
---|
182 | $db->connect($name, $host, $port, $user, $pass, 'pgsql'); |
---|
183 | } |
---|
184 | else |
---|
185 | { |
---|
186 | $db = $this->db; |
---|
187 | } |
---|
188 | |
---|
189 | $sql = "UPDATE phpgw_nextid set id = '".$id."' WHERE appname = '" . $type . "'"; |
---|
190 | if (!$db->query($sql)) |
---|
191 | { |
---|
192 | $db->disconnect(); |
---|
193 | return 'Erro em increment_id:' . pg_last_error(); |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | $db->disconnect(); |
---|
198 | return true; |
---|
199 | } |
---|
200 | } |
---|
201 | */ |
---|
202 | |
---|
203 | function add_user2group($gidnumber, $uidnumber) |
---|
204 | { |
---|
205 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
206 | if (!$this->db->query($query)) |
---|
207 | { |
---|
208 | $result['status'] = false; |
---|
209 | $result['msg'] = 'Erro na função db_functions->add_user2group:' . pg_last_error(); |
---|
210 | return $result; |
---|
211 | } |
---|
212 | while($this->db->next_record()) |
---|
213 | $user_in_group[] = $this->db->row(); |
---|
214 | |
---|
215 | if (count($user_in_group) == 0) |
---|
216 | { |
---|
217 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
218 | . "VALUES('phpgw_group','" . $gidnumber . "','" . $uidnumber . "','1')"; |
---|
219 | if (!$this->db->query($sql)) |
---|
220 | { |
---|
221 | $result['status'] = false; |
---|
222 | $result['msg'] = 'Erro na função db_functions->add_user2group:' . pg_last_error(); |
---|
223 | return $result; |
---|
224 | } |
---|
225 | } |
---|
226 | $result['status'] = true; |
---|
227 | return $result; |
---|
228 | } |
---|
229 | |
---|
230 | function remove_user2group($gidnumber, $uidnumber) |
---|
231 | { |
---|
232 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
233 | if (!$this->db->query($query)) |
---|
234 | { |
---|
235 | $result['status'] = false; |
---|
236 | $result['msg'] = 'Erro na função db_functions->add_user2group:' . pg_last_error(); |
---|
237 | return $result; |
---|
238 | } |
---|
239 | while($this->db->next_record()) |
---|
240 | $user_in_group[] = $this->db->row(); |
---|
241 | |
---|
242 | if (count($user_in_group) > 0) |
---|
243 | { |
---|
244 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '".$uidnumber."'"; |
---|
245 | if (!$this->db->query($sql)) |
---|
246 | { |
---|
247 | $result['status'] = false; |
---|
248 | $result['msg'] = 'Erro na função db_functions->add_user2group:' . pg_last_error(); |
---|
249 | return $result; |
---|
250 | } |
---|
251 | } |
---|
252 | $result['status'] = true; |
---|
253 | return $result; |
---|
254 | } |
---|
255 | |
---|
256 | function add_pref_changepassword($uidnumber) |
---|
257 | { |
---|
258 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
259 | if (!$this->db->query($query)) |
---|
260 | { |
---|
261 | $result['status'] = false; |
---|
262 | $result['msg'] = 'Erro na função db_functions->add_pref_changepassword:' . pg_last_error(); |
---|
263 | return $result; |
---|
264 | } |
---|
265 | while($this->db->next_record()) |
---|
266 | $user_pref_changepassword[] = $this->db->row(); |
---|
267 | |
---|
268 | if (count($user_pref_changepassword) == 0) |
---|
269 | { |
---|
270 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
271 | . "VALUES('preferences','changepassword','" . $uidnumber . "','1')"; |
---|
272 | if (!$this->db->query($sql)) |
---|
273 | { |
---|
274 | $result['status'] = false; |
---|
275 | $result['msg'] = 'Erro na função db_functions->add_pref_changepassword:' . pg_last_error(); |
---|
276 | return $result; |
---|
277 | } |
---|
278 | } |
---|
279 | $result['status'] = true; |
---|
280 | return $result; |
---|
281 | } |
---|
282 | |
---|
283 | function remove_pref_changepassword($uidnumber) |
---|
284 | { |
---|
285 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
286 | if (!$this->db->query($query)) |
---|
287 | { |
---|
288 | $result['status'] = false; |
---|
289 | $result['msg'] = 'Erro na função db_functions->add_pref_changepassword:' . pg_last_error(); |
---|
290 | return $result; |
---|
291 | } |
---|
292 | while($this->db->next_record()) |
---|
293 | $user_pref_changepassword[] = $this->db->row(); |
---|
294 | |
---|
295 | if (count($user_pref_changepassword) != 0) |
---|
296 | { |
---|
297 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
298 | if (!$this->db->query($sql)) |
---|
299 | { |
---|
300 | $result['status'] = false; |
---|
301 | $result['msg'] = 'Erro na função db_functions->remove_pref_changepassword:' . pg_last_error(); |
---|
302 | return $result; |
---|
303 | } |
---|
304 | } |
---|
305 | $result['status'] = true; |
---|
306 | return $result; |
---|
307 | } |
---|
308 | |
---|
309 | function add_id2apps($id, $apps) |
---|
310 | { |
---|
311 | $result['status'] = true; |
---|
312 | if ($apps) |
---|
313 | { |
---|
314 | foreach($apps as $app => $value) |
---|
315 | { |
---|
316 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = '".$app."' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
317 | if (!$this->db->query($query)) |
---|
318 | { |
---|
319 | $result['status'] = false; |
---|
320 | $result['msg'] = 'Erro na função db_functions->add_id2apps: ' . pg_last_error(); |
---|
321 | return $result; |
---|
322 | } |
---|
323 | |
---|
324 | while($this->db->next_record()) |
---|
325 | $user_app[] = $this->db->row(); |
---|
326 | |
---|
327 | if (count($user_app) == 0) |
---|
328 | { |
---|
329 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
330 | . "VALUES('".$app."','run','" . $id . "','1')"; |
---|
331 | |
---|
332 | if (!$this->db->query($sql)) |
---|
333 | { |
---|
334 | $result['status'] = false; |
---|
335 | $result['msg'] = 'Erro na função db_functions->add_id2apps: ' . pg_last_error(); |
---|
336 | return $result; |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | $this->write_log("Adicionado aplicativo $app ao id",$id,'','',''); |
---|
341 | } |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | return $result; |
---|
346 | } |
---|
347 | |
---|
348 | function remove_id2apps($id, $apps) |
---|
349 | { |
---|
350 | $result['status'] = true; |
---|
351 | if ($apps) |
---|
352 | { |
---|
353 | foreach($apps as $app => $value) |
---|
354 | { |
---|
355 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
356 | |
---|
357 | if (!$this->db->query($query)) |
---|
358 | { |
---|
359 | $result['status'] = false; |
---|
360 | $result['msg'] = 'Erro na função db_functions->remove_id2apps:' . pg_last_error(); |
---|
361 | return $result; |
---|
362 | } |
---|
363 | while($this->db->next_record()) |
---|
364 | $user_in_group[] = $this->db->row(); |
---|
365 | |
---|
366 | if (count($user_in_group) > 0) |
---|
367 | { |
---|
368 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '".$id."'"; |
---|
369 | if (!$this->db->query($sql)) |
---|
370 | { |
---|
371 | $result['status'] = false; |
---|
372 | $result['msg'] = 'Erro na função db_functions->remove_id2apps:' . pg_last_error(); |
---|
373 | return $result; |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | $this->write_log("Removido aplicativo $app do id",$id,'','',''); |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|
381 | } |
---|
382 | return $result; |
---|
383 | } |
---|
384 | |
---|
385 | |
---|
386 | function get_user_info($uidnumber) |
---|
387 | { |
---|
388 | // Groups |
---|
389 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_account = '".$uidnumber."'"; |
---|
390 | $this->db->query($query); |
---|
391 | while($this->db->next_record()) |
---|
392 | $user_app[] = $this->db->row(); |
---|
393 | |
---|
394 | for ($i=0; $i<count($user_app); $i++) |
---|
395 | $return['groups'][] = $user_app[$i]['acl_location']; |
---|
396 | |
---|
397 | // ChangePassword |
---|
398 | $query = "SELECT acl_rights FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
399 | $this->db->query($query); |
---|
400 | while($this->db->next_record()) |
---|
401 | $changepassword[] = $this->db->row(); |
---|
402 | $return['changepassword'] = $changepassword[0]['acl_rights']; |
---|
403 | |
---|
404 | // Apps |
---|
405 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$uidnumber."' AND acl_location = 'run'"; |
---|
406 | $this->db->query($query); |
---|
407 | while($this->db->next_record()) |
---|
408 | $user_apps[] = $this->db->row(); |
---|
409 | |
---|
410 | if ($user_apps) |
---|
411 | { |
---|
412 | foreach ($user_apps as $app) |
---|
413 | { |
---|
414 | $return['apps'][$app['acl_appname']] = '1'; |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | return $return; |
---|
419 | } |
---|
420 | |
---|
421 | function get_group_info($gidnumber) |
---|
422 | { |
---|
423 | // Apps |
---|
424 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$gidnumber."' AND acl_location = 'run'"; |
---|
425 | $this->db->query($query); |
---|
426 | while($this->db->next_record()) |
---|
427 | $group_apps[] = $this->db->row(); |
---|
428 | |
---|
429 | if ($group_apps) |
---|
430 | { |
---|
431 | foreach ($group_apps as $app) |
---|
432 | { |
---|
433 | $return['apps'][$app['acl_appname']] = '1'; |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | // Members |
---|
438 | $query = "SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "'"; |
---|
439 | |
---|
440 | $this->db->query($query); |
---|
441 | while($this->db->next_record()) |
---|
442 | $group_members[] = $this->db->row(); |
---|
443 | |
---|
444 | if ($group_members) |
---|
445 | { |
---|
446 | foreach ($group_members as $member) |
---|
447 | { |
---|
448 | $return['members'][] = $member['acl_account']; |
---|
449 | } |
---|
450 | } |
---|
451 | else |
---|
452 | $return['members'] = array(); |
---|
453 | |
---|
454 | return $return; |
---|
455 | } |
---|
456 | |
---|
457 | function default_user_password_is_set($uid) |
---|
458 | { |
---|
459 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
460 | $this->db->query($query); |
---|
461 | while($this->db->next_record()) |
---|
462 | { |
---|
463 | $userPassword[] = $this->db->row(); |
---|
464 | } |
---|
465 | if (count($userPassword) == 0) |
---|
466 | return false; |
---|
467 | else |
---|
468 | return true; |
---|
469 | } |
---|
470 | |
---|
471 | function set_user_password($uid, $password) |
---|
472 | { |
---|
473 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
474 | $this->db->query($query); |
---|
475 | while($this->db->next_record()) |
---|
476 | { |
---|
477 | $user[] = $this->db->row(); |
---|
478 | } |
---|
479 | if (count($user) == 0) |
---|
480 | { |
---|
481 | $sql = "INSERT INTO phpgw_expressoadmin_passwords (uid, password) VALUES('".$uid."','".$password."')"; |
---|
482 | |
---|
483 | if (!$this->db->query($sql)) |
---|
484 | { |
---|
485 | $result['status'] = false; |
---|
486 | $result['msg'] = 'Erro na função db_functions->set_user_password: ' . pg_last_error(); |
---|
487 | return $result; |
---|
488 | } |
---|
489 | } |
---|
490 | return true; |
---|
491 | } |
---|
492 | |
---|
493 | function get_user_password($uid) |
---|
494 | { |
---|
495 | $query = "SELECT password FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
496 | $this->db->query($query); |
---|
497 | while($this->db->next_record()) |
---|
498 | { |
---|
499 | $userPassword[] = $this->db->row(); |
---|
500 | } |
---|
501 | |
---|
502 | if (count($userPassword) == 1) |
---|
503 | { |
---|
504 | $sql = "DELETE FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
505 | $this->db->query($sql); |
---|
506 | return $userPassword[0]['password']; |
---|
507 | } |
---|
508 | else |
---|
509 | return false; |
---|
510 | } |
---|
511 | |
---|
512 | function delete_user($user_info) |
---|
513 | { |
---|
514 | // AGENDA |
---|
515 | $this->db->query('SELECT cal_id FROM phpgw_cal WHERE owner ='.$user_info['uidnumber']); |
---|
516 | while($this->db->next_record()) |
---|
517 | { |
---|
518 | $ids[] = $this->db->row(); |
---|
519 | } |
---|
520 | if (count($ids)) |
---|
521 | { |
---|
522 | foreach($ids as $i => $id) |
---|
523 | { |
---|
524 | $this->db->query('DELETE FROM phpgw_cal WHERE cal_id='.$id['cal_id']); |
---|
525 | $this->db->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id['cal_id']); |
---|
526 | $this->db->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$id['cal_id']); |
---|
527 | $this->db->query('DELETE FROM phpgw_cal_extra WHERE cal_id='.$id['cal_id']); |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | // CONATOS pessoais e grupos. |
---|
532 | $this->db->query('SELECT id_contact FROM phpgw_cc_contact WHERE id_owner ='.$user_info['uidnumber']); |
---|
533 | while($this->db->next_record()) |
---|
534 | { |
---|
535 | $ids[] = $this->db->row(); |
---|
536 | } |
---|
537 | |
---|
538 | if (count($ids)) |
---|
539 | { |
---|
540 | foreach($ids as $i => $id_contact) |
---|
541 | { |
---|
542 | $this->db->query('SELECT id_connection FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
543 | while($this->db->next_record()) |
---|
544 | { |
---|
545 | $id_conns[] = $this->db->row(); |
---|
546 | } |
---|
547 | if (count($id_conns)) |
---|
548 | { |
---|
549 | foreach($id_conns as $j => $id_conn) |
---|
550 | { |
---|
551 | $this->db->query('DELETE FROM phpgw_cc_connections WHERE id_connection='.$id_conn['id_connection']); |
---|
552 | $this->db->query('DELETE FROM phpgw_cc_contact_grps WHERE id_connection='.$id_conn['id_connection']); |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | $this->db->query('SELECT id_address FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
557 | while($this->db->next_record()) |
---|
558 | { |
---|
559 | $id_addresses[] = $$this->db->row(); |
---|
560 | } |
---|
561 | if (count($id_addresses)) |
---|
562 | { |
---|
563 | foreach($id_addresses as $j => $id_addrs) |
---|
564 | { |
---|
565 | $this->db->query('DELETE FROM phpgw_cc_addresses WHERE id_address='.$id_addrs['id_address']); |
---|
566 | } |
---|
567 | } |
---|
568 | $this->db->query('DELETE FROM phpgw_cc_contact WHERE id_contact='.$id_contact['id_contact']); |
---|
569 | $this->db->query('DELETE FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
570 | $this->db->query('DELETE FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
571 | } |
---|
572 | } |
---|
573 | $this->db->query('DELETE FROM phpgw_cc_groups WHERE owner='.$user_info['uidnumber']); |
---|
574 | |
---|
575 | // PREFERENCIAS |
---|
576 | $this->db->query('DELETE FROM phpgw_preferences WHERE preference_owner='.$user_info['uidnumber']); |
---|
577 | |
---|
578 | // ACL |
---|
579 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$user_info['uidnumber']); |
---|
580 | |
---|
581 | // Corrigir |
---|
582 | $return['status'] = true; |
---|
583 | return $return; |
---|
584 | } |
---|
585 | |
---|
586 | function delete_group($gidnumber) |
---|
587 | { |
---|
588 | // ACL |
---|
589 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_location='.$gidnumber); |
---|
590 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$gidnumber); |
---|
591 | |
---|
592 | // Corrigir |
---|
593 | $return['status'] = true; |
---|
594 | return $return; |
---|
595 | } |
---|
596 | |
---|
597 | function write_log($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='') |
---|
598 | { |
---|
599 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) " |
---|
600 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')"; |
---|
601 | $this->db->query($sql); |
---|
602 | return; |
---|
603 | } |
---|
604 | |
---|
605 | function get_sieve_info() |
---|
606 | { |
---|
607 | $this->db->query('SELECT profileID,imapenablesieve,imapsieveserver,imapsieveport FROM phpgw_emailadmin'); |
---|
608 | |
---|
609 | $i=0; |
---|
610 | while($this->db->next_record()) |
---|
611 | { |
---|
612 | $serverList[$i]['profileID'] = $this->db->f(0); |
---|
613 | $serverList[$i]['imapenablesieve'] = $this->db->f(1); |
---|
614 | $serverList[$i]['imapsieveserver'] = $this->db->f(2); |
---|
615 | $serverList[$i]['imapsieveport'] = $this->db->f(3); |
---|
616 | $i++; |
---|
617 | } |
---|
618 | |
---|
619 | return $serverList; |
---|
620 | } |
---|
621 | |
---|
622 | function get_apps($account_lid) |
---|
623 | { |
---|
624 | $this->db->query("SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'"); |
---|
625 | |
---|
626 | while($this->db->next_record()) |
---|
627 | { |
---|
628 | $tmp = $this->db->row(); |
---|
629 | $availableApps[$tmp['app']] = 'run'; |
---|
630 | } |
---|
631 | |
---|
632 | return $availableApps; |
---|
633 | } |
---|
634 | |
---|
635 | function get_sambadomains_list() |
---|
636 | { |
---|
637 | $query = "SELECT * FROM phpgw_expressoadmin_samba ORDER by samba_domain_name ASC"; |
---|
638 | $this->db->query($query); |
---|
639 | while($this->db->next_record()) |
---|
640 | $result[] = $this->db->row(); |
---|
641 | return $result; |
---|
642 | } |
---|
643 | |
---|
644 | function exist_domain_name_sid($sambadomainname, $sambasid) |
---|
645 | { |
---|
646 | $query = "SELECT * FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname' OR samba_domain_sid='$sambasid'"; |
---|
647 | $this->db->query($query); |
---|
648 | while($this->db->next_record()) |
---|
649 | $result[] = $this->db->row(); |
---|
650 | |
---|
651 | if (count($result) > 0) |
---|
652 | return true; |
---|
653 | else |
---|
654 | return false; |
---|
655 | } |
---|
656 | |
---|
657 | function delete_sambadomain($sambadomainname) |
---|
658 | { |
---|
659 | $this->db->query("DELETE FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname'"); |
---|
660 | return; |
---|
661 | } |
---|
662 | |
---|
663 | function add_sambadomain($sambadomainname, $sambasid) |
---|
664 | { |
---|
665 | $sql = "INSERT INTO phpgw_expressoadmin_samba (samba_domain_name, samba_domain_sid) VALUES('$sambadomainname','$sambasid')"; |
---|
666 | $this->db->query($sql); |
---|
667 | return; |
---|
668 | } |
---|
669 | |
---|
670 | function test_db_connection($params) |
---|
671 | { |
---|
672 | $host = $params['host']; |
---|
673 | $port = $params['port']; |
---|
674 | $name = $params['name']; |
---|
675 | $user = $params['user']; |
---|
676 | $pass = $params['pass']; |
---|
677 | |
---|
678 | $con_string = "host=$host port=$port dbname=$name user=$user password=$pass"; |
---|
679 | if ($db = pg_connect($con_string)) |
---|
680 | { |
---|
681 | pg_close($db); |
---|
682 | $result['status'] = true; |
---|
683 | } |
---|
684 | else |
---|
685 | { |
---|
686 | $result['status'] = false; |
---|
687 | } |
---|
688 | |
---|
689 | return $result; |
---|
690 | } |
---|
691 | |
---|
692 | function manager_lid_exist($manager_lid) |
---|
693 | { |
---|
694 | $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'"; |
---|
695 | $this->db->query($query); |
---|
696 | while($this->db->next_record()) |
---|
697 | $result[] = $this->db->row(); |
---|
698 | if (count($result) > 0) |
---|
699 | return true; |
---|
700 | else |
---|
701 | return false; |
---|
702 | } |
---|
703 | |
---|
704 | function create_manager($params, $manager_acl) |
---|
705 | { |
---|
706 | //Escrevre no Banco a ACL do gerente |
---|
707 | $sql = "INSERT INTO phpgw_expressoadmin (manager_lid, context, acl) " |
---|
708 | . "VALUES('" . $params['ea_select_manager'] . "','" . $params['context'] . "','" . $manager_acl . "')"; |
---|
709 | $this->db->query($sql); |
---|
710 | |
---|
711 | //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios. |
---|
712 | if (count($_POST['applications_list'])) |
---|
713 | { |
---|
714 | foreach($_POST['applications_list'] as $app=>$value) |
---|
715 | { |
---|
716 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
717 | . "VALUES('" . $_POST['manager_lid'] . "','" . $_POST['context'] . "','" . $app . "')"; |
---|
718 | $this->db->query($sql); |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | return; |
---|
723 | } |
---|
724 | |
---|
725 | function save_manager($params, $manager_acl) |
---|
726 | { |
---|
727 | $params['manager_lid'] = $params['hidden_manager_lid']; |
---|
728 | |
---|
729 | //Executa update na tabela para atualizar ACL |
---|
730 | $sql = "UPDATE phpgw_expressoadmin SET context = '" . $params['context'] . "',acl = '" . $manager_acl |
---|
731 | . "' WHERE manager_lid = '" . $params['manager_lid'] ."'"; |
---|
732 | $this->db->query($sql); |
---|
733 | |
---|
734 | //Deleta as aplicações e adiciona as novas. |
---|
735 | //Deleta |
---|
736 | $sql = "DELETE FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $params['manager_lid'] . "'"; |
---|
737 | $this->db->query($sql); |
---|
738 | |
---|
739 | // Adiciona |
---|
740 | if (count($params['applications_list'])) |
---|
741 | { |
---|
742 | foreach($params['applications_list'] as $app=>$value) |
---|
743 | { |
---|
744 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
745 | . "VALUES('" . $params['manager_lid'] . "','" . $params['context'] . "','" . $app . "')"; |
---|
746 | $this->db->query($sql); |
---|
747 | } |
---|
748 | } |
---|
749 | |
---|
750 | return; |
---|
751 | } |
---|
752 | |
---|
753 | } |
---|
754 | ?> |
---|