Project

General

Profile

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