Project

General

Profile

1 1457 Luisehahne
<?php
2
/**
3 1866 Luisehahne
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 1457 Luisehahne
 *
5 1866 Luisehahne
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9 1457 Luisehahne
 *
10 1866 Luisehahne
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 1457 Luisehahne
 */
18
19 1866 Luisehahne
/**
20
 *
21
 *
22 1875 Luisehahne
 * @category     Core
23 1935 darkviper
 * @package      Core_service
24 1875 Luisehahne
 * @subpackage   upgrade-script
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26 1866 Luisehahne
 * @author       Werner v.d.Decken <wkl@isteam.de>
27
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
28
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
29
 * @version      0.0.1
30
 * @revision     $Revision$
31
 * @link         $HeadURL$
32
 * @lastmodified $Date$
33
 * @since        File available since 17.01.2013
34
 * @deprecated
35
 * @description  xyz
36
 */
37 1965 darkviper
if(!class_exists('PasswordHash', false))
38
{
39 1966 darkviper
	include(dirname(__FILE__).'/framework/PasswordHashInterface.php');
40 1965 darkviper
	include(dirname(__FILE__).'/include/phpass/PasswordHash.php');
41
}
42 1785 Luisehahne
// Include config file
43 1965 darkviper
$config_file = dirname(__FILE__).'/config.php';
44 1785 Luisehahne
if(file_exists($config_file) && !defined('WB_URL'))
45
{
46 1813 Luisehahne
	require($config_file);
47 1785 Luisehahne
}
48 1965 darkviper
if(!class_exists('admin', false))
49
{
50
	include(WB_PATH.'/framework/class.admin.php');
51
}
52 1920 Luisehahne
$admin = new admin('Addons', 'modules', false, false);
53 1870 Luisehahne
// solved wrong pages_directory value before creating access files
54 1871 Luisehahne
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
55
      . 'WHERE `name`=\'pages_directory\'';
56
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
57
$sTmp = trim($sPagesDirectory, '/');
58
$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
59
if($sTmp != $sPagesDirectory) {
60 1965 darkviper
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
61
		 . 'SET `value` = \''.$sTmpDir.'\' '
62
		 . 'WHERE `name`=\'pages_directory\' ';
63
	WbDatabase::getInstance()->query($sql);
64 1870 Luisehahne
}
65 1484 Luisehahne
require_once(WB_PATH.'/framework/functions.php');
66 1684 Luisehahne
// require_once(WB_PATH.'/framework/Database.php');
67 1484 Luisehahne
68 1677 Luisehahne
$oldVersion  = 'Version '.WB_VERSION;
69 1689 darkviper
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
70 1688 Luisehahne
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
71 1677 Luisehahne
$newVersion  = 'Version '.VERSION;
72 1689 darkviper
$newVersion .= (defined('SP') ? SP : '');
73 1688 Luisehahne
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
74 1457 Luisehahne
75 1765 Luisehahne
$bDebugModus = false;
76
77 1677 Luisehahne
// set addition settings if not exists, otherwise upgrade will be breaks
78
if(!defined('WB_SP')) { define('WB_SP',''); }
79
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
80 1457 Luisehahne
// database tables including in WB package
81 1765 Luisehahne
$aPackage = array (
82 1457 Luisehahne
    'settings','groups','addons','pages','sections','search','users',
83 1889 Luisehahne
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
84 1457 Luisehahne
);
85
86 1484 Luisehahne
$OK            = ' <span class="ok">OK</span> ';
87
$FAIL          = ' <span class="error">FAILED</span> ';
88
$DEFAULT_THEME = 'wb_theme';
89 1677 Luisehahne
90 1671 Luisehahne
$stepID = 0;
91 1532 Luisehahne
$dirRemove = array(
92 1484 Luisehahne
/*
93
			'[TEMPLATE]/allcss/',
94
			'[TEMPLATE]/blank/',
95
			'[TEMPLATE]/round/',
96
			'[TEMPLATE]/simple/',
97
*/
98 1641 Luisehahne
			'[ADMIN]/themes/',
99 1484 Luisehahne
		 );
