Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker 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: upgrade-script.php 1762 2012-09-18 16:11:11Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-09-18 18:11:11 +0200 (Tue, 18 Sep 2012) $
15
 *
16
 */
17

    
18
require_once('config.php');
19

    
20
require_once(WB_PATH.'/framework/functions.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
// require_once(WB_PATH.'/framework/Database.php');
23
$admin = new admin('Addons', 'modules', false, false);
24

    
25
$oldVersion  = 'Version '.WB_VERSION;
26
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
27
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
28
$newVersion  = 'Version '.VERSION;
29
$newVersion .= (defined('SP') ? SP : '');
30
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
31

    
32
// 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
// database tables including in WB package
37
$aTable = array (
38
    '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
$OK            = ' <span class="ok">OK</span> ';
46
$FAIL          = ' <span class="error">FAILED</span> ';
47
$DEFAULT_THEME = 'wb_theme';
48

    
49
$stepID = 0;
50
$dirRemove = array(
51
/*
52
			'[TEMPLATE]/allcss/',
53
			'[TEMPLATE]/blank/',
54
			'[TEMPLATE]/round/',
55
			'[TEMPLATE]/simple/',
56
*/
57
			'[ADMIN]/themes/',
58
		 );
59

    
60
$filesRemove['0'] = array(
61

    
62
			'[ADMIN]/preferences/details.php',
63
			'[ADMIN]/preferences/email.php',
64
			'[ADMIN]/preferences/password.php',
65
			'[ADMIN]/pages/settings2.php',
66

    
67
			'[FRAMEWORK]/class.msg_queue.php',
68
			'[FRAMEWORK]/class.logfile.php',
69
//			'[FRAMEWORK]/class.database.php',
70

    
71
		 );
72

    
73
if(version_compare(WB_REVISION, '1681', '<'))
74
{
75
	$filesRemove['1'] = array(
76

    
77
			'[TEMPLATE]/argos_theme/templates/access.htt',
78
			'[TEMPLATE]/argos_theme/templates/addons.htt',
79
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
80
			'[TEMPLATE]/argos_theme/templates/error.htt',
81
			'[TEMPLATE]/argos_theme/templates/groups.htt',
82
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
83
			'[TEMPLATE]/argos_theme/templates/languages.htt',
84
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
85
	/*
86
			'[TEMPLATE]/argos_theme/templates/login.htt',
87
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
88
	*/
89
			'[TEMPLATE]/argos_theme/templates/media.htt',
90
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
91
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
92
			'[TEMPLATE]/argos_theme/templates/modules.htt',
93
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
94
			'[TEMPLATE]/argos_theme/templates/pages.htt',
95
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
96
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
97
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
98
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
99
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
100
			'[TEMPLATE]/argos_theme/templates/settings.htt',
101
			'[TEMPLATE]/argos_theme/templates/start.htt',
102
			'[TEMPLATE]/argos_theme/templates/success.htt',
103
			'[TEMPLATE]/argos_theme/templates/templates.htt',
104
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
105
			'[TEMPLATE]/argos_theme/templates/users.htt',
106
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
107

    
108
			'[TEMPLATE]/wb_theme/templates/access.htt',
109
			'[TEMPLATE]/wb_theme/templates/addons.htt',
110
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
111
			'[TEMPLATE]/wb_theme/templates/error.htt',
112
			'[TEMPLATE]/wb_theme/templates/groups.htt',
113
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
114
			'[TEMPLATE]/wb_theme/templates/languages.htt',
115
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
116

    
117
	/*
118
			'[TEMPLATE]/wb_theme/templates/login.htt',
119
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
120
	*/
121

    
122
			'[TEMPLATE]/wb_theme/templates/media.htt',
123
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
124
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
125
			'[TEMPLATE]/wb_theme/templates/modules.htt',
126
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
127
			'[TEMPLATE]/wb_theme/templates/pages.htt',
128
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
129
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
130
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
131
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
132
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
133
			'[TEMPLATE]/wb_theme/templates/settings.htt',
134
			'[TEMPLATE]/wb_theme/templates/start.htt',
135
			'[TEMPLATE]/wb_theme/templates/success.htt',
136
			'[TEMPLATE]/wb_theme/templates/templates.htt',
137
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
138
			'[TEMPLATE]/wb_theme/templates/users.htt',
139
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
140
		 );
141
}
142

    
143
/* display a status message on the screen **************************************
144
 * @param string $message: the message to show
145
 * @param string $class:   kind of message as a css-class
146
 * @param string $element: witch HTML-tag use to cover the message
147
 * @return void
148
 */
149
function status_msg($message, $class='check', $element='span')
150
{
151
	// returns a status message
152
	$msg  = '<'.$element.' class="'.$class.'">';
153
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
154
	$msg .= $message.'</'.$element.'>';
155
	echo $msg;
156
}
157

    
158
// analyze/check database tables
159
function mysqlCheckTables( $dbName )
160
{
161
    global $aTable;
162
    $table_prefix = TABLE_PREFIX;
163
    $sql = "SHOW TABLES FROM " . $dbName;
164
    $result = @mysql_query( $sql );
165
    $data = array();
166
    $x = 0;
167

    
168
    while( ( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
169
    {
170
        $tmp = str_replace($table_prefix, '', $row[0]);
171

    
172
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$aTable) )
173
        {
174
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
175
            $analyze = mysql_query( $sql );
176
            $rowFetch = mysql_fetch_array( $analyze, MYSQL_ASSOC );
177
            $data[$x]['Op'] = $rowFetch["Op"];
178
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
179
            $msgColor = '<span class="error">';
180
            $data[$x]['Table'] = $row[0];
181
           // print  " ";
182
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
183
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
184
           // print  "<br />";
185
            $x++;
186
        }
187
    }
188
    return $data;
189
}
190

    
191
// check existings tables for upgrade or install
192
function check_wb_tables()
193
{
194
    global $database,$aTable;
195

    
196
 // if prefix inludes '_' or '%'
197
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
198
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
199

    
200
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
201
        $all_tables = array();
202
        if($get_result->numRows() > 0)
203
        {
204
            while ($data = $get_result->fetchRow())
205
            {
206
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
207
                if(in_array($tmp,$aTable))
208
                {
209
                    $all_tables[] = $tmp;
210
                }
211
            }
212
        }
213
     return $all_tables;
214
}
215

    
216
// check existing tables
217
$all_tables = check_wb_tables();
218

    
219
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
220
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
221
<head>
222
<title>Upgrade script</title>
223
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
224
<style type="text/css">
225
html { overflow-y: scroll; /* Force firefox to always show room for a vertical scrollbar */ }
226

    
227
body {
228
	margin:0;
229
	padding:0;
230
	border:0;
231
	background: #EBF7FC;
232
	color:#000;
233
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
234
	font-size: small;
235
	height:101%;
236
}
237

    
238
#container {
239
	width:85%;
240
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
241
	border:1px solid #000;
242
	color:#000;
243
	margin:2em auto;
244
	padding:0 15px;
245
	min-height: 500px;
246
	text-align:left;
247
}
248

    
249
p { line-height:1.5em; }
250

    
251
form {
252
	display: inline-block;
253
	line-height: 20px;
254
	vertical-align: baseline;
255
}
256
input[type="submit"].restart {
257
	background-color: #FFDBDB;
258
	font-weight: bold;
259
}
260

    
261
h1,h2,h3,h4,h5,h6 {
262
	font-family: Verdana, Arial, Helvetica, sans-serif;
263
	color: #369;
264
	margin-top: 1.0em;
265
	margin-bottom: 0.1em;
266
}
267

    
268
h1 { font-size:150%; }
269
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
270
h3 { font-size: 110%; font-weight: bold;; }
271

    
272
.ok, .error { font-weight:bold; }
273
.ok { color:green; }
274
.error { color:red; }
275
.check { color:#555; }
276

    
277
.warning {
278
	width: 98%;
279
	background:#FFDBDB;
280
	padding:0.2em;
281
	margin-top:0.5em;
282
	border: 1px solid black;
283
}
284
.info {
285
	width: 98%;
286
	background:#99CC99;
287
	padding:0.2em;
288
	margin-top:0.5em;
289
	border: 1px solid black;
290
}
291

    
292
</style>
293
</head>
294
<body>
295
<div id="container">
296
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
297
<h1>WebsiteBaker Upgrade</h1>
298
<?php
299
	if( version_compare( WB_VERSION, '2.7', '<' )) {
300
		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');
301
		echo '<br /><br />';
302
		echo "</div>
303
		</body>
304
		</html>
305
		";
306
		exit();
307
	}
308

    
309
?>
310
<p>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>
311

    
312
<?php
313
/**
314
 * Check if disclaimer was accepted
315
 */
316
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
317
<h2>Step 1: Backup your files</h2>
318
<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>
319

    
320
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
321
<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>
322
<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.
323
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
324
</form>
325
<br />
326

    
327
<?php
328
	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');
329
	echo '<br /><br />';
330
    echo "</div>
331
    </body>
332
    </html>
333
    ";
334
	exit();
335
}
336

    
337
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
338

    
339
/**********************************************************
340
 *  - Adding field default_theme to settings table
341
 */
342
echo "<br />Adding default_theme to settings table";
343
// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
344
echo (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
345

    
346
// check again all tables, to get a new array
347
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
348
/**********************************************************
349
 *  - check tables comin with WebsiteBaker
350
 */
351
    $check_text = 'total ';
352
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
353

    
354
    if(sizeof($all_tables) == 22)
355
    {
356
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aTable).' included in package '.$OK.'</h4>';
357
    }
358
    else
359
    {
360
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
361
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
362
        $result = array_diff ( $aTable, $all_tables );
363
        echo '<h4 class="warning"><br />';
364
        while ( list ( $key, $val ) = each ( $result ) )
365
        {
366
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
367
        }
368
        echo '<br /></h4>';
369
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
370
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
371
    	echo '</form>';
372
        if(defined('ADMIN_URL'))
373
        {
374
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
375
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
376
        	echo '</form>';
377
        }
378
        echo "<br /><br /></div>
379
        </body>
380
        </html>
381
        ";
382
        exit();
383
    }
384

    
385

    
386
echo '<h3>Step '.(++$stepID).': Updating settings</h3>';
387
/**********************************************************
388
 *  - Adding field sec_anchor to settings table
389
 */
390
echo "<br />Adding/updating sec_anchor to settings table";
391
$cfg = array(
392
	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'wb_'
393
);
394

    
395
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
396

    
397

    
398
/**********************************************************
399
 *  - Adding redirect timer to settings table
400
 */
401
echo "Adding/updating redirect timer to settings table";
402
$cfg = array(
403
	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
404
);
405
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
406

    
407
/**********************************************************
408
 *  - Adding rename_files_on_upload to settings table
409
 */
410
echo "Adding/Updating rename_files_on_upload to settings table";
411
$cfg = array(
412
	'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')
413
);
414
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
415

    
416
/**********************************************************
417
 *  - Adding mediasettings to settings table
418
 */
