Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 714 2008-02-19 21:33:30Z Ruebenwurzel $
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
// upgrade-script for Website Baker from version 2.6.7 to 2.7
28
//
29

    
30
require('config.php');
31
require(WB_PATH.'/framework/functions.php');
32

    
33
?>
34

    
35
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
37
<head>
38
<title>Upgrade-Script</title>
39
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
40

    
41
<style type="text/css">
42
.red { background-color:#FF0000 }
43
.green { background-color:#00FF00 }
44

    
45
#warning {
46
width: 90%; 
47
padding: 10px; 
48
margin-left: 5%; 
49
margin-bottom: 5px; 
50
border: 1px solid #FF0000; 
51
background-color: #FFDBDB;
52
}
53

    
54
p { line-height:1.5em; }
55

    
56
</style>
57
</head>
58
<body>
59
<?php
60
/**
61
	AT THIS POINT IN TIME THE UPGRADE SCRIPT IS NOT MATURE ENOUGH
62
	SO PROVIDE A WARNING TO BACKUP THE DATABASE AND THE PAGES DIRECTORY
63
	BEFORE EXECUTING THIS SCRIPT (doc)
64
*/
65
if(!isset($_GET['action']) || $_GET['action'] != 'upgrade') {
66
?>
67
<div id="warning">
68
<strong>WARNING:</strong>
69
<p>The actual WB 2.7 version is still a developer version. <strong>It is not recommended to use this release in a
70
productive environment</strong>.<p>The upgrade-script is not sufficiently tested yet, so please <strong>backup your database and /pages directory before executing the upgrade script</strong>.<br />You may loose all your data if something goes wrong!!</p><p>If you want to start the upgrade-script, please click on: <a href="upgrade-script.php?action=upgrade" target="_self">execute upgrade-script</a></p>
71
</div>
72
<?php
73
die;
74
} ?>
75
	
76
<h2>Upgrade-script</h2>
77
<p>
78
will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7
79
</p>
80
<?php
81

    
82
$OK   = '<span class="green">OK</span>';
83
$FAIL = '<span class="red">failed</span>';
84

    
85

    
86
/**********************************************************
87
 *  - modules-based search
88
 */
89
function db_add_search_key_value($key, $value) {
90
	global $database; global $OK; global $FAIL;
91
	$table = TABLE_PREFIX.'search';
92
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
93
	if($query->numRows() > 0) {
94
		echo "$key: allready there. $OK.<br />";
95
		return true;
96
	} else {
97
		$database->query("INSERT INTO $table (name,value,extra) VALUES ('$key', '$value', '')");
98
		echo (mysql_error()?mysql_error().'<br />':'');
99
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
100
		if($query->numRows() > 0) {
101
			echo "$key: $OK.<br />";
102
			return true;
103
		} else {
104
			echo "$key: $FAIL!<br />";
105
			return false;
106
		}
107
	}
108
}
109
function db_add_field($field, $table, $desc) {
110
	global $database; global $OK; global $FAIL;
111
	echo "<u>Adding field '$field' to table '$table'</u><br />";
112
	$table = TABLE_PREFIX.$table;
113
	$query = $database->query("DESCRIBE $table '$field'");
114
	if($query->numRows() == 0) { // add field
115
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
116
		echo (mysql_error()?mysql_error().'<br />':'');
117
		$query = $database->query("DESCRIBE $table '$field'");
118
		echo (mysql_error()?mysql_error().'<br />':'');
119
		if($query->numRows() > 0) {
120
			echo "'$field' added. $OK.<br />";
121
		} else {
122
			echo "adding '$field' $FAIL!<br />";
123
		}
124
	} else {
125
		echo "'$field' allready there. $OK.<br />";
126
	}
127
}
128

    
129

    
130
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
131
// module_order - in which order to show the search-results
132
// max_excerpt - how many lines of excerpt to print per matching page
133

    
134
$cfg = array(
135
	'module_order' => 'faqbaker,manual,wysiwyg',
136
	'max_excerpt' => '15'
137
);
138
foreach($cfg as $key=>$value) {
139
	db_add_search_key_value($key, $value);
140
}
141

    
142
echo "<br /><u>Adding some internal config-elements to search-table</u><br />";
143
// These are global config-elements which don't appear in settings-page. Change them in the database if needed.
144
// cfg_show_description - whether to show page-description on the results page (true/false), def: true
145
// cfg_search_description - whether to search in page-description (true/false), def: true [only used while searching title/link/description/keywords]
146
// cfg_search_keywords - whether to search in page-keywords (true/false), def: true [only used while searching title/link/description/keywords]
147
// cfg_enable_old_search - use old search-method, too (true/false), def: true [use old method as fallback]
148
$cfg = array(
149
	'cfg_show_description' => 'true',
150
	'cfg_search_description' => 'true',
151
	'cfg_search_keywords' => 'true',
152
	'cfg_enable_old_search' => 'true'
153
);
154
foreach($cfg as $key=>$value) {
155
	db_add_search_key_value($key, $value);
156
}
157

    
158
echo "<br /><u>Changing results_loop in search-table</u><br />";
159
// adding [EXCERPT]
160

    
161
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
162
if($query->numRows() > 0) {
163
	$fetch_results_loop = $query->fetchRow();
164
	$string = $fetch_results_loop['value'];
165
	if(preg_match("/\[EXCERPT\]/", $string)) {
166
		echo "[EXCERPT] is allready there. $OK.<br />";
167
	} else {
168
		$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
169
		$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
170
		$string = addslashes($string);
171
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
172
		echo (mysql_error()?mysql_error().'<br />':'');
173
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
174
		if($query->numRows() > 0) {
175
			$fetch_results_loop = $query->fetchRow();
176
			$string = $fetch_results_loop['value'];
177
			if(preg_match("/\[EXCERPT\]/", $string)) {
178
				echo "[EXCERPT] added. $OK.<br />";
179
			} else {
180
				echo "adding [EXCERPT] $FAIL!<br />";
181
			}
182
		}
183
	}
184
}
185

    
186
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
187
// adding [SEARCH_PATH]
188

    
189
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
190
if($query->numRows() > 0) {
191
	$fetch_header = $query->fetchRow();
192
	$string = $fetch_header['value'];
193
	if(preg_match("/\[SEARCH_PATH\]/", $string)) {
194
		echo "[SEARCH_PATH] is allready there. $OK.<br />";
195
	} else {
196
		$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);
197
		$string = addslashes($string);
198
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
199
		echo (mysql_error()?mysql_error().'<br />':'');
200
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
201
		if($query->numRows() > 0) {
202
			$fetch_header = $query->fetchRow();
203
			$string = $fetch_header['value'];
204
			if(preg_match("/\[SEARCH_PATH\]/", $string)) {
205
				echo "[SEARCH_PATH] added. $OK.<br />";
206
			} else {
207
				echo "adding [SEARCH_PATH] $FAIL!<br />";
208
			}
209
		}
210
	}
211
}
212

    
213

    
214
/**********************************************************
215
 *  - publish-by-date
216
 */
