source: companies/serpro/admin/inc/class.uiconfig.inc.php @ 903

Revision 903, 7.0 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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                                foreach($_POST['newsettings'] as $key => $config)
83                                {
84                                        if ($config)
85                                        {
86                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists($key))
87                                                {
88                                                        call_user_func($key,$config);
89                                                        if($GLOBALS['config_error'])
90                                                        {
91                                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
92                                                                $GLOBALS['config_error'] = False;
93                                                        }
94                                                        else
95                                                        {
96                                                                $c->config_data[$key] = $config;
97                                                        }
98                                                }
99                                                else
100                                                {
101                                                        $c->config_data[$key] = $config;
102                                                }
103                                        }
104                                        else
105                                        {
106                                                /* don't erase passwords, since we also don't print them */
107                                                if(!ereg('passwd',$key) && !ereg('password',$key) && !ereg('root_pw',$key))
108                                                {
109                                                        unset($c->config_data[$key]);
110                                                }
111                                        }
112                                }
113
114                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
115                                {
116                                        final_validation($newsettings);
117                                        if($GLOBALS['config_error'])
118                                        {
119                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
120                                                $GLOBALS['config_error'] = False;
121                                        }
122                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
123                                }
124                               
125                                 if(!$_POST['newsettings']['posiciona_login'])
126                                 {
127                                        unset($c->config_data['posiciona_login']);
128                                 }
129                                 
130                                $c->save_repository();
131
132                                if(!$errors)
133                                {
134                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
135                                }
136                        }
137
138                        if($errors)
139                        {
140                                $t->set_var('error',lang('Error') . ': ' . $errors);
141                                $t->set_var('th_err','#FF8888');
142                                unset($errors);
143                                unset($GLOBALS['config_error']);
144                        }
145                        else
146                        {
147                                $t->set_var('error','');
148                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
149                        }
150
151                        if(!@is_object($GLOBALS['phpgw']->js))
152                        {
153                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
154                        }
155                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
156                        $GLOBALS['phpgw']->js->validate_file('jscode','MiniColorPicker','admin');
157
158                        $GLOBALS['phpgw']->common->phpgw_header();
159                        echo parse_navbar();
160
161                        $t->set_var('title',lang('Site Configuration'));
162                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
163                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
164                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
165                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
166                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
167                        $t->pparse('out','header');
168
169                        $vars = $t->get_undefined('body');
170
171                        $GLOBALS['phpgw']->hooks->single('config',$appname);
172                       
173               
174                        foreach($vars as $value)
175                        {
176                                $valarray = explode('_',$value);
177                                $type = array_shift($valarray);
178                                $newval = implode(' ',$valarray);
179                                switch ($type)
180                                {
181                                        case 'lang':
182                                                $t->set_var($value,lang($newval));
183                                                break;
184                                        case 'value':
185                                                $newval = str_replace(' ','_',$newval);
186                                                /* Don't show passwords in the form */
187                                                if(ereg('passwd',$value) || ereg('password',$value) || ereg('root_pw',$value))
188                                                {
189                                                        $t->set_var($value,'');
190                                                }
191                                                else
192                                                {
193                                                        $t->set_var($value,$current_config[$newval]);
194                                                }
195                                                break;
196
197                                        case 'checked':
198                                                $newval = str_replace(' ','_',$newval);
199                                                if ($current_config[$newval])
200                                                {
201                                                        $t->set_var($value,' checked');
202                                                }
203                                                else
204                                                {
205                                                        $t->set_var($value,'');
206                                                }
207                                                break;
208
209                                        case 'selected':
210                                                $configs = array();
211                                                $config  = '';
212                                                $newvals = explode(' ',$newval);
213                                                $setting = end($newvals);
214                                                for ($i=0;$i<(count($newvals) - 1); $i++)
215                                                {
216                                                        $configs[] = $newvals[$i];
217                                                }
218                                                $config = implode('_',$configs);
219                                                /* echo $config . '=' . $current_config[$config]; */
220                                                if ($current_config[$config] == $setting)
221                                                {
222                                                        $t->set_var($value,' selected');
223                                                }
224                                                else
225                                                {
226                                                        $t->set_var($value,'');
227                                                }
228                                                break;
229                                        case 'hook':
230                                                $newval = str_replace(' ','_',$newval);
231                                                if(function_exists($newval))
232                                                {
233                                                        $t->set_var($value,$newval($current_config));
234                                                }
235                                                else
236                                                {
237                                                        $t->set_var($value,'');
238                                                }
239                                                break;
240                                        default:
241                                        $t->set_var($value,'');
242                                        break;
243                                }
244                        }
245
246                        $t->pfp('out','body');
247
248                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
249                        $t->set_var('lang_cancel', lang('Cancel'));
250                        $t->pfp('out','footer');
251                }
252        }
253?>
Note: See TracBrowser for help on using the repository browser.