100 1866 Luisehahne
//
101 1963 darkviper
$aRemoveSingleFiles = array(
102 1525 Luisehahne
			'[ADMIN]/preferences/details.php',
103
			'[ADMIN]/preferences/email.php',
104 1666 Luisehahne
			'[ADMIN]/preferences/password.php',
105 1684 Luisehahne
			'[ADMIN]/pages/settings2.php',
106 1813 Luisehahne
			'[ADMIN]/users/users.php',
107 1883 Luisehahne
			'[ADMIN]/groups/add.php',
108
			'[ADMIN]/groups/groups.php',
109
			'[ADMIN]/groups/save.php',
110 1866 Luisehahne
			'[ADMIN]/skel/themes/htt/groups.htt',
111 1525 Luisehahne
112 1684 Luisehahne
			'[FRAMEWORK]/class.msg_queue.php',
113 1689 darkviper
			'[FRAMEWORK]/class.logfile.php',
114 1945 darkviper
			'[FRAMEWORK]/PasswordHash.php',
115 1785 Luisehahne
			'[MODULES]/droplets/js/mdcr.js',
116 1684 Luisehahne
117 1963 darkviper
);
118 1532 Luisehahne
119 1866 Luisehahne
// deleting files below only from less 2.8.4 stable
120 1883 Luisehahne
if(version_compare(WB_VERSION, '2.8.4', '<'))
121 1866 Luisehahne
{
122 1963 darkviper
	$aRemoveOldTemplates = array(
123 1532 Luisehahne
124 1529 Luisehahne
			'[TEMPLATE]/argos_theme/templates/access.htt',
125
			'[TEMPLATE]/argos_theme/templates/addons.htt',
126
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
127
			'[TEMPLATE]/argos_theme/templates/error.htt',
128
			'[TEMPLATE]/argos_theme/templates/groups.htt',
129
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
130
			'[TEMPLATE]/argos_theme/templates/languages.htt',
131
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
132
			'[TEMPLATE]/argos_theme/templates/login.htt',
133
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
134
			'[TEMPLATE]/argos_theme/templates/media.htt',
135
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
136
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
137
			'[TEMPLATE]/argos_theme/templates/modules.htt',
138
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
139
			'[TEMPLATE]/argos_theme/templates/pages.htt',
140
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
141
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
142
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
143
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
144
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
145
			'[TEMPLATE]/argos_theme/templates/settings.htt',
146
			'[TEMPLATE]/argos_theme/templates/start.htt',
147
			'[TEMPLATE]/argos_theme/templates/success.htt',
148
			'[TEMPLATE]/argos_theme/templates/templates.htt',
149
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
150
			'[TEMPLATE]/argos_theme/templates/users.htt',
151
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
152
153
			'[TEMPLATE]/wb_theme/templates/access.htt',
154
			'[TEMPLATE]/wb_theme/templates/addons.htt',
155
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
156
			'[TEMPLATE]/wb_theme/templates/error.htt',
157
			'[TEMPLATE]/wb_theme/templates/groups.htt',
158
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
159
			'[TEMPLATE]/wb_theme/templates/languages.htt',
160
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
161
			'[TEMPLATE]/wb_theme/templates/login.htt',
162
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
163
			'[TEMPLATE]/wb_theme/templates/media.htt',
164
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
165
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
166
			'[TEMPLATE]/wb_theme/templates/modules.htt',
167
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
168
			'[TEMPLATE]/wb_theme/templates/pages.htt',
169
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
170
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
171
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
172
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
173
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
174
			'[TEMPLATE]/wb_theme/templates/settings.htt',
175
			'[TEMPLATE]/wb_theme/templates/start.htt',
176
			'[TEMPLATE]/wb_theme/templates/success.htt',
177
			'[TEMPLATE]/wb_theme/templates/templates.htt',
178
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
179
			'[TEMPLATE]/wb_theme/templates/users.htt',
180 1866 Luisehahne
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
181 1963 darkviper
	);
182
}else {
183
	$aRemoveOldTemplates = array();
184 1671 Luisehahne
}
185 1963 darkviper
$aFilesToRemove = array_merge($aRemoveSingleFiles, $aRemoveOldTemplates);
186
unset($aRemoveSingleFiles);
187
unset($aRemoveOldTemplates);
188 1677 Luisehahne
/* display a status message on the screen **************************************
189
 * @param string $message: the message to show
190
 * @param string $class:   kind of message as a css-class
191
 * @param string $element: witch HTML-tag use to cover the message
192
 * @return void
193
 */
194 1765 Luisehahne
function status_msg($message, $class='check', $element='div')
195 1677 Luisehahne
{
196
	// returns a status message
197
	$msg  = '<'.$element.' class="'.$class.'">';
198
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
199
	$msg .= $message.'</'.$element.'>';
200
	echo $msg;
201
}
202
203 1772 Luisehahne
/**
204
 * add_modify_field_in_database()
205
 *
206
 * @param mixed $sTable
207
 * @param mixed $sField
208
 * @param mixed $sDescription
209
 * @return
210
 */
211
function add_modify_field_in_database($sTable,$sField,$sDescription){
212 1889 Luisehahne
	global $OK,$FAIL,$bDebugModus;
213
	$database=WbDatabase::getInstance();
214 1866 Luisehahne
	$aDebugMessage = array();
215 1772 Luisehahne
	if(!$database->field_exists($sTable,$sField)) {
216
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
217
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
218
	} else {
219
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
220
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
221
	}
222 1866 Luisehahne
	if($bDebugModus) {
223
		echo implode(PHP_EOL,$aDebugMessage);
224
	}
225
return;
226 1457 Luisehahne
}
227
228 1671 Luisehahne
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
229 1457 Luisehahne
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
230
<head>
231
<title>Upgrade script</title>
232
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
233
<style type="text/css">
234 1684 Luisehahne
html { overflow-y: scroll; /* Force firefox to always show room for a vertical scrollbar */ }
235 1457 Luisehahne
236
body {
237
	margin:0;
238
	padding:0;
239
	border:0;
240
	background: #EBF7FC;
241
	color:#000;
242
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
243
	font-size: small;
244
	height:101%;
245
}
246
247
#container {
248 1765 Luisehahne
	min-width:48em;
249
    width: 70%;
250 1866 Luisehahne
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/wb_theme/images/background.png) repeat-x;
251 1457 Luisehahne
	border:1px solid #000;
252
	color:#000;
253
	margin:2em auto;
254 1765 Luisehahne
	padding:0 20px;
255 1457 Luisehahne
	min-height: 500px;
256
	text-align:left;
