source: branches/2.2/expressoAdmin1_2/inc/class.db_functions.inc.php @ 1516

Revision 1516, 22.0 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #419 - Parte principal da funcionalidade. Falta add atributos no ldap

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