Project

General

Profile

1 1457 Luisehahne
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @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
@require_once('config.php');
19
20 1484 Luisehahne
require_once(WB_PATH.'/framework/functions.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22 1671 Luisehahne
require_once(WB_PATH.'/framework/class.database.php');
23 1484 Luisehahne
$admin = new admin('Addons', 'modules', false, false);
24
25
/* display a status message on the screen **************************************
26
 * @param string $message: the message to show
27
 * @param string $class:   kind of message as a css-class
28
 * @param string $element: witch HTML-tag use to cover the message
29
 * @return void
30
 */
31
function status_msg($message, $class='check', $element='span')
32
{
33 1457 Luisehahne
	// returns a status message
34 1484 Luisehahne
	$msg  = '<'.$element.' class="'.$class.'">';
35 1532 Luisehahne
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
36 1484 Luisehahne
	$msg .= $message.'</'.$element.'>';
37
	echo $msg;
38 1457 Luisehahne
}
39
40
// database tables including in WB package
41
$table_list = array (
42
    'settings','groups','addons','pages','sections','search','users',
43
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
44
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
45
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
46
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
47
);
48
49 1484 Luisehahne
$OK            = ' <span class="ok">OK</span> ';
50
$FAIL          = ' <span class="error">FAILED</span> ';
51
$DEFAULT_THEME = 'wb_theme';
52 1671 Luisehahne
$stepID = 0;
53 1532 Luisehahne
$dirRemove = array(
54 1484 Luisehahne
/*
55
			'[TEMPLATE]/allcss/',
56
			'[TEMPLATE]/blank/',
57
			'[TEMPLATE]/round/',
58
			'[TEMPLATE]/simple/',
59
*/
60 1641 Luisehahne
			'[ADMIN]/themes/',
61 1484 Luisehahne
		 );
62
63 1532 Luisehahne
$filesRemove['0'] = array(
64 1484 Luisehahne
65 1525 Luisehahne
			'[ADMIN]/preferences/details.php',
66
			'[ADMIN]/preferences/email.php',
67 1666 Luisehahne
			'[ADMIN]/preferences/password.php',
68
			'[ADMIN]/pages/settings2.php'
69 1525 Luisehahne
70 1532 Luisehahne
		 );
71
72 1671 Luisehahne
if(version_compare(WB_REVISION, '1671', '<'))
73
{
74
	$filesRemove['1'] = array(
75 1532 Luisehahne
76 1529 Luisehahne
			'[TEMPLATE]/argos_theme/templates/access.htt',
77
			'[TEMPLATE]/argos_theme/templates/addons.htt',
78
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
79
			'[TEMPLATE]/argos_theme/templates/error.htt',
80
			'[TEMPLATE]/argos_theme/templates/groups.htt',
81
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
82
			'[TEMPLATE]/argos_theme/templates/languages.htt',
83
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
84 1671 Luisehahne
	/*
85 1529 Luisehahne
			'[TEMPLATE]/argos_theme/templates/login.htt',
86
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
87 1671 Luisehahne
	*/
88 1529 Luisehahne
			'[TEMPLATE]/argos_theme/templates/media.htt',
89
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
90
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
91
			'[TEMPLATE]/argos_theme/templates/modules.htt',
92
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
93
			'[TEMPLATE]/argos_theme/templates/pages.htt',
94
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
95
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
96
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
97
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
98
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
99
			'[TEMPLATE]/argos_theme/templates/settings.htt',
100
			'[TEMPLATE]/argos_theme/templates/start.htt',
101
			'[TEMPLATE]/argos_theme/templates/success.htt',
102
			'[TEMPLATE]/argos_theme/templates/templates.htt',
103
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
104
			'[TEMPLATE]/argos_theme/templates/users.htt',
105
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
106
107
			'[TEMPLATE]/wb_theme/templates/access.htt',
108
			'[TEMPLATE]/wb_theme/templates/addons.htt',
109
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
110
			'[TEMPLATE]/wb_theme/templates/error.htt',
111
			'[TEMPLATE]/wb_theme/templates/groups.htt',
112
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
113
			'[TEMPLATE]/wb_theme/templates/languages.htt',
114
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
115 1625 Luisehahne
116 1671 Luisehahne
	/*
117 1529 Luisehahne
			'[TEMPLATE]/wb_theme/templates/login.htt',
118
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
119 1671 Luisehahne
	*/
120 1625 Luisehahne
121 1529 Luisehahne
			'[TEMPLATE]/wb_theme/templates/media.htt',
122
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
123
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
124
			'[TEMPLATE]/wb_theme/templates/modules.htt',
125
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
126
			'[TEMPLATE]/wb_theme/templates/pages.htt',
127
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
128
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
129
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
130
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
131
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
132
			'[TEMPLATE]/wb_theme/templates/settings.htt',
133
			'[TEMPLATE]/wb_theme/templates/start.htt',
134
			'[TEMPLATE]/wb_theme/templates/success.htt',
135
			'[TEMPLATE]/wb_theme/templates/templates.htt',
136
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
137
			'[TEMPLATE]/wb_theme/templates/users.htt',
138
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
139 1525 Luisehahne
		 );
140 1671 Luisehahne
}
141 1525 Luisehahne
142 1457 Luisehahne
// analyze/check database tables
143
function mysqlCheckTables( $dbName )
144
{
145
    global $table_list;
146
    $table_prefix = TABLE_PREFIX;
147
    $sql = "SHOW TABLES FROM " . $dbName;
148
    $result = @mysql_query( $sql );
149
    $data = array();
150
    $x = 0;
151
152
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
153
    {
154
        $tmp = str_replace($table_prefix, '', $row[0]);
155
156
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
157
        {
158
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
159
            $analyze = @mysql_query( $sql );
160
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
161
            $data[$x]['Op'] = $rowFetch["Op"];
162
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
163
            $msgColor = '<span class="error">';
164
            $data[$x]['Table'] = $row[0];
165
           // print  " ";
166
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
167
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
168
           // print  "<br />";
169
            $x++;
170
        }
171
    }
172
    return $data;
173
}
174
175
// check existings tables for upgrade or install
176
function check_wb_tables()
177
{
178
    global $database,$table_list;
179
180
 // if prefix inludes '_' or '%'
181
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
182
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
183
184
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
185
        $all_tables = array();
186
        if($get_result->numRows() > 0)
187
        {
188
            while ($data = $get_result->fetchRow())
189
            {
190
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
191
                if(in_array($tmp,$table_list))
192
                {
193
                    $all_tables[] = $tmp;
194
                }
195
            }
196
        }
197
     return $all_tables;
198
}
199
200
// check existing tables
201
$all_tables = check_wb_tables();
202
203 1671 Luisehahne
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
204 1457 Luisehahne
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
205
<head>
206
<title>Upgrade script</title>
207
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
208
<style type="text/css">
209
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
210
211
body {
212
	margin:0;
213
	padding:0;
214
	border:0;
215
	background: #EBF7FC;
216
	color:#000;
217
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
218
	font-size: small;
219
	height:101%;
220
}
221
222
#container {
223
	width:85%;
224
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
225
	border:1px solid #000;
226
	color:#000;
227
	margin:2em auto;
228
	padding:0 15px;
229
	min-height: 500px;
230
	text-align:left;
231
}
232
233
p { line-height:1.5em; }
234
235 1532 Luisehahne
form {
236
	display: inline-block;
237
	line-height: 20px;
238
	vertical-align: baseline;
239
}
240
input[type="submit"].restart {
241
	background-color: #FFDBDB;
242
	font-weight: bold;
243
}
244
245 1457 Luisehahne
h1,h2,h3,h4,h5,h6 {
246
	font-family: Verdana, Arial, Helvetica, sans-serif;
247
	color: #369;
248
	margin-top: 1.0em;
249
	margin-bottom: 0.1em;
250
}
251
252
h1 { font-size:150%; }
253
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
254 1671 Luisehahne
h3 { font-size: 110%; font-weight: bold;; }
255 1457 Luisehahne
256
.ok, .error { font-weight:bold; }
257
.ok { color:green; }
258
.error { color:red; }
259
.check { color:#555; }
260
261
.warning {
262
	width: 98%;
263
	background:#FFDBDB;
264
	padding:0.2em;
265
	margin-top:0.5em;
266
	border: 1px solid black;
267
}
268
.info {
269
	width: 98%;
270
	background:#99CC99;
271
	padding:0.2em;
272
	margin-top:0.5em;
273
	border: 1px solid black;
274
}
275
276
</style>
277
</head>
278
<body>
279
<div id="container">
280
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
281
<h1>WebsiteBaker Upgrade</h1>
282
<?php
283 1525 Luisehahne
	if( version_compare( WB_VERSION, '2.7', '<' )) {
284 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');
285 1457 Luisehahne
		echo '<br /><br />';
286
		echo "</div>
287
		</body>
288
		</html>
289
		";
290
		exit();
291
	}
292 1532 Luisehahne
293
$oldVersion  = 'Version '.WB_VERSION;
294
$oldVersion .= (defined('WB_SP') ? ' '.WB_SP : '');
295
$oldVersion .= (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
296
$newVersion  = 'Version '.VERSION;
297
$newVersion .= (defined('SP') ? ' '.SP : '');
298
$newVersion .= (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
299
// set addition settings if not exists, otherwise upgrade will be breaks
300
if(!defined('WB_SP')) { define('WB_SP',''); }
301
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
302
303 1457 Luisehahne
?>
304 1532 Luisehahne
<p>This script upgrades an existing WebsiteBaker <strong> <?php echo $oldVersion; ?></strong> installation to the <strong> <?php echo $newVersion ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
305 1457 Luisehahne
306
<?php
307
/**
308
 * Check if disclaimer was accepted
309
 */
310
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
311
<h2>Step 1: Backup your files</h2>
312
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
313
314 1532 Luisehahne
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
315 1457 Luisehahne
<textarea cols="80" 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 /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
316
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
317
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
318
</form>
319
<br />
320
321
<?php
322
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
323
	echo '<br /><br />';
324
    echo "</div>
325
    </body>
326
    </html>
327
    ";
328
	exit();
329
}
330
331 1671 Luisehahne
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
332 1532 Luisehahne
333 1457 Luisehahne
/**********************************************************
334
 *  - Adding field default_theme to settings table
335
 */
336 1671 Luisehahne
echo "<br />Adding default_theme to settings table";
337
// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
338
echo (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
339 1457 Luisehahne
340
// check again all tables, to get a new array
341
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
342
/**********************************************************
343
 *  - check tables comin with WebsiteBaker
344
 */
345
    $check_text = 'total ';
346
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
347
348
    if(sizeof($all_tables) == 22)
349
    {
350
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
351
    }
352
    else
353
    {
354
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
355
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
356
        $result = array_diff ( $table_list, $all_tables );
357
        echo '<h4 class="warning"><br />';
358
        while ( list ( $key, $val ) = each ( $result ) )
359
        {
360
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
361
        }
362
        echo '<br /></h4>';
363
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
364
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
365
    	echo '</form>';
366
        if(defined('ADMIN_URL'))
367
        {
368
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
369
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
370
        	echo '</form>';
371
        }
372
        echo "<br /><br /></div>
373
        </body>
374
        </html>
375
        ";
376
        exit();
377
    }
378
379 1671 Luisehahne
380
echo '<h3>Step '.(++$stepID).': Updating settings</h3>';
381 1457 Luisehahne
/**********************************************************
382
 *  - Adding field sec_anchor to settings table
383
 */
384 1671 Luisehahne
echo "<br />Adding sec_anchor to settings table";
385 1457 Luisehahne
$cfg = array(
386
	'sec_anchor' => 'wb_'
387
);
388
389 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
390
391
392 1457 Luisehahne
/**********************************************************
393
 *  - Adding redirect timer to settings table
394
 */
395 1671 Luisehahne
echo "Adding redirect timer to settings table";
396 1457 Luisehahne
$cfg = array(
397
	'redirect_timer' => '1500'
398
);
399 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
400 1457 Luisehahne
401
/**********************************************************
402 1532 Luisehahne
 *  - Adding rename_files_on_upload to settings table
403
 */
404 1671 Luisehahne
echo "Updating rename_files_on_upload to settings table";
405 1532 Luisehahne
$cfg = array(
406
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
407
);
408 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
409 1532 Luisehahne
410
/**********************************************************
411 1457 Luisehahne
 *  - Adding mediasettings to settings table
412
 */
413 1671 Luisehahne
echo "Adding mediasettings to settings table";
414 1457 Luisehahne
$cfg = array(
415 1476 Luisehahne
	'mediasettings' => '',
416 1457 Luisehahne
);
417 1484 Luisehahne
418 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
419 1457 Luisehahne
420
/**********************************************************
421
 *  - Adding fingerprint_with_ip_octets to settings table
422
 */
423 1671 Luisehahne
echo "Adding fingerprint_with_ip_octets to settings table";
424 1457 Luisehahne
$cfg = array(
425 1476 Luisehahne
	'fingerprint_with_ip_octets' => '2',
426
	'secure_form_module' => ''
427 1457 Luisehahne
);
428 1671 Luisehahne
429
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
430
431 1666 Luisehahne
/**********************************************************
432
 *  - Adding page_icon_dir to settings table
433
 */
434 1671 Luisehahne
echo "Adding page_icon_dir to settings table";
435 1666 Luisehahne
$cfg = array(
436
	'page_icon_dir' => '/templates/*/title_images',
437
);
438 1671 Luisehahne
439
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
440
441 1666 Luisehahne
/**********************************************************
442
 *  - Adding dev_infos to settings table
443
 */
444 1671 Luisehahne
echo "Adding dev_infos to settings table";
445 1666 Luisehahne
$cfg = array(
446
	'dev_infos' => 'true',
447
);
448 1457 Luisehahne
449 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
450
451
if(version_compare(WB_REVISION, '1671', '<'))
452
{
453
	echo '<h3>Step '.(++$stepID).': Updating core tables</h3>';
454
455
	/**********************************************************
456
	 *  - Update search no results database filed to create
457
	 *  valid XHTML if search is empty
458
	 */
459
	if (version_compare(WB_VERSION, '2.8', '<'))
460
	{
461
	    echo "<br />Updating database field `no_results` of search table: ";
462
	    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
463
	    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
464
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
465
		$sql .= 'WHERE `name`=\'no_results\'';
466
	    echo ($database->query($sql)) ? ' $OK<br />' : ' $FAIL<br />';
467
	}
468
	/**********************************************************
469 1457 Luisehahne
 *  - Add field "redirect_type" to table "mod_menu_link"
470
 */
471 1671 Luisehahne
	$table_name = TABLE_PREFIX.'mod_menu_link';
472
	$field_name = 'redirect_type';
473
	$description = "INT NOT NULL DEFAULT '302' AFTER `target_page_id`";
474
	if(!$database->field_exists($table_name,$field_name)) {
475
		echo "<br />Adding field redirect_type to mod_menu_link table";
476
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
477
	} else {
478
		echo "<br />Modify field redirect_type to mod_menu_link table";
479
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
480
	}
481 1457 Luisehahne
482 1671 Luisehahne
	/**********************************************************
483
	 *  - Add field "page_trail" to table "pages"
484
	 */
485
	$table_name = TABLE_PREFIX.'pages';
486
	$field_name = 'page_trail';
487
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
488
	echo "Modify field page_trail to pages table";
489
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
490
491
	/**********************************************************
492 1666 Luisehahne
 *  - Add field "page_icon" to table "pages"
493
 */
494 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
495
	$field_name = 'page_icon';
496
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `page_title`";
497
	if(!$database->field_exists($table_name,$field_name)) {
498
		echo "Adding field page_icon to pages table";
499
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
500
	} else {
501
		echo "Modify field page_icon to pages table";
502
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
503
	}
504 1666 Luisehahne
505 1671 Luisehahne
	/**********************************************************
506
	 *  - Add field "page_code" to table "pages"
507
	 */
508
	$table_name = TABLE_PREFIX.'pages';
509
	$field_name = 'page_code';
510
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
511
	if(!$database->field_exists($table_name,$field_name)) {
512
		echo "Adding field page_code to pages table";
513
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
514
	} else {
515
		echo "Modify field page_code to pages table";
516
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
517
	}
518
519
	/**********************************************************
520 1666 Luisehahne
 *  - Add field "menu_icon_0" to table "pages"
521
 */
522 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
523
	$field_name = 'menu_icon_0';
524
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `menu_title`";
525
	if(!$database->field_exists($table_name,$field_name)) {
526
		echo "Adding field menu_icon_0 to pages table";
527
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
528
	} else {
529
		echo "Modify field menu_icon_0 to pages table";
530
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
531
	}
532 1666 Luisehahne
533 1671 Luisehahne
	/**********************************************************
534
	 *  - Add field "menu_icon_1" to table "pages"
535 1666 Luisehahne
 */
536 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
537
	$field_name = 'menu_icon_1';
538
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
539
	if(!$database->field_exists($table_name,$field_name)) {
540
		echo "Adding field menu_icon_1 to pages table";
541
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
542
	} else {
543
		echo "Modify field menu_icon_1 to pages table";
544
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
545
	}
546 1666 Luisehahne
547 1671 Luisehahne
	/**********************************************************
548
	 *  - Add field "admin_groups" to table "pages"
549 1588 darkviper
 */
550 1671 Luisehahne
	$table_name = TABLE_PREFIX.'pages';
551
	$field_name = 'admin_groups';
552
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
553
	echo "Modify field admin_groups to pages table";
554
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
555
556
	/**********************************************************
557
	 *  - Add field "admin_users" to table "pages"
558
	 */
559
	$table_name = TABLE_PREFIX.'pages';
560
	$field_name = 'admin_users';
561
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
562
	echo "Modify field admin_users to pages table";
563
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
564
565
	/**********************************************************
566
	 *  - Add field "viewing_groups" to table "pages"
567
	 */
568
	$table_name = TABLE_PREFIX.'pages';
569
	$field_name = 'viewing_groups';
570
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
571
	echo "Modify field viewing_groups to pages table";
572
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
573
574
	/**********************************************************
575
	 *  - Add field "viewing_users" to table "pages"
576
	 */
577
	$table_name = TABLE_PREFIX.'pages';
578
	$field_name = 'viewing_users';
579
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
580
	echo "Modify field viewing_users to pages table";
581
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
582 1457 Luisehahne
}
583 1671 Luisehahne
584 1457 Luisehahne
/**********************************************************
585
 * upgrade media folder index protect files
586 1671 Luisehahne
 ALTER TABLE `wb_pages` CHANGE `page_icon` `page_icon` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''
587 1457 Luisehahne
 */
588 1588 darkviper
	$dir = (WB_PATH.MEDIA_DIRECTORY);
589
	echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
590
	$array = rebuildFolderProtectFile($dir);
591
	if( sizeof( $array ) ){
592
		print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
593
	} else {
594
		print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
595
		print implode ('<br />',$array);
596 1457 Luisehahne
	}
597 1593 Luisehahne
/**********************************************************
598
 * upgrade posts folder index protect files
599
 */
600
	$sPostsPath = WB_PATH.PAGES_DIRECTORY.'/posts';
601
	echo '<h4>Upgrade /posts/ index.php protect files</h4><br />';
602
	$array = rebuildFolderProtectFile($sPostsPath);
603
	if( sizeof( $array ) ){
604
		print '<br /><strong>Upgrade '.sizeof( $array ).' /posts/ protect files</strong>'." $OK<br />";
605
	} else {
606
		print '<br /><strong>Upgrade /posts/ protect files</strong>'." $FAIL!<br />";
607
		print implode ('<br />',$array);
608
	}
609 1484 Luisehahne
/* *****************************************************************************
610
 * - check for deprecated / never needed files
611
 */
612 1588 darkviper
	if(sizeof($filesRemove)) {
613 1671 Luisehahne
		echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
614 1588 darkviper
	}
615 1484 Luisehahne
	$searches = array(
616
		'[ADMIN]',
617
		'[MEDIA]',
618 1525 Luisehahne
		'[PAGES]',
619 1533 Luisehahne
		'[FRAMEWORK]',
620
		'[MODULES]',
621 1525 Luisehahne
		'[TEMPLATE]'
622 1484 Luisehahne
	);
623
	$replacements = array(
624 1525 Luisehahne
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
625 1484 Luisehahne
		MEDIA_DIRECTORY,
626 1525 Luisehahne
		PAGES_DIRECTORY,
627 1533 Luisehahne
		'/framework',
628
		'/modules',
629
		'/templates'
630 1484 Luisehahne
	);
631
632 1532 Luisehahne
	foreach( $filesRemove as $filesId )
633 1484 Luisehahne
	{
634 1532 Luisehahne
		$msg = '';
635
		foreach( $filesId as $file )
636
		{
637
			$file = str_replace($searches, $replacements, $file);
638
			$file = WB_PATH.'/'.$file;
639 1588 darkviper
			if( file_exists($file) ) {
640
				// try to unlink file
641
				if(!is_writable( $file ) || !unlink($file)) {
642
					// save in err-list, if failed
643 1532 Luisehahne
					$msg .= $file.'<br />';
644
				}
645 1484 Luisehahne
			}
646
		}
647 1532 Luisehahne
648
		if($msg != '')
649
		{
650
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
651
				    can not be removed automatically.<br /><br />Please delete them
652
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
653
	        status_msg($msg, 'error warning', 'div');
654
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
655
656
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
657
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
658
			echo '</form>';
659
			echo '<br /><br /></div></body></html>';
660
			exit;
661
		}
662 1484 Luisehahne
	}
663
664 1532 Luisehahne
665 1457 Luisehahne
/**********************************************************
666 1525 Luisehahne
 * - check for deprecated / never needed files
667
 */
668 1588 darkviper
	if(sizeof($dirRemove)) {
669 1671 Luisehahne
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
670 1588 darkviper
		$searches = array(
671
			'[ADMIN]',
672
			'[MEDIA]',
673
			'[PAGES]',
674
			'[TEMPLATE]'
675
		);
676
		$replacements = array(
677
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
678
			MEDIA_DIRECTORY,
679
			PAGES_DIRECTORY,
680
			'/templates',
681
		);
682
		$msg = '';
683
		foreach( $dirRemove as $dir ) {
684
			$dir = str_replace($searches, $replacements, $dir);
685
			$dir = WB_PATH.'/'.$dir;
686
			if( is_dir( $dir )) {
687
			// try to delete dir
688 1641 Luisehahne
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
689 1588 darkviper
				// save in err-list, if failed
690 1641 Luisehahne
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
691 1588 darkviper
				}
692 1525 Luisehahne
			}
693
		}
694 1588 darkviper
		if($msg != '') {
695 1641 Luisehahne
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
696 1588 darkviper
					can not be removed automatically.<br /><br />Please delete them
697
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
698
			status_msg($msg, 'error warning', 'div');
699
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
700
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
701
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
702
			echo '</form>';
703
			echo '<br /><br /></div></body></html>';
704
			exit;
705
		}
706 1525 Luisehahne
	}
707 1532 Luisehahne
708 1588 darkviper
/**********************************************************
709
 * upgrade modules if newer version is available
710
 */
711
	$aModuleList = array('news');
712
	foreach($aModuleList as $sModul) {
713
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
714
			$currModulVersion = get_modul_version ($sModul, false);
715
			$newModulVersion =  get_modul_version ($sModul, true);
716
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
717 1671 Luisehahne
				echo '<h3>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h3>';
718 1588 darkviper
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
719
			}
720
		}
721 1525 Luisehahne
	}
