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

Revision 2, 6.7 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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 'nntp':
38                                        /*
39                                        Other special apps can go here for now, e.g.:
40                                        case 'bogusappname':
41                                        */
42                                        $appname = $_GET['appname'];
43                                        $config_appname = 'phpgwapi';
44                                        break;
45                                case 'phpgwapi':
46                                case '':
47                                        /* This keeps the admin from getting into what is a setup-only config */
48                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
49                                        break;
50                                default:
51                                        $appname = $_GET['appname'];
52                                        $config_appname = $appname;
53                                        break;
54                        }
55
56                        $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir($appname));
57                        $t->set_unknowns('keep');
58                        $t->set_file(array('config' => 'config.tpl'));
59                        $t->set_block('config','header','header');
60                        $t->set_block('config','body','body');
61                        $t->set_block('config','footer','footer');
62
63                        $c = CreateObject('phpgwapi.config',$config_appname);
64                        $c->read_repository();
65
66                        if ($c->config_data)
67                        {
68                                $current_config = $c->config_data;
69                        }
70
71                        if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin'))
72                        {
73                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
74                        }
75
76                        if ($_POST['submit'])
77                        {
78                                /* Load hook file with functions to validate each config (one/none/all) */
79                                $GLOBALS['phpgw']->hooks->single('config_validate',$appname);
80
81                                foreach($_POST['newsettings'] as $key => $config)
82                                {
83                                        if ($config)
84                                        {
85                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists($key))
86                                                {
87                                                        call_user_func($key,$config);
88                                                        if($GLOBALS['config_error'])
89                                                        {
90                                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
91                                                                $GLOBALS['config_error'] = False;
92                                                        }
93                                                        else
94                                                        {
95                                                                $c->config_data[$key] = $config;
96                                                        }
97                                                }
98                                                else
99                                                {
100                                                        $c->config_data[$key] = $config;
101                                                }
102                                        }
103                                        else
104                                        {
105                                                /* don't erase passwords, since we also don't print them */
106                                                if(!ereg('passwd',$key) && !ereg('password',$key) && !ereg('root_pw',$key))
107                                                {
108                                                        unset($c->config_data[$key]);
109                                                }
110                                        }
111                                }
112                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
113                                {
114                                        final_validation($newsettings);
115                                        if($GLOBALS['config_error'])
116                                        {
117                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
118                                                $GLOBALS['config_error'] = False;
119                                        }
120                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
121                                }
122
123                                $c->save_repository();
124
125                                if(!$errors)
126                                {
127                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
128                                }
129                        }
130
131                        if($errors)
132                        {
133                                $t->set_var('error',lang('Error') . ': ' . $errors);
134                                $t->set_var('th_err','#FF8888');
135                                unset($errors);
136                                unset($GLOBALS['config_error']);
137                        }
138                        else
139                        {
140                                $t->set_var('error','');
141                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
142                        }
143
144                        if(!@is_object($GLOBALS['phpgw']->js))
145                        {
146                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
147                        }
148                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
149
150                        $GLOBALS['phpgw']->common->phpgw_header();
151                        echo parse_navbar();
152
153                        $t->set_var('title',lang('Site Configuration'));
154                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
155                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
156                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
157                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
158                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
159                        $t->pparse('out','header');
160
161                        $vars = $t->get_undefined('body');
162
163                        $GLOBALS['phpgw']->hooks->single('config',$appname);
164
165                        foreach($vars as $value)
166                        {
167                                $valarray = explode('_',$value);
168                                $type = array_shift($valarray);
169                                $newval = implode(' ',$valarray);
170                                switch ($type)
171                                {
172                                        case 'lang':
173                                                $t->set_var($value,lang($newval));
174                                                break;
175                                        case 'value':
176                                                $newval = str_replace(' ','_',$newval);
177                                                /* Don't show passwords in the form */
178                                                if(ereg('passwd',$value) || ereg('password',$value) || ereg('root_pw',$value))
179                                                {
180                                                        $t->set_var($value,'');
181                                                }
182                                                else
183                                                {
184                                                        $t->set_var($value,$current_config[$newval]);
185                                                }
186                                                break;
187                                        /*
188                                        case 'checked':
189                                                $newval = str_replace(' ','_',$newval);
190                                                if ($current_config[$newval])
191                                                {
192                                                        $t->set_var($value,' checked');
193                                                }
194                                                else
195                                                {
196                                                        $t->set_var($value,'');
197                                                }
198                                                break;
199                                        */
200                                        case 'selected':
201                                                $configs = array();
202                                                $config  = '';
203                                                $newvals = explode(' ',$newval);
204                                                $setting = end($newvals);
205                                                for ($i=0;$i<(count($newvals) - 1); $i++)
206                                                {
207                                                        $configs[] = $newvals[$i];
208                                                }
209                                                $config = implode('_',$configs);
210                                                /* echo $config . '=' . $current_config[$config]; */
211                                                if ($current_config[$config] == $setting)
212                                                {
213                                                        $t->set_var($value,' selected');
214                                                }
215                                                else
216                                                {
217                                                        $t->set_var($value,'');
218                                                }
219                                                break;
220                                        case 'hook':
221                                                $newval = str_replace(' ','_',$newval);
222                                                if(function_exists($newval))
223                                                {
224                                                        $t->set_var($value,$newval($current_config));
225                                                }
226                                                else
227                                                {
228                                                        $t->set_var($value,'');
229                                                }
230                                                break;
231                                        default:
232                                        $t->set_var($value,'');
233                                        break;
234                                }
235                        }
236
237                        $t->pfp('out','body');
238
239                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
240                        $t->set_var('lang_cancel', lang('Cancel'));
241                        $t->pfp('out','footer');
242                }
243        }
244?>
Note: See TracBrowser for help on using the repository browser.