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