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

Revision 8204, 26.4 KB checked in by cristiano, 11 years ago (diff)

Ticket #3915 - Não remoção de assinaturas de agendas ao excluir usuário

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