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

Revision 8175, 18.3 KB checked in by angelo, 11 years ago (diff)

Ticket #3461 - Link errado para interface de migracao de eventos da antiga para a nova agenda

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