Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * 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
 *
10
 * 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
 */
18

    
19
/**
20
 * 
21
 * 
22
 * @category     Core
23
 * @package      Core_package
24
 * @subpackage   upgrade-script
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26
 * @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: 1894 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-03-19 23:09:58 +0100 (Tue, 19 Mar 2013) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
// Include config file
38
$config_file = realpath('config.php');
39
if(file_exists($config_file) && !defined('WB_URL'))
40
{
41
	require($config_file);
42

    
43
}
44
// solved wrong pages_directory value before creating access files
45
$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
}
56
//require_once(WB_PATH.'/framework/class.admin.php');
57
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
58
require_once(WB_PATH.'/framework/functions.php');
59
// require_once(WB_PATH.'/framework/Database.php');
60
$admin = new admin('Addons', 'modules', false, false);
61

    
62
$oldVersion  = 'Version '.WB_VERSION;
63
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
64
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
65
$newVersion  = 'Version '.VERSION;
66
$newVersion .= (defined('SP') ? SP : '');
67
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
68

    
69
$bDebugModus = false;
70

    
71
// 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
// database tables including in WB package
75
$aPackage = array (
76
    'settings','groups','addons','pages','sections','search','users',
77
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
78
);
79

    
80
$OK            = ' <span class="ok">OK</span> ';
81
$FAIL          = ' <span class="error">FAILED</span> ';
82
$DEFAULT_THEME = 'wb_theme';
83

    
84
$stepID = 0;
85
$filesRemove = array();
86
$aFilesToRemove = array();
87
$dirRemove = array(
88
/*
89
			'[TEMPLATE]/allcss/',
90
			'[TEMPLATE]/blank/',
91
			'[TEMPLATE]/round/',
92
			'[TEMPLATE]/simple/',
93
*/
94
			'[ADMIN]/themes/',
95
		 );
96
//
97
	$filesRemove['0'] = array(
98

    
99
			'[ADMIN]/preferences/details.php',
100
			'[ADMIN]/preferences/email.php',
101
			'[ADMIN]/preferences/password.php',
102
			'[ADMIN]/pages/settings2.php',
103
			'[ADMIN]/users/users.php',
104
			'[ADMIN]/groups/add.php',
105
			'[ADMIN]/groups/groups.php',
106
			'[ADMIN]/groups/save.php',
107
			'[ADMIN]/skel/themes/htt/groups.htt',
108

    
109
			'[FRAMEWORK]/class.msg_queue.php',
110
			'[FRAMEWORK]/class.logfile.php',
111
			'[MODULES]/droplets/js/mdcr.js',
112

    
113
		 );
114
	$aFilesToRemove = array_merge($filesRemove['0']);
115

    
116
// deleting files below only from less 2.8.4 stable
117
if(version_compare(WB_VERSION, '2.8.4', '<'))
118
{
119
	$filesRemove['1'] = array(
120

    
121
			'[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
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
178
		 );
179

    
180
	$aFilesToRemove = array_merge($aFilesToRemove,$filesRemove['1']);
181

    
182
}
183
/* 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
function status_msg($message, $class='check', $element='div')
190
{
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
/**
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
	global $OK,$FAIL,$bDebugModus;
208
	$database=WbDatabase::getInstance();
209
	$aDebugMessage = array();
210
	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
	if($bDebugModus) {
218
		echo implode(PHP_EOL,$aDebugMessage);
219
	}
220
return;
221
}
222

    
223
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
224
<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
html { overflow-y: scroll; /* Force firefox to always show room for a vertical scrollbar */ }
230

    
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
	min-width:48em;
244
    width: 70%;
245
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/wb_theme/images/background.png) repeat-x;
246
	border:1px solid #000;
247
	color:#000;
248
	margin:2em auto;
249
	padding:0 20px;
250
	min-height: 500px;
251
	text-align:left;
