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
    	'website_signature' => (defined('WEBSITE_SIGNATURE') && (WEBSITE_SIGNATURE=='') ? '' : WEBSITE_SIGNATURE)
523
    );
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
    	'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') && (CONFIRMED_REGISTRATION=='') ? '' : CONFIRMED_REGISTRATION)
533
    );
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 1768 Luisehahne
$aDebugMessage = array();
774 1457 Luisehahne
/**********************************************************
775 1765 Luisehahne
 * This part with changing in mod_wysiwyg will be removed in the final version
776
 * special workout for the tester
777
 *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
778 1457 Luisehahne
 */
779 1768 Luisehahne
    $aDebugMessage[] = '<div style="margin-left:2em;">';
780 1677 Luisehahne
781 1765 Luisehahne
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
782
    $field_name = 'wysiwyg_id';
783
    if($database->field_exists($sTable, 'wysiwyg_id')) {
784
        if($database->index_exists($sTable, 'PRIMARY')) {
785 1768 Luisehahne
            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
786
            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
787 1688 Luisehahne
        }
788 1768 Luisehahne
        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
789
        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
790 1765 Luisehahne
    }
791 1688 Luisehahne
792 1768 Luisehahne
    $aDebugMessage[] = "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
793
    $aDebugMessage[] = $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
794
    $aDebugMessage[] = '</div>';
795
796
if($bDebugModus) {
797
// $aDebugMessage[] =
798
    echo implode(PHP_EOL,$aDebugMessage);
799 1765 Luisehahne
}
800 1768 Luisehahne
$aDebugMessage = array();
801 1813 Luisehahne
echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
802
    /**********************************************************
803
    * Updating group_id in table users
804
    */
805 1760 Luisehahne
806 1813 Luisehahne
        echo '<div style="margin-left:2em;">';
807
        $aUsers = array();
808
		// Get existing values
809
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
810
        $sql .= 'WHERE `user_id` != 1 ';
811
        if($oUser = $database->query($sql)){
812
            $iTotalUsers = $oUser->numRows();
813
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
814
815
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
816
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
817
            }
818
        } else {
819
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
820
        }
821
822
        foreach($aUsers AS $user_id => $value){
823
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
824 1815 Luisehahne
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
825
                $groups_id = $aUsers[$user_id]['groups_id'];
826 1813 Luisehahne
                $group_id = 0;
827
                //if user is in administrator-group, get this group else just get the first one
828 1815 Luisehahne
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
829 1813 Luisehahne
830
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
831
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
832 1815 Luisehahne
                $sql .= 'SET `group_id`  = '.$group_id.', ';
833
                $sql .=     '`groups_id` = '.$groups_id.' ';
834 1813 Luisehahne
                $sql .= 'WHERE `user_id` = '.intval($user_id);
835
836
                if($oRes = $database->query($sql)){  }
837
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
838
        }
839
        unset($aUsers);
840
841
    $aDebugMessage[] = '</div>';
842
843
if($bDebugModus) {
844
// $aDebugMessage[] =
845
    echo implode(PHP_EOL,$aDebugMessage);
846
}else {
847
    echo '<span><strong>'.$iTotalUsers.' users updating the group_id</strong></span>'." $OK<br />";
848
    echo '</div>';
849
}
850
851
$aDebugMessage = array();
852 1765 Luisehahne
echo '<h3>Step '.(++$stepID).': Updating acess and protected files in folders</h3>';
853
854
echo '<div style="margin-left:2em;">';
855
    /**********************************************************
856
    * upgrade media directory index protect files
857
    */
858
    $dir = (WB_PATH.MEDIA_DIRECTORY);
859
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
860
    $array = rebuildFolderProtectFile($dir);
