Project

General

Profile

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