Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 720 2008-02-20 21:03:17Z 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
	$group_id = '';
76
	status_msg(', Database connection: ');
77
	if(class_exists('database')) {
78
		$db = new database;
79
		$table = TABLE_PREFIX .'groups';
80
		$group_id = @$db->get_one("SELECT group_id FROM $table WHERE group_id = '1' LIMIT 1");
81
	}
82
	if($group_id == '1') {
83
		status_msg('OK', 'ok');
84
	} else {
85
		// output error message and return error status
86
		status_msg('FAILED', 'error');
87
		status_msg('<strong>Error:</strong><br />Unable to connect to your existing Website Baker database.'
88
			.'<br />Make sure that the database class is available and the connection data in the config.php file is correct '
89
			.'and your database is not corrupt.<br />To check if your database is corrupt, you can use a tool like '
90
			.'<a href="http://www.phpmyadmin.net/" target="_blank">phpMyAdmin</a>.'
91
			.'<br /><br />You can not proceed before this error is fixed!!!'
92
			, 'warning', 'div');
93
		return -1;
94
	}
95
	return 0;
96
}
97

    
98
?>
99

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

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

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

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

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

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

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

    
159
<h1>Website Baker Upgrade</h1>
160
<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>
161

    
162
<?php
163
if(!isset($_POST['backup_confirmed'])) { 
164
?>
165
<h2>Step 1: Check existing installation</h2>
166
<p>Checking the configuration of your existing Website Baker installation:<br />
167
<?php
168
// check the basic Website Baker installation before proceeding
169
if(check_baseline_configuration() != 0) die;
170
status_msg('<p>Congratulations: You have passed all the required pre-checks.', 'ok');
171
?>
172

    
173
<h2>Step 2: Create a backup of your existing data</h2>
174
<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>
175

    
176
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
177
<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>
178
<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.
179
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
180
</form>
181
<br />
182

    
183
<?php
184
if(isset($_POST['send'])) {
185
	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');
186
} 
187
?>
188
<br /><br />
189
<?php
190
} else {
191
/**
192
	THE WEBSITE BAKER UPGRADE SCRIPT STARTS HERE
193
**/
194
require_once('config.php');
195
require_once(WB_PATH.'/framework/functions.php');
196
?>
197
<h2>Step 3: Upgrading the existing Website Baker installation to WB 2.7</h2>
198
<p>will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7</p>
199
<?php
200

    
201
$OK   = '<span class="ok">OK</span>';
202
$FAIL = '<span class="error">FAILED</span>';
203

    
204

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

    
248
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
249
// module_order - in which order to show the search-results
250
// max_excerpt - how many lines of excerpt to print per matching page
251

    
252
$cfg = array(
253
	'module_order' => 'faqbaker,manual,wysiwyg',
254
	'max_excerpt' => '15'
255
);
256
foreach($cfg as $key=>$value) {
257
	db_add_search_key_value($key, $value);
258
}
259

    
260
echo "<br /><u>Adding some internal config-elements to search-table</u><br />";
261
// These are global config-elements which don't appear in settings-page. Change them in the database if needed.
262
// cfg_show_description - whether to show page-description on the results page (true/false), def: true
263
// cfg_search_description - whether to search in page-description (true/false), def: true [only used while searching title/link/description/keywords]
264
// cfg_search_keywords - whether to search in page-keywords (true/false), def: true [only used while searching title/link/description/keywords]
265
// cfg_enable_old_search - use old search-method, too (true/false), def: true [use old method as fallback]
266
$cfg = array(
267
	'cfg_show_description' => 'true',
268
	'cfg_search_description' => 'true',
269
	'cfg_search_keywords' => 'true',
270
	'cfg_enable_old_search' => 'true'
271
);
272
foreach($cfg as $key=>$value) {
273
	db_add_search_key_value($key, $value);
274
}
275

    
276
echo "<br /><u>Changing results_loop in search-table</u><br />";
277
// adding [EXCERPT]
278

    
279
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
280
if($query->numRows() > 0) {
281
	$fetch_results_loop = $query->fetchRow();
282
	$string = $fetch_results_loop['value'];
283
	if(preg_match("/\[EXCERPT\]/", $string)) {
284
		echo "[EXCERPT] is allready there. $OK.<br />";
285
	} else {
286
		$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
287
		$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
288
		$string = addslashes($string);
289
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
290
		echo (mysql_error()?mysql_error().'<br />':'');
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] added. $OK.<br />";
297
			} else {
298
				echo "adding [EXCERPT] $FAIL!<br />";
299
			}
300
		}
301
	}
