Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 722 2008-02-22 18:49:45Z doc $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
/** 
27
	PHP ROUTINES FOR THE UPGRADE SCRIPT
28
**/
29
// this function checks the basic configurations of an existing WB intallation
30
function status_msg($message, $class='check', $element='span') {
31
	// returns a status message
32
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
33
}
34

    
35
function check_baseline_configuration() {
36
	// check if config.php file exists and contains values
37
	status_msg('config.php: ');
38
	@include_once('config.php');
39
	if(defined('WB_PATH')) {
40
		status_msg('OK', 'ok');
41
	} else {
42
		// output error message and return error status
43
		status_msg('FAILED', 'error');
44
		status_msg('<strong>Error:</strong><br />No valid config.php found in: "<em>'
45
			.dirname(__FILE__).'</em>"<br />Please check if this script is placed in the WB root directory '
46
			.'and check/correct the config.php file before proceeding.<br /><br />You can not proceed before this error is fixed!!!'
47
			, 'warning', 'div');
48
		return -1;
49
	}
50

    
51
	// check if the WB 2.7 installation files were already uploaded via FTP
52
	status_msg(', WB 2.7 core files uploaded: ');
53
	@include_once(WB_PATH .'/framework/functions.php');
54
	@include_once(WB_PATH .'/admin/interface/version.php');
55
	if(defined('VERSION') && VERSION == '2.7'
56
		&& function_exists('get_variable_content') 
57
		&& file_exists(WB_PATH .'/modules/menu_link/languages/DE.php') 
58
		&& file_exists(WB_PATH .'/modules/output_filter/filter-routines.php') 
59
		&& file_exists(WB_PATH .'/modules/captcha_control/languages/DE.php')
60
		&& file_exists(WB_PATH .'/modules/jsadmin/jsadmin_backend_include.php')
61
		&& file_exists(WB_PATH .'/admin/admintools/tool.php')
62
		&& file_exists(WB_PATH .'/admin/interface/er_levels.php')) {
63
		status_msg('OK','ok');
64
	} else {
65
		// output a warning and return error status
66
		status_msg('FAILED','error');
67
		status_msg('<strong>Error:</strong><br />Some of the Website Baker 2.7 core files were not found.'
68
			.'<br />Please upload all core files (except config.php and folder /install) contained in the WB 2.7 installation package first.'
69
			.'<br /><br />You can not proceed before this error is fixed!!!'
70
			, 'warning', 'div');
71
		return -1;
72
	}
73

    
74
	// check database connection (try to extract a single value which should always exist)
75
	$matches = '';
76
	status_msg(', Database connection: ');
77
	if(class_exists('database')) {
78
		$table = TABLE_PREFIX .'groups';
79
		//$result = $database->query("SELECT group_id FROM $table WHERE group_id = '1' LIMIT 1");
80
		$result = $database->query("SELECT name FROM $table WHERE group_id = '1' LIMIT 1");
81
		$matches = ($result->numRows() > 0) ? $result->numRows() : '';
82
	}
83
	if($matches == '1') {
84
		status_msg('OK', 'ok');
85
	} else {
86
		// output error message and return error status
87
		status_msg('FAILED', 'error');
88
		status_msg('<strong>Error:</strong><br />Unable to connect to your existing Website Baker database.'
89
			.'<br />Make sure that the database class is available and the connection data in the config.php file is correct '
90
			.'and your database is not corrupt.<br />To check if your database is corrupt, you can use a tool like '
91
			.'<a href="http://www.phpmyadmin.net/" target="_blank">phpMyAdmin</a>.'
92
			.'<br /><br />You can not proceed before this error is fixed!!!'
93
			, 'warning', 'div');
94
		return -1;
95
	}
96
	return 0;
97
}
98

    
99
?>
100

    
101
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
102
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
103
<head>
104
<title>Upgrade script from Website Baker v2.6.7 to Website Baker v2.7</title>
105
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
106
<style type="text/css">
107
body {
108
	margin:0;
109
	padding:0;
110
	border:0;
111
	background: #EBF7FC;
112
	color:#000;
113
  font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
114
	font-size: small;
115
	height:101%;
116
}
117

    
118
#container {
119
	width:85%;
