source: branches/2.2/expressoAdmin1_2/inc/class.manager.inc.php @ 3018

Revision 3018, 4.0 KB checked in by amuller, 14 years ago (diff)

Ticket #1135 - Aplicando alterações do branches 2.0 no branches 2.2

Line 
1<?php
2        /***********************************************************************************\
3        * Expresso Administração                                                                                                   *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)  *
5        * ---------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                 *
7        *  under the terms of the GNU General Public License as published by the                   *
8        *  Free Software Foundation; either version 2 of the License, or (at your                  *
9        *  option) any later version.                                                                                                      *
10        \***********************************************************************************/
11
12        include_once('class.db_functions.inc.php');
13        include_once('class.functions.inc.php');
14       
15        class manager
16        {
17                var $db_functions;
18                var $functions;
19                var $current_config;
20               
21                function manager()
22                {
23                        $this->db_functions = new db_functions;
24                        $this->functions = new functions;
25                        $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin'];
26                }
27
28                function save($params)
29                {
30                        $manager_acl = $this->make_manager_acl($params);
31                         
32                        $this->db_functions->save_manager($params, $manager_acl);
33
34                        $return['status'] = 'true';
35                        $return['type'] = 'save';
36                        return $return;
37                }
38
39                function create($params)
40                {
41                        $manager_acl = $this->make_manager_acl($params);
42                         
43                        $this->db_functions->create_manager($params, $manager_acl);
44
45                        $return['status'] = 'true';
46                        $return['type'] = 'create';
47                        return $return;
48                }
49
50                function make_manager_acl($array_post)
51                {
52                        $total_manager_acl = 0;
53                        foreach ($array_post as $atribute=>$value)
54                        {
55                                $acl  = strstr($atribute, 'acl_');
56
57                                if ($acl !== false)
58                                {
59                                        /* Valmir Andre de Sena - valmir.sena@ati.pe.gov.br
60                                        * changed + operation to bcadd, because php plus operation get wrong over 41 bits
61                                        */
62                                        $total_manager_acl = bcadd( $total_manager_acl, $value);
63                                }
64                        }
65                        return $total_manager_acl;
66                }
67
68                function validate($params)
69                {
70                        if (is_array($_SESSION['phpgw_info']['expresso']['server']))
71                                $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
72                        else
73                                $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
74                       
75                        $return['status'] = 'true';
76                       
77                        $contexts = split("%", $params['contexts']);
78                        $manager_lid = $params['manager_lid'];
79                        $type = $params['type'];
80                       
81                        if ($contexts == '')
82                        {
83                                $return['status'] = 'false';
84                                $return['msg'] = $this->functions->lang('context field is empty') . '.';
85                               
86                                return $return;
87                        }
88                        if (($manager_lid == '') && ($type == 'add'))
89                        {
90                                $return['status'] = 'false';
91                                $return['msg'] = $this->functions->lang('select one manager') . '.';
92                               
93                                return $return;
94                        }
95                       
96                        // Verifica se o contexto existe.
97                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
98                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
99                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
100                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
101                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
102                        ldap_bind($ldap_conn,$dn,$passwd);
103                       
104                        foreach ($contexts as $index=>$context)
105                        {
106                                $sr=@ldap_list($ldap_conn, $context, "cn=*");
107                                if (!$sr)
108                                {
109                                        $return['status'] = 'false';
110                                        $this->functions->lang('context does not exist') . ": $context";
111                                        return $return;
112                                }                               
113                        }
114                       
115                        if ($type == 'add')
116                        {
117                                include_once('class.db_functions.inc.php');
118                                $db = new db_functions();
119                               
120                                if ($db->manager_lid_exist($manager_lid))
121                                {
122                                        $return['status'] = 'false';
123                                        $return['msg'] = $this->functions->lang('manager already exist') . ".";
124                                       
125                                        return $return;
126                                }
127                        }
128                       
129                        return $return;
130                }
131               
132                function manager_lid_exist($manager_lid)
133                {
134                        $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'";
135                        $this->db->query($query);
136                        while($this->db->next_record())
137                                $result[] = $this->db->row();
138                        if (count($result) > 0)
139                                return true;
140                        else
141                                return false;
142                }
143               
144        }
145?>
Note: See TracBrowser for help on using the repository browser.