252
}
253
.page {
254
	width:100%;
255
    overflow: hidden;
256
}
257
.content {
258
    padding: 10px;
259
}
260
p { line-height:1.5em; }
261

    
262
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
h1,h2,h3,h4,h5,h6 {
273
	font-family: Verdana, Arial, Helvetica, sans-serif;
274
	color: #26527D;
275
	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
h3 { font-size: 110%; font-weight: bold; }
282

    
283
textarea {
284
	width:100%;
285
	border: 2px groove #0F1D44;
286
	padding: 2px;
287
	color: #000;
288
	font-weight: normal;
289
}
290
.ok, .error { font-weight:bold; }
291
.ok { color:green; }
292
.error { color:red; }
293
.check { color:#555; }
294

    
295
span.ok,
296
span.error {
297
    margin-left: 0em;
298
}
299

    
300
.warning {
301
	background:#FFDBDB;
302
	padding:1em;
303
	margin-top:0.5em;
304
	border: 1px solid #DB0909;
305
}
306
.info {
307
	background:#C7F4C7;
308
	padding:1em;
309
	margin-top:0.5em;
310
	border: 1px solid #277A29;
311
}
312

    
313
</style>
314
</head>
315
<body>
316
<div id="container">
317
<div class="page">
318
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
319
<div class="content">
320
<h1>WebsiteBaker Upgrade</h1>
321
<?php
322
	if( version_compare( WB_VERSION, '2.7', '<' )) {
323
		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
		echo '<br /><br />';
325
		echo "</div>
326
		</div>
327
		</div>
328
		</body>
329
		</html>
330
		";
331
		exit();
332
	}
333

    
334
?>
335
<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

    
337
<?php
338

    
339
/**
340
 * Check if disclaimer was accepted
341
 */
342
$bDebugModus = false;
343
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
344
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
345
<h2>Step 1: Backup your files</h2>
346
<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

    
349
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
350
<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
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
354
</form>
355
<br />
356

    
357
<?php
358
	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
	echo "<br /><br /></div>
360
	</div>
361
	</div>
362
	</body>
363
	</html>";
364
	exit();
365
}
366

    
367
/**********************************************************
368
 *  - check tables coming with WebsiteBaker
369
 */
370
	$aMissingTables = UpgradeHelper::existsAllTables($aPackage);
371
	if( sizeof($aMissingTables) == 0){
372
        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
    } else {
374
        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
        echo 'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />';
378
        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
        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
        	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
        	echo '</form>';
393
        }
394
        echo "<br /><br /></div>
395
        </div>
396
        </div>
397
        </body>
398
        </html>";
399

    
400
		exit();
401
	}
402

    
403
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
404
$aDebugMessage = array();
405
	/**********************************************************
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

    
417
if($bDebugModus) {
418
	echo implode(PHP_EOL,$aDebugMessage);
419
}
420
$aDebugMessage = array();
421
echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
422
	/**********************************************************
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

    
433
	/**********************************************************
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

    
442
	/**********************************************************
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

    
451
	/**********************************************************
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

    
465
	/**********************************************************
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

    
473
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
474

    
475
	/**********************************************************
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

    
484
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
485

    
486
	/**********************************************************
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

    
494
	$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

    
503
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
504

    
505
	/**********************************************************
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

    
513
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
514

    
515
	/**********************************************************
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

    
523
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
524

    
525
	/**********************************************************
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

    
533
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
534

    
535
if($bDebugModus) {
536
    echo implode(PHP_EOL,$aDebugMessage);
537
}
538
echo '</div>';
539

    
540
$aDebugMessage = array();
541
if(version_compare(WB_REVISION, REVISION, '<='))
542
{
543
	echo '<div style="margin-left:2em;">';
544
	/**********************************************************
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
		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
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
555
		$sql .= 'WHERE `name`=\'no_results\'';
556
		echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
557
	}
558

    
559
	$aDebugMessage = array();
560
	echo "<h4>Adding/updating field on table pages</h4>";
561
	/**********************************************************
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
	add_modify_field_in_database($table_name,$field_name,$description);
568

    
569
	/**********************************************************
570
	 *  - Add field "page_icon" to table "pages"
571
	 */
572
	$table_name = TABLE_PREFIX.'pages';
573
	$field_name = 'page_icon';
574
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
575
	add_modify_field_in_database($table_name,$field_name,$description);
576

    
577
	/**********************************************************
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
	add_modify_field_in_database($table_name,$field_name,$description);
584

    
585
	/**********************************************************
586
	 *  - Add field "menu_icon_0" to table "pages"
587
	 */
588
	$table_name = TABLE_PREFIX.'pages';
589
	$field_name = 'menu_icon_0';
590
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
591
	add_modify_field_in_database($table_name,$field_name,$description);
592

    
593
	/**********************************************************
594
	 *  - Add field "menu_icon_1" to table "pages"
595
	 */
596
	$table_name = TABLE_PREFIX.'pages';
597
	$field_name = 'menu_icon_1';
