source: trunk/admin/inc/class.uiconfig.inc.php @ 5123

Revision 5123, 14.4 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo admin.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1<?php
2  /**************************************************************************\
3  * eGroupWare - Admin config                                                *
4  * Written by Miles Lott <milosch@phpwhere.org>                             *
5  * http://www.egroupware.org                                                *
6  * --------------------------------------------                             *
7  *  This program is free software; you can redistribute it and/or modify it *
8  *  under the terms of the GNU General Public License as published by the   *
9  *  Free Software Foundation; either version 2 of the License, or (at your  *
10  *  option) any later version.                                              *
11  \**************************************************************************/
12
13
14        class uiconfig
15        {
16                var $public_functions = array('index' => True);
17
18                function index()
19                {
20                        if ($GLOBALS['phpgw']->acl->check('site_config_access',1,'admin'))
21                        {
22                                $GLOBALS['phpgw']->redirect_link('/index.php');
23                        }
24
25                        if(get_magic_quotes_gpc() && is_array($_POST['newsettings']))
26                        {
27                                $_POST['newsettings'] = array_map("stripslashes", $_POST['newsettings']);
28                        }
29                       
30                        switch($_GET['appname'])
31                        {
32                                case 'admin':
33                                case 'addressbook':
34                                case 'calendar':
35                                case 'email':
36                                case 'instant_messenger':
[382]37                                case 'jabberit_messenger':
[2]38                                case 'nntp':
39                                        /*
40                                        Other special apps can go here for now, e.g.:
41                                        case 'bogusappname':
42                                        */
43                                        $appname = $_GET['appname'];
44                                        $config_appname = 'phpgwapi';
45                                        break;
46                                case 'phpgwapi':
47                                case '':
48                                        /* This keeps the admin from getting into what is a setup-only config */
49                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
50                                        break;
51                                default:
52                                        $appname = $_GET['appname'];
53                                        $config_appname = $appname;
54                                        break;
55                        }
56
57                        $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir($appname));
58                        $t->set_unknowns('keep');
59                        $t->set_file(array('config' => 'config.tpl'));
60                        $t->set_block('config','header','header');
61                        $t->set_block('config','body','body');
62                        $t->set_block('config','footer','footer');
63
64                        $c = CreateObject('phpgwapi.config',$config_appname);
65                        $c->read_repository();
66
67                        if ($c->config_data)
68                        {
69                                $current_config = $c->config_data;
70                        }
71
72                        if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin'))
73                        {
74                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
75                        }
76
77                        if ($_POST['submit'])
78                        {
79                                /* Load hook file with functions to validate each config (one/none/all) */
80                                $GLOBALS['phpgw']->hooks->single('config_validate',$appname);
[4500]81                               
82                                if (!isset($_POST['newsettings']['cc_allow_details'])) {
83                                        $_POST['newsettings']['cc_allow_details'] = "false";
84                                }
[2]85
86                                foreach($_POST['newsettings'] as $key => $config)
87                                {
[4500]88                                       
89                                        if ($config) 
90                                        {                                                                                                                                                                                 // Código adicionado 
91                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && (function_exists($key) || function_exists(substr($key,0,strrpos($key,'_')))) )
[2]92                                                {
[4500]93                                                        if(function_exists(substr($key,0,strrpos($key,'_'))))
94                                {
95                                call_user_func(substr($key,0,strrpos($key,'_')),&$config);
96                                }
97                                else
98                                {
99                                call_user_func($key,&$config);
100                                }
101
102                                if($GLOBALS['config_error'])
[2]103                                                        {
104                                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
105                                                                $GLOBALS['config_error'] = False;
106                                                        }
107                                                        else
108                                                        {
109                                                                $c->config_data[$key] = $config;
110                                                        }
111                                                }
112                                                else
113                                                {
114                                                        $c->config_data[$key] = $config;
115                                                }
116                                        }
117                                        else
118                                        {
119                                                /* don't erase passwords, since we also don't print them */
[4548]120                                                if(!ereg('passwd',$key) && !ereg('password',$key) && !ereg('root_pw',$key) && !ereg('pw',$key))
[2]121                                                {
122                                                        unset($c->config_data[$key]);
123                                                }
124                                        }
125                                }
126                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
127                                {
[4548]128                                        final_validation($c->config_data);
[2]129                                        if($GLOBALS['config_error'])
130                                        {
131                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
132                                                $GLOBALS['config_error'] = False;
133                                        }
134                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
135                                }
136
137                                $c->save_repository();
138
139                                if(!$errors)
140                                {
141                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
142                                }
143                        }
144
145                        if($errors)
146                        {
147                                $t->set_var('error',lang('Error') . ': ' . $errors);
148                                $t->set_var('th_err','#FF8888');
149                                unset($errors);
150                                unset($GLOBALS['config_error']);
151                        }
152                        else
153                        {
154                                $t->set_var('error','');
155                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
156                        }
157
158                        if(!@is_object($GLOBALS['phpgw']->js))
159                        {
160                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
161                        }
162                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
163
164                        $GLOBALS['phpgw']->common->phpgw_header();
165                        echo parse_navbar();
166
[4500]167                       
168                        $campos = '';
[4548]169                        $checked_box = array();
170                        $i = 0;
[4500]171                       
172                        if($appname=="contactcenter")
173                        {
174                               
175                                foreach ($c->config_data as $key => $config)
176                                {               
177                                        $parts = explode('_', $key);
178                        if (is_numeric($parts[3]) && $parts[1]=='attribute')
179                        {
180                        $fields[$parts[3]][$key] = $config;
181                        }
182                       
183                       
184                        if($key == 'cc_allow_details') {
185                                $checkedCoisa = 'value="details"';
186                                if ($config=='true') {
187                                        $checkedCoisa = 'value="details" checked="checked"';
188                                }
[4548]189                        }                       
190                                }
191       
192                                $campos_vazio = true;
[5123]193                                $campos = "
194                                                <input type=\"hidden\" id=\"textHidden\" value=\"".lang('Text')."\" />
195                                                <input type=\"hidden\" id=\"multitextHidden\" value=\"".lang('Multivalued')."\" />
196                                                <input type=\"hidden\" id=\"yesHidden\" value=\"".lang('Yes')."\" />
197                                                <input type=\"hidden\" id=\"noHidden\" value=\"".lang('No')."\" />
198                                                <input type=\"hidden\" id=\"deleteHidden\" value=\"".lang('Delete')."\" />
199                                                <table id=\"cc_newconf\" name=\"cc_newconf\" class=\"cc_attribute\">
200                                                   <tbody id=\"cc_newconftable\" name=\"cc_newconftable\">
201                                                        <tr>
202                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Name')               . "</td>
203                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Corresponding LDAP') . "</td>
204                                                                <td align=\"center\" style=\"width:100px; margin: 0px 0px 0px 8px;\">" . lang('Type')               . "</td>
205                                                                <td align=\"center\" style=\"width:80px; margin: 0px 16px;\">" . lang('Searchable')         . "</td>
206                                                                <td align=\"center\" style=\"width: 15px;\">
207                                                        </tr>";
[4500]208               
209                        foreach ($fields as $i => $line)
210                        {
[4548]211                                        if ($line["cc_attribute_name_$i"] != '' && $line["cc_attribute_ldapname_$i"] != '') {
212                                                $campos_vazio  = false;
[4500]213                        $selectedText  = $line["cc_attribute_type_$i"] == 'text' ? 'selected="selected"' : '';
214                        $selectedTMult = $line["cc_attribute_type_$i"] == 'multivalues' ? 'selected="selected"' : '';
[4548]215                                                $selectedYes   = $line["cc_attribute_searchable_$i"] == 'true'  ? 'selected="selected"' : '';
216                                                $selectedNo    = $line["cc_attribute_searchable_$i"] == 'false' ? 'selected="selected"' : '';
217
218                                               
[5123]219                                $campos = $campos . "
220                                                                <tr>
221                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_" . $i . "]\" value=\"".$line["cc_attribute_name_$i"]."\" style=\"width:170px;\"></input></td>
222                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_" . $i . "]\" value=\"".$line["cc_attribute_ldapname_$i"]."\" style=\"width:170px;\"></input></td>
223                                                                        <td><select name=\"newsettings[cc_attribute_type_" . $i . "]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
[4548]224                                                                                        <option value=\"text\" $selectedText>" . lang('Text') . "</option>
225                                                                                        <option value=\"multivalues\" $selectedTMult>" . lang('Multivalued') ."</option>
[5123]226                                                                        </select></td>
227                                                                        <td><select name=\"newsettings[cc_attribute_searchable_$i]\" style=\"margin: 0px 16px;\">
[4548]228                                                                                        <option value=\"true\" $selectedYes>" . lang('Yes') . "</option>
229                                                                                        <option value=\"false\" $selectedNo>" . lang('No') . "</option>
[5123]230                                                                        </select></td>
231                                                                        <td><img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') . "\" title=\"". lang('Delete') ."\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"></img></td> 
232                                                                </tr>";
[4500]233                        }
234                        }
235               
[4548]236                            if ($campos_vazio)
[4500]237                        {
[5123]238                                        $campos .= "<tr>
239                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_0]\" value=\"\" style=\"width:170px;\"/> </td>
240                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_0]\" value=\"\" style=\"width:170px;\"/> </td>
241                                                                        <td><select name=\"newsettings[cc_attribute_type_0]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
[4500]242                                        <option value=\"text\">" . lang('Text') . "</option>
243                                        <option value=\"multivalues\">" . lang('Multivalued') . "</option>
[5123]244                                                                        </select></td>
245                                                                        <td><select name=\"newsettings[cc_attribute_searchable_0]\" style=\"margin: 0px 16px;\">
[4548]246                                        <option value=\"true\">" . lang('Yes') . "</option>
247                                        <option value=\"false\" selected=\"selected\">" . lang('No') . "</option>
[5123]248                                                                        </select></td>
249                                                                        <td><img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') ."\" title=\"". lang('Delete') ."\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"/></td>
250                                                                </tr>";                         
[4500]251                        }
[5123]252                        $campos = $campos . "</tbody></table>";
[4500]253                       
254                        $t->set_var('lang_add_button', lang('Add'));
255                                $t->set_var('lang_cc_Set_details_attributes',   lang('Details on the Global Catalog Address'));
256                        $t->set_var('lang_cc_Allow_view_details_label', lang('Enable display of contact details for the Global Catalog'));                             
257                        $t->set_var('attribute_fields', $campos);               
258                        $t->set_var('cc_config_js', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_config.js');
259                        $t->set_var('cc_allow_view_details_value', $checkedCoisa);
260                        }
261               
262                       
[540]263                        if($appname=="expressoAdmin1_2") {
264                                /* Varre a pasta inc do admin do expresso procurando scripts de geração de login automático
265                                   (classes com nomes iniciados pela string 'login', procedida da string '_' mais o nome
266                                   do algoritmo.
267                                */
[597]268                               
[540]269                                $dir = $GLOBALS['phpgw']->common->get_app_dir($appname) . "/inc";
270                                $options = ' ';
[608]271                                if (is_dir($dir))
272                                {
273                                        if ($dh = opendir($dir))
274                                        {
275                                                while (($file = readdir($dh)) !== false)
276                                                {
[540]277                                                        $temp = explode(".",$file);
[608]278                                                        if( (substr($temp[1],0,5) =='login') && ($temp[0] == 'class') )
279                                                        {
[540]280                                                                $options .= "<option value='".$temp[1]."'";
281                                                                if($current_config['expressoAdmin_loginGenScript'] == $temp[1])
282                                                                        $options .= " selected";
283                                                                $options .= ">" . ucwords(str_replace("_"," ",substr($temp[1],6))) . "</option>";
284                                                        }                               
285                                                }
286                                                closedir($dh);
287                                        }
288                                }
289                               
290                                $t->set_var('rows_login_generator',$options);
291                        }
[547]292                       
293                       
[597]294                        if($appname=="admin") {                                                 
295                                /*
[608]296                                 * FCK editor to agree term
[597]297                                 */
298                                include_once("news_admin/inc/fckeditor.php");
299                                $oFCKeditor = new FCKeditor('newsettings[agree_term]');//CreateObject('news_admin.fckeditor','newsettings[agree_term]');
[1325]300                                $oFCKeditor->BasePath = 'news_admin/templates/default/fckeditor/';
[597]301                                $oFCKeditor->ToolbarSet = 'Basic';
[608]302                                $oFCKeditor->Value = isset($GLOBALS['phpgw_info']['server']['agree_term']) ? $GLOBALS['phpgw_info']['server']['agree_term'] : '';
[597]303                                $t->set_var('agree_term_input',$oFCKeditor->Create());                 
304                        }
[2]305                        $t->set_var('title',lang('Site Configuration'));
306                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
307                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
308                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
309                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
310                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
[3018]311                        $t->set_var('php_upload_limit',str_replace('M','',ini_get('upload_max_filesize')));
[2]312                        $t->pparse('out','header');
313
314                        $vars = $t->get_undefined('body');
315
316                        $GLOBALS['phpgw']->hooks->single('config',$appname);
317
318                        foreach($vars as $value)
319                        {
320                                $valarray = explode('_',$value);
321                                $type = array_shift($valarray);
322                                $newval = implode(' ',$valarray);
323                                switch ($type)
324                                {
325                                        case 'lang':
326                                                $t->set_var($value,lang($newval));
327                                                break;
328                                        case 'value':
329                                                $newval = str_replace(' ','_',$newval);
330                                                /* Don't show passwords in the form */
331                                                if(ereg('passwd',$value) || ereg('password',$value) || ereg('root_pw',$value))
332                                                {
333                                                        $t->set_var($value,'');
334                                                }
335                                                else
336                                                {
[1085]337                                                        $t->set_var($value,htmlspecialchars($current_config[$newval]));
[2]338                                                }
339                                                break;
340                                        /*
341                                        case 'checked':
342                                                $newval = str_replace(' ','_',$newval);
343                                                if ($current_config[$newval])
344                                                {
345                                                        $t->set_var($value,' checked');
346                                                }
347                                                else
348                                                {
349                                                        $t->set_var($value,'');
350                                                }
351                                                break;
352                                        */
353                                        case 'selected':
354                                                $configs = array();
355                                                $config  = '';
356                                                $newvals = explode(' ',$newval);
357                                                $setting = end($newvals);
358                                                for ($i=0;$i<(count($newvals) - 1); $i++)
359                                                {
360                                                        $configs[] = $newvals[$i];
361                                                }
362                                                $config = implode('_',$configs);
363                                                /* echo $config . '=' . $current_config[$config]; */
364                                                if ($current_config[$config] == $setting)
365                                                {
366                                                        $t->set_var($value,' selected');
367                                                }
368                                                else
369                                                {
370                                                        $t->set_var($value,'');
371                                                }
372                                                break;
373                                        case 'hook':
374                                                $newval = str_replace(' ','_',$newval);
375                                                if(function_exists($newval))
376                                                {
377                                                        $t->set_var($value,$newval($current_config));
378                                                }
379                                                else
380                                                {
381                                                        $t->set_var($value,'');
382                                                }
383                                                break;
384                                        default:
385                                        $t->set_var($value,'');
386                                        break;
387                                }
388                        }
389
390                        $t->pfp('out','body');
391
392                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
393                        $t->set_var('lang_cancel', lang('Cancel'));
394                        $t->pfp('out','footer');
395                }
396        }
397?>
Note: See TracBrowser for help on using the repository browser.