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

Revision 7769, 26.6 KB checked in by cristiano, 11 years ago (diff)

Ticket #2948 - Log criacao, exclusao e modificacao de contas compartilhadas e institucionais

  • 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        //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                         
77        /*
78        *       Reativa os usuários desabilitados por tempo inativo modificando o seu ultimo acesso para o dia atual.
79        */
80        function reactivate_inactive_user($uidNumber) {
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       
94        function insert_log_inactive_user_control($uid,$uidNumber) {
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
100        function copy_manager($params)
101        {
102                $manager = $params['manager'];
103                $new_manager = $params['new_manager'];
104                $manager_info = $this->read_acl($manager);
105               
106                 //Deleta todas as acls do Gerente
107                $this->db->delete('phpgw_expressoadmin_acls',array('manager_lid' => $new_manager));
108               
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))
123                {
124                        echo lang('error in') . 'copy_manager: ' . pg_last_error();
125                        return false;
126                }
127                    }
128
129
130                }
131               
132       
133               
134                //Pesquisa no Banco e pega os valores dos apps.
135                $sql = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $manager . "' AND context = '" . $manager_info['raw_context'] . "'";
136                $this->db->query($sql);
137                while($this->db->next_record())
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        $aplications_count = count($aplications);
144                for ($i=0; $i<$aplications_count; ++$i)
145                {
146                        $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) "
147                        . "VALUES('" . $new_manager . "','" . $manager_info['raw_context'] . "','" . $aplications[$i]['app'] . "')";
148                        if (!$this->db->query($sql))
149                        {
150                                echo lang('error adding application to new manager') . ': '. pg_last_error();
151                                return false;
152                        }
153                }
154                return true;
155        }
156
157        function get_next_id($type)
158        {
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               
181                // Busco o ID dos accounts
182                $query_accounts_nextid = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'";
183        if (!$db->query($query_accounts_nextid))
184        {
185                $return['status'] = false;
186                        $result['msg'] = lang('Problems running query on DB') . '.';
187                        $db->disconnect();
188                return $return;
189        }
190        else
191        {
192                $accounts_nextid = $db->Query_ID->fields[0];
193        }
194               
195                // Busco o ID dos groups
196                $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'";
197        if (!$db->query($query_groups))
198        {
199                $return['status'] = false;
200                        $result['msg'] = lang('Problems running query on DB') . '.';
201                        $db->disconnect();
202                return $return;
203        }
204        else
205        {
206                $groups_nextid = $db->Query_ID->fields[0];
207        }
208
209                //Retorna o maior dos ID's incrementado de 1
210                if ($accounts_nextid >= $groups_nextid)
211                        $id = $accounts_nextid;
212                else
213                        $id = $groups_nextid;
214                $return['id'] = (int)($id + 1);
215               
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;
222                        $result['msg'] = lang('Problems running query on DB') . '.';
223                }
224                $db->disconnect();
225                return $return;
226        }
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;
234                        $result['msg'] = lang('Error on function') . " db_functions->add_user2group.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
247                                $result['msg'] = lang('Error on function') . " db_functions->add_user2group.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
261                        $result['msg'] = lang('Error on function') . " db_functions->remove_user2group.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
273                                $result['msg'] = lang('Error on function') . " db_functions->remove_user2group.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
287                        $result['msg'] = lang('Error on function') . " db_functions->add_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
300                                $result['msg'] = lang('Error on function') . " db_functions->add_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
314                        $result['msg'] = lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
326                                $result['msg'] = lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
345                                        $result['msg'] = lang('Error on function') . " db_functions->add_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
360                                                $result['msg'] = lang('Error on function') . " db_functions->add_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error();
361                                                return $result;
362                                        }
363                                        else
364                                        {
365                                                $this->write_log("Added application","$id:$app");       
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;
385                                        $result['msg'] = lang('Error on function') . " db_functions->remove_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error();
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;
397                                                $result['msg'] = lang('Error on function') . " db_functions->remove_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error();
398                                                return $result;
399                                        }
400                                        else
401                                        {
402                                                $this->write_log("Removed application from id","$id: $app");   
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();
418
419        $user_app_count = count($user_app);
420                for ($i=0; $i<$user_app_count; ++$i)
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;
512                                $result['msg'] = lang('Error on function') . " db_functions->set_user_password.\n" . lang('Server returns') . ': ' . pg_last_error();
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
541                $this->db->query('SELECT cal_id FROM phpgw_cal WHERE owner ='.$user_info['uidnumber']);
542                while($this->db->next_record())
543                {
544                        $ids[] = $this->db->row();
545                }
546                if (count($ids))
547                {
548                        foreach($ids as $i => $id)
549                        {
550                                $this->db->query('DELETE FROM phpgw_cal WHERE cal_id='.$id['cal_id']);
551                                $this->db->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id['cal_id']);
552                                $this->db->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$id['cal_id']);
553                                $this->db->query('DELETE FROM phpgw_cal_extra WHERE cal_id='.$id['cal_id']);
554                        }
555                }
556               
557                // CONTATOS pessoais e grupos.
558                $this->db->query('SELECT id_contact FROM phpgw_cc_contact WHERE id_owner ='.$user_info['uidnumber']);
559                while($this->db->next_record())
560                {
561                        $ids[] = $this->db->row();
562                }
563
564                if (count($ids))
565                {
566                        foreach($ids as $i => $id_contact)
567                        {
568                                $this->db->query('SELECT id_connection FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']);
569                                while($this->db->next_record())
570                                {
571                                        $id_conns[] = $this->db->row();
572                                }
573                                if (count($id_conns))
574                                {
575                                        foreach($id_conns as $j => $id_conn)
576                                        {
577                                                $this->db->query('DELETE FROM phpgw_cc_connections WHERE id_connection='.$id_conn['id_connection']);
578                                                $this->db->query('DELETE FROM phpgw_cc_contact_grps WHERE id_connection='.$id_conn['id_connection']);
579                                        }
580                                }
581                                       
582                                $this->db->query('SELECT id_address FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']);
583                                while($this->db->next_record())
584                                {
585                                        $id_addresses[] = $$this->db->row();
586                                }
587                                if (count($id_addresses))
588                                {
589                                        foreach($id_addresses as $j => $id_addrs)
590                                        {
591                                                $this->db->query('DELETE FROM phpgw_cc_addresses WHERE id_address='.$id_addrs['id_address']);
592                                        }
593                                }
594                                $this->db->query('DELETE FROM phpgw_cc_contact WHERE id_contact='.$id_contact['id_contact']);
595                                $this->db->query('DELETE FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']);
596                                $this->db->query('DELETE FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']);
597                        }
598                }
599                $this->db->query('DELETE FROM phpgw_cc_groups WHERE owner='.$user_info['uidnumber']);
600                       
601                // PREFERENCIAS
602                $this->db->query('DELETE FROM phpgw_preferences WHERE preference_owner='.$user_info['uidnumber']);
603                       
604                // ACL
605                $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$user_info['uidnumber']);
606               
607                // Corrigir
608                $return['status'] = true;
609                return $return;
610        }
611
612        function delete_group($gidnumber)
613        {
614                // ACL
615                $this->db->query('DELETE FROM phpgw_acl WHERE acl_location='.$gidnumber);
616                $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$gidnumber);
617               
618                // Corrigir
619                $return['status'] = true;
620                return $return;
621        }
622       
623        function write_log($action, $about)
624        {
625                $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) "
626                . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')";
627                if (!$this->db->query($sql))
628                {
629                        //echo pg_last_error();
630                        return false;
631        }
632       
633                return true;
634        }
635       
636        function get_sieve_info()
637        {
638                $this->db->query('SELECT profileID,imapenablesieve,imapsieveserver,imapsieveport FROM phpgw_emailadmin');
639               
640                $i=0;
641                while($this->db->next_record())
642                {
643                        $serverList[$i]['profileID']            = $this->db->f(0);
644                        $serverList[$i]['imapenablesieve']      = $this->db->f(1);
645                        $serverList[$i]['imapsieveserver']      = $this->db->f(2);
646                        $serverList[$i]['imapsieveport']        = $this->db->f(3);
647                        ++$i;
648                }
649               
650                return $serverList;
651        }
652       
653        function get_apps($account_lid)
654        {
655                $this->db->query("SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'");
656               
657                while($this->db->next_record())
658                {
659                        $tmp = $this->db->row();
660                        $availableApps[$tmp['app']] = 'run';
661                }
662                       
663                return $availableApps;
664        }
665       
666        function get_sambadomains_list()
667        {
668                $query = "SELECT * FROM phpgw_expressoadmin_samba ORDER by samba_domain_name ASC";
669                $this->db->query($query);
670                while($this->db->next_record())
671                        $result[] = $this->db->row();
672                return $result;
673        }
674       
675        function exist_domain_name_sid($sambadomainname, $sambasid)
676        {
677                $query = "SELECT * FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname' OR samba_domain_sid='$sambasid'";
678                $this->db->query($query);
679                while($this->db->next_record())
680                        $result[] = $this->db->row();
681               
682                if (count($result) > 0)
683                        return true;
684                else
685                        return false;
686        }
687       
688        function delete_sambadomain($sambadomainname)
689        {
690                $this->db->query("DELETE FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname'");
691                return;
692        }
693       
694        function add_sambadomain($sambadomainname, $sambasid)
695        {
696                $sql = "INSERT INTO phpgw_expressoadmin_samba (samba_domain_name, samba_domain_sid) VALUES('$sambadomainname','$sambasid')";
697                $this->db->query($sql);
698                return;
699        }
700       
701        function test_db_connection($params)
702        {
703                $host = $params['host'];
704                $port = $params['port'];
705                $name = $params['name'];
706                $user = $params['user'];
707                $pass = $params['pass'];
708               
709                $con_string = "host=$host port=$port dbname=$name user=$user password=$pass";
710                if ($db = pg_connect($con_string))
711                {
712                        pg_close($db);
713                        $result['status'] = true;
714                }
715                else
716                {
717                        $result['status'] = false;
718                }
719                       
720                return $result;
721        }
722       
723        function manager_lid_exist($manager_lid)
724        {
725                $query = "SELECT manager_lid FROM phpgw_expressoadmin_acls WHERE manager_lid = '" . $manager_lid . "'";
726                $this->db->query($query);
727                while($this->db->next_record())
728                        $result[] = $this->db->row();
729                if (count($result) > 0)
730                        return true;
731                else
732                        return false;
733        }
734       
735        function delete_manager($uid, $uidNumber){
736                if($this->manager_lid_exist($uid)){
737                        $this->db->query("DELETE FROM phpgw_expressoadmin_acls WHERE manager_lid = '".$uid."'");
738                        $this->db->query("DELETE FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$uid."'");
739                        $this->db->query("DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $uidNumber . "'");
740                }
741                $return['status'] = true;
742                return $return;
743        }
744       
745        function create_manager($params, $manager_acl)
746        {
747
748                //Insere novas regras
749                foreach ($manager_acl as $acl)
750                {
751                    $fields = array(
752                                    'manager_lid' => $params['ea_select_manager'],
753                                    'context' =>    $params['context'],
754                                    'acl_name' => $acl,
755                                   );
756
757                    $this->db->insert('phpgw_expressoadmin_acls', $fields);
758                }
759
760                       
761                //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios.
762                if (count($_POST['applications_list']))
763                {
764                        foreach($_POST['applications_list'] as $app=>$value)
765                        {
766                                $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) "
767                                . "VALUES('" . $_POST['manager_lid'] . "','" . $_POST['context'] . "','" . $app . "')";
768                                $this->db->query($sql);
769                        }
770                }
771               
772                return;
773        }
774       
775        function save_manager($params, $manager_acl)
776        {
777
778
779                $params['manager_lid'] = $params['hidden_manager_lid'];
780               
781                //Deleta todas as acls do Gerente
782                $this->db->delete('phpgw_expressoadmin_acls',array('manager_lid' => $params['manager_lid'],'context' => $params['old_url_context']));
783
784                //Insere novas regras
785                foreach ($manager_acl as $acl)
786                {
787                    $fields = array(
788                                    'manager_lid' => $params['manager_lid'],
789                                    'context' =>    $params['context'],
790                                    'acl_name' => $acl,
791                                   );
792
793                    $this->db->insert('phpgw_expressoadmin_acls', $fields);
794                }
795                       
796                //Deleta as aplicações e adiciona as novas.
797                //Deleta
798                $sql = "DELETE FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $params['manager_lid'] . "'";
799                $this->db->query($sql);
800                                       
801                // Adiciona
802                if (count($params['applications_list']))
803                {
804                        foreach($params['applications_list'] as $app=>$value)
805                        {
806                                $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) "
807                                . "VALUES('" . $params['manager_lid'] . "','" . $params['context'] . "','" . $app . "')";
808                                $this->db->query($sql);
809                        }
810                }
811                       
812                return;
813        }
814
815         function save_calendar_acls($user,$acl,$owner)
816         {
817
818
819             $aclArray = explode('-', $acl);
820             $rights = 0;
821
822             foreach ($aclArray as $number)
823                 $rights = $rights + $number;
824
825             $this->db->delete('phpgw_acl', array('acl_appname' => 'calendar','acl_location' => $user,'acl_account' => $owner), null, null);
826
827             if($rights > 0)
828             {
829                 if($this->db->insert('phpgw_acl', array('acl_appname' => 'calendar','acl_location' => $user,'acl_account' => $owner,'acl_rights' => $rights ), null, null, null))
830                      return true;
831                else
832                     return false;
833             }else
834                 return true;
835                               
836         }
837
838         function get_calendar_acls($owner)
839         {
840
841                $colunas = array('acl_appname','acl_location','acl_account','acl_rights');
842                $where = array('acl_appname' => 'calendar','acl_account' => $owner);
843                $this->db->select('phpgw_acl', $colunas, $where, null, null);
844
845                $return;
846
847                include_once 'class.ldap_functions.inc.php';
848                $ldap = new ldap_functions();
849                include_once 'class.functions.inc.php';
850                $function = new functions();
851
852
853                while ($this->db->next_record())
854                {
855                    $row = $this->db->row();
856                    $return[$ldap->uidnumber2uid($row['acl_location'])] = $function->normalize_calendar_acl($row['acl_rights']);
857                   
858                }
859                return $return;
860               
861        }
862       
863}
864?>
Note: See TracBrowser for help on using the repository browser.