source: sandbox/2.5.1-evolucao/admin/inc/class.uiconfig.inc.php @ 8231

Revision 8231, 18.3 KB checked in by angelo, 10 years ago (diff)

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

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