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

Revision 548, 21.9 KB checked in by eduardoalex, 15 years ago (diff)

Desenvolvimento da tarefa #371

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