257
}
258 1765 Luisehahne
.page {
259
	width:100%;
260
    overflow: hidden;
261
}
262
.content {
263
    padding: 10px;
264
}
265 1457 Luisehahne
p { line-height:1.5em; }
266
267 1532 Luisehahne
form {
268
	display: inline-block;
269
	line-height: 20px;
270
	vertical-align: baseline;
271
}
272
input[type="submit"].restart {
273
	background-color: #FFDBDB;
274
	font-weight: bold;
275
}
276
277 1457 Luisehahne
h1,h2,h3,h4,h5,h6 {
278
	font-family: Verdana, Arial, Helvetica, sans-serif;
279 1765 Luisehahne
	color: #26527D;
280 1457 Luisehahne
	margin-top: 1.0em;
281
	margin-bottom: 0.1em;
282
}
283
284
h1 { font-size:150%; }
285
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
286 1765 Luisehahne
h3 { font-size: 110%; font-weight: bold; }
287 1457 Luisehahne
288 1765 Luisehahne
textarea {
289
	width:100%;
290 1866 Luisehahne
	border: 2px groove #0F1D44;
291
	padding: 2px;
292
	color: #000;
293
	font-weight: normal;
294 1765 Luisehahne
}
295 1457 Luisehahne
.ok, .error { font-weight:bold; }
296
.ok { color:green; }
297
.error { color:red; }
298
.check { color:#555; }
299
300 1765 Luisehahne
span.ok,
301
span.error {
302
    margin-left: 0em;
303
}
304
305 1457 Luisehahne
.warning {
306
	background:#FFDBDB;
307 1765 Luisehahne
	padding:1em;
308 1457 Luisehahne
	margin-top:0.5em;
309 1765 Luisehahne
	border: 1px solid #DB0909;
310 1457 Luisehahne
}
311
.info {
312 1765 Luisehahne
	background:#C7F4C7;
313
	padding:1em;
314 1457 Luisehahne
	margin-top:0.5em;
315 1765 Luisehahne
	border: 1px solid #277A29;
316 1457 Luisehahne
}
317
318
</style>
319
</head>
320
<body>
321
<div id="container">
322 1765 Luisehahne
<div class="page">
323 1866 Luisehahne
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
324 1765 Luisehahne
<div class="content">
325 1457 Luisehahne
<h1>WebsiteBaker Upgrade</h1>
326
<?php
327 1525 Luisehahne
	if( version_compare( WB_VERSION, '2.7', '<' )) {
328 1920 Luisehahne
		status_msg('<br />It is not possible to upgrade from WebsiteBaker Versions before 2.7.<br />For upgrading to version '.VERSION.' you must upgrade first to v.2.7 at least!!!', 'warning', 'div');
329 1457 Luisehahne
		echo "</div>
330 1866 Luisehahne
		</div>
331
		</div>
332 1457 Luisehahne
		</body>
333
		</html>
334
		";
335
		exit();
336
	}
337 1920 Luisehahne
if($admin->get_user_id()!=1){
338 1965 darkviper
	status_msg('<br /><h3>WebsiteBaker upgrading is not possible!<br />Before upgrading '
339
	          .'to Revision '.REVISION.' you have to login as System-Administrator!</h3>',
340
	           'warning', 'div');
341
	echo '<br /><br />';
342 1920 Luisehahne
// delete remember key of current user from database
343 1965 darkviper
	//if (isset($_SESSION['USER_ID']) && isset($database)) {
344
	//	$table = TABLE_PREFIX . 'users';
345
	//	$sql = "UPDATE `$table` SET `remember_key` = '' WHERE `user_id` = '" . (int) $_SESSION['USER_ID'] . "'";
346
	//	$database->query($sql);
347
	//}
348 1920 Luisehahne
// delete remember key cookie if set
349 1965 darkviper
	if (isset($_COOKIE['REMEMBER_KEY']) && !headers_sent() ) {
350
		setcookie('REMEMBER_KEY', '', time() - 3600, '/');
351
	}
352
	// delete most critical session variables manually
353
	$_SESSION['USER_ID'] = null;
354
	$_SESSION['GROUP_ID'] = null;
355
	$_SESSION['GROUPS_ID'] = null;
356
	$_SESSION['USERNAME'] = null;
357
	$_SESSION['PAGE_PERMISSIONS'] = null;
358
	$_SESSION['SYSTEM_PERMISSIONS'] = null;
359
	// overwrite session array
360
	$_SESSION = array();
361
	// delete session cookie if set
362
	if (isset($_COOKIE[session_name()]) && !headers_sent()) {
363
		setcookie(session_name(), '', time() - 42000, '/');
364
	}
365
	// delete the session itself
366
	session_destroy();
367
	status_msg('<br /><h3>You have to login as System-Adminstrator start '
368
	          .'upgrade-script.php again!</h3>',
369
	           'info', 'div');
370
	echo '<br /><br />';
371
	if(defined('ADMIN_URL')) {
372
		echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
373
		    .'&nbsp;<input name="backend_send" type="submit" value="Kick me to the Login" />'
374
		    .'</form>';
375
	}
376
	echo '<br /><br /></div>'
377
	    .'</div>'
378
	    .'</div>'
379
	    .'</body>'
380
	    .'</html>';
381 1920 Luisehahne
	exit();
382
}
383
384 1457 Luisehahne
?>
385 1765 Luisehahne
<p class="info">This script upgrades an existing WebsiteBaker <strong> <?php echo $oldRevision; ?></strong> installation to the <strong> <?php echo $newRevision ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
386 1457 Luisehahne
387
<?php
388 1870 Luisehahne
389 1457 Luisehahne
/**
390
 * Check if disclaimer was accepted
391
 */
392 1765 Luisehahne
$bDebugModus = false;
393
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
394 1457 Luisehahne
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
395
<h2>Step 1: Backup your files</h2>
396 1785 Luisehahne
<h5 class="warning">It is highly recommended to <strong>create a manual backup</strong> of the entire <strong class="error"><?php echo  PAGES_DIRECTORY ?>/</strong> folder and the <strong>MySQL database</strong> before proceeding.</h5>
397
<p><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
398 1457 Luisehahne
399 1866 Luisehahne
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
400 1765 Luisehahne
<textarea cols="92" rows="5">DISCLAIMER: The WebsiteBaker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the <?php echo  PAGES_DIRECTORY ?>/ folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
401
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;<strong>I confirm that a manual backup of the <?php echo  PAGES_DIRECTORY ?>/ folder and the MySQL database was created.</strong>
402
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
403 1457 Luisehahne
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
404
</form>
405
<br />
406
407
<?php
408 1965 darkviper
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created '
409
			  .'a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL '
410
	          .'database before you can proceed.',
411
	           'warning', 'div');
