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