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