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

Revision 6195, 26.2 KB checked in by gustavo, 12 years ago (diff)

Ticket #2723 - Inconsistência no Expresso - admin / Lista de gerentes

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