412
	echo '<br /><br /></div>'
413
	    .'</div>'
414
	    .'</div>'
415
	    .'</body>'
416
	    .'</html>';
417 1457 Luisehahne
	exit();
418
}
419
420
/**********************************************************
421 1765 Luisehahne
 *  - check tables coming with WebsiteBaker
422 1457 Luisehahne
 */
423 1965 darkviper
	$aMissingTables = UpgradeHelper::getMissingTables($aPackage);
424 1889 Luisehahne
	if( sizeof($aMissingTables) == 0){
425 1965 darkviper
        echo '<h4 style="margin-left:0;">NOTICE: '.sizeof($aPackage).' total tables '
426
		    .'included in package are successfully installed into your database `'
427
		    .$database->DbName.'` '.$OK.'</h4>';
428 1889 Luisehahne
    } else {
429 1765 Luisehahne
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
430 1965 darkviper
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />'
431
            .'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />'
432
            .'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />'
433
            .'After installing missing tables upload and run again upgrade-script.php<br /><br /></h4>'
434
            .'<h4 class="warning">'
435
            .'Missing required tables.<br /><br />'
436
            .'TABLE `'.implode('` missing! '.$FAIL.'<br />TABLE `',$aMissingTables).'` missing! '.$FAIL
437
            .'<br /><br /></h4>'
438
            .'<br /><br />';
439 1765 Luisehahne
        if(isset($_SERVER['SCRIPT_NAME'])) {
440 1965 darkviper
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">'
441
        	    .'&nbsp;<input type="submit" value="Start upgrade again" />'
442
        	    .'</form>';
443 1765 Luisehahne
        }
444
        if(defined('ADMIN_URL')) {
445 1965 darkviper
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
446
        	    .'&nbsp;<input name="backend_send" type="submit" value="kick me to the Backend" />'
447
        	    .'</form>';
448 1457 Luisehahne
        }
449 1965 darkviper
        echo '<br /><br /></div>'
450
            .'</div>'
451
            .'</div>'
452
            .'</body>'
453
            .'</html>';
454 1894 Luisehahne
		exit();
455
	}
456 1457 Luisehahne
457 1965 darkviper
	echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
458
	$aDebugMessage = array();
459 1894 Luisehahne
	/**********************************************************
460
	 *  - Adding field default_theme to settings table
461
	 */
462
	$aDebugMessage[] = '<div style="margin-left:2em;">';
463
	$aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
464
	// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
465
	$cfg = array(
466 1920 Luisehahne
		'default_theme' => $DEFAULT_THEME
467 1894 Luisehahne
	);
468
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
469
	$aDebugMessage[] = '</div>';
470 1457 Luisehahne
471 1965 darkviper
	if($bDebugModus) {
472
		echo implode(PHP_EOL,$aDebugMessage);
473
	}
474
	$aDebugMessage = array();
475
	echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
476 1894 Luisehahne
	/**********************************************************
477
	 *  - Adding field sec_anchor to settings table
478
	 */
479
	echo '<div style="margin-left:2em;">';
480
	echo "<h4>Adding/updating entries on table settings</h4>";
481
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
482
	$cfg = array(
483 1920 Luisehahne
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
484 1894 Luisehahne
	);
485
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
486 1457 Luisehahne
487 1894 Luisehahne
	/**********************************************************
488
	 *  - Adding redirect timer to settings table
489
	 */
490
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
491
	$cfg = array(
492
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
493
	);
494
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
495 1484 Luisehahne
496 1894 Luisehahne
	/**********************************************************
497
	 *  - Adding default_time_formatr to settings table
498
	 */
499
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
500
	$cfg = array(
501
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
502
	);
503
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
504 1889 Luisehahne
505 1894 Luisehahne
	/**********************************************************
506
	 *  - Adding rename_files_on_upload to settings table
507
	 */
508
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
509
	$cfg = array(
510
	    'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD')&& (RENAME_FILES_ON_UPLOAD!='') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
511
	);
512
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
513
		$cfg = array(
514
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
515
		);
516
	}
517
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
518 1457 Luisehahne
519 1894 Luisehahne
	/**********************************************************
520
	 *  - Adding mediasettings to settings table
521
	 */
522
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
523
	$cfg = array(
524
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
525
	);
526 1671 Luisehahne
527 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
528 1671 Luisehahne
529 1894 Luisehahne
	/**********************************************************
530
	 *  - Adding fingerprint_with_ip_octets to settings table
531
	 */
532
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
533
	$cfg = array(
534
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
535
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
536
	);
537 1671 Luisehahne
538 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
539 1671 Luisehahne
540 1894 Luisehahne
	/**********************************************************
541
	 *  - Adding page_icon_dir to settings table
542
	 */
543
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
544
	$cfg = array(
545
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
546
	);
547 1731 Luisehahne
548 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
549
	/**********************************************************
550
	 *  - Adding page_extended to settings table
551
	 */
552
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
553
	$cfg = array(
554
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
555
	);
556 1745 Luisehahne
557 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
558 1457 Luisehahne
559 1894 Luisehahne
	/**********************************************************
560
	 *  - Adding wbmail_signature to settings table
561
	 */
562
	$aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
563
	$cfg = array(
564
		'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
565
	);
566 1671 Luisehahne
567 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
568 1765 Luisehahne
569 1894 Luisehahne
	/**********************************************************
570
	 *  - Adding confirmed_registration to settings table
571
	 */
572
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
573
	$cfg = array(
574
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
575
	);
