Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 701 2008-02-16 12:28:19Z 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

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

    
221

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

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

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

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

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

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

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

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

    
425

    
426

    
427
//******************************************************************************
428
//Start of upgrade script for the form modul
429
//******************************************************************************
430

    
431
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
432
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
433
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
434
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
435
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
436
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
437
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
438

    
439
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
440

    
441
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
442
	echo 'Database field success_message droped successfully<br>';
443
}
444
echo mysql_error().'<br />';
445

    
446

    
447
// UPDATING DATA INTO FIELDS
448
echo "<BR>";
449

    
450
// These are the default setting
451
$success_page = 'none';
452
$success_email_to = '';
453
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
454
$success_email_text = addslashes($success_email_text);
455
$success_email_subject = 'You have submitted a form';
456

    
457
// Insert default settings into database
458
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
459
while($result = $query_dates->fetchRow()) {
460
	
461
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
462
	$section_id = $result['section_id'];
463

    
464
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
465
		echo 'Database data success_page added successfully<br>';
466
	}
467
	echo mysql_error().'<br />';
468
	
469
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
470
		echo 'Database data success_email_to added successfully<br>';
471
	}
472
	echo mysql_error().'<br />';
473
	
474
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
475
		echo 'Database data success_email_text added successfully<br>';
476
	}
477
	echo mysql_error().'<br />';
478
	
479
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
480
		echo 'Database data success_email_subject added successfully<br>';
481
	}
482
	echo mysql_error().'<br />';
483
	
484
}
485

    
486
// copy field email_to to success_email_from
487
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
488
while($result = $query_dates->fetchRow()) {
489
	
490
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
491
	$section_id = $result['section_id'];
492

    
493
	$success_email_from = $result['email_to'];
494
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
495
		echo 'Copyied field email_to to success_email_from successfully<br>';
496
	}
497
	echo mysql_error().'<br />';
498
}
499

    
500
//******************************************************************************
501
//End of upgrade script for the form modul
502
//******************************************************************************
503

    
504
//******************************************************************************
505
//Start of upgrade script for the news modul
506
//******************************************************************************
507

    
508
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
509
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
510

    
511
// UPDATING DATA INTO FIELDS
512
echo "<BR>";
513

    
514
// These are the default setting
515
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
516
$post_loop = '<tr class=\"post_top\">
517
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
518
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
519
</tr>
520
<tr>
521
<td class=\"post_short\" colspan=\"2\">
522
[SHORT] 
523
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
524
</td>
525
</tr>';
526
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
527
<tr>
528
<td height="30"><h1>[TITLE]</h1></td>
529
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
530
</tr>
531
<tr>
532
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
533
</tr>
534
<tr style="display: [DISPLAY_GROUP]">
535
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
536
</tr>
537
</table>
538
<p style="text-align: justify;">');
539
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
540
<a href=\"[BACK]\">Back</a>';
541
$comments_header = addslashes('<br /><br />
542
<h2>Comments</h2>
543
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
544

    
545
// Insert default settings into database
546
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
547
while($result = $query_dates->fetchRow()) {
548
	
549
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
550
	$section_id = $result['section_id'];
551

    
552
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
553
		echo 'Database data header added successfully<br>';
554
	}
555
	echo mysql_error().'<br />';
556
	
557
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
558
		echo 'Database data post_loop added successfully<br>';
559
	}
560
	echo mysql_error().'<br />';
561
	
562
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
563
		echo 'Database data post_header added successfully<br>';
564
	}
565
	echo mysql_error().'<br />';
566
	
567
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
568
		echo 'Database data post_footer added successfully<br>';
569
	}
570
	echo mysql_error().'<br />';
571
	
572
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
573
		echo 'Database data comments_header added successfully<br>';
574
	}
575
	echo mysql_error().'<br />';
576

    
577
}
578

    
579
// MIGRATING FIELD DATES to POSTED_WHEN
580
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
581
if($query_dates->numRows() > 0) {
582
	echo "<B>Copying field posted_when value to published_when</B><BR>";
583
}
584
while($result = $query_dates->fetchRow()) {
585
	$pid = $result['post_id'];
586
	$NEW_DATE = $result['posted_when'];
587
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
588
		echo 'Copying posted_when value to published_when successfully<br>';
589
	}
590
	echo mysql_error().'<br />';
591
}
592

    
593
//******************************************************************************
594
//End of upgrade script for the news modul
595
//******************************************************************************
596

    
597

    
598

    
599

    
600
echo "<br /><br />Done<br />";
601

    
602
?>
603

    
604
</body>
605
</html>
(4-4/4)