Project

General

Profile

1
<?php
2

    
3
// $Id: admin.php 286 2006-01-23 21:15:10Z stefan $
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_URL')) {
37
	header('Location: ../index.php');
38
	exit(0);
39
}
40

    
41
// Get page id
42
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
43
	if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) {
44
		if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
45
			if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) {
46
				header("Location: index.php");
47
				exit(0);
48
			} else {
49
				$page_id = $_POST['page_id'];
50
			}
51
		} else {
52
			$page_id = $_GET['page_id'];
53
		}
54
	} else {
55
		$page_id = $_POST['page_id'];
56
	}
57
} else {
58
	$page_id = $_GET['page_id'];
59
}
60

    
61
// Get section id if there is one
62
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
63
	$section_id = $_GET['section_id'];
64
} elseif(isset($_POST['section_id']) AND is_numeric($_POST['section_id'])) {
65
	$section_id = $_POST['section_id'];
66
} else {
67
	// Check if we should redirect the user if there is no section id
68
	if(!isset($section_required)) {
69
		$section_id = 0;
70
	} else {
71
		header("Location: $section_required");
72
		exit(0);
73
	}
74
}
75

    
76
// Create js back link
77
$js_back = 'javascript: history.go(-1);';
78

    
79
// Create new admin object
80
require(WB_PATH.'/framework/class.admin.php');
81
$admin = new admin('Pages', 'pages_modify');
82

    
83
// Get perms
84
$database = new database();
85
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
86
$results_array = $results->fetchRow();
87
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
88
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
89
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
90
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
91
}
92

    
93
// Workout if the developer wants to show the info banner
94
if(isset($print_info_banner) AND $print_info_banner == true) {
95
	
96
// Get page details
97
$database = new database();
98
$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
99
$results = $database->query($query);
100
if($database->is_error()) {
101
	$admin->print_header();
102
	$admin->print_error($database->get_error());
103
}
104
if($results->numRows() == 0) {
105
	$admin->print_header();
106
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
107
}
108
$results_array = $results->fetchRow();
109

    
110
// Get display name of person who last modified the page
111
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '".$results_array['modified_by']."'";
112
$get_user = $database->query($query_user);
113
if($get_user->numRows() != 0) {
114
	$user = $get_user->fetchRow();
115
} else {
116
	$user['display_name'] = 'Unknown';
117
	$user['username'] = 'unknown';
118
}
119
// Convert the unix ts for modified_when to human a readable form
120
if($results_array['modified_when'] != 0) {
121
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
122
} else {
123
	$modified_ts = 'Unknown';
124
}
125

    
126
// Include page info script
127
$template = new Template(ADMIN_PATH.'/pages');
128
$template->set_file('page', 'modify.html');
129
$template->set_block('page', 'main_block', 'main');
130
$template->set_var(array(
131
								'PAGE_ID' => $results_array['page_id'],
132
								'PAGE_TITLE' => ($results_array['page_title']),
133
								'MODIFIED_BY' => $user['display_name'],
134
								'MODIFIED_BY_USERNAME' => $user['username'],
135
								'MODIFIED_WHEN' => $modified_ts,
136
								'ADMIN_URL' => ADMIN_URL
137
								)
138
						);
139
if($modified_ts == 'Unknown') {
140
	$template->set_var('DISPLAY_MODIFIED', 'hide');
141
} else {
142
	$template->set_var('DISPLAY_MODIFIED', '');
143
}
144

    
145
// Work-out if we should show the "manage sections" link
146
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
147
if($query_sections->numRows() > 0) {
148
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
149
} elseif(MANAGE_SECTIONS == 'enabled') {
150
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
151
} else {
152
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
153
}
154

    
155
// Insert language TEXT
156
$template->set_var(array(
157
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
158
								'TEXT_CHANGE' => $TEXT['CHANGE'],
159
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
160
								'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
161
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
162
								)
163
						);
164

    
165
// Parse and print header template
166
$template->parse('main', 'main_block', false);
167
$template->pparse('output', 'page');
168

    
169
}
170

    
171
// Work-out if the developer wants us to update the timestamp for when the page was last modified
172
if(isset($update_when_modified) AND $update_when_modified == true) {
173
	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".mktime()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
174
}
175

    
176
?>
(1-1/2)