Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 627 2008-01-28 16:49:52Z 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
// 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
</head>
41
<body>
42
<style type="text/css">
43
<!--
44
*.red { background-color:#FF0000 }
45
*.green { background-color:#00FF00 }
46
-->
47
</style>
48

    
49
<h2>Upgrade-script</h2>
50
<p>
51
will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7
52
</p>
53
<?php
54

    
55
$OK   = '<span class="green">OK</span>';
56
$FAIL = '<span class="red">failed</span>';
57

    
58

    
59
/**********************************************************
60
 *  - modules-based search
61
 */
62
function db_add_search_key_value($key, $value) {
63
	global $database; global $OK; global $FAIL;
64
	$table = TABLE_PREFIX.'search';
65
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
66
	if($query->numRows() > 0) {
67
		echo "$key: allready there. $OK.<br />";
68
		return true;
69
	} else {
70
		$database->query("INSERT INTO $table (name,value,extra) VALUES ('$key', '$value', '')");
71
		echo mysql_error()?mysql_error().'<br />':'';
72
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
73
		if($query->numRows() > 0) {
74
			echo "$key: $OK.<br />";
75
			return true;
76
		} else {
77
			echo "$key: $FAIL!<br />";
78
			return false;
79
		}
80
	}
81
}
82

    
83

    
84
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
85
// module_order - in which order to show the search-results
86
// max_excerpt - how many lines of excerpt to print per matching page
87

    
88
$cfg = array(
89
	'module_order' => 'faqbaker,manual,wysiwyg',
90
	'max_excerpt' => '15'
91
);
92
foreach($cfg as $key=>$value) {
93
	db_add_search_key_value($key, $value);
94
}
95

    
96

    
97
echo "<br /><u>Changing results_loop in search-table</u><br />";
98
// adding [EXCERPT]
99

    
100
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
101
if($query->numRows() > 0) {
102
	$fetch_results_loop = $query->fetchRow();
103
	$string = $fetch_results_loop['value'];
104
	if(preg_match("/\[EXCERPT\]/", $string)) {
105
		echo "[EXCERPT] is allready there. $OK.<br />";
106
	} else {
107
		$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
108
		$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
109
		$string = addslashes($string);
110
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
111
		echo mysql_error()?mysql_error().'<br />':'';
112
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
113
		if($query->numRows() > 0) {
114
			$fetch_results_loop = $query->fetchRow();
115
			$string = $fetch_results_loop['value'];
116
			if(preg_match("/\[EXCERPT\]/", $string)) {
117
				echo "[EXCERPT] added. $OK.<br />";
118
			} else {
119
				echo "adding [EXCERPT] $FAIL!<br />";
120
			}
121
		}
122
	}
123
}
124

    
125
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
126
// adding [SEARCH_PATH]
127

    
128
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
129
if($query->numRows() > 0) {
130
	$fetch_header = $query->fetchRow();
131
	$string = $fetch_header['value'];
132
	if(preg_match("/\[SEARCH_PATH\]/", $string)) {
133
		echo "[SEARCH_PATH] is allready there. $OK.<br />";
134
	} else {
135
		$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);
136
		$string = addslashes($string);
137
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
138
		echo mysql_error()?mysql_error().'<br />':'';
139
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
140
		if($query->numRows() > 0) {
141
			$fetch_header = $query->fetchRow();
142
			$string = $fetch_header['value'];
143
			if(preg_match("/\[SEARCH_PATH\]/", $string)) {
144
				echo "[SEARCH_PATH] added. $OK.<br />";
145
			} else {
146
				echo "adding [SEARCH_PATH] $FAIL!<br />";
147
			}
148
		}
149
	}
150
}
151

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

    
168

    
169
/**********************************************************
170
 *  - publish-by-date
171
 */
172
echo "<br /><u>Adding fields 'publ_start' and 'publ_end' to table 'sections'</u><br />";
173
// Add fields "publ_start" and "publ_end" to table "sections"
174
// check if fields are present
175
$table = TABLE_PREFIX."sections";
176
$query = $database->query("DESCRIBE $table 'publ_start'");
177
if($query->numRows() == 0) { // add field
178
	$query = $database->query("ALTER TABLE $table ADD publ_start INT NOT NULL DEFAULT '0'");
179
	echo mysql_error()?mysql_error().'<br />':'';
180
	$query = $database->query("DESCRIBE $table 'publ_start'");
181
	echo mysql_error()?mysql_error().'<br />':'';
182
	if($query->numRows() > 0) {
183
		echo "'publ_start' added. $OK.<br />";
184
	} else {
185
		echo "adding 'publ_start' $FAIL!<br />";
186
	}
187
} else {
188
	echo "'publ_start' allready there. $OK.<br />";
189
}
190
$query = $database->query("DESCRIBE $table 'publ_end'");
191
if($query->numRows() == 0) { // add field
192
	$query = $database->query("ALTER TABLE $table ADD publ_end INT NOT NULL DEFAULT '0'");
193
	echo mysql_error()?mysql_error().'<br />':'';
194
	$query = $database->query("DESCRIBE $table 'publ_end'");
195
	if($query->numRows() > 0) {
196
		echo "'publ_end' added. $OK.<br />";
197
	} else {
198
		echo "adding 'publ_end' $FAIL!<br />";
199
	}
200
} else {
201
	echo "'publ_end' allready there. $OK<br />";
202
}
203

    
204

    
205
/**********************************************************
206
 *  - core-module menu_link
207
 */
208
echo "<br /><u>Convert menu_links</u><br />";
209
// create table
210
$table = TABLE_PREFIX ."mod_menu_link";
211
$database->query("DROP TABLE IF EXISTS `$table`");
212
$database->query("
213
	CREATE TABLE `$table` (
214
		`section_id` INT(11) NOT NULL DEFAULT '0',
215
		`page_id` INT(11) NOT NULL DEFAULT '0',
216
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
217
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
218
		PRIMARY KEY (`section_id`)
219
	)
220
");
221
// fetch all menu_link-pages in $pages
222
$pages = array();
223
$table_p = TABLE_PREFIX.'pages';
224
$table_s = TABLE_PREFIX.'sections';
225
$table_mm = TABLE_PREFIX ."mod_menu_link";
226

    
227
$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'");
228
if($query_page->numRows() > 0) {
229
	while($page = $query_page->fetchRow()) {
230
		$pages[$page['page_id']]['page_details'] = $page;
231
	}
232
}
233
// get all related files with content from pages/ in $pages, too
234
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
235
	$dh=opendir($dir);
236
	while(($file = readdir($dh)) !== false) {
237
		if($file == '.' || $file == '..') {
238
			continue;
239
		}
240
		if(is_dir($dir.'/'.$file)) {
241
			if($depth) {
242
				$dirs[] = $dir.'/'.$file;
243
				list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
244
			}
245
		} else {
246
			$files[] = $dir.'/'.$file;
247
		}
248
	}
249
	closedir($dh);
250
	natcasesort($files);
251
	natcasesort($dirs);
252
	return(array($files, $dirs));
253
}
254
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
255
foreach($files as $file) {
256
	if(($content = implode('', file($file))) !== FALSE) {
257
		if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
258
			if(array_key_exists($matches[1], $pages)) {
259
				$pages[$matches[1]]['file_content'] = $content;
260
				$pages[$matches[1]]['filename'] = $file;
261
			}
262
		}
263
	}
264
}
265
unset($files); unset($dirs);
266
// try to convert old menu_links to new ones
267
foreach($pages as $p) {
268
	$page = $p['page_details'];
269
	$file_content = $p['file_content'];
270
	$filename = $p['filename'];
271
	$link = $p['page_details']['link'];
272
	$parent_pid = $p['page_details']['parent'];
273
	$page_id = $p['page_details']['page_id'];
274
	$section_id = $p['page_details']['section_id'];
275
	$menu_title = $p['page_details']['menu_title'];
276

    
277
	// calculate link from wb_pages.parent and menu_title
278
	$cur_link = '';
279
	if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
280
		$res = $query_link->fetchRow();
281
		$cur_link .= $res['link'];
282
	}