302
}
303

    
304
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
305
// adding [SEARCH_PATH]
306

    
307
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
308
if($query->numRows() > 0) {
309
	$fetch_header = $query->fetchRow();
310
	$string = $fetch_header['value'];
311
	if(preg_match("/\[SEARCH_PATH\]/", $string)) {
312
		echo "[SEARCH_PATH] is allready there. $OK.<br />";
313
	} else {
314
		$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);
315
		$string = addslashes($string);
316
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
317
		echo (mysql_error()?mysql_error().'<br />':'');
318
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
319
		if($query->numRows() > 0) {
320
			$fetch_header = $query->fetchRow();
321
			$string = $fetch_header['value'];
322
			if(preg_match("/\[SEARCH_PATH\]/", $string)) {
323
				echo "[SEARCH_PATH] added. $OK.<br />";
324
			} else {
325
				echo "adding [SEARCH_PATH] $FAIL!<br />";
326
			}
327
		}
328
	}
329
}
330

    
331

    
332
/**********************************************************
333
 *  - publish-by-date
334
 */
335
// Add fields "publ_start" and "publ_end" to table "sections"
336
// check if fields are present
337
db_add_field('publ_start', 'sections', "INT NOT NULL DEFAULT '0'");
338
db_add_field('publ_end', 'sections', "INT NOT NULL DEFAULT '0'");
339

    
340

    
341
/**********************************************************
342
 *  - core-module menu_link
343
 */
344
// create table
345
$table = TABLE_PREFIX ."mod_menu_link";
346
$database->query("DROP TABLE IF EXISTS `$table`");
347
$database->query("
348
	CREATE TABLE `$table` (
349
		`section_id` INT(11) NOT NULL DEFAULT '0',
350
		`page_id` INT(11) NOT NULL DEFAULT '0',
351
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
352
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
353
		`extern` VARCHAR(255) NOT NULL DEFAULT '' ,
354
		PRIMARY KEY (`section_id`)
355
	)
356
");
357
// fetch all menu_link-pages in $pages
358
$pages = array();
359
$table_p = TABLE_PREFIX.'pages';
360
$table_s = TABLE_PREFIX.'sections';
361
$table_mm = TABLE_PREFIX ."mod_menu_link";
362

    
363
$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'");
364
if($query_page->numRows() > 0) {
365
	while($page = $query_page->fetchRow()) {
366
		$pages[$page['page_id']]['page_details'] = $page;
367
	}
368
}
369
if($pages!=array())
370
	echo "<br /><u>Convert menu_links</u><br />";
371

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

    
416
	// calculate link from wb_pages.parent and menu_title
417
	$cur_link = '';
418
	if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
419
		$res = $query_link->fetchRow();
420
		$cur_link .= $res['link'];
421
	}
422
	$cur_link .= '/'.page_filename($menu_title);
423
echo "found: $cur_link<br />";
424
	$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
425
	echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
426
	
427
	$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
428
	$new_filenames[$page_id]['link'] = $cur_link;
429
	$new_filenames[$page_id]['menu'] = $menu_title;
430

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

    
497
// some code missing to regenerate page_title from link/filename
498
// for_all_pages: if filename($page_title) != basename($link) {
499
//   rename $page_title to basename($link)
500
// }
501
// This must be done after menu_link-upgrade
502
// 
503
// Should we really do this? - must be checked
504

    
505

    
506
/**********************************************************
507
 *  - asp - Advanced Spam Protection
508
 */
509
echo "<br /><u>Adding table mod_captcha_control</u><br />";
510
$table = TABLE_PREFIX.'mod_captcha_control';
511
$database->query("DROP TABLE IF EXISTS `$table`");
512
$database->query("CREATE TABLE `$table` (
513
	`enabled_captcha` VARCHAR(1) NOT NULL DEFAULT '1',
514
	`enabled_asp` VARCHAR(1) NOT NULL DEFAULT '1',
515
	`captcha_type` VARCHAR(255) NOT NULL DEFAULT 'calc_text',
516
	`asp_session_min_age` INT(11) NOT NULL DEFAULT '20',
517
	`asp_view_min_age` INT(11) NOT NULL DEFAULT '10',
518
	`asp_input_min_age` INT(11) NOT NULL DEFAULT '5',
519
	`ct_text` LONGTEXT NOT NULL DEFAULT ''
520
	)"
