Project

General

Profile

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