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