283
	$cur_link .= '/'.page_filename($menu_title);
284
echo "found: $cur_link<br />";
285
	$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
286
	echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
287
	
288
	$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
289
	$new_filenames[$page_id]['link'] = $cur_link;
290
	$new_filenames[$page_id]['menu'] = $menu_title;
291

    
292
	// delete old access files in pages
293
	if(file_exists($filename)) {
294
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
295
			echo "Cannot delete access file in pages/ - permission denied ($FAIL)<br />";
296
		} else {
297
			unlink($filename);
298
		}
299
	}
300
	
301
	// make entry in wb_mod_menu_link
302
	if($query_pid = $database->query("SELECT page_id FROM $table_p WHERE page_id != '$page_id' AND link = '$link'")) {
303
		$res = $query_pid->fetchRow();
304
		$target_page_id = $res['page_id'];
305
		$database->query("INSERT INTO $table_mm (page_id, section_id, target_page_id, anchor) VALUES ('$page_id', '$section_id', '$target_page_id', '0')");
306
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
307
	}
308
}
309
// create new access files in pages/; make directories as needed
310
foreach($pages as $p) {
311
	$page_id = $p['page_details']['page_id'];
312
	$filename = $new_filenames[$page_id]['file'];
313
	$menu_title = $new_filenames[$page_id]['menu'];
314
	$link = $new_filenames[$page_id]['link'];
315
	$content = $p['file_content'];
316
	$level = $p['page_details']['level'];
317
	$depth = '';
318
	for($i=0; $i<=$level; $i++)
319
		$depth .= '../';
320
	$content = preg_replace('#((../)+)config\.php#', "{$depth}config.php", $content);
321
	while(file_exists($filename)) {
322
		echo "Cannot create '$filename' - file exist. Renamed to: ";
323
		$menu_title .= '_';
324
		$link .= '_';
325
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
326
		echo "$filename<br />";
327
		$database->query("UPDATE $table_p SET link='$link', menu_title='$menu_title' WHERE page_id = '$page_id'");
328
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
329
	}
330
	// check if we need to create a subdir somewhere
331
	$dirs = array();
332
	while(dirname($link) != '/') {
333
		$link = dirname($link);
334
		$dirs[] = WB_PATH.PAGES_DIRECTORY.$link;
335
	}
336
	foreach(array_reverse($dirs) as $dir) {
337
		if(!file_exists($dir)) {
338
			mkdir($dir, OCTAL_DIR_MODE);
339
		}
340
	}
341
	// create new file in pages/
342
	if($handle=fopen($filename, "wb")) {
343
		if(!fwrite($handle, $content)) {
344
			echo "Cannot write to $filename - ($FAIL)<br />";
345
		}
346
		fclose($handle);
347
	} else {
348
		echo "Cannot create $filename - ($FAIL)<br />";
349
	}
350
	
351
}
352

    
353
// some code missing to regenerate page_title from link/filename
354
// for_all_pages: if filename($page_title) != basename($link) {
355
//   rename $page_title to basename($link)
356
// }
357
// This must be done after menu_link-upgrade
358
// 
359
// Should we really do this? - must be checked
360

    
361
/**********************************************************
362
 *  - asp - Advanced Spam Protection
363
 */