120
	background: #9ACBF1 url(admin/interface/background.png) repeat-x;
121
	border:1px solid #000;
122
	color:#000;
123
	margin:2em auto;
124
	padding:0 15px;
125
	min-height: 500px;
126
	text-align:left;
127
}
128

    
129
p { line-height:1.5em; }
130

    
131
h1,h2,h3,h4,h5,h6 {
132
	font-family: Verdana, Arial, Helvetica, sans-serif;
133
	color: #369;
134
	margin-top: 1.0em;
135
	margin-bottom: 0.1em;
136
}
137

    
138
h1 { font-size:150%; }
139
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
140
h3 { font-size: 120%; }
141

    
142
.ok, .error { font-weight:bold; }
143
.ok { color:green; }
144
.error { color:red; }
145
.check { color:#555; }
146

    
147
.warning {
148
	width: 98%;
149
	background:#FFDBDB;
150
	padding:0.2em;
151
	margin-top:0.5em;
152
	border: 1px solid black;
153
}
154
</style>
155
</head>
156
<body>
157
<div id="container">
158
<img src="admin/interface/logo.png" alt="Website Baker Logo" />
159

    
160
<h1>Website Baker Upgrade</h1>
161
<p>This script is for <strong>upgrading an existing v2.6.7</strong> installation to the latest Website Baker <strong>version 2.7</strong>. The upgrade script checks the configuration of your installed Website Baker system and alters the existing WB database to reflect the changes introduced with WB 2.7.</p>
162

    
163
<?php
164
if(!isset($_POST['backup_confirmed'])) { 
165
?>
166
<h2>Prerequisites</h2>
167
<p>To upgrade from an existing WB 2.6.7 version, please perform the following steps in advance:
168
<ol>
169
<li>Backup the entire <strong>/pages</strong> folder (including all subfolder and files) of your existing WB installation</li>
170
<li>Backup the entire <strong>Database</strong> of your existing WB installation (e.g. by the WB admin tool)</li>
171
<li>Download the WB 2.7 installation package from the <a href="http://download.websitebaker.org/" target="_blank">official project site</a></li>
172
<li>Upload all files contained in the WB 2.7 installation package (except config.php and the folder /install) via FTP over your existing installation</li>
173
<li>start this script by typing the URL into your browser</li>
174
</ol>
175
<strong class="error">Note: </strong>If you have an version lower than 2.6.7, you need to upgrade to 2.6.7 first!! Instructions can be found on the <a href="http://help.websitebaker.org/pages/en/basic-docu/installation/upgrade.php" target="_blank">Website Baker Help portal</a>.</p>
176

    
177
<h2>Step 1: Check existing installation</h2>
178
<p>Checking the configuration of your existing Website Baker installation:<br />
179
<?php
180
// check the basic Website Baker installation before proceeding
181
if(check_baseline_configuration() != 0) die;
182
status_msg('<p>Congratulations: You have passed all the required pre-checks.', 'ok');
183
?>
184

    
185
<h2>Step 2: Create a backup of your existing data</h2>
186
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding. The upgrade script is not sufficiently tested at the moment and should therefore only be used for testing purposes!!! Please confirm the disclaimer before starting this script.</p>
187

    
188
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
189
<textarea cols="80" rows="5">DISCLAIMER: The Website Baker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire Website Baker MySQL database was created before you can proceed.</textarea>
190
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
191
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
192
</form>
193
<br />
194

    
195
<?php
196
if(isset($_POST['send'])) {
197
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
198
} 
199
?>
200
<br /><br />
201
<?php
202
} else {
203
/**
204
	THE WEBSITE BAKER UPGRADE SCRIPT STARTS HERE
205
**/
206
require_once('config.php');
207
require_once(WB_PATH.'/framework/functions.php');
208
?>
209
<h2>Step 3: Upgrading the existing Website Baker installation to WB 2.7</h2>
210
<p>will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7</p>
211
<?php
212

    
213
$OK   = '<span class="ok">OK</span>';
214
$FAIL = '<span class="error">FAILED</span>';
215

    
216

    
217
/**********************************************************
218
 *  - modules-based search
219
 */
220
function db_add_search_key_value($key, $value) {
221
	global $database; global $OK; global $FAIL;
222
	$table = TABLE_PREFIX.'search';
223
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
224
	if($query->numRows() > 0) {
225
		echo "$key: allready there. $OK.<br />";
226
		return true;
227
	} else {
228
		$database->query("INSERT INTO $table (name,value,extra) VALUES ('$key', '$value', '')");
229
		echo (mysql_error()?mysql_error().'<br />':'');
230
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
231
		if($query->numRows() > 0) {
232
			echo "$key: $OK.<br />";
233
			return true;
234
		} else {
235
			echo "$key: $FAIL!<br />";
236
			return false;
237
		}
238
	}
239
}
240
function db_add_field($field, $table, $desc) {
241
	global $database; global $OK; global $FAIL;
242
	echo "<u>Adding field '$field' to table '$table'</u><br />";
243
	$table = TABLE_PREFIX.$table;
244
	$query = $database->query("DESCRIBE $table '$field'");
245
	if($query->numRows() == 0) { // add field
246
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
247
		echo (mysql_error()?mysql_error().'<br />':'');
248
		$query = $database->query("DESCRIBE $table '$field'");
249
		echo (mysql_error()?mysql_error().'<br />':'');
250
		if($query->numRows() > 0) {
251
			echo "'$field' added. $OK.<br />";
252
		} else {
253
			echo "adding '$field' $FAIL!<br />";
254
		}
255
	} else {
256
		echo "'$field' allready there. $OK.<br />";
257
	}
258
}
259

    
260
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
261
// module_order - in which order to show the search-results
262
// max_excerpt - how many lines of excerpt to print per matching page
263

    
264
$cfg = array(
265
	'module_order' => 'faqbaker,manual,wysiwyg',
266
	'max_excerpt' => '15'
267
);
268
foreach($cfg as $key=>$value) {
269
	db_add_search_key_value($key, $value);
270
}
271

    
272
echo "<br /><u>Adding some internal config-elements to search-table</u><br />";
273
// These are global config-elements which don't appear in settings-page. Change them in the database if needed.
274
// cfg_show_description - whether to show page-description on the results page (true/false), def: true
275
// cfg_search_description - whether to search in page-description (true/false), def: true [only used while searching title/link/description/keywords]
276
// cfg_search_keywords - whether to search in page-keywords (true/false), def: true [only used while searching title/link/description/keywords]
277
// cfg_enable_old_search - use old search-method, too (true/false), def: true [use old method as fallback]
278
$cfg = array(
279
	'cfg_show_description' => 'true',
280
	'cfg_search_description' => 'true',
281
	'cfg_search_keywords' => 'true',
282
	'cfg_enable_old_search' => 'true'
283
);
284
foreach($cfg as $key=>$value) {
285
	db_add_search_key_value($key, $value);
286
}
287

    
288
echo "<br /><u>Changing results_loop in search-table</u><br />";
289
// adding [EXCERPT]
290

    
291
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
292
if($query->numRows() > 0) {
293
	$fetch_results_loop = $query->fetchRow();
294
	$string = $fetch_results_loop['value'];
295
	if(preg_match("/\[EXCERPT\]/", $string)) {
296
		echo "[EXCERPT] is allready there. $OK.<br />";
297
	} else {
298
		$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
299
		$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
300
		$string = addslashes($string);
301
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
302
		echo (mysql_error()?mysql_error().'<br />':'');
303
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
304
		if($query->numRows() > 0) {
305
			$fetch_results_loop = $query->fetchRow();
306
			$string = $fetch_results_loop['value'];
307
			if(preg_match("/\[EXCERPT\]/", $string)) {
308
				echo "[EXCERPT] added. $OK.<br />";
309
			} else {
310
				echo "adding [EXCERPT] $FAIL!<br />";
311
			}
312
		}
313
	}
314
}
315

    
316
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
317
// adding [SEARCH_PATH]
318

    
319
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
320
if($query->numRows() > 0) {
321
	$fetch_header = $query->fetchRow();
322
	$string = $fetch_header['value'];
323
	if(preg_match("/\[SEARCH_PATH\]/", $string)) {
324
		echo "[SEARCH_PATH] is allready there. $OK.<br />";
325
	} else {
326
		$string = preg_replace("/<input type=\"text\" name=\"string\" value=\"\[SEARCH_STRING\]\" style=\"width: 100%;\" \/>/", "<input type=\"hidden\" name=\"search_path\" value=\"[SEARCH_PATH]\" /><input type=\"text\" name=\"string\" value=\"[SEARCH_STRING]\" style=\"width: 100%;\" />", $string);
327
		$string = addslashes($string);
328
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
329
		echo (mysql_error()?mysql_error().'<br />':'');
330
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
331
		if($query->numRows() > 0) {
332
			$fetch_header = $query->fetchRow();
333
			$string = $fetch_header['value'];
334
			if(preg_match("/\[SEARCH_PATH\]/", $string)) {
335
				echo "[SEARCH_PATH] added. $OK.<br />";
336
			} else {
337
				echo "adding [SEARCH_PATH] $FAIL!<br />";
338
			}
339
		}
340
	}
341
}
342

    
343

    
344
/**********************************************************
345
 *  - publish-by-date
346
 */
347
// Add fields "publ_start" and "publ_end" to table "sections"
348
// check if fields are present
349
db_add_field('publ_start', 'sections', "INT NOT NULL DEFAULT '0'");
350
db_add_field('publ_end', 'sections', "INT NOT NULL DEFAULT '0'");
351

    
352

    
353
/**********************************************************
354
 *  - core-module menu_link
355
 */
356
// create table
357
$table = TABLE_PREFIX ."mod_menu_link";
358
$database->query("DROP TABLE IF EXISTS `$table`");
359
$database->query("
360
	CREATE TABLE `$table` (
361
		`section_id` INT(11) NOT NULL DEFAULT '0',
362
		`page_id` INT(11) NOT NULL DEFAULT '0',
363
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
364
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
365
		`extern` VARCHAR(255) NOT NULL DEFAULT '' ,
366
		PRIMARY KEY (`section_id`)
367
	)
368
");
369
// fetch all menu_link-pages in $pages
370
$pages = array();
371
$table_p = TABLE_PREFIX.'pages';
372
$table_s = TABLE_PREFIX.'sections';
373
$table_mm = TABLE_PREFIX ."mod_menu_link";
374

    
375
$query_page = $database->query("SELECT p.*, s.section_id FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module = 'menu_link'");
376
if($query_page->numRows() > 0) {
377
	while($page = $query_page->fetchRow()) {
378
		$pages[$page['page_id']]['page_details'] = $page;
379
	}
380
}
381
if($pages!=array())
382
	echo "<br /><u>Convert menu_links</u><br />";
383

    
384
// get all related files with content from pages/ in $pages, too
385
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
386
	$dh=opendir($dir);
387
	while(($file = readdir($dh)) !== false) {
388
		if($file == '.' || $file == '..') {
389
			continue;
390
		}
391
		if(is_dir($dir.'/'.$file)) {
392
			if($depth) {
393
				$dirs[] = $dir.'/'.$file;
394
				list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
395
			}
396
		} else {
397
			$files[] = $dir.'/'.$file;
398
		}
399
	}
400
	closedir($dh);
401
	natcasesort($files);
402
	natcasesort($dirs);
403
	return(array($files, $dirs));
404
}
405
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
406
foreach($files as $file) {
407
	if(($content = implode('', file($file))) !== FALSE) {
408
		if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
409
			if(array_key_exists($matches[1], $pages)) {
410
				$pages[$matches[1]]['file_content'] = $content;
411
				$pages[$matches[1]]['filename'] = $file;
412
			}
413
		}
414
	}
415
}
416
unset($files); unset($dirs);
417
// try to convert old menu_links to new ones
418
foreach($pages as $p) {
419
	$page = $p['page_details'];
420
	$file_content = $p['file_content'];
421
	$filename = $p['filename'];
422
	$link = $p['page_details']['link'];
423
	$parent_pid = $p['page_details']['parent'];
424
	$page_id = $p['page_details']['page_id'];
425
	$section_id = $p['page_details']['section_id'];
426
	$menu_title = $p['page_details']['menu_title'];
427

    
428
	// calculate link from wb_pages.parent and menu_title
429
	$cur_link = '';
430
	if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
431
		$res = $query_link->fetchRow();
432
		$cur_link .= $res['link'];
433
	}
434
	$cur_link .= '/'.page_filename($menu_title);
435
echo "found: $cur_link<br />";
436
	$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
437
	echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
438
	
439
	$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
440
	$new_filenames[$page_id]['link'] = $cur_link;
441
	$new_filenames[$page_id]['menu'] = $menu_title;
442

    
443
	// delete old access files in pages
444
	if(file_exists($filename)) {
445
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
446
			echo "Cannot delete access file in pages/ - permission denied ($FAIL)<br />";
447
		} else {
448
			unlink($filename);
449
		}
450
	}
