Project

General

Profile

1
<?php
2

    
3
// $Id: modify.php 310 2006-02-19 05:31:10Z ryan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2006, 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
// Get page id
27
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
28
	header("Location: index.php");
29
	exit(0);
30
} else {
31
	$page_id = $_GET['page_id'];
32
}
33

    
34
// Create new admin object
35
require('../../config.php');
36
require_once(WB_PATH.'/framework/class.admin.php');
37
$admin = new admin('Pages', 'pages_modify');
38

    
39
// Get perms
40
$database = new database();
41
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
42
$results_array = $results->fetchRow();
43
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
44
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
45
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
46
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
47
}
48

    
49
// Get page details
50
$database = new database();
51
$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
52
$results = $database->query($query);
53
if($database->is_error()) {
54
	$admin->print_header();
55
	$admin->print_error($database->get_error());
56
}
57
if($results->numRows() == 0) {
58
	$admin->print_header();
59
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
60
}
61
$results_array = $results->fetchRow();
62

    
63
// Get display name of person who last modified the page
64
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '".$results_array['modified_by']."'";
65
$get_user = $database->query($query_user);
66
if($get_user->numRows() != 0) {
67
	$user = $get_user->fetchRow();
68
} else {
69
	$user['display_name'] = 'Unknown';
70
	$user['username'] = 'unknown';
71
}
72
// Convert the unix ts for modified_when to human a readable form
73
if($results_array['modified_when'] != 0) {
74
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
75
} else {
76
	$modified_ts = 'Unknown';
77
}
78

    
79
// Include page info script
80
$template = new Template(ADMIN_PATH.'/pages');
81
$template->set_file('page', 'modify.html');
82
$template->set_block('page', 'main_block', 'main');
83
$template->set_var(array(
84
								'PAGE_ID' => $results_array['page_id'],
85
								'PAGE_TITLE' => ($results_array['page_title']),
86
								'MODIFIED_BY' => $user['display_name'],
87
								'MODIFIED_BY_USERNAME' => $user['username'],
88
								'MODIFIED_WHEN' => $modified_ts,
89
								'ADMIN_URL' => ADMIN_URL
90
								)
91
						);
92
if($modified_ts == 'Unknown') {
93
	$template->set_var('DISPLAY_MODIFIED', 'hide');
94
} else {
95
	$template->set_var('DISPLAY_MODIFIED', '');
96
}
97

    
98
// Work-out if we should show the "manage sections" link
99
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
100
if($query_sections->numRows() > 0) {
101
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
102
} elseif(MANAGE_SECTIONS == 'enabled') {
103
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
104
} else {
105
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
106
}
107

    
108
// Insert language TEXT
109
$template->set_var(array(
110
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
111
								'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
112
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
113
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
114
								)
115
						);
116

    
117
// Parse and print header template
118
$template->parse('main', 'main_block', false);
119
$template->pparse('output', 'page');
120

    
121
// Get sections for this page
122
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
123
if($query_sections->numRows() > 0) {
124
	while($section = $query_sections->fetchRow()) {
125
		$section_id = $section['section_id'];
126
		$module = $section['module'];
127
		// Include the modules editing script if it exists
128
		if(file_exists(WB_PATH.'/modules/'.$module.'/modify.php')) {
129
			echo '<a name="'.$section_id.'"></a>';
130
			require(WB_PATH.'/modules/'.$module.'/modify.php');
131
		}
132
	}
133
}
134

    
135
// Print admin footer
136
$admin->print_footer();
137

    
138
?>
(8-8/19)