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