451
	
452
	// make entry in wb_mod_menu_link
453
	if($query_pid = $database->query("SELECT page_id FROM $table_p WHERE page_id != '$page_id' AND link = '$link'")) {
454
		$res = $query_pid->fetchRow();
455
		$target_page_id = $res['page_id'];
456
		$extern = '';
457
		if(strpos($link, '://') !== FALSE || strpos($link, 'mailto:') !== FALSE) {
458
			$target_page_id=-1;
459
			$extern=addslashes($link);
460
		}
461
		$database->query("INSERT INTO $table_mm (page_id, section_id, target_page_id, anchor, extern) VALUES ('$page_id', '$section_id', '$target_page_id', '0', '$extern')");
462
		echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
463
	}
464
}
465
// create new access files in pages/; make directories as needed
466
foreach($pages as $p) {
467
	$page_id = $p['page_details']['page_id'];
468
	$filename = $new_filenames[$page_id]['file'];
469
	$menu_title = $new_filenames[$page_id]['menu'];
470
	$link = $new_filenames[$page_id]['link'];
471
	$content = $p['file_content'];
472
	$level = $p['page_details']['level'];
473
	$depth = '';
474
	for($i=0; $i<=$level; $i++)
475
		$depth .= '../';
476
	$content = preg_replace('#((../)+)config\.php#', "{$depth}config.php", $content);
477
	while(file_exists($filename)) {
478
		echo "Cannot create '$filename' - file exist. Renamed to: ";
479
		$menu_title .= '_';
480
		$link .= '_';
481
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
482
		echo "$filename<br />";
483
		$database->query("UPDATE $table_p SET link='$link', menu_title='$menu_title' WHERE page_id = '$page_id'");
484
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
485
	}
486
	// check if we need to create a subdir somewhere
487
	$dirs = array();
488
	while(dirname($link) != '/') {
489
		$link = dirname($link);
490
		$dirs[] = WB_PATH.PAGES_DIRECTORY.$link;
491
	}
492
	foreach(array_reverse($dirs) as $dir) {
493
		if(!file_exists($dir)) {
494
			mkdir($dir, OCTAL_DIR_MODE);
495
		}
496
	}
497
	// create new file in pages/
498
	if($handle=fopen($filename, "wb")) {
499
		if(!fwrite($handle, $content)) {
500
			echo "Cannot write to $filename - ($FAIL)<br />";
501
		}
502
		fclose($handle);
503
	} else {
504
		echo "Cannot create $filename - ($FAIL)<br />";
505
	}
506
	
507
}
508

    
509
// some code missing to regenerate page_title from link/filename
510
// for_all_pages: if filename($page_title) != basename($link) {
511
//   rename $page_title to basename($link)
512
// }
513
// This must be done after menu_link-upgrade
514
// 
515
// Should we really do this? - must be checked
516

    
517

    
518
/**********************************************************
519
 *  - asp - Advanced Spam Protection
520
 */
