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

Revision 5133, 25.0 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoAdmin.

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