419
echo "Adding/updating mediasettings to settings table";
420
$cfg = array(
421
	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
422
);
423

    
424
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
425

    
426
/**********************************************************
427
 *  - Adding fingerprint_with_ip_octets to settings table
428
 */
429
echo "Adding/updating fingerprint_with_ip_octets to settings table";
430
$cfg = array(
431
	'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
432
	'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
433
);
434

    
435
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
436

    
437
/**********************************************************
438
 *  - Adding page_icon_dir to settings table
439
 */
440
echo "Adding/updating page_icon_dir to settings table";
441
$cfg = array(
442
	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
443
);
444

    
445
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
446
/**********************************************************
447
 *  - Adding page_extended to settings table
448
 */
449
echo "Adding/updating page_extended to settings table";
450
$cfg = array(
451
	'page_extended' => (defined('PAGE_EXTENDED') ? PAGE_EXTENDED : 'true'),
452
);
453

    
454
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
455

    
456
/**********************************************************
457
 *  - Adding sec_anchor to settings table
458
 */
459
echo "Adding/updating sec_anchor to settings table";
460
$cfg = array(
461
	'sec_anchor' => (defined('SEC_ANCHOR') && (SEC_ANCHOR=='') ? 'section_' : SEC_ANCHOR)
462
);
463

    
464
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
465
/**********************************************************
466
 *  - Adding dev_infos to settings table
467
 */