521
echo "<br /><u>Adding table mod_captcha_control</u><br />";
522
$table = TABLE_PREFIX.'mod_captcha_control';
523
$database->query("DROP TABLE IF EXISTS `$table`");
524
$database->query("CREATE TABLE `$table` (
525
	`enabled_captcha` VARCHAR(1) NOT NULL DEFAULT '1',
526
	`enabled_asp` VARCHAR(1) NOT NULL DEFAULT '1',
527
	`captcha_type` VARCHAR(255) NOT NULL DEFAULT 'calc_text',
528
	`asp_session_min_age` INT(11) NOT NULL DEFAULT '20',
529
	`asp_view_min_age` INT(11) NOT NULL DEFAULT '10',
530
	`asp_input_min_age` INT(11) NOT NULL DEFAULT '5',
531
	`ct_text` LONGTEXT NOT NULL DEFAULT ''
532
	)"
533
);
534
$database->query("
535
	INSERT INTO `$table`
536
		(`enabled_captcha`, `enabled_asp`, `captcha_type`)
537
	VALUES
538
		('1', '1', 'calc_text')
539
");
540

    
541

    
542
/**********************************************************
543
 *  - multi-group
544
 */
545
db_add_field('groups_id', 'users', "VARCHAR( 255 ) NOT NULL DEFAULT '0' AFTER group_id");
546
$table = TABLE_PREFIX.'users';
547
if($query_group = $database->query("SELECT user_id,group_id,groups_id FROM $table")) {
548
	while($group = $query_group->fetchRow()) {
549
		if($group['groups_id'] == '0') {
550
			if($database->query("UPDATE $table SET groups_id = group_id WHERE user_id = {$group['user_id']}")) {
551
				echo 'groups_id updated successfully<br>';
552
			}
553
			echo mysql_error().'<br />';
554
		}
555
	}
556
}
557

    
558

    
559
/**********************************************************
560
 *  -Javascript Admin
561
 */
562
echo "<br /><u>Adding table mod_jsadmin</u><br />";
563
$table = TABLE_PREFIX ."mod_jsadmin";
564
$database->query("DROP TABLE IF EXISTS `$table`");
565

    
566
$database->query("
567
	CREATE TABLE `$table` (
568
    `id` INT(11) NOT NULL DEFAULT '0',
569
		`name` VARCHAR(255) NOT NULL DEFAULT '0',
570
		`value` INT(11) NOT NULL DEFAULT '0',
571
   	PRIMARY KEY (`id`)
572
	)
573
");
574

    
575
global $database;
576
echo "Insert default value for mod_jsadmin_persist_order: ";
577
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('1','mod_jsadmin_persist_order','0')")) ? " $OK<br />" : " $FAIL<br />"; 
578
echo "Insert default value for mod_jsadmin_ajax_order_pages: ";
579
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('2','mod_jsadmin_ajax_order_pages','0')")) ? " $OK<br />" : " $FAIL<br />"; 
580
echo "Insert default value for mod_jsadmin_ajax_order_sections: ";
581
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('3','mod_jsadmin_ajax_order_sections','0')")) ? " $OK<br />" : " $FAIL<br />"; 
582

    
583
/**********************************************************
584
 *  - Output Filter
585
 */
586
echo "<br /><u>Adding table mod_outputfilter</u><br />Status: ";
587
$table = TABLE_PREFIX .'mod_output_filter';
588
$database->query("DROP TABLE IF EXISTS `$table`");
589

    
590
$database->query("CREATE TABLE `$table` (
591
	`email_filter` VARCHAR(1) NOT NULL DEFAULT '0',
592
	`mailto_filter` VARCHAR(1) NOT NULL DEFAULT '0',
593
	`at_replacement` VARCHAR(255) NOT NULL DEFAULT '(at)',
594
	`dot_replacement` VARCHAR(255) NOT NULL DEFAULT '(dot)'
595
	)"
596
);
597

    
598
// add default values to the module table
599
echo ($database->query("INSERT INTO ".TABLE_PREFIX
600
	."mod_output_filter (email_filter, mailto_filter, at_replacement, dot_replacement) VALUES ('0', '0', '(at)', '(dot)')")) ? " $OK<br />" : " $FAIL<br />"; 
601
	
602

    
603
/**********************************************************
604
 *  - Form Modul
605
 */
606
echo '<br />';
607
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
608
echo '<br />';
609
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
610
echo '<br />';
611
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
612
echo '<br />';
613
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
614
echo '<br />';
615
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
616
echo '<br />';
617
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
618
echo '<br />';
619
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
620

    
621
echo "<br /><b>Deleting field success_message from table mod_form_settings</b><br />";
622

    
623
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
624
	echo 'Database field success_message droped successfully<br>';
625
}
626
echo mysql_error().'<br />';
627

    
628
// These are the default setting
629
$success_page = 'none';
630
$success_email_to = '';
631
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
632
$success_email_text = addslashes($success_email_text);
633
$success_email_subject = 'You have submitted a form';
634

    
635
// Insert default settings into database
636
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
637
while($result = $query_dates->fetchRow()) {
638
	
639
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
640
	$section_id = $result['section_id'];
641

    
642
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
643
		echo 'Database data success_page added successfully<br>';
644
	}
