Project

General

Profile

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