364
echo "<br /><u>Adding table mod_captcha_control</u><br />";
365
$table = TABLE_PREFIX.'mod_captcha_control';
366
$database->query("DROP TABLE IF EXISTS `$table`");
367
$database->query("CREATE TABLE `$table` (
368
	`enabled_captcha` VARCHAR(1) NOT NULL DEFAULT '1',
369
	`enabled_asp` VARCHAR(1) NOT NULL DEFAULT '1',
370
	`captcha_type` VARCHAR(255) NOT NULL DEFAULT 'calc_text',
371
	`asp_session_min_age` INT(11) NOT NULL DEFAULT '20',
372
	`asp_view_min_age` INT(11) NOT NULL DEFAULT '10',
373
	`asp_input_min_age` INT(11) NOT NULL DEFAULT '5'
374
	)"
375
);
376
$database->query("
377
	INSERT INTO `$table`
378
		(`enabled_captcha`, `enabled_asp`, `captcha_type`)
379
	VALUES
380
		('1', '1', 'calc_text')
381
");
382

    
383

    
384
//******************************************************************************
385
//Start of upgrade script for the form modul
386
//******************************************************************************
387

    
388
echo "<BR><B>Adding new field to database table mod_form_settings</B><BR>";
389

    
390
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_subject` VARCHAR(255) NOT NULL AFTER `success_message`")) {
391
	echo 'Database Field success_email_subject added successfully<br />';
392
}
393
echo mysql_error().'<br />';
394

    
395
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_text` TEXT NOT NULL AFTER `success_message`")) {
396
	echo 'Database Field success_email_text added successfully<br />';
397
}
398
echo mysql_error().'<br />';
399

    
400
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_from` VARCHAR(255) NOT NULL AFTER `success_message`")) {
401
	echo 'Database Field success_email_from added successfully<br />';
402
}
403
echo mysql_error().'<br />';
404

    
405
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_to` TEXT NOT NULL AFTER `success_message`")) {
406
	echo 'Database Field success_email_to added successfully<br />';