645
	echo mysql_error().'<br />';
646
	
647
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
648
		echo 'Database data success_email_to added successfully<br>';
649
	}
650
	echo mysql_error().'<br />';
651
	
652
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
653
		echo 'Database data success_email_text added successfully<br>';
654
	}
655
	echo mysql_error().'<br />';
656
	
657
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
658
		echo 'Database data success_email_subject added successfully<br>';
659
	}
660
	echo mysql_error().'<br />';
661
	
662
}
663

    
664
// copy field email_to to success_email_from
665
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
666
while($result = $query_dates->fetchRow()) {
667
	
668
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
669
	$section_id = $result['section_id'];
670

    
671
	$success_email_from = $result['email_to'];
672
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
673
		echo 'Copyied field email_to to success_email_from successfully<br>';
674
	}
675
	echo mysql_error().'<br />';
676
}
677

    
678

    
679
/**********************************************************
680
 *  - News Modul
681
 */
682
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
683
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
684

    
685
// These are the default setting
686
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
687
$post_loop = '<tr class=\"post_top\">
688
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
689
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
690
</tr>
691
<tr>
692
<td class=\"post_short\" colspan=\"2\">
693
[SHORT] 
694
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
695
</td>
696
</tr>';
697
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
698
<tr>
699
<td height="30"><h1>[TITLE]</h1></td>
700
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
701
</tr>
702
<tr>
703
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
704
</tr>
705
<tr style="display: [DISPLAY_GROUP]">
706
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
707
</tr>
708
</table>
709
<p style="text-align: justify;">');
710
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
711
<a href=\"[BACK]\">Back</a>';
712
$comments_header = addslashes('<br /><br />
713
<h2>Comments</h2>
714
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
715

    
716
// Insert default settings into database
717
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
718
while($result = $query_dates->fetchRow()) {
719
	
720
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
721
	$section_id = $result['section_id'];
722

    
723
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
724
		echo 'Database data header added successfully<br>';
725
	}
726
	echo mysql_error().'<br />';
727
	
728
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
729
		echo 'Database data post_loop added successfully<br>';
730
	}