722
/**********************************************************
723 1457 Luisehahne
 *  - Reload all addons
724
 */
725
726 1671 Luisehahne
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3>';
727 1588 darkviper
	////delete modules
728
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
729
	// Load all modules
730
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
731
		while(false !== ($file = readdir($handle))) {
732
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
733
				load_module(WB_PATH.'/modules/'.$file );
734
			   // 	upgrade_module($file, true);
735
			}
736 1457 Luisehahne
		}
737 1588 darkviper
		closedir($handle);
738 1457 Luisehahne
	}
739 1588 darkviper
	echo '<br />Modules reloaded<br />';
740 1457 Luisehahne
741 1588 darkviper
	////delete templates
742
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
743
	// Load all templates
744
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
745
		while(false !== ($file = readdir($handle))) {
746
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
747
				load_template(WB_PATH.'/templates/'.$file);
748
			}
749 1457 Luisehahne
		}
750 1588 darkviper
		closedir($handle);
751 1457 Luisehahne
	}
752 1588 darkviper
	echo '<br />Templates reloaded<br />';
753 1457 Luisehahne
754 1588 darkviper
	////delete languages
755
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
756
	// Load all languages
757
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
758
		while(false !== ($file = readdir($handle))) {
759
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
760
				load_language(WB_PATH.'/languages/'.$file);
761
			}