217
// Add fields "publ_start" and "publ_end" to table "sections"
218
// check if fields are present
219
db_add_field('publ_start', 'sections', "INT NOT NULL DEFAULT '0'");
220
db_add_field('publ_end', 'sections', "INT NOT NULL DEFAULT '0'");
221

    
222

    
223
/**********************************************************
224
 *  - core-module menu_link
225
 */
226
// create table
227
$table = TABLE_PREFIX ."mod_menu_link";
228
$database->query("DROP TABLE IF EXISTS `$table`");
229
$database->query("
230
	CREATE TABLE `$table` (
231
		`section_id` INT(11) NOT NULL DEFAULT '0',
232
		`page_id` INT(11) NOT NULL DEFAULT '0',
233
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
234
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
235
		`extern` VARCHAR(255) NOT NULL DEFAULT '' ,
236
		PRIMARY KEY (`section_id`)
237
	)
238
");
239
// fetch all menu_link-pages in $pages
240
$pages = array();
241
$table_p = TABLE_PREFIX.'pages';
242
$table_s = TABLE_PREFIX.'sections';
243
$table_mm = TABLE_PREFIX ."mod_menu_link";
244

    
245
$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'");
246
if($query_page->numRows() > 0) {
247
	while($page = $query_page->fetchRow()) {
248
		$pages[$page['page_id']]['page_details'] = $page;
249
	}
250
}
251
if($pages!=array())
252
	echo "<br /><u>Convert menu_links</u><br />";
253

    
254
// get all related files with content from pages/ in $pages, too
255
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
256
	$dh=opendir($dir);
257
	while(($file = readdir($dh)) !== false) {
258
		if($file == '.' || $file == '..') {
259
			continue;
260
		}
261
		if(is_dir($dir.'/'.$file)) {
262
			if($depth) {
263
				$dirs[] = $dir.'/'.$file;
264
				list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
265
			}
266
		} else {
267
			$files[] = $dir.'/'.$file;
268
		}
269
	}
270
	closedir($dh);
271
	natcasesort($files);
272
	natcasesort($dirs);
273
	return(array($files, $dirs));
274
}
275
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
276
foreach($files as $file) {
277
	if(($content = implode('', file($file))) !== FALSE) {
278
		if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
279
			if(array_key_exists($matches[1], $pages)) {
280
				$pages[$matches[1]]['file_content'] = $content;
281
				$pages[$matches[1]]['filename'] = $file;
282
			}
283
		}
284
	}