468
echo "Adding/updating dev_infos to settings table";
469
$cfg = array(
470
	'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
471
);
472

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

    
475
if(version_compare(WB_REVISION, REVISION, '<'))
476
{
477
	echo '<h3>Step '.(++$stepID).': Updating core tables</h3>';
478

    
479
	/**********************************************************
480
	 *  - Update search no results database filed to create
481
	 *  valid XHTML if search is empty
482
	 */
483
	if (version_compare(WB_VERSION, '2.8', '<'))
484
	{
485
	    echo "<br />Updating database field `no_results` of search table: ";
486
	    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
487
	    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
488
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
489
		$sql .= 'WHERE `name`=\'no_results\'';
490
	    echo ($database->query($sql)) ? ' $OK<br />' : ' $FAIL<br />';
491
	}
492

    
493
	/**********************************************************
494
     *  - Add field "redirect_type" to table "mod_menu_link"
495
     *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
496
     */
497
	$table_name = TABLE_PREFIX.'mod_menu_link';
498
	$field_name = 'redirect_type';
499
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
500
	if(!$database->field_exists($table_name,$field_name)) {
501
		echo "<br />Adding field redirect_type to mod_menu_link table";
502
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
503
	} else {
504
		echo "<br />Modify field redirect_type to mod_menu_link table";
505
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
506
	}
507

    
508
	/**********************************************************
509
	 *  - Add field "page_trail" to table "pages"
510
	 */
511
	$table_name = TABLE_PREFIX.'pages';
512
	$field_name = 'page_trail';
513
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
514
	echo "Modify field page_trail to pages table";
515
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
516

    
517
	/**********************************************************
518
     *  - Add field "page_icon" to table "pages"
519
     */
520
	$table_name = TABLE_PREFIX.'pages';
521
	$field_name = 'page_icon';
522
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
523
	if(!$database->field_exists($table_name,$field_name)) {
524
		echo "Adding field page_icon to pages table";
525
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
526
	} else {
527
		echo "Modify field page_icon to pages table";
528
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
529
	}
530

    
531
	/**********************************************************
532
	 *  - Add field "page_code" to table "pages"
533
	 */
534
	$table_name = TABLE_PREFIX.'pages';
535
	$field_name = 'page_code';
536
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
537
	if(!$database->field_exists($table_name,$field_name)) {
538
		echo "Adding field page_code to pages table";
539
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
540
	} else {
541
		echo "Modify field page_code to pages table";
542
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
543
	}
544

    
545
	/**********************************************************
546
     *  - Add field "menu_icon_0" to table "pages"
547
     */
548
	$table_name = TABLE_PREFIX.'pages';
549
	$field_name = 'menu_icon_0';
550
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
551
	if(!$database->field_exists($table_name,$field_name)) {
552
		echo "Adding field menu_icon_0 to pages table";
553
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
554
	} else {
555
		echo "Modify field menu_icon_0 to pages table";
556
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
557
	}
558

    
559
	/**********************************************************
560
	 *  - Add field "menu_icon_1" to table "pages"
561
     */
562
	$table_name = TABLE_PREFIX.'pages';
563
	$field_name = 'menu_icon_1';
564
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
565
	if(!$database->field_exists($table_name,$field_name)) {
566
		echo "Adding field menu_icon_1 to pages table";
567
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
568
	} else {
569
		echo "Modify field menu_icon_1 to pages table";
570
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
571
	}
572

    
573
	/**********************************************************
574
	 *  - Add field "tooltip" to table "pages"
575
     */
576
	$table_name = TABLE_PREFIX.'pages';
577
	$field_name = 'tooltip';
578
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
579
	if(!$database->field_exists($table_name,$field_name)) {
580
		echo "Adding field tooltip to pages table";
581
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
582
	} else {
583
		echo "Modify field tooltip to pages table";
584
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
585
	}
586

    
587
	/**********************************************************
588
	 *  - Add field "admin_groups" to table "pages"
589
     */
590
	$table_name = TABLE_PREFIX.'pages';
591
	$field_name = 'admin_groups';
592
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
593
	echo "Modify field admin_groups to pages table";
594
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
595

    
596
	/**********************************************************
597
	 *  - Add field "admin_users" to table "pages"
598
	 */
599
	$table_name = TABLE_PREFIX.'pages';
600
	$field_name = 'admin_users';
601
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
602
	echo "Modify field admin_users to pages table";
603
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
604

    
605
	/**********************************************************
606
	 *  - Add field "viewing_groups" to table "pages"
607
	 */
608
	$table_name = TABLE_PREFIX.'pages';
609
	$field_name = 'viewing_groups';
610
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
611
	echo "Modify field viewing_groups to pages table";
612
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
613

    
614
	/**********************************************************
615
	 *  - Add field "viewing_users" to table "pages"
616
	 */
617
	$table_name = TABLE_PREFIX.'pages';
618
	$field_name = 'viewing_users';
619
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
620
	echo "Modify field viewing_users to pages table";
621
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
622

    
623

    
624
/**
625
 * This part with changing in mod_wysiwyg will be removed in the final version
626
 * special workout for the tester
627
 */
628
	/**********************************************************
629
	 *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
630
	 */
631
	$sTable = TABLE_PREFIX.'mod_wysiwyg';
632
	$field_name = 'wysiwyg_id';
633
	if($database->field_exists($sTable,$field_name)) {
634
    	echo "Remove PRIMARY KEY from table mod_wysiwygs";
635
//ALTER TABLE `wb283_mod_wysiwyg` DROP `wysiwyg_id`
636
        $sql = 'ALTER TABLE `'.DB_NAME.'`.`'.$sTable.'` DROP `wysiwyg_id`';
637
        echo ($database->query($sql) ? " $OK<br />" : " $FAIL!<br />");
638

    
639
//    	echo "add new PRIMARY KEY to table mod_wysiwygs";
640
//        $sql = 'ALTER TABLE `'.$sTable.'` DROP `wysiwyg_id`';
641
//        echo ($database->query($sql) ? " $OK<br />" : " $FAIL!<br />");
642
    }
643
	echo "Change PRIMARY KEY from table mod_wysiwygs";
644
    $sql = 'ALTER TABLE `'.DB_NAME.'`.`'.$sTable.'` ADD PRIMARY KEY (`section_id`)';
645
    echo ($database->query($sql) ? " $OK<br />" : " $FAIL!<br />");
646

    
647

    
648
}
649

    
650
/**********************************************************
651
 * upgrade media folder index protect files
652
 ALTER TABLE `wb_pages` CHANGE `page_icon` `page_icon` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''
653
 */
