source: companies/celepar/expressoAdmin1_2/inc/class.manager.inc.php @ 763

Revision 763, 3.8 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1<?
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                                        $total_manager_acl += $value;
60                                }
61                        }
62                        return $total_manager_acl;
63                }
64
65                function validate($params)
66                {
67                        if (is_array($_SESSION['phpgw_info']['expresso']['server']))
68                                $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
69                        else
70                                $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
71                       
72                        $return['status'] = 'true';
73                       
74                        $contexts = split("%", $params['contexts']);
75                        $manager_lid = $params['manager_lid'];
76                        $type = $params['type'];
77                       
78                        if ($contexts == '')
79                        {
80                                $return['status'] = 'false';
81                                $return['msg'] = $this->functions->lang('context field is empty') . '.';
82                               
83                                return $return;
84                        }
85                        if (($manager_lid == '') && ($type == 'add'))
86                        {
87                                $return['status'] = 'false';
88                                $return['msg'] = $this->functions->lang('select one manager') . '.';
89                               
90                                return $return;
91                        }
92                       
93                        // Verifica se o contexto existe.
94                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
95                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
96                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
97                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
98                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
99                        ldap_bind($ldap_conn,$dn,$passwd);
100                       
101                        foreach ($contexts as $index=>$context)
102                        {
103                                $sr=@ldap_list($ldap_conn, $context, "cn=*");
104                                if (!$sr)
105                                {
106                                        $return['status'] = 'false';
107                                        $this->functions->lang('context does not exist') . ": $context";
108                                        return $return;
109                                }                               
110                        }
111                       
112                        if ($type == 'add')
113                        {
114                                include_once('class.db_functions.inc.php');
115                                $db = new db_functions();
116                               
117                                if ($db->manager_lid_exist($manager_lid))
118                                {
119                                        $return['status'] = 'false';
120                                        $return['msg'] = $this->functions->lang('manager already exist') . ".";
121                                       
122                                        return $return;
123                                }
124                        }
125                       
126                        return $return;
127                }
128               
129                function manager_lid_exist($manager_lid)
130                {
131                        $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'";
132                        $this->db->query($query);
133                        while($this->db->next_record())
134                                $result[] = $this->db->row();
135                        if (count($result) > 0)
136                                return true;
137                        else
138                                return false;
139                }
140               
141        }
142?>
Note: See TracBrowser for help on using the repository browser.