Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 692 2008-02-10 15:00:19Z 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

    
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
		PRIMARY KEY (`section_id`)
235
	)
236
");
237
// fetch all menu_link-pages in $pages
238
$pages = array();
239
$table_p = TABLE_PREFIX.'pages';
240
$table_s = TABLE_PREFIX.'sections';
241
$table_mm = TABLE_PREFIX ."mod_menu_link";
242

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

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

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

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

    
372
// some code missing to regenerate page_title from link/filename
373
// for_all_pages: if filename($page_title) != basename($link) {
374
//   rename $page_title to basename($link)
375
// }
376
// This must be done after menu_link-upgrade
377
// 
378
// Should we really do this? - must be checked
379

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

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

    
419

    
420

    
421
//******************************************************************************
422
//Start of upgrade script for the form modul
423
//******************************************************************************
424

    
425
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
426
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
427
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
428
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
429
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
430
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
431
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
432

    
433
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
434

    
435
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
436
	echo 'Database field success_message droped successfully<br>';
437
}
438
echo mysql_error().'<br />';
439

    
440

    
441
// UPDATING DATA INTO FIELDS
442
echo "<BR>";
443

    
444
// These are the default setting
445
$success_page = 'none';
446
$success_email_to = '';
447
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
448
$success_email_text = addslashes($success_email_text);
449
$success_email_subject = 'You have submitted a form';
450

    
451
// Insert default settings into database
452
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
453
while($result = $query_dates->fetchRow()) {
454
	
455
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
456
	$section_id = $result['section_id'];
457

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

    
480
// copy field email_to to success_email_from
481
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
482
while($result = $query_dates->fetchRow()) {
483
	
484
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
485
	$section_id = $result['section_id'];
486

    
487
	$success_email_from = $result['email_to'];
488
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
489
		echo 'Copyied field email_to to success_email_from successfully<br>';
490
	}
491
	echo mysql_error().'<br />';
492
}
493

    
494
//******************************************************************************
495
//End of upgrade script for the form modul
496
//******************************************************************************
497

    
498
//******************************************************************************
499
//Start of upgrade script for the news modul
500
//******************************************************************************
501

    
502
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
503
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
504

    
505
// UPDATING DATA INTO FIELDS
506
echo "<BR>";
507

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

    
539
// Insert default settings into database
540
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
541
while($result = $query_dates->fetchRow()) {
542
	
543
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
544
	$section_id = $result['section_id'];
545

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

    
571
}
572

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

    
587
//******************************************************************************
588
//End of upgrade script for the news modul
589
//******************************************************************************
590

    
591

    
592

    
593

    
594
echo "<br /><br />Done<br />";
595

    
596
?>
597

    
598
</body>
599
</html>
(4-4/4)