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

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

Importacao inicial do Expresso do Serpro

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        class uimanagers
13        {
14                var $public_functions = array
15                (
16                        'list_managers'         => True,
17                        'add_managers'          => True,
18                        'delete_managers'       => True,
19                        'edit_managers'         => True,
20                        'validate'                      => True
21                );
22
23                var $functions;
24                var $config;
25
26                function uimanagers()
27                {
28                        $this->functions = CreateObject('expressoAdminSerpro.functions');
29                        $c = CreateObject('phpgwapi.config','expressoAdminSerpro');
30                        $c->read_repository();
31                        $this->config = $c->config_data;
32
33                        if(!@is_object($GLOBALS['phpgw']->js))
34                        {
35                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
36                        }
37                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdminSerpro');#diretorio, arquivo.js, aplicacao
38                        $GLOBALS['phpgw']->js->validate_file('jscode','managers','expressoAdminSerpro');
39                }
40
41                function row_action($lang,$link,$manager_lid,$context)
42                {
43                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
44                                'menuaction' => 'expressoAdminSerpro.uimanagers.'.$link,
45                                'action'                =>      $lang,
46                                'manager_lid' => $manager_lid,
47                                'context' => $context
48                        )).'" onmouseover="window.status=\''.lang($lang).' Manager\'; return true;" onmouseout="window.status=\'\';" >'.lang($lang).' </a>';
49                }
50
51                function list_managers()
52                {
53                        // Caso nao seja admin, sai.
54                        if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin'))
55                        {
56                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
57                        }
58                        // Imprime o NavBar
59                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
60                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdminSerpro']['title'].' - '.lang('List Managers');
61                        $GLOBALS['phpgw']->common->phpgw_header();
62
63                        // Seta o template
64                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
65                        $p->set_file(array('managers' => 'managers.tpl'));
66                        $p->set_block('managers','body','body');
67                        $p->set_block('managers','row','row');
68                        $p->set_block('managers','row_empty','row_empty');
69                        $tpl_vars = $p->get_undefined('body');
70
71                        $var = Array(
72                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uimanagers.add_managers'),
73                                'tr_color'                      => '#DDDDDD',
74                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg']
75                        );
76
77                        // Cria dinamicamente os langs
78                        foreach ($tpl_vars as $atribute)
79                        {
80                                $lang = strstr($atribute, 'lang_');
81                                if($lang !== false)
82                                {
83                                        $p->set_var($atribute, $this->make_lang($atribute));
84                                }
85                        }
86
87                        // Le BD para pegar os administradors.
88                        $query = 'SELECT manager_lid,context FROM phpgw_expressoadmin ORDER by manager_lid';
89                        $GLOBALS['phpgw']->db->query($query);
90                        while($GLOBALS['phpgw']->db->next_record())
91                        {
92                                $managers[] = $GLOBALS['phpgw']->db->row();
93                        }
94                        $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect();
95                        $justthese = array("cn");
96                        // Loop para listar os administradores
97                        if (count($managers))
98                        {
99                                foreach($managers as $array_managers)
100                                {
101                                        $managers_context = "";
102                                        $a_managers_context = split("%", $array_managers['context']);
103
104                                        foreach ($a_managers_context as $context)
105                                        {
106                                                $managers_context .= "$context<br>";
107                                        }
108
109                                        $filter="(&(phpgwAccountType=u)(uid=".$array_managers['manager_lid']."))";
110                                        $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
111                                        $ldap_result = ldap_get_entries($ldap_conn, $ldap_search);
112                                        $p->set_var('manager_lid', $array_managers[manager_lid]);
113                                        $p->set_var('manager_cn', $ldap_result[0]['cn'][0] == '' ? '<font color=red>NÃO ENCONTRADO NO LDAP</font>' : $ldap_result[0]['cn'][0]);
114                                        $p->set_var('context', $managers_context);
115                                        $p->set_var('link_edit',$this->row_action('edit','edit_managers',$array_managers[manager_lid],$array_managers[context]));
116                                        $p->set_var('link_delete',$this->row_action('delete','delete_managers',$array_managers[manager_lid],$array_managers[context]));
117                                        $p->set_var('link_copy',"<a href='#' onClick='javascript:copy_manager(\"".$array_managers['manager_lid']."\");'>Copiar</a>");
118                                        $p->fp('rows','row',True);
119                                }
120                        }
121                        $p->set_var($var);
122                        $p->pfp('out','body');
123                        ldap_close($ldap_conn);
124                }
125
126
127                function add_managers()
128                {
129                        // Caso nao seja admin, sai.
130                        if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin'))
131                        {
132                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
133                        }
134
135                        // Seta o template
136                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
137                        $p->set_file(array('managers' => 'managers_form.tpl'));
138                        $p->set_block('managers','form','form');
139                        $tpl_vars = $p->get_undefined('form');
140
141                        // Imprime o NavBar
142                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
143                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdminSerpro']['title'].' - '.lang('Add Managers');
144                        $GLOBALS['phpgw']->common->phpgw_header();
145
146                        // Seta variaveis javascript necessárias
147                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
148                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdminSerpro/js/jscode/expressoadmin.js"></script>';
149
150                        // App, create list of available apps
151                        $applications_list = $this->make_app_list('');
152
153                        /*
154                        if ($_POST['context'])
155                        {
156                                $contexts = split("%", $_POST['context']);
157                                foreach ($contexts as $manager_context)
158                                        $input_context_fields .= "<input type='text' size=60 value=$manager_context></input><br>";
159                        }
160                        else
161                                $input_context_fields = '<input type="text" size=60></input><br>';
162                        */
163
164                        $options_context = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', false, true, false);
165
166                        // Seta variaveis que estao no TPL
167                        $var = Array(
168                                'scripts_java'                  =>      $scripts_java,
169                                //'action'                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uimanagers.validate'),
170                                //'action'                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.bomanagers.add_managers'),
171                                'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none',
172                                'type'                                  => "add",
173                                'color_bg1'                             => "#E8F0F0",
174                                'color_bg2'                             => "#D3DCE3",
175                                'color_font1'                   => "#DDDDDD",
176                                'color_font2'                   => "#EEEEEE",
177                                'input_context_fields'  => $input_context_fields,
178                                'error_messages'                => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript">alert("'.$_POST['error_messages'].'");</script>',
179                                'manager_lid'                   => $_POST['manager_lid'],
180                                'context'                               => $_POST['context'],
181                                'app_list'                              => $applications_list,
182                                'options_contexts'              => $options_context
183                        );
184                        $p->set_var($var);
185
186                        // Cria dinamicamente os langs e seta acls
187                        foreach ($tpl_vars as $atribute)
188                        {
189                                $acl  = strstr($atribute, 'acl_');
190                                $lang = strstr($atribute, 'lang_');
191                                // Recuperar os valores das ACLS
192                                if ($acl !== false)
193                                {
194                                        $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : '');
195                                }
196                                // Setar os langs do tpl.
197                                elseif($lang !== false)
198                                {
199                                        $p->set_var($atribute, $this->make_lang($atribute));
200                                }
201                        }
202
203                        echo $p->fp('out','form');
204                }
205
206                function delete_managers()
207                {
208                        // Criar uma verificação e jogar a query para o BO.
209                        $context = $_GET['context'];
210                        $manager_lid = $_GET['manager_lid'];
211
212                        $query = "DELETE FROM phpgw_expressoadmin WHERE manager_lid = '".$manager_lid."' AND context = '" . $context ."'";
213                        $GLOBALS['phpgw']->db->query($query);
214
215                        // Remove Gerente da tabela dos apps
216                        $query = "DELETE FROM phpgw_expressoadmin_apps WHERE "
217                        . "manager_lid = '".$manager_lid."' AND "
218                        . "context = '".$context."'";
219                        $GLOBALS['phpgw']->db->query($query);
220
221                        // Remove Gerente na ACL do expressoadmin
222                        $accounts = CreateObject('phpgwapi.accounts');
223                        $manager_id = $accounts->name2id($_GET['manager_lid']);
224                        $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $manager_id . "'";
225                        $GLOBALS['phpgw']->db->query($sql);
226
227                        ExecMethod('expressoAdminSerpro.uimanagers.list_managers');
228                }
229
230                function edit_managers()
231                {
232                        // Caso nao seja admin, sai.
233                        if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin'))
234                        {
235                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
236                        }
237
238                        // Verifica se eh a primeira entrada, ai eu tenho o get, senao pego o post.
239                        if ($_GET['manager_lid'] != '')
240                        {
241                                $first_time = true;
242                                $_POST['manager_lid']   = $_GET['manager_lid'];
243                                $_POST['context']               = $_GET['context'];
244                                $hidden_manager_lid             = $_GET['manager_lid'];
245                        }
246                        elseif ($_POST['manager_lid'] != '')
247                        {
248                                $first_time             = false;
249                                $hidden_manager_lid     = $_POST['old_manager_lid'];
250                        }
251
252                        if ($first_time)
253                        {
254                                //Pego ACL do gerente
255                                $manager = $this->functions->read_acl($_GET['manager_lid']);
256                                //Cria vetor da ACL
257                                $manager_acl = $this->functions->make_array_acl($manager['acl']);
258                                //Pesquisa no Banco e pega os valores dos apps.
259                                $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'";
260                                $GLOBALS['phpgw']->db->query($query);
261                                $i=0;
262                                $manager[0]['apps'] = array();
263                                while($GLOBALS['phpgw']->db->next_record())
264                                {
265                                        $tmp[$i] = $GLOBALS['phpgw']->db->row();
266                                        $_POST['applications_list'][$tmp[$i]['app']] = 1;
267                                        $manager[0]['apps'][$tmp[$i]['app']] = 1;
268                                        $i++;
269                                }
270                        }
271
272                        // Seta o template
273                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
274                        $p->set_file(array('managers' => 'managers_form.tpl'));
275                        $p->set_block('managers','form','form');
276                        $tpl_vars = $p->get_undefined('form');
277
278                        // Imprime o NavBar
279                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
280                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdminSerpro']['title'].' - '.lang('Edit Managers');
281                        $GLOBALS['phpgw']->common->phpgw_header();
282
283                        // Seta variaveis javas necessárias
284                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
285                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdminSerpro/js/jscode/expressoadmin.js"></script>';
286
287                        // App, create list of available apps
288                        $applications_list = $this->make_app_list($manager[0]['apps']);
289
290                        $a_context = split("%", $_POST['context']);
291                        foreach ($a_context as $context)
292                                $input_context_fields .= '<div><input disabled type="text" value="'.$context.'" size=60></input><span onclick="this.parentNode.parentNode.removeChild(this.parentNode);" style="cursor:pointer"> -</span></div>';
293                        $options_context = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', false, true, false);
294
295                        $var = Array(
296                                'scripts_java'                          => $scripts_java,
297                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdminSerpro.uimanagers.validate'),
298                                'display_samba_suport'          => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none',
299                                'color_bg1'                                     => "#E8F0F0",
300                                'color_bg2'                                     => "#D3DCE3",
301                                'color_font1'                           => "#DDDDDD",
302                                'color_font2'                           => "#EEEEEE",
303                                'type'                                          => "edit",
304                                'display_manager_select'        => 'none',
305                                'input_manager_lid_disabled'=> 'disabled',
306                                'error_messages'                        => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>',
307                                'manager_lid'                           => $_POST['manager_lid'],
308                                'hidden_manager_lid'            => $_POST['manager_lid'],
309                                'context'                                       => $_POST['context'],
310
311                                'input_context_fields'          => $input_context_fields,
312                                'options_contexts'                      => $options_context,
313
314                                'hidden_manager_lid'            => $hidden_manager_lid,
315                                'app_list'                                      => $applications_list
316                        );
317                        $p->set_var($var);
318
319                        // Cria dinamicamente os langs e seta acls
320                        foreach ($tpl_vars as $atribute)
321                        {
322                                $acl  = strstr($atribute, 'acl_');
323                                $lang = strstr($atribute, 'lang_');
324                                // Recuperar os valores das ACLS
325                                if ($acl !== false)
326                                {
327                                        if ($first_time)
328                                                $p->set_var($atribute, $manager_acl[$atribute] === '1' ? 'checked' : '');
329                                        else
330                                                $p->set_var($atribute, $_POST[$atribute] === '1' ? 'checked' : '');
331                                }
332                                // Setar os langs do tpl.
333                                elseif($lang !== false)
334                                {
335                                        $p->set_var($atribute, $this->make_lang($atribute));
336                                }
337                        }
338
339                        echo $p->fp('out','form');
340                }
341
342                function make_lang($ram_lang)
343                {
344                        $a_lang = split("_", $ram_lang);
345                        $a_lang_reverse  = array_reverse ( $a_lang, true );
346                        //Retira o lang do array.
347                        array_pop ( $a_lang_reverse );
348                        $a_lang  = array_reverse ( $a_lang_reverse, true );
349                        $a_new_lang = implode ( " ", $a_lang );
350                        return lang($a_new_lang);
351                }
352
353                function make_app_list($manager_app_list)
354                {
355                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
356                        $apps = CreateObject('phpgwapi.applications',$_account_id);
357                        $db_perms = $apps->read_account_specific();
358                        $availableApps = $GLOBALS['phpgw_info']['apps'];
359
360                        uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);'));
361
362                        // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box.
363                        $applications_list = '';
364                        $app_col1 = '';
365                        $app_col2 = '';
366                        $app_col3 = '';
367                        $total_apps = count($availableApps);
368                        $i = 0;
369
370                        foreach($availableApps as $app => $data)
371                        {
372                                // 1 coluna
373                                if (($i +1) % 3 == 1)
374                                {
375                                        if ($manager_app_list[$app] == 1)
376                                                $checked = 'checked';
377                                        else
378                                                $checked = '';
379                                        $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
380                                        $data['title'],$app,$checked, $disabled);
381
382                                        if ($i == ($total_apps-1))
383                                                $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1);
384                                }
385                                // 2 coluna
386                                if (($i +1) % 3 == 2)
387                                {
388                                        if ($manager_app_list[$app] == 1)
389                                                $checked = 'checked';
390                                        else
391                                                $checked = '';
392                                        $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
393                                        $data['title'],$app,$checked, $disabled);
394
395                                        if ($i == ($total_apps-1))
396                                                $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1,$app_col2);
397                                }
398                                // 3 coluna
399                                if (($i +1) % 3 == 0)
400                                {
401                                        if ($manager_app_list[$app] == 1)
402                                                $checked = 'checked';
403                                        else
404                                                $checked = '';
405                                        $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
406                                        $data['title'],$app,$checked, $disabled);
407
408                                        // Cria nova linha
409                                        $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1, $app_col2, $app_col3);
410                                }
411                                $i++;
412                        }
413                        return $applications_list;
414                }
415        }
416?>
Note: See TracBrowser for help on using the repository browser.