861
    if( sizeof( $array ) ){
862 1789 Luisehahne
    	echo '<span><strong>Upgrade '.sizeof( $array ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
863 1765 Luisehahne
    } else {
864 1789 Luisehahne
    	echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
865
    	echo implode ('<br />',$array);
866 1677 Luisehahne
    }
867
868 1765 Luisehahne
    /**********************************************************
869
     * upgrade pages directory index access files
870
     */
871
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
872 1677 Luisehahne
873 1765 Luisehahne
    /**********************************************************
874
     *  - Reformat/rebuild all existing access files
875
     */
876
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
877
    $msg = rebuild_all_accessfiles();
878 1677 Luisehahne
879 1789 Luisehahne
	echo implode ('<br />',$msg);
880 1765 Luisehahne
    echo '</div>';
881
    /* *****************************************************************************
882
     * - check for deprecated / never needed files
883
     */
884
    if(sizeof($aFilesToRemove)) {
885
    	echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
886
    	$searches = array(
887
    		'[ADMIN]',
888
    		'[MEDIA]',
889
    		'[PAGES]',
890
    		'[FRAMEWORK]',
891
    		'[MODULES]',
892
    		'[TEMPLATE]'
893
    	);
894
    	$replacements = array(
895
    		'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
896
    		MEDIA_DIRECTORY,
897
    		PAGES_DIRECTORY,
898
    		'/framework',
899
    		'/modules',
900
    		'/templates'
901
    	);
902 1677 Luisehahne
903 1532 Luisehahne
		$msg = '';
904 1765 Luisehahne
    	foreach( $aFilesToRemove as $file )
905
    	{
906 1532 Luisehahne
			$file = str_replace($searches, $replacements, $file);
907 1765 Luisehahne
			if( is_writable(WB_PATH.'/'.$file) ) {
908 1588 darkviper
				// try to unlink file
909 1765 Luisehahne
				if(!unlink(WB_PATH.$file)) {
910 1588 darkviper
					// save in err-list, if failed
911 1801 Luisehahne
				}
912 1484 Luisehahne
			}
913 1801 Luisehahne
            if( is_readable(WB_PATH.'/'.$file) ) {
914
                $msg .= $file.'<br />';
915
            }
916 1765 Luisehahne
    	}
917 1532 Luisehahne
918
		if($msg != '')
919
		{
920
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
921
				    can not be removed automatically.<br /><br />Please delete them
922
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
923
	        status_msg($msg, 'error warning', 'div');
924
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
925
926
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
927
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
928
			echo '</form>';
929 1765 Luisehahne
            echo "<br /><br /></div>
930
            </div>
931
            </div>
932
            </body>
933
            </html>
934
            ";
935 1532 Luisehahne
			exit;
936
		}
937 1765 Luisehahne
    }
938 1484 Luisehahne
939 1532 Luisehahne
940 1457 Luisehahne
/**********************************************************
941 1525 Luisehahne
 * - check for deprecated / never needed files
942
 */
943 1588 darkviper
	if(sizeof($dirRemove)) {
944 1671 Luisehahne
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
945 1588 darkviper
		$searches = array(
946
			'[ADMIN]',
947
			'[MEDIA]',
948
			'[PAGES]',
949
			'[TEMPLATE]'
950
		);
951
		$replacements = array(
952
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
953
			MEDIA_DIRECTORY,
954
			PAGES_DIRECTORY,
955
			'/templates',
956
		);
957
		$msg = '';
958
		foreach( $dirRemove as $dir ) {
959
			$dir = str_replace($searches, $replacements, $dir);
960
			$dir = WB_PATH.'/'.$dir;
961
			if( is_dir( $dir )) {
962
			// try to delete dir
963 1641 Luisehahne
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
964 1588 darkviper
				// save in err-list, if failed
965 1801 Luisehahne
                    if( is_readable(WB_PATH.'/'.$file) ) {
966
                    	$msg .= str_replace(WB_PATH,'',$dir).'<br />';
967
                    }
968 1588 darkviper
				}
969 1525 Luisehahne
			}
970
		}
971 1765 Luisehahne
972 1588 darkviper
		if($msg != '') {
973 1641 Luisehahne
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
974 1588 darkviper
					can not be removed automatically.<br /><br />Please delete them
975
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
976
			status_msg($msg, 'error warning', 'div');
977
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
978
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
979
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
980
			echo '</form>';
981 1765 Luisehahne
            echo "<br /><br /></div>
982
            </div>
983
            </div>
984
            </body>
985
            </html>
986
            ";
987 1588 darkviper
			exit;
988
		}
989 1525 Luisehahne
	}
990 1532 Luisehahne
991 1765 Luisehahne
    /**********************************************************
992
     * upgrade modules if newer version is available
993
     * $aModuleList list of proofed modules
994
     */
995 1801 Luisehahne
    $sModuleList = 'news,wysiwyg,form';
996 1765 Luisehahne
    $aModuleList = explode(',', (defined('MODULES_UPGRADE_LIST') ? MODULES_UPGRADE_LIST : $sModuleList));
997
    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