654
	$dir = (WB_PATH.MEDIA_DIRECTORY);
655
	echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
656
	$array = rebuildFolderProtectFile($dir);
657
	if( sizeof( $array ) ){
658
		print '<strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
659
	} else {
660
		print '<<strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
661
		print implode ('<br />',$array);
662
	}
663

    
664
/**********************************************************
665
 * upgrade pages folder index access files
666
 */
667
	echo '<h4>Upgrade /pages/ index.php access files</h4>';
668

    
669
    ///**********************************************************
670
    // *  - try to remove access files
671
    // */
672
	$sTempDir = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
673
	if(($sTempDir!='') && is_readable(WB_PATH.$sTempDir)==true) {
674
	 	if(rm_full_dir (WB_PATH.$sTempDir, true )==false) {
675
			$msg[] = '<strong>Could not delete existing access files</strong>';
676
	 	} else {
677
			$msg[] = createFolderProtectFile(rtrim( WB_PATH.$sTempDir,'/') );
678
        }
679
	}
680

    
681
    ///**********************************************************
682
    // *  - Reformat/rebuild all existing access files
683
    // */
684
    $msg[] = "Refresh all existing access files ";
685
    $sql = 'SELECT `page_id`,`root_parent`,`link`, `level` FROM `'.TABLE_PREFIX.'pages` ORDER BY `link`';
