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

Revision 2707, 16.0 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problemas no expressoAdmin1_2.

  • 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','globals','expressoAdmin1_2');
38                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','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 manager_lid,context FROM phpgw_expressoadmin 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 = 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
124                        ldap_close($ldap_conn);
125
126                        $p->set_var($var);
127                        $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script_thirst' ] .= "<script>var expressoAdmin_controller = '{$GLOBALS[ 'phpgw' ] -> link( '/expressoAdmin1_2/controller.php' )}?action=';</script>";
128                        //echo "<script>var expressoAdmin_controller = '{$GLOBALS[ 'phpgw' ] -> link( '/controller.php' )}?action=';</script>" . $GLOBALS['phpgw']->js->get_script_links( );
129                        $p->pfp('out','body');
130                }
131
132
133                function add_managers()
134                {
135                        // Caso nao seja admin, sai.
136                        if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
137                        {
138                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
139                        }
140                       
141                        // Seta o template
142                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
143                        $p->set_file(array('managers' => 'managers_form.tpl'));
144                        $p->set_block('managers','form','form');
145                        $tpl_vars = $p->get_undefined('form');
146
147                        // Imprime o NavBar
148                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
149                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Add Managers');
150                        //$GLOBALS['phpgw']->common->phpgw_header();
151                       
152                        // Seta variaveis javascript necessárias
153                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
154                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>';
155                       
156                        // App, create list of available apps
157                        $applications_list = $this->make_app_list('');
158                       
159                        /*
160                        if ($_POST['context'])
161                        {
162                                $contexts = split("%", $_POST['context']);
163                                foreach ($contexts as $manager_context)
164                                        $input_context_fields .= "<input type='text' size=60 value=$manager_context></input><br>";
165                        }
166                        else
167                                $input_context_fields = '<input type="text" size=60></input><br>';
168                        */
169                       
170                        $options_context = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', false, true, false);
171                       
172                        // Seta variaveis que estao no TPL
173                        $var = Array(
174                                'scripts_java'                  =>      '',//$scripts_java,     
175                                //'action'                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'),
176                                //'action'                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bomanagers.add_managers'),
177                                'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none',
178                                'type'                                  => "add",
179                                'color_bg1'                             => "#E8F0F0",
180                                'color_bg2'                             => "#D3DCE3",
181                                'color_font1'                   => "#DDDDDD",
182                                'color_font2'                   => "#EEEEEE",
183                                'input_context_fields'  => $input_context_fields,
184                                'error_messages'                => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript">alert("'.$_POST['error_messages'].'");</script>',
185                                'manager_lid'                   => $_POST['manager_lid'],
186                                'context'                               => $_POST['context'],
187                                'app_list'                              => $applications_list,
188                                'options_contexts'              => $options_context
189                        );
190                        $p->set_var($var);
191                       
192                        // Cria dinamicamente os langs e seta acls
193                        foreach ($tpl_vars as $atribute)
194                        {
195                                $acl  = strstr($atribute, 'acl_');
196                                $lang = strstr($atribute, 'lang_');
197                                // Recuperar os valores das ACLS
198                                if ($acl !== false)
199                                {
200                                        $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : '');
201                                }
202                                // Setar os langs do tpl.
203                                elseif($lang !== false)
204                                {
205                                        $p->set_var($atribute, $this->make_lang($atribute));
206                                }
207                        }
208                       
209                        echo $p->fp('out','form');
210                }
211       
212                function delete_managers()
213                {
214                        if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
215                        {
216                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
217                        }
218                        // Criar uma verificação e jogar a query para o BO.
219                        $context = $_GET['context'];
220                        $manager_lid = $_GET['manager_lid'];
221                       
222                        $query = "DELETE FROM phpgw_expressoadmin WHERE manager_lid = '".$manager_lid."' AND context = '" . $context ."'";
223                        $GLOBALS['phpgw']->db->query($query);
224                       
225                        // Remove Gerente da tabela dos apps
226                        $query = "DELETE FROM phpgw_expressoadmin_apps WHERE "
227                        . "manager_lid = '".$manager_lid."' AND "
228                        . "context = '".$context."'";
229                        $GLOBALS['phpgw']->db->query($query);           
230                       
231                        // Remove Gerente na ACL do expressoadmin
232                        $accounts = CreateObject('phpgwapi.accounts');
233                        $manager_id = $accounts->name2id($_GET['manager_lid']);
234                        $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $manager_id . "'";
235                        $GLOBALS['phpgw']->db->query($sql);                     
236                       
237                        ExecMethod('expressoAdmin1_2.uimanagers.list_managers');
238                }
239       
240                function edit_managers()
241                {
242                        // Caso nao seja admin, sai.
243                        if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
244                        {
245                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
246                        }
247                       
248                        // Verifica se eh a primeira entrada, ai eu tenho o get, senao pego o post.
249                        if ($_GET['manager_lid'] != '')
250                        {
251                                $first_time = true;
252                                $_POST['manager_lid']   = $_GET['manager_lid'];
253                                $_POST['context']               = $_GET['context'];
254                                $hidden_manager_lid             = $_GET['manager_lid'];
255                        }
256                        elseif ($_POST['manager_lid'] != '')
257                        {
258                                $first_time             = false;
259                                $hidden_manager_lid     = $_POST['old_manager_lid'];                           
260                        }
261                       
262                        if ($first_time)
263                        {
264                                //Pego ACL do gerente
265                                $manager = $this->functions->read_acl($_GET['manager_lid']);
266                                //Cria vetor da ACL
267                                $manager_acl = $this->functions->make_array_acl($manager['acl']);
268                                //Pesquisa no Banco e pega os valores dos apps.
269                                $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'";
270                                $GLOBALS['phpgw']->db->query($query);
271                                $i=0;
272                                $manager[0]['apps'] = array();
273                                while($GLOBALS['phpgw']->db->next_record())
274                                {
275                                        $tmp[$i] = $GLOBALS['phpgw']->db->row();
276                                        $_POST['applications_list'][$tmp[$i]['app']] = 1;
277                                        $manager[0]['apps'][$tmp[$i]['app']] = 1;
278                                        $i++;
279                                }
280                        }
281                       
282                        // Seta o template
283                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
284                        $p->set_file(array('managers' => 'managers_form.tpl'));
285                        $p->set_block('managers','form','form');
286                        $tpl_vars = $p->get_undefined('form');
287                       
288                        // Imprime o NavBar
289                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
290                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Managers');
291                        //$GLOBALS['phpgw']->common->phpgw_header();
292
293                        // Seta variaveis javas necessárias
294                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
295                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>';
296
297                        // App, create list of available apps
298                        $applications_list = $this->make_app_list($manager[0]['apps']);
299
300                        $a_context = split("%", $_POST['context']);
301                        foreach ($a_context as $context)
302                                $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>';
303                        $options_context = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', false, true, false);
304
305                        $var = Array(
306                                'scripts_java'                          => '',//$scripts_java,
307                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'),
308                                'display_samba_suport'          => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none',
309                                'color_bg1'                                     => "#E8F0F0",
310                                'color_bg2'                                     => "#D3DCE3",
311                                'color_font1'                           => "#DDDDDD",
312                                'color_font2'                           => "#EEEEEE",
313                                'type'                                          => "edit",
314                                'display_manager_select'        => 'none',
315                                'input_manager_lid_disabled'=> 'disabled',
316                                'error_messages'                        => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>',
317                                'manager_lid'                           => $_POST['manager_lid'],
318                                'hidden_manager_lid'            => $_POST['manager_lid'],
319                                'context'                                       => $_POST['context'],
320                               
321                                'input_context_fields'          => $input_context_fields,
322                                'options_contexts'                      => $options_context,
323                               
324                                'hidden_manager_lid'            => $hidden_manager_lid,
325                                'app_list'                                      => $applications_list
326                        );
327                        $p->set_var($var);
328                       
329                        // Cria dinamicamente os langs e seta acls
330                        foreach ($tpl_vars as $atribute)
331                        {
332                                $acl  = strstr($atribute, 'acl_');
333                                $lang = strstr($atribute, 'lang_');
334                                // Recuperar os valores das ACLS
335                                if ($acl !== false)
336                                {
337                                        if ($first_time)
338                                                $p->set_var($atribute, $manager_acl[$atribute] === '1' ? 'checked' : '');
339                                        else
340                                                $p->set_var($atribute, $_POST[$atribute] === '1' ? 'checked' : '');
341                                }
342                                // Setar os langs do tpl.
343                                elseif($lang !== false)
344                                {
345                                        $p->set_var($atribute, $this->make_lang($atribute));
346                                }
347                        }
348
349                        $GLOBALS[ 'phpgw_info' ][ 'flags' ][ 'java_script_thirst' ] .= "<script>var expressoAdmin_controller = '{$GLOBALS[ 'phpgw' ] -> link( '/expressoAdmin1_2/controller.php' )}?action=';</script>";
350                        echo $p->fp('out','form');
351                }
352                               
353                function make_lang($ram_lang)
354                {
355                        $a_lang = split("_", $ram_lang);
356                        $a_lang_reverse  = array_reverse ( $a_lang, true );
357                        //Retira o lang do array.
358                        array_pop ( $a_lang_reverse );
359                        $a_lang  = array_reverse ( $a_lang_reverse, true );
360                        $a_new_lang = implode ( " ", $a_lang );
361                        return lang($a_new_lang);
362                }
363               
364                function make_app_list($manager_app_list)
365                {
366                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
367                        $apps = CreateObject('phpgwapi.applications',$_account_id);
368                        $db_perms = $apps->read_account_specific();
369                        $availableApps = $GLOBALS['phpgw_info']['apps'];
370                       
371                        uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);'));
372                       
373                        // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box.
374                        $applications_list = '';
375                        $app_col1 = '';
376                        $app_col2 = '';
377                        $app_col3 = '';
378                        $total_apps = count($availableApps);
379                        $i = 0;
380
381                        foreach($availableApps as $app => $data)
382                        {
383                                // 1 coluna
384                                if (($i +1) % 3 == 1)
385                                {
386                                        if ($manager_app_list[$app] == 1)
387                                                $checked = 'checked';
388                                        else
389                                                $checked = '';
390                                        $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
391                                        $data['title'],$app,$checked, $disabled);
392                                       
393                                        if ($i == ($total_apps-1))
394                                                $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1);
395                                }
396                                // 2 coluna
397                                if (($i +1) % 3 == 2)
398                                {
399                                        if ($manager_app_list[$app] == 1)
400                                                $checked = 'checked';
401                                        else
402                                                $checked = '';
403                                        $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
404                                        $data['title'],$app,$checked, $disabled);
405                                       
406                                        if ($i == ($total_apps-1))
407                                                $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1,$app_col2);
408                                }
409                                // 3 coluna
410                                if (($i +1) % 3 == 0)
411                                {
412                                        if ($manager_app_list[$app] == 1)
413                                                $checked = 'checked';
414                                        else
415                                                $checked = '';
416                                        $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n",
417                                        $data['title'],$app,$checked, $disabled);
418                                       
419                                        // Cria nova linha
420                                        $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1, $app_col2, $app_col3);                                       
421                                }
422                                $i++;
423                        }
424                        return $applications_list;
425                }
426        }
427?>
Note: See TracBrowser for help on using the repository browser.