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