731
	echo mysql_error().'<br />';
732
	
733
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
734
		echo 'Database data post_header added successfully<br>';
735
	}
736
	echo mysql_error().'<br />';
737
	
738
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
739
		echo 'Database data post_footer added successfully<br>';
740
	}
741
	echo mysql_error().'<br />';
742
	
743
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
744
		echo 'Database data comments_header added successfully<br>';
745
	}
746
	echo mysql_error().'<br />';
747

    
748
}
749

    
750
// MIGRATING FIELD DATES to POSTED_WHEN
751
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
752
if($query_dates->numRows() > 0) {
753
	echo "<B>Copying field posted_when value to published_when</B><BR>";
754
}
755
while($result = $query_dates->fetchRow()) {
756
	$pid = $result['post_id'];
757
	$NEW_DATE = $result['posted_when'];
758
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
759
		echo 'Copying posted_when value to published_when successfully<br>';
760
	}
761
	echo mysql_error().'<br />';
762
}
763

    
764
/**********************************************************
765
 *  - Alter the WYSIWYG editor content from text to longtext
766
 */
767
echo "<br /><u>Alter WYSIWYG editor content field from text to longtext</u><br />Status: ";
768
echo ($database->query("ALTER TABLE ".TABLE_PREFIX."mod_wysiwyg MODIFY content LONGTEXT NOT NULL")) ?" $OK<br />" : " $FAIL<br />";
769

    
770
/**********************************************************
771
 *  - Add Admintools to Administrator group
772
 */
