Project

General

Profile

1 4 ryan
<?php
2
3 19 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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
28
Admin Wrapper Script
29
30
This script allows modules to be written without the need to copy code
31
from Website Baker Administration to take advantage of the interface.
32
33
*/
34
35
// Stop this file being access directly
36 19 stefan
if(!defined('WB_URL')) {
37
	header('Location: ../index.php');
38
}
39 4 ryan
40
// Get page id
41
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
42
	if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) {
43
		if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
44
			if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) {
45
				header("Location: index.php");
46
			} else {
47
				$page_id = $_POST['page_id'];
48
			}
49
		} else {
50
			$page_id = $_GET['page_id'];
51
		}
52
	} else {
53
		$page_id = $_POST['page_id'];
54
	}
55
} else {
56
	$page_id = $_GET['page_id'];
57
}
58
59
// Get section id if there is one
60
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
61
	$section_id = $_GET['section_id'];
62
} elseif(isset($_POST['section_id']) AND is_numeric($_POST['section_id'])) {
63
	$section_id = $_POST['section_id'];
64
} else {
65
	// Check if we should redirect the user if there is no section id
66
	if(!isset($section_required)) {
67
		$section_id = 0;
68
	} else {
69
		header("Location: $section_required");
70
	}
71
}
72
73
// Create js back link
74
$js_back = 'javascript: history.go(-1);';
75
76
// Create new admin object
77
require(WB_PATH.'/framework/class.admin.php');
78
$admin = new admin('Pages', 'pages_modify');
79
80
// Get perms
81
$database = new database();
82
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
83
$results_array = $results->fetchRow();
84
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
85
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
86
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
87
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
88
}
89
90
// Workout if the developer wants to show the info banner
91
if(isset($print_info_banner) AND $print_info_banner == true) {
92
93
// Get page details
94
$database = new database();
95
$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
96
$results = $database->query($query);
97
if($database->is_error()) {
98
	$admin->print_header();
99
	$admin->print_error($database->get_error());
100
}
101
if($results->numRows() == 0) {
102
	$admin->print_header();
103
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
104
}
105
$results_array = $results->fetchRow();
106
107
// Get display name of person who last modified the page
108
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '".$results_array['modified_by']."'";
109
$get_user = $database->query($query_user);
110
if($get_user->numRows() != 0) {
111
	$user = $get_user->fetchRow();
112
} else {
113
	$user['display_name'] = 'Unknown';
114
	$user['username'] = 'unknown';
115
}
116
// Convert the unix ts for modified_when to human a readable form
117
if($results_array['modified_when'] != 0) {
118
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
119
} else {
120
	$modified_ts = 'Unknown';
121
}
122
123
// Include page info script
124
$template = new Template(ADMIN_PATH.'/pages');
125
$template->set_file('page', 'modify.html');
126
$template->set_block('page', 'main_block', 'main');
127
$template->set_var(array(
128
								'PAGE_ID' => $results_array['page_id'],
129
								'PAGE_TITLE' => stripslashes($results_array['page_title']),
130
								'MODIFIED_BY' => $user['display_name'],
131
								'MODIFIED_BY_USERNAME' => $user['username'],
132
								'MODIFIED_WHEN' => $modified_ts,
133
								'ADMIN_URL' => ADMIN_URL
134
								)
135
						);
136
if($modified_ts == 'Unknown') {
137
	$template->set_var('DISPLAY_MODIFIED', 'hide');
138
} else {
139
	$template->set_var('DISPLAY_MODIFIED', '');
140
}
141
142
// Work-out if we should show the "manage sections" link
143
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
144
if($query_sections->numRows() > 0) {
145
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
146
} elseif(MANAGE_SECTIONS == 'enabled') {
147
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
148
} else {
149
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
150
}
151
152
// Insert language TEXT
153
$template->set_var(array(
154
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
155
								'TEXT_CHANGE' => $TEXT['CHANGE'],
156
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
157
								'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
158
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
159
								)
160
						);
161
162
// Parse and print header template
163
$template->parse('main', 'main_block', false);
164
$template->pparse('output', 'page');
165
166
}
167
168
// Work-out if the developer wants us to update the timestamp for when the page was last modified
169
if(isset($update_when_modified) AND $update_when_modified == true) {
170
	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".mktime()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
171
}
172
173
?>