576 1765 Luisehahne
577 1894 Luisehahne
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
578 1765 Luisehahne
579 1894 Luisehahne
	/**********************************************************
580
	 *  - Adding dev_infos to settings table
581
	 */
582
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
583
	$cfg = array(
584
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
585
	);
586 1765 Luisehahne
587 1768 Luisehahne
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
588 1765 Luisehahne
589 1930 darkviper
	/**********************************************************
590 1963 darkviper
	 *  - Adding server_timezone to settings table
591
	 */
592
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
593
	$cfg = array(
594
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
595
	);
596
597
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
598
599
	/**********************************************************
600 1930 darkviper
	 *  - Adding password settings to settings table
601
	 */
602
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
603
	$cfg = array();
604
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
605
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
606
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
607
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
608
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
609
610 1768 Luisehahne
if($bDebugModus) {
611
    echo implode(PHP_EOL,$aDebugMessage);
612 1765 Luisehahne
}
613 1768 Luisehahne
echo '</div>';
614 1765 Luisehahne
615 1768 Luisehahne
$aDebugMessage = array();
616 1772 Luisehahne
if(version_compare(WB_REVISION, REVISION, '<='))
617 1671 Luisehahne
{
618 1894 Luisehahne
	echo '<div style="margin-left:2em;">';
619 1671 Luisehahne
	/**********************************************************
620
	 *  - Update search no results database filed to create
621
	 *  valid XHTML if search is empty
622
	 */
623
	if (version_compare(WB_VERSION, '2.8', '<'))
624
	{
625 1894 Luisehahne
		echo "<h4>Adding/updating fields on table search</h4>";
626
		echo "Updating database field `no_results` on search table: ";
627
		$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
628
		$sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
629 1671 Luisehahne
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
630
		$sql .= 'WHERE `name`=\'no_results\'';
631 1894 Luisehahne
		echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
632 1671 Luisehahne
	}
633 1760 Luisehahne
634 1894 Luisehahne
	$aDebugMessage = array();
635
	echo "<h4>Adding/updating field on table pages</h4>";
636 1671 Luisehahne
	/**********************************************************
637
	 *  - Add field "page_trail" to table "pages"
638
	 */
639
	$table_name = TABLE_PREFIX.'pages';
640
	$field_name = 'page_trail';
641
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
642 1889 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
643 1671 Luisehahne
644
	/**********************************************************
645 1894 Luisehahne
	 *  - Add field "page_icon" to table "pages"
646
	 */
647 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
648
	$field_name = 'page_icon';
649 1684 Luisehahne
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
650 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
651 1666 Luisehahne
652 1671 Luisehahne
	/**********************************************************
653
	 *  - Add field "page_code" to table "pages"
654 1963 darkviper
	 *
655
	 *  will be done in upgrade.php of the module MultiLingual
656
	 *  until the module is integrated completely
657 1671 Luisehahne
	 */
658 1963 darkviper
//	$table_name = TABLE_PREFIX.'pages';
659
//	$field_name = 'page_code';
660
//	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
661
//	add_modify_field_in_database($table_name,$field_name,$description);
662 1671 Luisehahne
663
	/**********************************************************
664 1894 Luisehahne
	 *  - Add field "menu_icon_0" to table "pages"
665
	 */
666 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
667
	$field_name = 'menu_icon_0';
668 1684 Luisehahne
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
669 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
670 1666 Luisehahne
671 1671 Luisehahne
	/**********************************************************
672
	 *  - Add field "menu_icon_1" to table "pages"
673 1894 Luisehahne
	 */
674 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
675
	$field_name = 'menu_icon_1';
676 1684 Luisehahne
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
677 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
678 1666 Luisehahne
679 1671 Luisehahne
	/**********************************************************
680 1684 Luisehahne
	 *  - Add field "tooltip" to table "pages"
681 1894 Luisehahne
	 */
682 1684 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
683
	$field_name = 'tooltip';
684
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
685 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
686 1684 Luisehahne
687
	/**********************************************************
688 1671 Luisehahne
	 *  - Add field "admin_groups" to table "pages"
689 1894 Luisehahne
	 */
690 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
691
	$field_name = 'admin_groups';
692
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
693 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
694 1671 Luisehahne
695
	/**********************************************************
696
	 *  - Add field "admin_users" to table "pages"
697
	 */
698
	$table_name = TABLE_PREFIX.'pages';
699
	$field_name = 'admin_users';
700
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
701 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
702 1671 Luisehahne
703
	/**********************************************************
704
	 *  - Add field "viewing_groups" to table "pages"
705
	 */
706
	$table_name = TABLE_PREFIX.'pages';
707
	$field_name = 'viewing_groups';
708
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
709 1894 Luisehahne
	 add_modify_field_in_database($table_name,$field_name,$description);
710 1671 Luisehahne
711
	/**********************************************************
712
	 *  - Add field "viewing_users" to table "pages"
713
	 */
714
	$table_name = TABLE_PREFIX.'pages';
715
	$field_name = 'viewing_users';
716
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
717 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
718 1755 Luisehahne
719 1768 Luisehahne
	/**********************************************************
720 1894 Luisehahne
	 *  - Add field "custom01" to table "pages"
721
	 */
722 1768 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
723
	$field_name = 'custom01';
724
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
725 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
726 1760 Luisehahne
727 1768 Luisehahne
	/**********************************************************
728 1894 Luisehahne
	 *  - Add field "custom02" to table "pages"
729
	 */
730 1768 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
731
	$field_name = 'custom02';
732
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
733 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
734 1768 Luisehahne
735 1894 Luisehahne
	if($bDebugModus) {
736
		echo implode(PHP_EOL,$aDebugMessage);
737
	}
738 1772 Luisehahne
739 1866 Luisehahne
	$aDebugMessage = array();
740
	/**********************************************************
741 1894 Luisehahne
	 * modify wrong strucre on table sections
742
	 * wrong structure let crash wb
743
	 */
744 1765 Luisehahne
	echo "<h4>Change field structure on table sections</h4>";
745
	$table_name = TABLE_PREFIX.'sections';
746
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
747 1772 Luisehahne
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
748
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
749
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
750 1889 Luisehahne
	$description = "int(11) NOT NULL DEFAULT '1'";
751 1772 Luisehahne
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
752 1889 Luisehahne
	$description = "int(11) NOT NULL DEFAULT '0'";
753 1772 Luisehahne
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
754
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
755
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
756
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
757 1755 Luisehahne
758 1894 Luisehahne
	if($bDebugModus) {
759
		echo implode(PHP_EOL,$aDebugMessage);
760
	}
761
	echo '</div>';
762 1890 Luisehahne
}
763 1772 Luisehahne
764 1890 Luisehahne
if(version_compare(WB_REVISION, REVISION, '<='))
765
{
766 1894 Luisehahne
	$aDebugMessage = array();
767
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
768 1789 Luisehahne
	/**********************************************************
769 1890 Luisehahne
	 * Modify Administrator on groups table
770
	 */
771
	echo '<div style="margin-left:2em;">';
772 1893 Luisehahne
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
773 1789 Luisehahne
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
774 1866 Luisehahne
	$sModulePermissions = '';
775
	$sTemplatePermissions = '';
776 1789 Luisehahne
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
777
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
778
	$sSystemPermissions .= 'modules,modules_advanced,modules_install,modules_uninstall,modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,pages_modify,pages_settings,pages_view,';
779
	$sSystemPermissions .= 'preferences,preferences_view,settings,settings_advanced,settings_basic,settings_view,templates,templates_install,templates_uninstall,templates_view,users,users_add,users_delete,users_modify,users_view';
780
781
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
782
	$sql .= 'SET `name` = \'Administrators\', ';
783
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
784
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
785
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
786
	$sql .= 'WHERE `group_id` = \'1\' ';
787 1894 Luisehahne
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
788
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
789
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
790
	}