773
echo "<br /><u>Add Admintools to Adminsitrator group</u><br />Status: ";
774
$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
775
echo ($database->query("UPDATE `".TABLE_PREFIX."groups` SET `system_permissions` = '$full_system_permissions' WHERE `name` = 'Administrators'")) ? " $OK<br />" : " $FAIL<br />";
776

    
777
/**********************************************************
778
 *  - Add Mailer Settings to settings table
779
 */
780
echo "<br /><u>Add Mailer Settings to settings table</u><br />Status: ";
781
//delete rows to prevent double entries
782
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_routine'");
783
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'server_email'");
784
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_default_sendername'");
785
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_host'");
786
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_auth'");
787
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_username'");
788
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_password'");
789
//add new rows with default values
790
$wbmailer_smtp_host = (defined('WBMAILER_SMTP_HOST')) ? WBMAILER_SMTP_HOST : '';
791
$wbmailer_routine = ($wbmailer_smtp_host = '') ? 'phpmail' : 'smtp';
792
$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
793
." (name, value) VALUES "
794
." ('wbmailer_routine', '$wbmailer_routine'),"
795
." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
796
." ('wbmailer_default_sendername', 'WB Mailer'),"
797
." ('wbmailer_smtp_host', '$wbmailer_smtp_host'),"
798
." ('wbmailer_smtp_auth', ''),"
799
." ('wbmailer_smtp_username', ''),"
800
." ('wbmailer_smtp_password', '')";
801
echo ($database->query($settings_rows)) ? " $OK<br />" : " $FAIL<br />";
802

    
803
/**********************************************************
804
 *  - Set Version to WB 2.7
805
 */