598
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
599
	add_modify_field_in_database($table_name,$field_name,$description);
600

    
601
	/**********************************************************
602
	 *  - Add field "tooltip" to table "pages"
603
	 */
604
	$table_name = TABLE_PREFIX.'pages';
605
	$field_name = 'tooltip';
606
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
607
	add_modify_field_in_database($table_name,$field_name,$description);
608

    
609
	/**********************************************************
610
	 *  - Add field "admin_groups" to table "pages"
611
	 */
612
	$table_name = TABLE_PREFIX.'pages';
613
	$field_name = 'admin_groups';
614
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
615
	add_modify_field_in_database($table_name,$field_name,$description);
616

    
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
	add_modify_field_in_database($table_name,$field_name,$description);
624

    
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
	 add_modify_field_in_database($table_name,$field_name,$description);
632

    
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
	add_modify_field_in_database($table_name,$field_name,$description);
640

    
641
	/**********************************************************
642
	 *  - Add field "custom01" to table "pages"
643
	 */
644
	$table_name = TABLE_PREFIX.'pages';
645
	$field_name = 'custom01';
646
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
647
	add_modify_field_in_database($table_name,$field_name,$description);
648

    
649
	/**********************************************************
650
	 *  - Add field "custom02" to table "pages"
651
	 */
652
	$table_name = TABLE_PREFIX.'pages';
653
	$field_name = 'custom02';
654
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
655
	add_modify_field_in_database($table_name,$field_name,$description);
656

    
657
	if($bDebugModus) {
658
		echo implode(PHP_EOL,$aDebugMessage);
659
	}
660

    
661
	$aDebugMessage = array();
662
	/**********************************************************
663
	 * modify wrong strucre on table sections
664
	 * wrong structure let crash wb
665
	 */
666
	echo "<h4>Change field structure on table sections</h4>";
667
	$table_name = TABLE_PREFIX.'sections';
668
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
669
	$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
	$description = "int(11) NOT NULL DEFAULT '1'";
673
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
674
	$description = "int(11) NOT NULL DEFAULT '0'";
675
	$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

    
680
	if($bDebugModus) {
681
		echo implode(PHP_EOL,$aDebugMessage);
682
	}
683
	echo '</div>';
684
}
685

    
686
if(version_compare(WB_REVISION, REVISION, '<='))
687
{
688
	$aDebugMessage = array();
689
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
690
	/**********************************************************
691
	 * Modify Administrator on groups table
692
	 */
693
	echo '<div style="margin-left:2em;">';
694
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
695
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
696
	$sModulePermissions = '';
697
	$sTemplatePermissions = '';
698
	$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
	$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

    
714
	if($bDebugModus) {
715
		echo implode(PHP_EOL,$aDebugMessage);
716
	}
717
	echo '</div>';
718
	$aDebugMessage = array();
719
	/**********************************************************
720
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
721
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
722
	 */
723
	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
	add_modify_field_in_database($table_name,$field_name,$description);
729

    
730
	$table_name = TABLE_PREFIX.'users';
731
	$field_name = 'confirm_timeout';
732
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
733
	add_modify_field_in_database($table_name,$field_name,$description);
734

    
735
	if($bDebugModus) {
736
	    echo implode(PHP_EOL,$aDebugMessage);
737
	}
738
	echo '</div>';
739

    
740
	$aDebugMessage = array();
741
	/**********************************************************
742
	* Updating group_id in table users
743
	*/
744
	echo '<div style="margin-left:2em;">';
745
	echo "<h4>Updating users groups permissions on table groups</h4>";
746
	    $aUsers = array();
747
		// 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
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
762
                $groups_id = $aUsers[$user_id]['groups_id'];
763
                $group_id = 0;
764
                //if user is in administrator-group, get this group else just get the first one
765
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
766
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
767
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
768
                $sql .= 'SET `group_id`  = '.$group_id.', ';
769
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
770
                $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
	$aDebugMessage[] = '</div>';
776

    
777
	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
}
785

    
786
$aDebugMessage = array();
787
echo '<h3>Step '.(++$stepID).': Updating access and protected files in folders</h3>';
788

    
789
echo '<div style="margin-left:2em;">';
790
	/**********************************************************
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

    
803
    $aDebugMessage = array();
804
    /**********************************************************
805
     * upgrade pages directory index access files
806
     */
807
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
808

    
809
    /**********************************************************
810
     *  - Reformat/rebuild all existing access files
811
     */