998
//	$aModuleList = array('news');
999 1588 darkviper
	foreach($aModuleList as $sModul) {
1000
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1001
			$currModulVersion = get_modul_version ($sModul, false);
1002
			$newModulVersion =  get_modul_version ($sModul, true);
1003
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1004 1765 Luisehahne
                echo '<div style="margin-left:2em;">';
1005
				echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1006 1588 darkviper
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1007 1765 Luisehahne
                echo '</div>';
1008 1588 darkviper
			}
1009
		}
1010 1525 Luisehahne
	}
1011 1765 Luisehahne
1012 1525 Luisehahne
/**********************************************************
1013 1457 Luisehahne
 *  - Reload all addons
1014
 */
1015
1016 1765 Luisehahne
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1017
    echo '<div style="margin-left:2em;">';
1018
    $iFound = 0;
1019
    $iLoaded = 0;
1020 1588 darkviper
	////delete modules
1021
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1022
	// Load all modules
1023
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1024
		while(false !== ($file = readdir($handle))) {
1025 1769 Luisehahne
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1026 1765 Luisehahne
                $iFound++;
1027
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1028 1588 darkviper
			   // 	upgrade_module($file, true);
1029
			}
1030 1457 Luisehahne
		}
1031 1588 darkviper
		closedir($handle);
1032 1457 Luisehahne
	}
1033 1765 Luisehahne
	echo '<span><strong>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1034 1457 Luisehahne
1035 1765 Luisehahne
    $iFound = 0;
1036
    $iLoaded = 0;
1037 1588 darkviper
	////delete templates
1038
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1039
	// Load all templates
1040
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1041
		while(false !== ($file = readdir($handle))) {
1042
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1043 1769 Luisehahne
1044 1765 Luisehahne
                $iFound++;
1045
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1046 1769 Luisehahne
1047 1588 darkviper
			}
1048 1457 Luisehahne
		}
1049 1588 darkviper
		closedir($handle);
1050 1457 Luisehahne
	}
1051 1765 Luisehahne
	echo '<span><strong>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1052 1457 Luisehahne
1053 1765 Luisehahne
    $iFound = 0;
1054
    $iLoaded = 0;
1055 1588 darkviper
	////delete languages
1056
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1057
	// Load all languages
1058
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1059
		while(false !== ($file = readdir($handle))) {
1060 1769 Luisehahne
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1061 1765 Luisehahne
                $iFound++;
1062
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1063 1588 darkviper
			}
1064 1457 Luisehahne
		}
1065 1588 darkviper
		closedir($handle);
1066 1457 Luisehahne
	}
1067 1765 Luisehahne
	echo '<span><strong>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1068
    echo '</div>';
1069 1457 Luisehahne
1070
/**********************************************************
1071 1671 Luisehahne
 *  - install new droplets
1072
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1073
	echo $drops;
1074
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1075
	require_once (WB_PATH."/modules/droplets/".$file_name);
1076
********************************************************** */
1077
1078
/**********************************************************
1079 1457 Luisehahne
 *  - End of upgrade script
1080
 */
1081 1588 darkviper
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1082
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1083 1532 Luisehahne
/**********************************************************
1084
 *  - Set Version to new Version
1085
 */
1086 1765 Luisehahne
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1087
echo '<div style="margin-left:2em;">';
1088 1457 Luisehahne
1089 1671 Luisehahne
$cfg = array(
1090
	'wb_version' => VERSION,
1091
	'wb_revision' => REVISION,
1092
	'wb_sp' => SP
1093
);
1094 1765 Luisehahne
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1095 1671 Luisehahne
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1096 1765 Luisehahne
echo '</div>';
1097 1671 Luisehahne
1098 1765 Luisehahne
echo '<p style="font-size:140%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
1099
status_msg('<strong>:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
1100
// show buttons to go to the backend or frontend
1101
echo '<br />';
1102 1532 Luisehahne
1103 1765 Luisehahne
if(defined('WB_URL')) {
1104
	echo '<form action="'.WB_URL.'/">';
1105
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1106
	echo '</form>';
1107
}
1108
if(defined('ADMIN_URL')) {
1109
	echo '<form action="'.ADMIN_URL.'/">';
1110
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1111
	echo '</form>';
1112
}
1113 1457 Luisehahne
1114 1765 Luisehahne
echo "<br /><br /></div>
1115
</div>
1116
</div>
1117
</body>
1118
</html>
1119
";
1120
exit();