806
echo "<br /><u>Update database version number to 2.7</u><br />Status: ";
807
$version = '2.7';
808
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
809

    
810
/**********************************************************
811
 *  - Reload all addons
812
 */
813

    
814
//delete modules
815
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
816
// Load all modules
817
if($handle = opendir(WB_PATH.'/modules/')) {
818
	while(false !== ($file = readdir($handle))) {
819
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
820
			load_module(WB_PATH.'/modules/'.$file);
821
		}
822
	}
823
	closedir($handle);
824
}
825
echo '<br />Modules reloaded<br />';
826

    
827
//delete templates		
828
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
829
// Load all templates
830
if($handle = opendir(WB_PATH.'/templates/')) {
831
	while(false !== ($file = readdir($handle))) {
832
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
833
			load_template(WB_PATH.'/templates/'.$file);
834
		}
835
	}
836
	closedir($handle);
837
}
838
echo '<br />Templates reloaded<br />';
839

    
840
//delete languages
841
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
842
// Load all languages
843
if($handle = opendir(WB_PATH.'/languages/')) {
844
	while(false !== ($file = readdir($handle))) {
845
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
846
			load_language(WB_PATH.'/languages/'.$file);
847
		}
848
	}
849
	closedir($handle);
850
}
851
echo '<br />Languages reloaded<br />';
852

    
853
/**********************************************************
854
 *  - End of upgrade script
855
 */
856
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
857
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.<br />If you do not delete this script from your server, others can delete/overwritte database settings by executing this script again.', 'warning', 'div');
858
// show buttons to go to the backend or frontend
859
echo '<br />';
860
if(defined('WB_URL')) {
861
	echo '<form action="'.WB_URL.'" target="_self">';
862
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;"';
863
	echo '</form>';
864
}
865
if(defined('ADMIN_URL')) {
866
	echo '<form action="'.ADMIN_URL.'" target="_self">';
867
	echo '&nbsp;<input type="submit" value="kick me to the Backend"';
868
	echo '</form>';
869
}
870
echo '<p>&nbsp;</p>';
871
}
872
?>
873
</div>
874
</body>
875
</html>
(4-4/4)