285
}
286
unset($files); unset($dirs);
287
// try to convert old menu_links to new ones
288
foreach($pages as $p) {
289
	$page = $p['page_details'];
290
	$file_content = $p['file_content'];
291
	$filename = $p['filename'];
292
	$link = $p['page_details']['link'];
293
	$parent_pid = $p['page_details']['parent'];
294
	$page_id = $p['page_details']['page_id'];
295
	$section_id = $p['page_details']['section_id'];
296
	$menu_title = $p['page_details']['menu_title'];
297

    
298
	// calculate link from wb_pages.parent and menu_title
299
	$cur_link = '';
300
	if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
301
		$res = $query_link->fetchRow();
302
		$cur_link .= $res['link'];
303
	}
304
	$cur_link .= '/'.page_filename($menu_title);
305
echo "found: $cur_link<br />";
306
	$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
307
	echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
308
	
309
	$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
310
	$new_filenames[$page_id]['link'] = $cur_link;
311
	$new_filenames[$page_id]['menu'] = $menu_title;
312

    
313
	// delete old access files in pages
314
	if(file_exists($filename)) {
315
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
316
			echo "Cannot delete access file in pages/ - permission denied ($FAIL)<br />";
317
		} else {
318
			unlink($filename);
319
		}
320
	}
321
	
322
	// make entry in wb_mod_menu_link
323
	if($query_pid = $database->query("SELECT page_id FROM $table_p WHERE page_id != '$page_id' AND link = '$link'")) {
324
		$res = $query_pid->fetchRow();
325
		$target_page_id = $res['page_id'];
326
		$extern = '';
327
		if(strpos($link, '://') !== FALSE || strpos($link, 'mailto:') !== FALSE) {
328
			$target_page_id=-1;
329
			$extern=addslashes($link);
330
		}
331
		$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')");
332
		echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
333
	}
