source: sandbox/2.5.1-evolucao/setup/config.php @ 8229

Revision 8229, 8.5 KB checked in by angelo, 10 years ago (diff)

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Setup                                                       *
4  * http://www.egroupware.org                                                *
5  * --------------------------------------------                             *
6  *  This program is free software; you can redistribute it and/or modify it *
7  *  under the terms of the GNU General Public License as published by the   *
8  *  Free Software Foundation; either version 2 of the License, or (at your  *
9  *  option) any later version.                                              *
10  \**************************************************************************/
11
12
13        $phpgw_info = array();
14        $GLOBALS['phpgw_info']['flags'] = array(
15                'noheader' => True,
16                'nonavbar' => True,
17                'currentapp' => 'home',
18                'noapi' => True
19        );
20        include('./inc/functions.inc.php');
21
22        /*
23        Authorize the user to use setup app and load the database
24        Does not return unless user is authorized
25        */
26        if(!$GLOBALS['phpgw_setup']->auth('Config') || @$_POST['cancel'])
27        {
28                Header('Location: index.php');
29                exit;
30        }
31
32        $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
33        $setup_tpl = CreateObject('setup.Template',$tpl_root);
34
35        // test if $path lies within the webservers document-root
36        //
37        function in_docroot($path)
38        {
39                $docroots = array(PHPGW_SERVER_ROOT,$_SERVER['DOCUMENT_ROOT']);
40               
41                foreach ($docroots as $docroot)
42                {
43                        $len = strlen($docroot);
44
45                        if ($docroot == substr($path,0,$len))
46                        {
47                                $rest = substr($path,$len);
48
49                                if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR)
50                                {
51                                        return True;
52                                }
53                        }
54                }
55                return False;
56        }
57
58        $setup_tpl->set_file(array(
59                'T_head' => 'head.tpl',
60                'T_footer' => 'footer.tpl',
61                'T_alert_msg' => 'msg_alert_msg.tpl',
62                'T_config_pre_script' => 'config_pre_script.tpl',
63                'T_config_post_script' => 'config_post_script.tpl'
64        ));
65
66        /* Following to ensure windows file paths are saved correctly */
67        //set_magic_quotes_runtime(0);
68        //magic_quotes_runtime(0);
69
70        $GLOBALS['phpgw_setup']->loaddb();
71
72        /* Check api version, use correct table */
73        $setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions();
74
75        if($GLOBALS['phpgw_setup']->alessthanb($setup_info['phpgwapi']['currentver'], '0.9.10pre7'))
76        {
77                $configtbl = 'config';
78        }
79        else
80        {
81                $configtbl = 'phpgw_config';
82        }
83
84        $newsettings = $_POST['newsettings'];
85        $files_in_docroot = in_docroot($newsettings['files_dir']);
86
87        if(@get_var('submit',Array('POST')) && @$newsettings && !$files_in_docroot)
88        {
89                $datetime = CreateObject('phpgwapi.date_time');
90                switch((int)$newsettings['daytime_port'])
91                {
92                        case 13:
93                                $newsettings['tz_offset'] = $datetime->getntpoffset();
94                                break;
95                        case 80:
96                                $newsettings['tz_offset'] = $datetime->gethttpoffset();
97                                break;
98                        default:
99                                $newsettings['tz_offset'] = $datetime->getbestguess();
100                                break;
101                }
102                unset($datetime);
103
104                print_debug('TZ_OFFSET',$newsettings['tz_offset']);
105
106                $GLOBALS['phpgw_setup']->db->transaction_begin();
107                /* This is only temp: */
108                $GLOBALS['phpgw_setup']->db->query("DELETE FROM $configtbl WHERE config_name='useframes'");
109                $GLOBALS['phpgw_setup']->db->query("INSERT INTO $configtbl (config_app,config_name, config_value) values ('phpgwapi','useframes','never')");
110
111                while(list($setting,$value) = @each($newsettings))
112                {
113                        /* echo '<br>Updating: ' . $setting . '=' . $value; */
114                        /* Don't erase passwords, since we also do not print them below */
115                        if($value || (!preg_match('/passwd/',$setting) && !preg_match('/password/',$setting) && !preg_match('/root_pw/',$setting)))
116                        {
117                                @$GLOBALS['phpgw_setup']->db->query("DELETE FROM $configtbl WHERE config_name='" . $setting . "'");
118                        }
119                        if($value)
120                        {
121                                $GLOBALS['phpgw_setup']->db->query("INSERT INTO $configtbl (config_app,config_name, config_value) VALUES ('phpgwapi','" . $GLOBALS['phpgw_setup']->db->db_addslashes($setting)
122                                        . "','" . $GLOBALS['phpgw_setup']->db->db_addslashes($value) . "')");
123                        }
124                }
125                $GLOBALS['phpgw_setup']->db->transaction_commit();
126
127                /* Add cleaning of app_sessions per skeeter, but with a check for the table being there, just in case */
128                $tablenames = $GLOBALS['phpgw_setup']->db->table_names();
129                while(list($key,$val) = @each($tablenames))
130                {
131                        $tables[] = $val['table_name'];
132                }
133                if(in_array('phpgw_app_sessions',$tables))
134                {
135                        $GLOBALS['phpgw_setup']->db->lock(array('phpgw_app_sessions'));
136                        @$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_app_sessions WHERE sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'",__LINE__,__FILE__);
137                        @$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_app_sessions WHERE app = 'phpgwapi' and location = 'phpgw_info_cache'",__LINE__,__FILE__);
138                        $GLOBALS['phpgw_setup']->db->unlock();
139                }
140
141                if($newsettings['auth_type'] == 'ldap')
142                {
143                        Header('Location: '.$newsettings['webserver_url'].'/setup/ldap.php');
144                        exit;
145                }
146                else
147                {
148                        Header('Location: index.php');
149                        exit;
150                }
151        }
152
153        if($newsettings['auth_type'] != 'ldap')
154        {
155                $GLOBALS['phpgw_setup']->html->show_header(lang('Configuration'),False,'config',$GLOBALS['phpgw_setup']->ConfigDomain . '(' . $phpgw_domain[$GLOBALS['phpgw_setup']->ConfigDomain]['db_type'] . ')');
156        }
157
158        @$GLOBALS['phpgw_setup']->db->query("SELECT * FROM $configtbl where config_app='phpgwapi'");
159        while(@$GLOBALS['phpgw_setup']->db->next_record())
160        {
161                $GLOBALS['current_config'][$GLOBALS['phpgw_setup']->db->f('config_name')] = $GLOBALS['phpgw_setup']->db->f('config_value');
162        }
163       
164        // are we here because of an error: files-dir in docroot
165        if (is_array($_POST['newsettings']) && $files_in_docroot)
166        {
167                echo '<p align="center"><font color="red"><b>'.lang('Path to user and group files HAS TO BE OUTSIDE of the webservers document-root!!!')."</b></font></p>\n";
168
169                foreach($_POST['newsettings'] as $key => $val)
170                {
171                        $GLOBALS['current_config'][$key] = $val;
172                }
173        }
174
175        if($GLOBALS['error'] == 'badldapconnection')
176        {
177                /* Please check the number and dial again :) */
178                $GLOBALS['phpgw_setup']->html->show_alert_msg('Error',
179                        lang('There was a problem trying to connect to your LDAP server. <br>'
180                                .'please check your LDAP server configuration') . '.');
181        }
182
183        $setup_tpl->pparse('out','T_config_pre_script');
184
185        /* Now parse each of the templates we want to show here */
186        class phpgw
187        {
188                var $common;
189                var $accounts;
190                var $applications;
191                var $db;
192        }
193        $GLOBALS['phpgw'] = new phpgw;
194        $GLOBALS['phpgw']->common = CreateObject('phpgwapi.common');
195        $GLOBALS['phpgw']->db     = $GLOBALS['phpgw_setup']->db;
196
197        /*$cfg_apps = array('phpgwapi','admin','preferences');
198        while(list(,$cfg_app) = each($cfg_apps))
199        {*/
200                $t = CreateObject('setup.Template',$GLOBALS['phpgw']->common->get_tpl_dir('setup'));
201
202                $t->set_unknowns('keep');
203                $t->set_file(array('config' => 'config.tpl'));
204                $t->set_block('config','body','body');
205
206                $vars = $t->get_undefined('body');
207                $GLOBALS['phpgw_setup']->hook('config','setup');
208
209                while(list($null,$value) = each($vars))
210                {
211                        $valarray = explode('_',$value);
212                        $type = $valarray[0];
213                        $new = $newval = '';
214
215                        while($chunk = next($valarray))
216                        {
217                                $new[] = $chunk;
218                        }
219                        $newval = implode(' ',$new);
220
221                        switch ($type)
222                        {
223                                case 'lang':
224                                        $t->set_var($value,lang($newval));
225                                        break;
226                                case 'value':
227                                        $newval = str_replace(' ','_',$newval);
228                                        /* Don't show passwords in the form */
229                                        if(strstr($value,'passwd') || strstr($value,'password') || strstr($value,'root_pw'))
230                                        {
231                                                $t->set_var($value,'');
232                                        }
233                                        else
234                                        {
235                                                $t->set_var($value,@$current_config[$newval]);
236                                        }
237                                        break;
238                                case 'selected':
239                                        $configs = array();
240                                        $config  = '';
241                                        $newvals = explode(' ',$newval);
242                                        $setting = end($newvals);
243                                        for($i=0;$i<(count($newvals) - 1); ++$i)
244                                        {
245                                                $configs[] = $newvals[$i];
246                                        }
247                                        $config = implode('_',$configs);
248                                        /* echo $config . '=' . $current_config[$config]; */
249                                        if(@$current_config[$config] == $setting)
250                                        {
251                                                $t->set_var($value,' selected');
252                                        }
253                                        else
254                                        {
255                                                $t->set_var($value,'');
256                                        }
257                                        break;
258                                case 'hook':
259                                        $newval = str_replace(' ','_',$newval);
260                                        $t->set_var($value,$newval($current_config));
261                                        break;
262                                default:
263                                        $t->set_var($value,'');
264                                        break;
265                        }
266                }
267
268                $t->pfp('out','body');
269                unset($t);
270        //}
271
272        $setup_tpl->set_var('more_configs',lang('Please login to egroupware and run the admin application for additional site configuration') . '.');
273
274        $setup_tpl->set_var('lang_submit',lang('Save'));
275        $setup_tpl->set_var('lang_cancel',lang('Cancel'));
276        $setup_tpl->pparse('out','T_config_post_script');
277
278        $GLOBALS['phpgw_setup']->html->show_footer();
279?>
280
Note: See TracBrowser for help on using the repository browser.