521
);
522
$database->query("
523
	INSERT INTO `$table`
524
		(`enabled_captcha`, `enabled_asp`, `captcha_type`)
525
	VALUES
526
		('1', '1', 'calc_text')
527
");
528

    
529

    
530
/**********************************************************
531
 *  - multi-group
532
 */
533
db_add_field('groups_id', 'users', "VARCHAR( 255 ) NOT NULL DEFAULT '0' AFTER group_id");
534
$table = TABLE_PREFIX.'users';
535
if($query_group = $database->query("SELECT user_id,group_id,groups_id FROM $table")) {
536
	while($group = $query_group->fetchRow()) {
537
		if($group['groups_id'] == '0') {
538
			if($database->query("UPDATE $table SET groups_id = group_id WHERE user_id = {$group['user_id']}")) {
539
				echo 'groups_id updated successfully<br>';
540
			}
541
			echo mysql_error().'<br />';
542
		}
543
	}
544
}
545

    
546

    
547
/**********************************************************
548
 *  -Javascript Admin
549
 */
550
echo "<br /><u>Adding table mod_jsadmin</u><br />";
551
$table = TABLE_PREFIX ."mod_jsadmin";
552
$database->query("DROP TABLE IF EXISTS `$table`");
553

    
554
$database->query("
555
	CREATE TABLE `$table` (
556
    `id` INT(11) NOT NULL DEFAULT '0',
557
		`name` VARCHAR(255) NOT NULL DEFAULT '0',
558
		`value` INT(11) NOT NULL DEFAULT '0',
559
   	PRIMARY KEY (`id`)
560
	)
561
");
562

    
563
global $database;
564
echo "Insert default value for mod_jsadmin_persist_order: ";
565
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('1','mod_jsadmin_persist_order','0')")) ? " $OK<br />" : " $FAIL<br />"; 
566
echo "Insert default value for mod_jsadmin_ajax_order_pages: ";
567
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('2','mod_jsadmin_ajax_order_pages','0')")) ? " $OK<br />" : " $FAIL<br />"; 
568
echo "Insert default value for mod_jsadmin_ajax_order_sections: ";
569
echo ($database->query("INSERT INTO ".$table." (id,name,value) VALUES ('3','mod_jsadmin_ajax_order_sections','0')")) ? " $OK<br />" : " $FAIL<br />"; 
570

    
571
/**********************************************************
572
 *  - Output Filter
573
 */
574
echo "<br /><u>Adding table mod_outputfilter</u><br />Status: ";
575
$table = TABLE_PREFIX .'mod_output_filter';
576
$database->query("DROP TABLE IF EXISTS `$table`");
577

    
578
$database->query("CREATE TABLE `$table` (
579
	`email_filter` VARCHAR(1) NOT NULL DEFAULT '0',
580
	`mailto_filter` VARCHAR(1) NOT NULL DEFAULT '0',
581
	`at_replacement` VARCHAR(255) NOT NULL DEFAULT '(at)',
582
	`dot_replacement` VARCHAR(255) NOT NULL DEFAULT '(dot)'
583
	)"
584
);
585

    
586
// add default values to the module table
587
echo ($database->query("INSERT INTO ".TABLE_PREFIX
588
	."mod_output_filter (email_filter, mailto_filter, at_replacement, dot_replacement) VALUES ('0', '0', '(at)', '(dot)')")) ? " $OK<br />" : " $FAIL<br />"; 
589
	
590

    
591
/**********************************************************
592
 *  - Form Modul
593
 */
594
echo '<br />';
595
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
596
echo '<br />';
597
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
598
echo '<br />';
599
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
600
echo '<br />';
601
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
602
echo '<br />';
603
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
604
echo '<br />';
605
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
606
echo '<br />';
607
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
608

    
609
echo "<br /><b>Deleting field success_message from table mod_form_settings</b><br />";
610

    
611
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
612
	echo 'Database field success_message droped successfully<br>';
613
}
614
echo mysql_error().'<br />';
615

    
616
// These are the default setting
617
$success_page = 'none';
618
$success_email_to = '';
619
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
620
$success_email_text = addslashes($success_email_text);
621
$success_email_subject = 'You have submitted a form';
622

    
623
// Insert default settings into database
624
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
625
while($result = $query_dates->fetchRow()) {
626
	
627
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
628
	$section_id = $result['section_id'];
629

    
630
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
631
		echo 'Database data success_page added successfully<br>';
632
	}
633
	echo mysql_error().'<br />';
634
	
635
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
636
		echo 'Database data success_email_to added successfully<br>';
637
	}
638
	echo mysql_error().'<br />';
639
	
640
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
641
		echo 'Database data success_email_text added successfully<br>';
642
	}
643
	echo mysql_error().'<br />';
644
	
645
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
646
		echo 'Database data success_email_subject added successfully<br>';
647
	}
648
	echo mysql_error().'<br />';
649
	
650
}
651

    
652
// copy field email_to to success_email_from
653
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
654
while($result = $query_dates->fetchRow()) {
655
	
656
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
657
	$section_id = $result['section_id'];
658

    
659
	$success_email_from = $result['email_to'];
660
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
661
		echo 'Copyied field email_to to success_email_from successfully<br>';
662
	}