791 1789 Luisehahne
792 1894 Luisehahne
	if($bDebugModus) {
793
		echo implode(PHP_EOL,$aDebugMessage);
794
	}
795
	echo '</div>';
796 1890 Luisehahne
	$aDebugMessage = array();
797
	/**********************************************************
798 1894 Luisehahne
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
799
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
800
	 */
801 1890 Luisehahne
	echo '<div style="margin-left:2em;">';
802
	echo "<h4>Change field structure on table users</h4>";
803
	$table_name = TABLE_PREFIX.'users';
804
	$field_name = 'confirm_code';
805
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
806 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
807 1671 Luisehahne
808 1890 Luisehahne
	$table_name = TABLE_PREFIX.'users';
809
	$field_name = 'confirm_timeout';
810
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
811 1894 Luisehahne
	add_modify_field_in_database($table_name,$field_name,$description);
812 1890 Luisehahne
813 1894 Luisehahne
	if($bDebugModus) {
814
	    echo implode(PHP_EOL,$aDebugMessage);
815
	}
816
	echo '</div>';
817 1893 Luisehahne
818 1894 Luisehahne
	$aDebugMessage = array();
819
	/**********************************************************
820
	* Updating group_id in table users
821
	*/
822 1890 Luisehahne
	echo '<div style="margin-left:2em;">';
823 1893 Luisehahne
	echo "<h4>Updating users groups permissions on table groups</h4>";
824 1894 Luisehahne
	    $aUsers = array();
825 1813 Luisehahne
		// Get existing values
826
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
827
        $sql .= 'WHERE `user_id` != 1 ';
828
        if($oUser = $database->query($sql)){
829
            $iTotalUsers = $oUser->numRows();
830
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
831
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
832
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
833
            }
834
        } else {
835
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
836
        }
837
        foreach($aUsers AS $user_id => $value){
838
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
839 1815 Luisehahne
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
840
                $groups_id = $aUsers[$user_id]['groups_id'];
841 1813 Luisehahne
                $group_id = 0;
842
                //if user is in administrator-group, get this group else just get the first one
843 1815 Luisehahne
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
844 1813 Luisehahne
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
845
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
846 1815 Luisehahne
                $sql .= 'SET `group_id`  = '.$group_id.', ';
847 1817 Luisehahne
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
848 1813 Luisehahne
                $sql .= 'WHERE `user_id` = '.intval($user_id);
849
                if($oRes = $database->query($sql)){  }
850
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
851
        }
852
        unset($aUsers);
853 1894 Luisehahne
	$aDebugMessage[] = '</div>';
854 1813 Luisehahne
855 1894 Luisehahne
	if($bDebugModus) {
856
	// $aDebugMessage[] =
857
	    echo implode(PHP_EOL,$aDebugMessage);
858
	}else {
859
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
860
	    echo '</div>';
861
	}
862 1813 Luisehahne
}
863
864
$aDebugMessage = array();
865 1866 Luisehahne
echo '<h3>Step '.(++$stepID).': Updating access and protected files in folders</h3>';
866 1765 Luisehahne
867
echo '<div style="margin-left:2em;">';
868 1894 Luisehahne
	/**********************************************************
869
	* upgrade media directory index protect files
870
	*/
871
	$dir = (WB_PATH.MEDIA_DIRECTORY);
872
	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
873
	$aDebugMessage = rebuildFolderProtectFile($dir);
874
	if( sizeof( $aDebugMessage ) ){
875
		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
876
	} else {
877
		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
878
		echo implode ('<br />',$aDebugMessage);
879
	}
