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

Revision 5988, 16.0 KB checked in by marcieli, 12 years ago (diff)

Ticket #2633 - Concluído: Inserir validação de limite de marcadores no Administrador.

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