663
	echo mysql_error().'<br />';
664
}
665

    
666

    
667
/**********************************************************
668
 *  - News Modul
669
 */
670
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
671
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
672

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

    
704
// Insert default settings into database
705
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
706
while($result = $query_dates->fetchRow()) {
707
	
708
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
709
	$section_id = $result['section_id'];
710

    
711
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
712
		echo 'Database data header added successfully<br>';
713
	}
714
	echo mysql_error().'<br />';
715
	
716
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
717
		echo 'Database data post_loop added successfully<br>';
718
	}
719
	echo mysql_error().'<br />';
720
	
721
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
722
		echo 'Database data post_header added successfully<br>';
723
	}
724
	echo mysql_error().'<br />';
725
	
726
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
727
		echo 'Database data post_footer added successfully<br>';
728
	}
729
	echo mysql_error().'<br />';
730
	
731
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
732
		echo 'Database data comments_header added successfully<br>';
733
	}
734
	echo mysql_error().'<br />';
735

    
736
}
737

    
738
// MIGRATING FIELD DATES to POSTED_WHEN
739
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
740
if($query_dates->numRows() > 0) {
741
	echo "<B>Copying field posted_when value to published_when</B><BR>";
742
}
743
while($result = $query_dates->fetchRow()) {
744
	$pid = $result['post_id'];
745
	$NEW_DATE = $result['posted_when'];
746
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
747
		echo 'Copying posted_when value to published_when successfully<br>';
748
	}
749
	echo mysql_error().'<br />';
750
}
751

    
752
/**********************************************************
753
 *  - Alter the WYSIWYG editor content from text to longtext
754
 */
755
echo "<br /><u>Alter WYSIWYG editor content field from text to longtext</u><br />Status: ";
756
echo ($database->query("ALTER TABLE ".TABLE_PREFIX."mod_wysiwyg MODIFY content LONGTEXT NOT NULL")) ?" $OK<br />" : " $FAIL<br />";
757

    
758
/**********************************************************
759
 *  - Add Admintools to Administrator group
760
 */
761
echo "<br /><u>Add Admintools to Adminsitrator group</u><br />Status: ";
762
$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';
763
echo ($database->query("UPDATE `".TABLE_PREFIX."groups` SET `system_permissions` = '$full_system_permissions' WHERE `name` = 'Administrators'")) ? " $OK<br />" : " $FAIL<br />";
764

    
765
/**********************************************************
766
 *  - Add Mailer Settings to settings table
767
 */
768
echo "<br /><u>Add Mailer Settings to settings table</u><br />Status: ";
769
//delete rows to prevent double entries
770
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_routine'");
771
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'server_email'");
772
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_default_sendername'");
773
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_host'");
774
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_auth'");
775
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_username'");
776
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_password'");
777
//add new rows with default values
778
$wbmailer_smtp_host = (defined('WBMAILER_SMTP_HOST')) ? WBMAILER_SMTP_HOST : '';
779
$wbmailer_routine = ($wbmailer_smtp_host = '') ? 'phpmail' : 'smtp';
780
$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
781
." (name, value) VALUES "
782
." ('wbmailer_routine', '$wbmailer_routine'),"
783
." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
784
." ('wbmailer_default_sendername', 'WB Mailer'),"
785
." ('wbmailer_smtp_host', '$wbmailer_smtp_host'),"
786
." ('wbmailer_smtp_auth', ''),"
787
." ('wbmailer_smtp_username', ''),"
788
." ('wbmailer_smtp_password', '')";
789
echo ($database->query($settings_rows)) ? " $OK<br />" : " $FAIL<br />";
790

    
791
/**********************************************************
792
 *  - Set Version to WB 2.7
793
 */
794
echo "<br /><u>Update database version number to 2.7</u><br />Status: ";
795
$version = '2.7';
796
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
797

    
798
/**********************************************************
799
 *  - Reload all addons
800
 */
801

    
802
//delete modules
803
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
804
// Load all modules
805
if($handle = opendir(WB_PATH.'/modules/')) {
806
	while(false !== ($file = readdir($handle))) {
807
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
808
			load_module(WB_PATH.'/modules/'.$file);
809
		}
810
	}
811
	closedir($handle);
812
}
813
echo '<br />Modules reloaded<br />';
814

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

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

    
841
/**********************************************************
842
 *  - End of upgrade script
843
 */
844
echo "<p><strong>Upgrade script finished </strong></p><br />";
845

    
846
}
847
?>
848
</div>
849
</body>
850
</html>
(4-4/4)