880 1677 Luisehahne
881 1866 Luisehahne
    $aDebugMessage = array();
882 1765 Luisehahne
    /**********************************************************
883
     * upgrade pages directory index access files
884
     */
885
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
886 1677 Luisehahne
887 1765 Luisehahne
    /**********************************************************
888
     *  - Reformat/rebuild all existing access files
889
     */
890
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
891
    $msg = rebuild_all_accessfiles();
892 1920 Luisehahne
	$dir = (WB_PATH.PAGES_DIRECTORY);
893
//	$aDebugMessage = rebuildFolderProtectFile($dir);
894 1866 Luisehahne
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
895 1765 Luisehahne
    echo '</div>';
896 1866 Luisehahne
897 1883 Luisehahne
	/* *****************************************************************************
898
	 * - check for deprecated / never needed files
899
	 */
900
	$iLoaded = sizeof($aFilesToRemove);
901
	if($iLoaded) {
902
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
903
		$iFailed = 0;
904
		$iFound = 0;
905
		$searches = array(
906
			'[ADMIN]',
907
			'[MEDIA]',
908
			'[PAGES]',
909
			'[FRAMEWORK]',
910
			'[MODULES]',
911
			'[TEMPLATE]'
912
		);
913
		$replacements = array(
914
			'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
915
			MEDIA_DIRECTORY,
916
			PAGES_DIRECTORY,
917
			'/framework',
918
			'/modules',
919
			'/templates'
920
		);
921 1677 Luisehahne
922 1532 Luisehahne
		$msg = '';
923 1883 Luisehahne
		echo '<div style="margin-left:2em;">';
924
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
925
		foreach( $aFilesToRemove as $file )
926
		{
927 1532 Luisehahne
			$file = str_replace($searches, $replacements, $file);
928 1765 Luisehahne
			if( is_writable(WB_PATH.'/'.$file) ) {
929 1883 Luisehahne
				$iFound++;
930 1588 darkviper
				// try to unlink file
931 1765 Luisehahne
				if(!unlink(WB_PATH.$file)) {
932 1883 Luisehahne
					$iFailed++;
933 1801 Luisehahne
				}
934 1484 Luisehahne
			}
935 1883 Luisehahne
			if( is_readable(WB_PATH.'/'.$file) ) {
936
				// save in err-list, if failed
937
				$msg .= $file.'<br />';
938
			}
939
		}
940
		$iRemove = $iFound-$iFailed;
941
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
942
		echo ($iFailed == 0) ? $OK : $FAIL;
943
		echo '</div>';
944 1532 Luisehahne
945
		if($msg != '')
946
		{
947
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
948
				    can not be removed automatically.<br /><br />Please delete them
949
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
950 1889 Luisehahne
			status_msg($msg, 'error warning', 'div');
951 1532 Luisehahne
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
952
953
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
954
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
955
			echo '</form>';
956 1866 Luisehahne
			echo "<br /><br /></div>
957
			</div>
958
			</div>
959
			</body>
960
			</html>";
961 1532 Luisehahne
			exit;
962
		}
963 1889 Luisehahne
	}
964 1484 Luisehahne
965 1532 Luisehahne
966 1883 Luisehahne
	/**********************************************************
967
	 * - check for deprecated / never needed files
968
	 */
969
	$iLoaded = sizeof($dirRemove);
970
	if($iLoaded) {
971
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
972
		$iFailed = 0;
973
		$iFound = 0;
974 1588 darkviper
		$searches = array(
975
			'[ADMIN]',
976
			'[MEDIA]',
977
			'[PAGES]',
978
			'[TEMPLATE]'
979
		);
980
		$replacements = array(
981
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
982
			MEDIA_DIRECTORY,
983
			PAGES_DIRECTORY,
984
			'/templates',
985
		);
986
		$msg = '';
987 1883 Luisehahne
		echo '<div style="margin-left:2em;">';
988
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
989 1588 darkviper
		foreach( $dirRemove as $dir ) {
990
			$dir = str_replace($searches, $replacements, $dir);
991
			$dir = WB_PATH.'/'.$dir;
992
			if( is_dir( $dir )) {
993 1883 Luisehahne
				$iFound++;
994 1588 darkviper
			// try to delete dir
995 1641 Luisehahne
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
996 1588 darkviper
				// save in err-list, if failed
997 1883 Luisehahne
					$iFailed++;
998 1588 darkviper
				}
999 1525 Luisehahne
			}
1000 1883 Luisehahne
			if( is_readable(WB_PATH.'/'.$dir) ) {
1001
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
1002
			}
1003 1525 Luisehahne
		}
1004 1883 Luisehahne
1005
		$iRemove = $iFound-$iFailed;
1006
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
1007
		echo ($iFailed == 0) ? $OK : $FAIL;
1008
		echo '</div>';
1009 1765 Luisehahne
1010 1588 darkviper
		if($msg != '') {
1011 1641 Luisehahne
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1012 1588 darkviper
					can not be removed automatically.<br /><br />Please delete them
1013
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1014
			status_msg($msg, 'error warning', 'div');
1015
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1016
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1017
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1018
			echo '</form>';
1019 1866 Luisehahne
			echo "<br /><br /></div>
1020
			</div>
1021
			</div>
1022
			</body>
1023
			</html>";
1024 1588 darkviper
			exit;
1025
		}
1026 1883 Luisehahne
1027
1028 1525 Luisehahne
	}
1029 1532 Luisehahne
1030 1883 Luisehahne
	/**********************************************************
1031
	 * upgrade modules if newer version is available
1032
	 * $aModuleList list of proofed modules
1033
	 */
1034 1894 Luisehahne
	$aModuleList = array(
1035 1920 Luisehahne
	              'captcha_control','code','droplets','form','jsadmin',
1036
	              'menu_link','news','output_filter','wrapper','wysiwyg','MultiLingual');
