Project

General

Profile

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