686
    if (($oPage = $database->query($sql)))
687
    {
688
        $x = 0;
689
        while (($page = $oPage->fetchRow(MYSQL_ASSOC)))
690
        {
691
            // Work out level
692
            $level = level_count($page['page_id']);
693
            // Work out root parent
694
            $root_parent = root_parent($page['page_id']);
695
            // Work out page trail
696
            $page_trail = get_page_trail($page['page_id']);
697
            // Update page with new level and link
698
            $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
699
            $sql .= '`root_parent` = '.$root_parent.', ';
700
            $sql .= '`level` = '.$level.', ';
701
            $sql .= '`page_trail` = "'.$page_trail.'" ';
702
            $sql .= 'WHERE `page_id` = '.$page['page_id'];
703

    
704
            if(!$database->query($sql)) {}
705
            $filename = WB_PATH.PAGES_DIRECTORY.$page['link'].PAGE_EXTENSION;
706
            $msg = create_access_file($filename, $page['page_id'], $page['level']);
707
            $x++;
708
        }
709
        $msg[] = '<strong>Number of new formatted access files: '.$x.'</strong>';
710
    }
711

    
712
	print implode ('<br />',$msg);
713

    
714
/*
715
	if( sizeof( $msg ) ){
716

    
717
		print '<br /><strong>Upgrade '.sizeof( $msg ).' /pages/ access files</strong>'." $OK<br />";
718
	} else {
719
		print '<br /><strong>Upgrade /pages/ access files</strong>'." $FAIL!<br />";
720
		print implode ('<br />',$msg);
721
	}
722
*/
723
/**********************************************************
724
 * upgrade posts folder index protect files
725
 */