1037 1866 Luisehahne
	if(sizeof($aModuleList))
1038
	{
1039 1890 Luisehahne
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1040 1866 Luisehahne
		foreach($aModuleList as $sModul) {
1041
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1042
				$currModulVersion = get_modul_version ($sModul, false);
1043
				$newModulVersion =  get_modul_version ($sModul, true);
1044
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1045 1883 Luisehahne
					echo '<div style="margin-left:2em;">';
1046 1866 Luisehahne
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1047
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1048 1883 Luisehahne
					echo '</div>';
1049 1866 Luisehahne
				}
1050 1588 darkviper
			}
1051
		}
1052 1525 Luisehahne
	}
1053 1765 Luisehahne
1054 1883 Luisehahne
	/**********************************************************
1055
	 * Reformat/rebuild all existing moules access files
1056
	 * $aModuleList list of modules
1057
	 */
1058
	$aModuleList = array('bakery','topics','news');
1059 1866 Luisehahne
	if(sizeof($aModuleList))
1060
	{
1061
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1062
		foreach($aModuleList as $sModul) {
1063
			$aReturnMsg = array();
1064
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1065
			if(class_exists($sModulReorg)) {
1066
				$sModulVersion =  get_modul_version ($sModul, true);
1067
				echo '<div style="margin-left:2em;">';
1068
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1069
				$oReorg = new $sModulReorg();
1070
				$aReturnMsg = $oReorg->execute(); // show details
1071 1881 Luisehahne
				if(is_array($aReturnMsg)) {
1072 1866 Luisehahne
					foreach($aReturnMsg as $title) {
1073
					echo '<strong>'.$title.'</strong><br />';
1074
					}
1075
				}
1076
				echo '</div>';
1077
			}
1078
		}
1079
	}
1080 1525 Luisehahne
/**********************************************************
1081 1457 Luisehahne
 *  - Reload all addons
1082
 */
1083
1084 1765 Luisehahne
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1085 1883 Luisehahne
	echo '<div style="margin-left:2em;">';
1086
	$iFound = 0;
1087
	$iLoaded = 0;
1088 1588 darkviper
	////delete modules
1089
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1090
	// Load all modules
1091
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1092
		while(false !== ($file = readdir($handle))) {
1093 1769 Luisehahne
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1094 1889 Luisehahne
				$iFound++;
1095 1765 Luisehahne
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1096 1889 Luisehahne
// 	upgrade_module($file, true);
1097 1588 darkviper
			}
1098 1457 Luisehahne
		}
1099 1588 darkviper
		closedir($handle);
1100 1457 Luisehahne
	}
1101 1866 Luisehahne
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1102 1457 Luisehahne
1103 1889 Luisehahne
	$iFound = 0;
1104
	$iLoaded = 0;
1105 1588 darkviper
	////delete templates
1106
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1107
	// Load all templates
1108
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1109
		while(false !== ($file = readdir($handle))) {
1110
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1111 1769 Luisehahne
1112 1889 Luisehahne
				$iFound++;
1113 1765 Luisehahne
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1114 1769 Luisehahne
1115 1588 darkviper
			}
1116 1457 Luisehahne
		}
1117 1588 darkviper
		closedir($handle);
1118 1457 Luisehahne
	}
1119 1866 Luisehahne
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1120 1457 Luisehahne
1121 1889 Luisehahne
	$iFound = 0;
1122
	$iLoaded = 0;
1123 1588 darkviper
	////delete languages
1124
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1125
	// Load all languages
1126
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1127
		while(false !== ($file = readdir($handle))) {
1128 1769 Luisehahne
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1129 1889 Luisehahne
				$iFound++;
1130 1765 Luisehahne
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1131 1588 darkviper
			}
1132 1457 Luisehahne
		}
1133 1588 darkviper
		closedir($handle);
1134 1457 Luisehahne
	}
1135 1866 Luisehahne
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1136 1889 Luisehahne
	echo '</div>';
1137 1457 Luisehahne
1138
/**********************************************************
1139 1671 Luisehahne
 *  - install new droplets
1140
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1141
	echo $drops;
1142
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1143
	require_once (WB_PATH."/modules/droplets/".$file_name);
1144
********************************************************** */
1145
1146
/**********************************************************
1147 1457 Luisehahne
 *  - End of upgrade script
1148
 */
1149 1588 darkviper
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1150
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1151 1532 Luisehahne
/**********************************************************
1152
 *  - Set Version to new Version
1153
 */
1154 1765 Luisehahne
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1155
echo '<div style="margin-left:2em;">';
1156 1457 Luisehahne
1157 1671 Luisehahne
$cfg = array(
1158
	'wb_version' => VERSION,
1159
	'wb_revision' => REVISION,
1160
	'wb_sp' => SP
1161
);
1162 1883 Luisehahne
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1163 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1164 1765 Luisehahne
echo '</div>';
1165 1671 Luisehahne
1166 1765 Luisehahne
echo '<p style="font-size:140%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
1167
status_msg('<strong>:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
1168
// show buttons to go to the backend or frontend
1169
echo '<br />';
1170 1532 Luisehahne
1171 1765 Luisehahne
if(defined('WB_URL')) {
1172
	echo '<form action="'.WB_URL.'/">';
1173
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1174
	echo '</form>';
1175
}
1176
if(defined('ADMIN_URL')) {
1177
	echo '<form action="'.ADMIN_URL.'/">';
1178
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1179
	echo '</form>';
1180
}
1181 1457 Luisehahne
1182 1765 Luisehahne
echo "<br /><br /></div>
1183
</div>
1184
</div>
1185
</body>
1186
</html>
1187
";
1188
exit();