762 1457 Luisehahne
		}
763 1588 darkviper
		closedir($handle);
764 1457 Luisehahne
	}
765 1588 darkviper
	echo '<br />Languages reloaded<br />';
766 1457 Luisehahne
767
/**********************************************************
768 1671 Luisehahne
 *  - install new droplets
769
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
770
	echo $drops;
771
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
772
	require_once (WB_PATH."/modules/droplets/".$file_name);
773
********************************************************** */
774
775
/**********************************************************
776 1457 Luisehahne
 *  - End of upgrade script
777
 */
778 1588 darkviper
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
779
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
780 1532 Luisehahne
/**********************************************************
781
 *  - Set Version to new Version
782
 */
783 1671 Luisehahne
echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
784 1457 Luisehahne
785 1671 Luisehahne
$cfg = array(
786
	'wb_version' => VERSION,
787
	'wb_revision' => REVISION,
788
	'wb_sp' => SP
789
);
790
791
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
792
793 1588 darkviper
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
794
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
795
	// show buttons to go to the backend or frontend
796
	echo '<br />';
797 1532 Luisehahne
798 1588 darkviper
	if(defined('WB_URL')) {
799
		echo '<form action="'.WB_URL.'/">';
800
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
801
		echo '</form>';
802
	}
803
	if(defined('ADMIN_URL')) {
804
		echo '<form action="'.ADMIN_URL.'/">';
805
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
806
		echo '</form>';
807
	}
808 1457 Luisehahne
809 1588 darkviper
	echo '<br /><br /></div></body></html>';