726
	$sPostsPath = WB_PATH.PAGES_DIRECTORY.'/posts';
727
	echo '<h4>Upgrade /posts/ index.php protect files</h4>';
728
	$array = rebuildFolderProtectFile($sPostsPath);
729
	if( sizeof( $array ) ){
730
		print '<strong>Upgrade '.sizeof( $array ).' /posts/ protect files</strong>'." $OK<br />";
731
	} else {
732
		print '<strong>Upgrade /posts/ protect files</strong>'." $FAIL!<br />";
733
		print implode ('<br />',$array);
734
	}
735

    
736
/* *****************************************************************************
737
 * - check for deprecated / never needed files
738
 */
739
	if(sizeof($filesRemove)) {
740
		echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
741
	}
742
	$searches = array(
743
		'[ADMIN]',
744
		'[MEDIA]',
745
		'[PAGES]',
746
		'[FRAMEWORK]',
747
		'[MODULES]',
748
		'[TEMPLATE]'
749
	);
750
	$replacements = array(
751
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
752
		MEDIA_DIRECTORY,
753
		PAGES_DIRECTORY,
754
		'/framework',
755
		'/modules',
756
		'/templates'
757
	);
758

    
759
	foreach( $filesRemove as $filesId )
760
	{
761
		$msg = '';
762
		foreach( $filesId as $file )
763
		{
764
			$file = str_replace($searches, $replacements, $file);
765
			$file = WB_PATH.'/'.$file;
766
			if( file_exists($file) ) {
767
				// try to unlink file
768
				if(!is_writable( $file ) || !unlink($file)) {
769
					// save in err-list, if failed
770
					$msg .= $file.'<br />';
771
				}
772
			}
773
		}
774

    
775
		if($msg != '')
776
		{
777
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
778
				    can not be removed automatically.<br /><br />Please delete them
779
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
780
	        status_msg($msg, 'error warning', 'div');
781
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
782

    
783
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
784
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
785
			echo '</form>';
786
			echo '<br /><br /></div></body></html>';
787
			exit;
788
		}
789
	}