334
}
335
// create new access files in pages/; make directories as needed
336
foreach($pages as $p) {
337
	$page_id = $p['page_details']['page_id'];
338
	$filename = $new_filenames[$page_id]['file'];
339
	$menu_title = $new_filenames[$page_id]['menu'];
340
	$link = $new_filenames[$page_id]['link'];
341
	$content = $p['file_content'];
342
	$level = $p['page_details']['level'];
343
	$depth = '';
344
	for($i=0; $i<=$level; $i++)
345
		$depth .= '../';
346
	$content = preg_replace('#((../)+)config\.php#', "{$depth}config.php", $content);
347
	while(file_exists($filename)) {
348
		echo "Cannot create '$filename' - file exist. Renamed to: ";
349
		$menu_title .= '_';
350
		$link .= '_';
351
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
352
		echo "$filename<br />";
353
		$database->query("UPDATE $table_p SET link='$link', menu_title='$menu_title' WHERE page_id = '$page_id'");
354
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
355
	}
356
	// check if we need to create a subdir somewhere
357
	$dirs = array();
358
	while(dirname($link) != '/') {
359
		$link = dirname($link);
360
		$dirs[] = WB_PATH.PAGES_DIRECTORY.$link;
361
	}
362
	foreach(array_reverse($dirs) as $dir) {
363
		if(!file_exists($dir)) {
364
			mkdir($dir, OCTAL_DIR_MODE);
365
		}
366
	}
367
	// create new file in pages/
368
	if($handle=fopen($filename, "wb")) {
369
		if(!fwrite($handle, $content)) {
370
			echo "Cannot write to $filename - ($FAIL)<br />";
371
		}
372
		fclose($handle);
373
	} else {
374
		echo "Cannot create $filename - ($FAIL)<br />";
375
	}
376
	
377
}
378

    
379
// some code missing to regenerate page_title from link/filename
380
// for_all_pages: if filename($page_title) != basename($link) {
381
//   rename $page_title to basename($link)
382
// }
383
// This must be done after menu_link-upgrade
384
// 
385
// Should we really do this? - must be checked
386

    
387

    
388
/**********************************************************
389
 *  - asp - Advanced Spam Protection
390
 */
391
echo "<br /><u>Adding table mod_captcha_control</u><br />";
392
$table = TABLE_PREFIX.'mod_captcha_control';
393
$database->query("DROP TABLE IF EXISTS `$table`");
394
$database->query("CREATE TABLE `$table` (
395
	`enabled_captcha` VARCHAR(1) NOT NULL DEFAULT '1',
396
	`enabled_asp` VARCHAR(1) NOT NULL DEFAULT '1',
397
	`captcha_type` VARCHAR(255) NOT NULL DEFAULT 'calc_text',
398
	`asp_session_min_age` INT(11) NOT NULL DEFAULT '20',
399
	`asp_view_min_age` INT(11) NOT NULL DEFAULT '10',
400
	`asp_input_min_age` INT(11) NOT NULL DEFAULT '5',
401
	`ct_text` LONGTEXT NOT NULL DEFAULT ''
402
	)"
