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