source: trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php @ 5593

Revision 5593, 15.5 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2398 - Compatibilizacao com PHP-5.3 no modulo ExpressoAdmin

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