source: trunk/expressoAdmin1_2/inc/class.db_functions.inc.php @ 2707

Revision 2707, 22.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problemas no expressoAdmin1_2.

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