source: branches/2.4/admin/inc/class.uiconfig.inc.php @ 6754

Revision 6754, 16.9 KB checked in by niltonneto, 12 years ago (diff)

Ticket #0000 - Copiadas as alterações do Trunk. Versão final da 2.4.1.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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
13require_once('prototype/api/config.php');
14use prototype\api\Config as Config;
15
16        class uiconfig
17        {
18                var $public_functions = array('index' => True);
19
20                function index()
21                {
22                        if ($GLOBALS['phpgw']->acl->check('site_config_access',1,'admin'))
23                        {
24                                $GLOBALS['phpgw']->redirect_link('/index.php');
25                        }
26
27                        if(get_magic_quotes_gpc() && is_array($_POST['newsettings']))
28                        {
29                                $_POST['newsettings'] = array_map("stripslashes", $_POST['newsettings']);
30                        }
31                       
32                        switch($_GET['appname'])
33                        {
34                                case 'admin':
35                                case 'addressbook':
36                                case 'calendar':
37                                case 'email':
38                                case 'instant_messenger':
39                                case 'jabberit_messenger':
40                                case 'nntp':
41                                        /*
42                                        Other special apps can go here for now, e.g.:
43                                        case 'bogusappname':
44                                        */
45                                        $appname = $_GET['appname'];
46                                        $config_appname = 'phpgwapi';
47                                        break;
48                                case 'phpgwapi':
49                                case '':
50                                        /* This keeps the admin from getting into what is a setup-only config */
51                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
52                                        break;
53                                default:
54                                        $appname = $_GET['appname'];
55                                        $config_appname = $appname;
56                                        break;
57                        }
58
59                        $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir($appname));
60                        $t->set_unknowns('keep');
61                        $t->set_file(array('config' => 'config.tpl'));
62                        $t->set_block('config','header','header');
63                        $t->set_block('config','body','body');
64                        $t->set_block('config','footer','footer');
65
66                        $c = CreateObject('phpgwapi.config',$config_appname);
67                        $c->read_repository();
68
69                        if ($c->config_data)
70                        {
71                                $current_config = $c->config_data;
72                        }
73       
74                if($appname === "expressoCalendar"){                                           
75                        if (isset($_POST['migration']) && ($_POST['migration']  == "true")){
76                       
77                                require_once dirname(__FILE__ )."/../../expressoCalendar/inc/class.ui_migration.inc.php";
78
79                                $migratrion = new Migra();
80                                $migratrion->calendar();
81                        }
82                }
83
84                        if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin'))
85                        {
86                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
87                        }
88
89                        if ($_POST['submit'])
90                        {
91                                /* Load hook file with functions to validate each config (one/none/all) */
92                                $GLOBALS['phpgw']->hooks->single('config_validate',$appname);
93                               
94                                if (!isset($_POST['newsettings']['cc_allow_details'])) {
95                                        $_POST['newsettings']['cc_allow_details'] = "false";
96                                }
97
98                                foreach($_POST['newsettings'] as $key => $config)
99                                {
100                                       
101                                        if ($config) 
102                                        {                                                                                                                                                                                 // Código adicionado 
103                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && (function_exists($key) || function_exists(substr($key,0,strrpos($key,'_')))) )
104                                                {
105                                                        if(function_exists(substr($key,0,strrpos($key,'_'))))
106                                {
107                                call_user_func(substr($key,0,strrpos($key,'_')),&$config);
108                                }
109                                else
110                                {
111                                call_user_func($key,&$config);
112                                }
113
114                                if($GLOBALS['config_error'])
115                                                        {
116                                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
117                                                                $GLOBALS['config_error'] = False;
118                                                        }
119                                                        else
120                                                        {
121                                                                $c->config_data[$key] = $config;
122                                                        }
123                                                }
124                                                else
125                                                {
126                                                        $c->config_data[$key] = $config;
127                                                }
128                                        }
129                                        else
130                                        {
131                                                /* don't erase passwords, since we also don't print them */
132                                                if(!preg_match('/passwd/',$key) && !preg_match('/password/',$key) && !preg_match('/root_pw/',$key) && !preg_match('/pw/',$key))
133                                                {
134                                                        unset($c->config_data[$key]);
135                                                }
136                                        }
137                                }
138                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
139                                {
140                                        final_validation($c->config_data);
141                                        if($GLOBALS['config_error'])
142                                        {
143                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
144                                                $GLOBALS['config_error'] = False;
145                                        }
146                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
147                                }
148
149                                $c->save_repository();
150
151                                if(!$errors)
152                                {
153                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
154                                }
155                        }
156
157                        if($errors)
158                        {
159                                $t->set_var('error',lang('Error') . ': ' . $errors);
160                                $t->set_var('th_err','#FF8888');
161                                unset($errors);
162                                unset($GLOBALS['config_error']);
163                        }
164                        else
165                        {
166                                $t->set_var('error','');
167                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
168                        }
169
170                        if(!@is_object($GLOBALS['phpgw']->js))
171                        {
172                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
173                        }
174                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
175
176                        $GLOBALS['phpgw']->common->phpgw_header();
177                        echo parse_navbar();
178
179                       
180                        $campos = '';
181                        $checked_box = array();
182                        $i = 0;
183                       
184                        if($appname=="contactcenter")
185                        {
186                               
187                                foreach ($c->config_data as $key => $config)
188                                {               
189                                        $parts = explode('_', $key);
190                        if (is_numeric($parts[3]) && $parts[1]=='attribute')
191                        {
192                        $fields[$parts[3]][$key] = $config;
193                        }
194                       
195                       
196                        if($key == 'cc_allow_details') {
197                                $checkedCoisa = 'value="details"';
198                                if ($config=='true') {
199                                        $checkedCoisa = 'value="details" checked="checked"';
200                                }
201                        }                       
202                                }
203       
204                                $campos_vazio = true;
205                                $campos = "
206                                                <input type=\"hidden\" id=\"textHidden\" value=\"".lang('Text')."\" />
207                                                <input type=\"hidden\" id=\"multitextHidden\" value=\"".lang('Multivalued')."\" />
208                                                <input type=\"hidden\" id=\"yesHidden\" value=\"".lang('Yes')."\" />
209                                                <input type=\"hidden\" id=\"noHidden\" value=\"".lang('No')."\" />
210                                                <input type=\"hidden\" id=\"deleteHidden\" value=\"".lang('Delete')."\" />
211                                                <table id=\"cc_newconf\" name=\"cc_newconf\" class=\"cc_attribute\">
212                                                   <tbody id=\"cc_newconftable\" name=\"cc_newconftable\">
213                                                        <tr>
214                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Name')               . "</td>
215                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Corresponding LDAP') . "</td>
216                                                                <td align=\"center\" style=\"width:100px; margin: 0px 0px 0px 8px;\">" . lang('Type')               . "</td>
217                                                                <td align=\"center\" style=\"width:80px; margin: 0px 16px;\">" . lang('Searchable')         . "</td>
218                                                                <td align=\"center\" style=\"width: 15px;\">
219                                                        </tr>";
220               
221                        foreach ($fields as $i => $line)
222                        {
223                                        if ($line["cc_attribute_name_$i"] != '' && $line["cc_attribute_ldapname_$i"] != '') {
224                                                $campos_vazio  = false;
225                        $selectedText  = $line["cc_attribute_type_$i"] == 'text' ? 'selected="selected"' : '';
226                        $selectedTMult = $line["cc_attribute_type_$i"] == 'multivalues' ? 'selected="selected"' : '';
227                                                $selectedYes   = $line["cc_attribute_searchable_$i"] == 'true'  ? 'selected="selected"' : '';
228                                                $selectedNo    = $line["cc_attribute_searchable_$i"] == 'false' ? 'selected="selected"' : '';
229
230                                               
231                                $campos = $campos . "
232                                                                <tr>
233                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_" . $i . "]\" value=\"".$line["cc_attribute_name_$i"]."\" style=\"width:170px;\"></input></td>
234                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_" . $i . "]\" value=\"".$line["cc_attribute_ldapname_$i"]."\" style=\"width:170px;\"></input></td>
235                                                                        <td><select name=\"newsettings[cc_attribute_type_" . $i . "]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
236                                                                                        <option value=\"text\" $selectedText>" . lang('Text') . "</option>
237                                                                                        <option value=\"multivalues\" $selectedTMult>" . lang('Multivalued') ."</option>
238                                                                        </select></td>
239                                                                        <td><select name=\"newsettings[cc_attribute_searchable_$i]\" style=\"margin: 0px 16px;\">
240                                                                                        <option value=\"true\" $selectedYes>" . lang('Yes') . "</option>
241                                                                                        <option value=\"false\" $selectedNo>" . lang('No') . "</option>
242                                                                        </select></td>
243                                                                        <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> 
244                                                                </tr>";
245                        }
246                        }
247               
248                            if ($campos_vazio)
249                        {
250                                        $campos .= "<tr>
251                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_0]\" value=\"\" style=\"width:170px;\"/> </td>
252                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_0]\" value=\"\" style=\"width:170px;\"/> </td>
253                                                                        <td><select name=\"newsettings[cc_attribute_type_0]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
254                                        <option value=\"text\">" . lang('Text') . "</option>
255                                        <option value=\"multivalues\">" . lang('Multivalued') . "</option>
256                                                                        </select></td>
257                                                                        <td><select name=\"newsettings[cc_attribute_searchable_0]\" style=\"margin: 0px 16px;\">
258                                        <option value=\"true\">" . lang('Yes') . "</option>
259                                        <option value=\"false\" selected=\"selected\">" . lang('No') . "</option>
260                                                                        </select></td>
261                                                                        <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>
262                                                                </tr>";                         
263                        }
264                        $campos = $campos . "</tbody></table>";
265                       
266                        $t->set_var('lang_add_button', lang('Add'));
267                                $t->set_var('lang_cc_Set_details_attributes',   lang('Details on the Global Catalog Address'));
268                        $t->set_var('lang_cc_Allow_view_details_label', lang('Enable display of contact details for the Global Catalog'));                             
269                        $t->set_var('attribute_fields', $campos);               
270                        $t->set_var('cc_config_js', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_config.js');
271                        $t->set_var('cc_allow_view_details_value', $checkedCoisa);
272                        }
273               
274                       
275                        if($appname=="expressoAdmin1_2") {
276                                /* Varre a pasta inc do admin do expresso procurando scripts de geração de login automático
277                                   (classes com nomes iniciados pela string 'login', procedida da string '_' mais o nome
278                                   do algoritmo.
279                                */
280                               
281                                $dir = $GLOBALS['phpgw']->common->get_app_dir($appname) . "/inc";
282                                $options = ' ';
283                                if (is_dir($dir))
284                                {
285                                        if ($dh = opendir($dir))
286                                        {
287                                                while (($file = readdir($dh)) !== false)
288                                                {
289                                                        $temp = explode(".",$file);
290                                                        if( (substr($temp[1],0,5) =='login') && ($temp[0] == 'class') )
291                                                        {
292                                                                $options .= "<option value='".$temp[1]."'";
293                                                                if($current_config['expressoAdmin_loginGenScript'] == $temp[1])
294                                                                        $options .= " selected";
295                                                                $options .= ">" . ucwords(str_replace("_"," ",substr($temp[1],6))) . "</option>";
296                                                        }                               
297                                                }
298                                                closedir($dh);
299                                        }
300                                }
301                               
302                                $t->set_var('rows_login_generator',$options);
303                        }               
304                       
305                        if($appname=="admin") {                                                 
306                                /*
307                                 * New CKEditor to agree term
308                                 */
309                                $content = isset($GLOBALS['phpgw_info']['server']['agree_term']) ? $GLOBALS['phpgw_info']['server']['agree_term'] : '';
310                                $ckeditor = '<script type="text/javascript" src="./library/ckeditor/ckeditor.js"></script>
311                                                        <textarea cols="80" id="newsettings[agree_term]" name="newsettings[agree_term]" rows="10">' . $content . '</textarea>
312                                                        <script type="text/javascript"> CKEDITOR.replace( \'newsettings[agree_term]\',{
313                                                                removePlugins : \'elementspath\',
314                                                                skin : \'office2003\',
315                                                                toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
316                                                                "Undo","Redo","-","Find","Replace","-","SelectAll" ],
317                                                                ["Table","HorizontalRule","SpecialChar","PageBreak","-","Bold",
318                                                                "Italic","Underline","Strike","-","Subscript","Superscript",
319                                                                "NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
320                                                                "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
321                                                                "Link", "TextColor","BGColor","Maximize"],
322                                                                ["Styles","Format","Font","FontSize"]]
323                                                        });</script>';
324                                $t->set_var('agree_term_input',$ckeditor);
325                        }
326                        $t->set_var('title',lang('Site Configuration'));
327                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
328                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
329                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
330                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
331                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
332                        $t->set_var('php_upload_limit',str_replace('M','',ini_get('upload_max_filesize')));
333                        $t->pparse('out','header');
334
335                        $vars = $t->get_undefined('body');
336
337                        $GLOBALS['phpgw']->hooks->single('config',$appname);
338                       
339                        /* Seta o valor padrão para a configuração de número máximo de marcadores */
340                        $current_config['expressoMail_limit_labels'] = (isset($current_config['expressoMail_limit_labels']) && !!$current_config['expressoMail_limit_labels'] ) ? $current_config['expressoMail_limit_labels'] : 20;
341                        //Pegar os todos os Atributos LDAP mapeados no arquivo user.ini
342                        $map = Config::get('user', 'OpenLDAP.mapping');
343                        $validate = false;     
344                        $options = "<option value=''>".lang('None')."</option>";
345                        foreach($map as $value){
346                                $options .= "<option value='".$value."'";
347                                if($current_config['expressoMail_ldap_identifier_recipient'] == $value){
348                                        $validate = true;
349                                        $options .= " selected='selected'";
350                                }
351                                $options .= ">". $value . "</option>";
352                        }
353
354                        if(!$validate){
355                                // Limpa Atributo LDAP do banco de dados caso a atribuição não exista mais.     
356                                $db = '';
357                                $db = $db ? $db : $GLOBALS['phpgw']->db;        // this is to allow setup to set the db
358                                $db->query("DELETE FROM phpgw_config WHERE config_app = '".$appname."' AND config_name = 'expressoMail_ldap_identifier_recipient'");
359                        }
360                        /* Recupera o número mínimo de marcadores que pode ser definido */
361                        $db = '';
362                        $db = $db ? $db : $GLOBALS['phpgw']->db;        // this is to allow setup to set the db
363                        $db->query("SELECT max(slot) as slot from expressomail_label",__LINE__,__FILE__);
364                        while( $db->next_record() )
365                        {
366                                $cont_labels = $db->f('slot');
367                        }
368
369                        foreach($vars as $value)
370                        {
371                                $valarray = explode('_',$value);
372                                $type = array_shift($valarray);
373                                $newval = implode(' ',$valarray);
374                                switch ($type)
375                                {
376                                        case 'lang':
377                                                $t->set_var($value,lang($newval));
378                                                break;
379                                        case 'value':
380                                                $newval = str_replace(' ','_',$newval);
381                                                /* Don't show passwords in the form */
382                                                if(preg_match('/passwd/',$value) || preg_match('/password/',$value) || preg_match('/root_pw/',$value))
383                                                {
384                                                        $t->set_var($value,'');
385                                                }
386                                                else
387                                                {
388                                                        $t->set_var($value,htmlspecialchars($current_config[$newval]));
389                                                }
390                                                break;
391                                        /*
392                                        case 'checked':
393                                                $newval = str_replace(' ','_',$newval);
394                                                if ($current_config[$newval])
395                                                {
396                                                        $t->set_var($value,' checked');
397                                                }
398                                                else
399                                                {
400                                                        $t->set_var($value,'');
401                                                }
402                                                break;
403                                        */
404                                        case 'selected':
405                                                $configs = array();
406                                                $config  = '';
407                                                $newvals = explode(' ',$newval);
408                                                $setting = end($newvals);
409                                                for ($i=0;$i<(count($newvals) - 1); $i++)
410                                                {
411                                                        $configs[] = $newvals[$i];
412                                                }
413                                                $config = implode('_',$configs);
414                                                /* echo $config . '=' . $current_config[$config]; */
415                                                if ($current_config[$config] == $setting)
416                                                {
417                                                        $t->set_var($value,' selected');
418                                                }
419                                                else
420                                                {
421                                                        $t->set_var($value,'');
422                                                }
423                                                break;
424                                        case 'hook':
425                                                $newval = str_replace(' ','_',$newval);
426                                                if(function_exists($newval))
427                                                {
428                                                        $t->set_var($value,$newval($current_config));
429                                                }
430                                                else
431                                                {
432                                                        $t->set_var($value,'');
433                                                }
434                                                break;
435                                        default:
436                                        $t->set_var($value,'');
437                                        break;
438                                }
439                        }
440
441                        $t->set_var('min_labels',$cont_labels);
442                       
443                        $t->set_var('rows_ldap_identifier',$options);
444                        $t->pfp('out','body');
445
446                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
447                        $t->set_var('lang_cancel', lang('Cancel'));
448                        $t->pfp('out','footer');
449                }
450        }
451?>
Note: See TracBrowser for help on using the repository browser.