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

Revision 6553, 26.5 KB checked in by eduardow, 12 years ago (diff)

Ticket #2863 - Backport da funcionalidade de Controle de Cotas de usuário e disco(Cotas OU).

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