source: sandbox/2.2.0.2/admin/inc/class.uiconfig.inc.php @ 4500

Revision 4500, 12.9 KB checked in by airton, 13 years ago (diff)

Ticket #1926 - Permitir configurar mais atributos cadastrados de um contato para exibição

  • 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 ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin'))
73                        {
74                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
75                        }
76
77                        if ($_POST['submit'])
78                        {
79                                /* Load hook file with functions to validate each config (one/none/all) */
80                                $GLOBALS['phpgw']->hooks->single('config_validate',$appname);
81                               
82                                if (!isset($_POST['newsettings']['cc_allow_details'])) {
83                                        $_POST['newsettings']['cc_allow_details'] = "false";
84                                }
85
86                                foreach($_POST['newsettings'] as $key => $config)
87                                {
88                                       
89                                        if ($config) 
90                                        {                                                                                                                                                                                 // Código adicionado 
91                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && (function_exists($key) || function_exists(substr($key,0,strrpos($key,'_')))) )
92                                                {
93                                                        if(function_exists(substr($key,0,strrpos($key,'_'))))
94                                {
95                                call_user_func(substr($key,0,strrpos($key,'_')),&$config);
96                                }
97                                else
98                                {
99                                call_user_func($key,&$config);
100                                }
101
102                                if($GLOBALS['config_error'])
103                                                        {
104                                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
105                                                                $GLOBALS['config_error'] = False;
106                                                        }
107                                                        else
108                                                        {
109                                                                $c->config_data[$key] = $config;
110                                                        }
111                                                }
112                                                else
113                                                {
114                                                        $c->config_data[$key] = $config;
115                                                }
116                                        }
117                                        else
118                                        {
119                                                /* don't erase passwords, since we also don't print them */
120                                                if(!ereg('passwd',$key) && !ereg('password',$key) && !ereg('root_pw',$key))
121                                                {
122                                                        unset($c->config_data[$key]);
123                                                }
124                                        }
125                                }
126                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
127                                {
128                                        final_validation($newsettings);
129                                        if($GLOBALS['config_error'])
130                                        {
131                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
132                                                $GLOBALS['config_error'] = False;
133                                        }
134                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
135                                }
136
137                                $c->save_repository();
138
139                                if(!$errors)
140                                {
141                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
142                                }
143                        }
144
145                        if($errors)
146                        {
147                                $t->set_var('error',lang('Error') . ': ' . $errors);
148                                $t->set_var('th_err','#FF8888');
149                                unset($errors);
150                                unset($GLOBALS['config_error']);
151                        }
152                        else
153                        {
154                                $t->set_var('error','');
155                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
156                        }
157
158                        if(!@is_object($GLOBALS['phpgw']->js))
159                        {
160                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
161                        }
162                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
163
164                        $GLOBALS['phpgw']->common->phpgw_header();
165                        echo parse_navbar();
166
167                       
168                        $campos = '';
169                       
170                        if($appname=="contactcenter")
171                        {
172                               
173                                foreach ($c->config_data as $key => $config)
174                                {               
175                                        $parts = explode('_', $key);
176                        if (is_numeric($parts[3]) && $parts[1]=='attribute')
177                        {
178                        $fields[$parts[3]][$key] = $config;
179                        }
180                       
181                       
182                        if($key == 'cc_allow_details') {
183                                $checkedCoisa = 'value="details"';
184                                if ($config=='true') {
185                                        $checkedCoisa = 'value="details" checked="checked"';
186                                }
187                        }
188                }
189                       
190               
191                        foreach ($fields as $i => $line)
192                        {
193                        if ($line["cc_attribute_name_$i"] != '' && $line["cc_attribute_ldapname_$i"] != '') {
194                        $selectedText  = $line["cc_attribute_type_$i"] == 'text' ? 'selected="selected"' : '';
195                        $selectedTMult = $line["cc_attribute_type_$i"] == 'multivalues' ? 'selected="selected"' : '';
196                               
197                                $campos = $campos . "<div class=\"cc_attribute\">
198                                <label>" . lang('Name') .":</label>
199                                <input type=\"text\" name=\"newsettings[cc_attribute_name_" . $i . "]\" value=\"".$line["cc_attribute_name_$i"]."\" />
200                                <label>" . lang('Corresponding LDAP') . ":</label>
201                                <input type=\"text\" name=\"newsettings[cc_attribute_ldapname_" . $i . "]\" value=\"".$line["cc_attribute_ldapname_$i"]."\" />
202                                <label>" . lang('Type') . ":</label>
203                                <select name=\"newsettings[cc_attribute_type_" . $i . "]\">
204                                        <option value=\"text\" $selectedText>" . lang('Text') . "</option>
205                                        <option value=\"multivalues\" $selectedTMult>" . lang('Multivalued') ."</option>
206                                </select>
207                                <img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') . "\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"/> 
208                        </div>";
209                        }
210                        }
211               
212                            if ($campos == '')
213                        {
214                                $campos = "<div class=\"cc_attribute\">
215                                <label>" . lang('Name') .":</label>
216                                <input type=\"text\" name=\"newsettings[cc_attribute_name_0]\" value=\"\" />
217                                <label>" . lang('Corresponding LDAP') . ":</label>
218                                <input type=\"text\" name=\"newsettings[cc_attribute_ldapname_0]\" value=\"\" />
219                                <label>" . lang('Type') . ":</label>
220                                <select name=\"newsettings[cc_attribute_type_0]\">
221                                        <option value=\"text\">" . lang('Text') . "</option>
222                                        <option value=\"multivalues\">" . lang('Multivalued') . "</option>
223                                </select>
224                                <img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') ."\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"/>
225                        </div>";
226                        }
227                       
228                        $t->set_var('lang_add_button', lang('Add'));
229                                $t->set_var('lang_cc_Set_details_attributes',   lang('Details on the Global Catalog Address'));
230                        $t->set_var('lang_cc_Allow_view_details_label', lang('Enable display of contact details for the Global Catalog'));                             
231                        $t->set_var('attribute_fields', $campos);               
232                        $t->set_var('cc_config_js', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_config.js');
233                        $t->set_var('cc_allow_view_details_value', $checkedCoisa);
234                        }
235               
236                       
237                        if($appname=="expressoAdmin1_2") {
238                                /* Varre a pasta inc do admin do expresso procurando scripts de geração de login automático
239                                   (classes com nomes iniciados pela string 'login', procedida da string '_' mais o nome
240                                   do algoritmo.
241                                */
242                               
243                                $dir = $GLOBALS['phpgw']->common->get_app_dir($appname) . "/inc";
244                                $options = ' ';
245                                if (is_dir($dir))
246                                {
247                                        if ($dh = opendir($dir))
248                                        {
249                                                while (($file = readdir($dh)) !== false)
250                                                {
251                                                        $temp = explode(".",$file);
252                                                        if( (substr($temp[1],0,5) =='login') && ($temp[0] == 'class') )
253                                                        {
254                                                                $options .= "<option value='".$temp[1]."'";
255                                                                if($current_config['expressoAdmin_loginGenScript'] == $temp[1])
256                                                                        $options .= " selected";
257                                                                $options .= ">" . ucwords(str_replace("_"," ",substr($temp[1],6))) . "</option>";
258                                                        }                               
259                                                }
260                                                closedir($dh);
261                                        }
262                                }
263                               
264                                $t->set_var('rows_login_generator',$options);
265                        }
266                       
267                       
268                        if($appname=="admin") {                                                 
269                                /*
270                                 * FCK editor to agree term
271                                 */
272                                include_once("news_admin/inc/fckeditor.php");
273                                $oFCKeditor = new FCKeditor('newsettings[agree_term]');//CreateObject('news_admin.fckeditor','newsettings[agree_term]');
274                                $oFCKeditor->BasePath = 'news_admin/templates/default/fckeditor/';
275                                $oFCKeditor->ToolbarSet = 'Basic';
276                                $oFCKeditor->Value = isset($GLOBALS['phpgw_info']['server']['agree_term']) ? $GLOBALS['phpgw_info']['server']['agree_term'] : '';
277                                $t->set_var('agree_term_input',$oFCKeditor->Create());                 
278                        }
279                        $t->set_var('title',lang('Site Configuration'));
280                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
281                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
282                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
283                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
284                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
285                        $t->set_var('php_upload_limit',str_replace('M','',ini_get('upload_max_filesize')));
286                        $t->pparse('out','header');
287
288                        $vars = $t->get_undefined('body');
289
290                        $GLOBALS['phpgw']->hooks->single('config',$appname);
291
292                        foreach($vars as $value)
293                        {
294                                $valarray = explode('_',$value);
295                                $type = array_shift($valarray);
296                                $newval = implode(' ',$valarray);
297                                switch ($type)
298                                {
299                                        case 'lang':
300                                                $t->set_var($value,lang($newval));
301                                                break;
302                                        case 'value':
303                                                $newval = str_replace(' ','_',$newval);
304                                                /* Don't show passwords in the form */
305                                                if(ereg('passwd',$value) || ereg('password',$value) || ereg('root_pw',$value))
306                                                {
307                                                        $t->set_var($value,'');
308                                                }
309                                                else
310                                                {
311                                                        $t->set_var($value,htmlspecialchars($current_config[$newval]));
312                                                }
313                                                break;
314                                        /*
315                                        case 'checked':
316                                                $newval = str_replace(' ','_',$newval);
317                                                if ($current_config[$newval])
318                                                {
319                                                        $t->set_var($value,' checked');
320                                                }
321                                                else
322                                                {
323                                                        $t->set_var($value,'');
324                                                }
325                                                break;
326                                        */
327                                        case 'selected':
328                                                $configs = array();
329                                                $config  = '';
330                                                $newvals = explode(' ',$newval);
331                                                $setting = end($newvals);
332                                                for ($i=0;$i<(count($newvals) - 1); $i++)
333                                                {
334                                                        $configs[] = $newvals[$i];
335                                                }
336                                                $config = implode('_',$configs);
337                                                /* echo $config . '=' . $current_config[$config]; */
338                                                if ($current_config[$config] == $setting)
339                                                {
340                                                        $t->set_var($value,' selected');
341                                                }
342                                                else
343                                                {
344                                                        $t->set_var($value,'');
345                                                }
346                                                break;
347                                        case 'hook':
348                                                $newval = str_replace(' ','_',$newval);
349                                                if(function_exists($newval))
350                                                {
351                                                        $t->set_var($value,$newval($current_config));
352                                                }
353                                                else
354                                                {
355                                                        $t->set_var($value,'');
356                                                }
357                                                break;
358                                        default:
359                                        $t->set_var($value,'');
360                                        break;
361                                }
362                        }
363
364                        $t->pfp('out','body');
365
366                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
367                        $t->set_var('lang_cancel', lang('Cancel'));
368                        $t->pfp('out','footer');
369                }
370        }
371?>
Note: See TracBrowser for help on using the repository browser.