source: companies/serpro/expressoAdminSerpro/inc/class.manager.inc.php @ 903

Revision 903, 3.7 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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
31                        $manager_acl = $this->make_manager_acl($params);
32                         
33                        $this->db_functions->save_manager($params, $manager_acl);
34
35                        $return['status'] = 'true';
36                        $return['type'] = 'save';
37                        return $return;
38                }
39
40                function create($params)
41                {
42                        $manager_acl = $this->make_manager_acl($params);
43                         
44                        $this->db_functions->create_manager($params, $manager_acl);
45
46                        $return['status'] = 'true';
47                        $return['type'] = 'create';
48                        return $return;
49                }
50
51                function make_manager_acl($array_post)
52                {
53                        $total_manager_acl = 0;
54                        foreach ($array_post as $atribute=>$value)
55                        {
56                                $acl  = strstr($atribute, 'acl_');
57
58                                if ($acl !== false)
59                                {
60                                        $total_manager_acl += $value;
61                                }
62                        }
63                        return $total_manager_acl;
64                }
65
66                function validate($params)
67                {
68                        if (is_array($_SESSION['phpgw_info']['expresso']['server']))
69                                $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
70                        else
71                                $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
72                       
73                        $return['status'] = 'true';
74                       
75                        $contexts = split("%", $params['contexts']);
76                        $manager_lid = $params['manager_lid'];
77                        $type = $params['type'];
78                       
79                        if ($contexts == '')
80                        {
81                                $return['status'] = 'false';
82                                $return['msg'] = 'Campo contexto está vazio.';
83                                return $return;
84                        }
85                        if (($manager_lid == '') && ($type == 'add'))
86                        {
87                                $return['status'] = 'false';
88                                $return['msg'] = 'Selecione um gerente.';
89                                return $return;
90                        }
91                       
92                        // Verifica se o contexto existe.
93                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
94                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
95                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
96                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
97                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
98                        ldap_bind($ldap_conn,$dn,$passwd);
99                       
100                        foreach ($contexts as $index=>$context)
101                        {
102                                $sr=@ldap_list($ldap_conn, $context, "cn=*");
103                                if (!$sr)
104                                {
105                                        $return['status'] = 'false';
106                                        $return['msg'] = "Contexto $context não existe.";
107                                        return $return;
108                                }                               
109                        }
110                       
111                        if ($type == 'add')
112                        {
113                                include_once('class.db_functions.inc.php');
114                                $db = new db_functions();
115                               
116                                if ($db->manager_lid_exist($manager_lid))
117                                {
118                                        $return['status'] = 'false';
119                                        $return['msg'] = "Gerente já cadastrado.";
120                                        return $return;
121                                }
122                        }
123                       
124                        return $return;
125                }
126               
127                function manager_lid_exist($manager_lid)
128                {
129                        $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'";
130                        $this->db->query($query);
131                        while($this->db->next_record())
132                                $result[] = $this->db->row();
133                        if (count($result) > 0)
134                                return true;
135                        else
136                                return false;
137                }
138               
139        }
140?>
Note: See TracBrowser for help on using the repository browser.