812
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
813
    $msg = rebuild_all_accessfiles();
814

    
815
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
816
    echo '</div>';
817

    
818
	/* *****************************************************************************
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

    
843
		$msg = '';
844
		echo '<div style="margin-left:2em;">';
845
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
846
		foreach( $aFilesToRemove as $file )
847
		{
848
			$file = str_replace($searches, $replacements, $file);
849
			if( is_writable(WB_PATH.'/'.$file) ) {
850
				$iFound++;
851
				// try to unlink file
852
				if(!unlink(WB_PATH.$file)) {
853
					$iFailed++;
854
				}
855
			}
856
			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

    
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
			status_msg($msg, 'error warning', 'div');
872
			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
			echo "<br /><br /></div>
878
			</div>
879
			</div>
880
			</body>
881
			</html>";
882
			exit;
883
		}
884
	}
885

    
886

    
887
	/**********************************************************
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
		$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
		echo '<div style="margin-left:2em;">';
909
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
910
		foreach( $dirRemove as $dir ) {
911
			$dir = str_replace($searches, $replacements, $dir);
912
			$dir = WB_PATH.'/'.$dir;
913
			if( is_dir( $dir )) {
914
				$iFound++;
915
			// try to delete dir
916
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
917
				// save in err-list, if failed
918
					$iFailed++;
919
				}
920
			}
921
			if( is_readable(WB_PATH.'/'.$dir) ) {
922
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
923
			}
924
		}
925
		
926
		$iRemove = $iFound-$iFailed;
927
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
928
		echo ($iFailed == 0) ? $OK : $FAIL;
929
		echo '</div>';
930

    
931
		if($msg != '') {
932
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
933
					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
			echo "<br /><br /></div>
941
			</div>
942
			</div>
943
			</body>
944
			</html>";
945
			exit;
946
		}
947

    
948

    
949
	}
950

    
951
	/**********************************************************
952
	 * upgrade modules if newer version is available
953
	 * $aModuleList list of proofed modules
954
	 */
955
	$aModuleList = array(
956
	              'captcha_control','code','form','menu_link',
957
	              'output_filter','wysiwyg');
958
	if(sizeof($aModuleList)) 
959
	{
960
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
961
		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
					echo '<div style="margin-left:2em;">';
967
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
968
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
969
					echo '</div>';
970
				}
971
			}
972
		}
973
	}
974

    
975
	/**********************************************************
976
	 * Reformat/rebuild all existing moules access files
977
	 * $aModuleList list of modules
978
	 */
979
	$aModuleList = array('bakery','topics','news');
980
	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
				if(is_array($aReturnMsg)) {
993
					foreach($aReturnMsg as $title) {
994
					echo '<strong>'.$title.'</strong><br />';
995
					}
996
				}
997
				echo '</div>';
998
			}
999
		}
1000
	}
1001
/**********************************************************
1002
 *  - Reload all addons
1003
 */
1004

    
1005
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1006
	echo '<div style="margin-left:2em;">';
1007
	$iFound = 0;
1008
	$iLoaded = 0;
1009
	////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
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1015
				$iFound++;
1016
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1017
// 	upgrade_module($file, true);
1018
			}
1019
		}
1020
		closedir($handle);
1021
	}
1022
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1023

    
1024
	$iFound = 0;
1025
	$iLoaded = 0;
1026
	////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

    
1033
				$iFound++;
1034
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1035

    
1036
			}
1037
		}
1038
		closedir($handle);
1039
	}
1040
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1041

    
1042
	$iFound = 0;
1043
	$iLoaded = 0;
1044
	////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
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1050
				$iFound++;
1051
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1052
			}
1053
		}
1054
		closedir($handle);
1055
	}
1056
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1057
	echo '</div>';
1058

    
1059
/**********************************************************
1060
 *  - 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
 *  - End of upgrade script
1069
 */
1070
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1071
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1072
/**********************************************************
1073
 *  - Set Version to new Version
1074
 */
1075
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1076
echo '<div style="margin-left:2em;">';
1077

    
1078
$cfg = array(
1079
	'wb_version' => VERSION,
1080
	'wb_revision' => REVISION,
1081
	'wb_sp' => SP
1082
);
1083
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1084
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1085
echo '</div>';
1086

    
1087
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

    
1092
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

    
1103
echo "<br /><br /></div>
1104
</div>
1105
</div>
1106
</body>
1107
</html>
1108
";
1109
exit();
(6-6/6)