407
}
408
echo mysql_error().'<br />';
409

    
410
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_page` TEXT NOT NULL AFTER `success_message`")) {
411
	echo 'Database Field success_page added successfully<br />';
412
}
413
echo mysql_error().'<br />';
414

    
415
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
416

    
417
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
418
	echo 'Database field success_message droped successfully<br>';
419
}
420
echo mysql_error().'<br />';
421

    
422

    
423
// UPDATING DATA INTO FIELDS
424
echo "<BR>";
425

    
426
// These are the default setting
427
$success_page = 'none';
428
$success_email_to = '';
429
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
430
$success_email_text = addslashes($success_email_text);
431
$success_email_subject = 'You have submitted a form';
432

    
433
// Insert default settings into database
434
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
435
while($result = $query_dates->fetchRow()) {
436
	
437
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
438
	$section_id = $result['section_id'];
439

    
440
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
441
		echo 'Database data success_page added successfully<br>';
442
	}
443
	echo mysql_error().'<br />';
444
	
445
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
446
		echo 'Database data success_email_to added successfully<br>';
447
	}
448
	echo mysql_error().'<br />';
449
	
450
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
451
		echo 'Database data success_email_text added successfully<br>';
452
	}
453
	echo mysql_error().'<br />';
454
	
455
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
456
		echo 'Database data success_email_subject added successfully<br>';
457
	}
458
	echo mysql_error().'<br />';
459
	
460
}
461

    
462
// copy field email_to to success_email_from
463
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
464
while($result = $query_dates->fetchRow()) {
465
	
466
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
467
	$section_id = $result['section_id'];
468

    
469
	$success_email_from = $result['email_to'];
470
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
471
		echo 'Copyied field email_to to success_email_from successfully<br>';
472
	}
473
	echo mysql_error().'<br />';
474
}
475

    
476
//******************************************************************************
477
//End of upgrade script for the form modul
478
//******************************************************************************
479

    
480
//******************************************************************************
481
//Start of upgrade script for the news modul
482
//******************************************************************************
483

    
484
echo "<BR><B>Adding new fields to database table mod_news_posts</B><BR>";
485
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_when` INT NOT NULL AFTER `commenting`")) {
486
	echo 'Database Field published_when added successfully<br />';
487
}
488
echo mysql_error().'<br />';
489
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_until` INT NOT NULL AFTER `published_when`")) {
490
	echo 'Database Field published_until added successfully<br />';
491
}
492
echo mysql_error().'<br />';
493

    
494
// UPDATING DATA INTO FIELDS
495
echo "<BR>";
496

    
497
// These are the default setting
498
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
499
$post_loop = '<tr class=\"post_top\">
500
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
501
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
502
</tr>
503
<tr>
504
<td class=\"post_short\" colspan=\"2\">
505
[SHORT] 
506
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
507
</td>
508
</tr>';
509
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
510
<tr>
511
<td height="30"><h1>[TITLE]</h1></td>
512
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
513
</tr>
514
<tr>
515
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
516
</tr>
517
<tr style="display: [DISPLAY_GROUP]">
518
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
519
</tr>
520
</table>
521
<p style="text-align: justify;">');
522
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
523
<a href=\"[BACK]\">Back</a>';
524
$comments_header = addslashes('<br /><br />
525
<h2>Comments</h2>
526
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
527

    
528
// Insert default settings into database
529
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
530
while($result = $query_dates->fetchRow()) {
531
	
532
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
533
	$section_id = $result['section_id'];
534

    
535
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
536
		echo 'Database data header added successfully<br>';
537
	}
538
	echo mysql_error().'<br />';
539
	
540
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
541
		echo 'Database data post_loop added successfully<br>';
542
	}
543
	echo mysql_error().'<br />';
544
	
545
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
546
		echo 'Database data post_header added successfully<br>';
547
	}
548
	echo mysql_error().'<br />';
549
	
550
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
551
		echo 'Database data post_footer added successfully<br>';
552
	}
553
	echo mysql_error().'<br />';
554
	
555
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
556
		echo 'Database data comments_header added successfully<br>';
557
	}
558
	echo mysql_error().'<br />';
559

    
560
}
561

    
562
// MIGRATING FIELD DATES to POSTED_WHEN
563
echo "<B>Copying field posted_when value to published_when</B><BR>";
564
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
565

    
566
while($result = $query_dates->fetchRow()) {
567
	$pid = $result['post_id'];
568
	$NEW_DATE = $result['posted_when'];
569
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
570
		echo 'Copying posted_when value to published_when successfully<br>';
571
	}
572
	echo mysql_error().'<br />';
573
}
574

    
575
//******************************************************************************
576
//End of upgrade script for the news modul
577
//******************************************************************************
578

    
579
echo "<br /><br />Done<br />";
580

    
581
?>
582

    
583
</body>
584
</html>
(4-4/4)