790

    
791

    
792
/**********************************************************
793
 * - check for deprecated / never needed files
794
 */
795
	if(sizeof($dirRemove)) {
796
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
797
		$searches = array(
798
			'[ADMIN]',
799
			'[MEDIA]',
800
			'[PAGES]',
801
			'[TEMPLATE]'
802
		);
803
		$replacements = array(
804
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
805
			MEDIA_DIRECTORY,
806
			PAGES_DIRECTORY,
807
			'/templates',
808
		);
809
		$msg = '';
810
		foreach( $dirRemove as $dir ) {
811
			$dir = str_replace($searches, $replacements, $dir);
812
			$dir = WB_PATH.'/'.$dir;
813
			if( is_dir( $dir )) {
814
			// try to delete dir
815
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
816
				// save in err-list, if failed
817
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
818
				}
819
			}
820
		}
821
		if($msg != '') {
822
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
823
					can not be removed automatically.<br /><br />Please delete them
824
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
825
			status_msg($msg, 'error warning', 'div');
826
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
827
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
828
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
829
			echo '</form>';
830
			echo '<br /><br /></div></body></html>';
831
			exit;
832
		}
833
	}
834

    
835
/**********************************************************
836
 * upgrade modules if newer version is available
837
 */
838
	$aModuleList = array('news');
839
	foreach($aModuleList as $sModul) {
840
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
841
			$currModulVersion = get_modul_version ($sModul, false);
842
			$newModulVersion =  get_modul_version ($sModul, true);
843
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
844
				echo '<h3>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h3>';
845
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
846
			}
847
		}
848
	}
849
/**********************************************************
850
 *  - Reload all addons
851
 */
852

    
853
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3>';
854
	////delete modules
855
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
856
	// Load all modules
857
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
858
		while(false !== ($file = readdir($handle))) {
859
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
860
				load_module(WB_PATH.'/modules/'.$file );
861
			   // 	upgrade_module($file, true);
862
			}
863
		}
864
		closedir($handle);
865
	}
866
	echo '<strong><br />Modules reloaded<br /></strong>';
867

    
868
	////delete templates
869
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
870
	// Load all templates
871
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
872
		while(false !== ($file = readdir($handle))) {
873
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
874
				load_template(WB_PATH.'/templates/'.$file);
875
			}
876
		}
877
		closedir($handle);
878
	}
879
	echo '<strong><br />Templates reloaded<br /></strong>';
880

    
881
	////delete languages
882
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
883
	// Load all languages
884
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
885
		while(false !== ($file = readdir($handle))) {
886
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
887
				load_language(WB_PATH.'/languages/'.$file);
888
			}
889
		}
890
		closedir($handle);
891
	}
892
	echo '<strong><br />Languages reloaded<br /></strong>';
893

    
894
/**********************************************************
895
 *  - install new droplets
896
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
897
	echo $drops;
898
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
899
	require_once (WB_PATH."/modules/droplets/".$file_name);
900
********************************************************** */
901

    
902
/**********************************************************
903
 *  - End of upgrade script
904
 */
905
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
906
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
907
/**********************************************************
908
 *  - Set Version to new Version
909
 */
910
echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
911

    
912
$cfg = array(
913
	'wb_version' => VERSION,
914
	'wb_revision' => REVISION,
915
	'wb_sp' => SP
916
);
917

    
918
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
919

    
920
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
921
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
922
	// show buttons to go to the backend or frontend
923
	echo '<br />';
924

    
925
	if(defined('WB_URL')) {
926
		echo '<form action="'.WB_URL.'/">';
927
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
928
		echo '</form>';
929
	}
930
	if(defined('ADMIN_URL')) {
931
		echo '<form action="'.ADMIN_URL.'/">';
932
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
933
		echo '</form>';
934
	}
935

    
936
	echo '<br /><br /></div></body></html>';
(5-5/5)