403
);
404
$database->query("
405
	INSERT INTO `$table`
406
		(`enabled_captcha`, `enabled_asp`, `captcha_type`)
407
	VALUES
408
		('1', '1', 'calc_text')
409
");
410

    
411

    
412
/**********************************************************
413
 *  - multi-group
414
 */
415
db_add_field('groups_id', 'users', "VARCHAR( 255 ) NOT NULL DEFAULT '0' AFTER group_id");
416
$table = TABLE_PREFIX.'users';
417
if($query_group = $database->query("SELECT user_id,group_id,groups_id FROM $table")) {
418
	while($group = $query_group->fetchRow()) {
419
		if($group['groups_id'] == '0') {
420
			if($database->query("UPDATE $table SET groups_id = group_id WHERE user_id = {$group['user_id']}")) {
421
				echo 'groups_id updated successfully<br>';
422
			}
423
			echo mysql_error().'<br />';
424
		}
425
	}
426
}
427

    
428

    
429
/**********************************************************
430
 *  -Javascript Admin
431
 */
432
echo "<br /><u>Adding table mod_jsadmin</u><br />";
433
$table = TABLE_PREFIX ."mod_jsadmin";
434
$database->query("DROP TABLE IF EXISTS `$table`");
435

    
436
$database->query("
437
	CREATE TABLE `$table` (
438
    `id` INT(11) NOT NULL DEFAULT '0',
439
		`name` VARCHAR(255) NOT NULL DEFAULT '0',
440
		`value` INT(11) NOT NULL DEFAULT '0',
441
   	PRIMARY KEY (`id`)
442
	)
443
");
444

    
445
global $database;
446
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('1','mod_jsadmin_persist_order','0')");
447
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('2','mod_jsadmin_ajax_order_pages','0')");
448
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('3','mod_jsadmin_ajax_order_sections','0')");
449

    
450

    
451
/**********************************************************
452
 *  - Output Filter
453
 */
454
echo "<br /><u>Adding table mod_outputfilter</u><br />";
455
$table = TABLE_PREFIX .'mod_output_filter';
456
$database->query("DROP TABLE IF EXISTS `$table`");
457

    
458
$database->query("CREATE TABLE `$table` (
459
	`email_filter` VARCHAR(1) NOT NULL DEFAULT '0',
460
	`mailto_filter` VARCHAR(1) NOT NULL DEFAULT '0',
461
	`at_replacement` VARCHAR(255) NOT NULL DEFAULT '(at)',
462
	`dot_replacement` VARCHAR(255) NOT NULL DEFAULT '(dot)'
463
	)"
464
);
465

    
466
// add default values to the module table
467
$database->query("INSERT INTO ".TABLE_PREFIX
468
	."mod_output_filter (email_filter, mailto_filter, at_replacement, dot_replacement) VALUES ('0', '0', '(at)', '(dot)')");
469
	
470

    
471
/**********************************************************
472
 *  - Form Modul
473
 */
474
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
475
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
476
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
477
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
478
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
479
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
480
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
481

    
482
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
483

    
484
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
485
	echo 'Database field success_message droped successfully<br>';
486
}
487
echo mysql_error().'<br />';
488

    
489
// These are the default setting
490
$success_page = 'none';
491
$success_email_to = '';
492
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
493
$success_email_text = addslashes($success_email_text);
494
$success_email_subject = 'You have submitted a form';
495

    
496
// Insert default settings into database
497
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
498
while($result = $query_dates->fetchRow()) {
499
	
500
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
501
	$section_id = $result['section_id'];
502

    
503
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
504
		echo 'Database data success_page added successfully<br>';
505
	}
506
	echo mysql_error().'<br />';
507
	
508
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
509
		echo 'Database data success_email_to added successfully<br>';
510
	}
511
	echo mysql_error().'<br />';
512
	
513
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
514
		echo 'Database data success_email_text added successfully<br>';
515
	}
516
	echo mysql_error().'<br />';
517
	
518
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
519
		echo 'Database data success_email_subject added successfully<br>';
520
	}
521
	echo mysql_error().'<br />';
522
	
523
}
524

    
525
// copy field email_to to success_email_from
526
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
527
while($result = $query_dates->fetchRow()) {
528
	
529
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
530
	$section_id = $result['section_id'];
531

    
532
	$success_email_from = $result['email_to'];
533
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
534
		echo 'Copyied field email_to to success_email_from successfully<br>';
535
	}
536
	echo mysql_error().'<br />';
537
}
538

    
539

    
540
/**********************************************************
541
 *  - News Modul
542
 */
543
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
544
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
545

    
546
// These are the default setting
547
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
548
$post_loop = '<tr class=\"post_top\">
549
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
550
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
551
</tr>
552
<tr>
553
<td class=\"post_short\" colspan=\"2\">
554
[SHORT] 
555
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
556
</td>
557
</tr>';
558
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
559
<tr>
560
<td height="30"><h1>[TITLE]</h1></td>
561
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
562
</tr>
563
<tr>
564
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
565
</tr>
566
<tr style="display: [DISPLAY_GROUP]">
567
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
568
</tr>
569
</table>
570
<p style="text-align: justify;">');
571
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
572
<a href=\"[BACK]\">Back</a>';
573
$comments_header = addslashes('<br /><br />
574
<h2>Comments</h2>
575
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
576

    
577
// Insert default settings into database
578
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
579
while($result = $query_dates->fetchRow()) {
580
	
581
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
582
	$section_id = $result['section_id'];
583

    
584
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
585
		echo 'Database data header added successfully<br>';
586
	}
587
	echo mysql_error().'<br />';
588
	
589
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
590
		echo 'Database data post_loop added successfully<br>';
591
	}
