Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 642 2008-01-29 14:32:38Z thorn $
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
	`ct_text` LONGTEXT NOT NULL DEFAULT ''
375
	)"
376
);
377
$database->query("
378
	INSERT INTO `$table`
379
		(`enabled_captcha`, `enabled_asp`, `captcha_type`)
380
	VALUES
381
		('1', '1', 'calc_text')
382
");
383

    
384

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

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

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

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

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

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

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

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

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

    
423

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

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

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

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

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

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

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

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

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

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

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

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

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

    
561
}
562

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

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

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

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

    
582
?>
583

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