source: trunk/expressoAdmin1_2/inc/class.manager.inc.php @ 182

Revision 182, 3.7 KB checked in by niltonneto, 16 years ago (diff)
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'] = 'Campo contexto está vazio.';
82                                return $return;
83                        }
84                        if (($manager_lid == '') && ($type == 'add'))
85                        {
86                                $return['status'] = 'false';
87                                $return['msg'] = 'Selecione um gerente.';
88                                return $return;
89                        }
90                       
91                        // Verifica se o contexto existe.
92                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
93                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
94                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
95                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
96                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
97                        ldap_bind($ldap_conn,$dn,$passwd);
98                       
99                        foreach ($contexts as $index=>$context)
100                        {
101                                $sr=@ldap_list($ldap_conn, $context, "cn=*");
102                                if (!$sr)
103                                {
104                                        $return['status'] = 'false';
105                                        $return['msg'] = "Contexto $context não existe.";
106                                        return $return;
107                                }                               
108                        }
109                       
110                        if ($type == 'add')
111                        {
112                                include_once('class.db_functions.inc.php');
113                                $db = new db_functions();
114                               
115                                if ($db->manager_lid_exist($manager_lid))
116                                {
117                                        $return['status'] = 'false';
118                                        $return['msg'] = "Gerente já cadastrado.";
119                                        return $return;
120                                }
121                        }
122                       
123                        return $return;
124                }
125               
126                function manager_lid_exist($manager_lid)
127                {
128                        $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'";
129                        $this->db->query($query);
130                        while($this->db->next_record())
131                                $result[] = $this->db->row();
132                        if (count($result) > 0)
133                                return true;
134                        else
135                                return false;
136                }
137               
138        }
139?>
Note: See TracBrowser for help on using the repository browser.