592
	echo mysql_error().'<br />';
593
	
594
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
595
		echo 'Database data post_header added successfully<br>';
596
	}
597
	echo mysql_error().'<br />';
598
	
599
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
600
		echo 'Database data post_footer added successfully<br>';
601
	}
602
	echo mysql_error().'<br />';
603
	
604
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
605
		echo 'Database data comments_header added successfully<br>';
606
	}
607
	echo mysql_error().'<br />';
608

    
609
}
610

    
611
// MIGRATING FIELD DATES to POSTED_WHEN
612
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
613
if($query_dates->numRows() > 0) {
614
	echo "<B>Copying field posted_when value to published_when</B><BR>";
615
}
616
while($result = $query_dates->fetchRow()) {
617
	$pid = $result['post_id'];
618
	$NEW_DATE = $result['posted_when'];
619
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
620
		echo 'Copying posted_when value to published_when successfully<br>';
621
	}
622
	echo mysql_error().'<br />';
623
}
624

    
625

    
626
/**********************************************************
627
 *  - Add Admintools to Administrator group
628
 */
629
echo "<br /><u>Add Admintools to Adminsitrator group</u><br />";
630
$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';
631
$database->query("UPDATE `".TABLE_PREFIX."groups` SET `system_permissions` = '$full_system_permissions' WHERE `name` = 'Administrators'");
632

    
633

    
634
/**********************************************************
635
 *  - Add Mailer Settings to settings table
636
 */
637
echo "<br /><u>Add Mailer Settings to settings table</u><br />";
638
//delete rows to prevent double entries
639
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_routine'");
640
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'server_email'");
641
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_default_sendername'");
642
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_host'");
643
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_auth'");
644
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_username'");
645
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_password'");
646
//add new rows with default values
647
$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
648
." (name, value) VALUES "
649
." ('wbmailer_routine', 'phpmail'),"
650
." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
651
." ('wbmailer_default_sendername', 'WB Mailer'),"
652
." ('wbmailer_smtp_host', ''),"
653
." ('wbmailer_smtp_auth', ''),"
654
." ('wbmailer_smtp_username', ''),"
655
." ('wbmailer_smtp_password', '')";
656
$database->query($settings_rows);
657

    
658

    
659
/**********************************************************
660
 *  - Reload all addons
661
 */
662

    
663
//delete modules
664
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
665
// Load all modules
666
if($handle = opendir(WB_PATH.'/modules/')) {
667
	while(false !== ($file = readdir($handle))) {
668
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
669
			load_module(WB_PATH.'/modules/'.$file);
670
		}
671
	}
672
	closedir($handle);
673
}
674
echo '<br />Modules reloaded<br />';
675

    
676
//delete templates		
677
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
678
// Load all templates
679
if($handle = opendir(WB_PATH.'/templates/')) {
680
	while(false !== ($file = readdir($handle))) {
681
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
682
			load_template(WB_PATH.'/templates/'.$file);
683
		}
684
	}
685
	closedir($handle);
686
}
687
echo '<br />Templates reloaded<br />';
688

    
689
//delete languages
690
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
691
// Load all languages
692
if($handle = opendir(WB_PATH.'/languages/')) {
693
	while(false !== ($file = readdir($handle))) {
694
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
695
			load_language(WB_PATH.'/languages/'.$file);
696
		}
697
	}
698
	closedir($handle);
699
}
700
echo '<br />Languages reloaded<br />';
701

    
702
/**********************************************************
703
 *  - Set Version to WB 2.7
704
 */
705
echo "<br /><u>Set Version number to 2.7</u><br />";
706
$version = '2.7';
707
$database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'");
708

    
709

    
710
/**********************************************************
711
 *  - End of upgrade script
712
 */
713
echo "<br /><br />Done<br />";
714

    
715
?>
716

    
717
</body>
718
</html>
(4-4/4)