Project

General

Profile

« Previous | Next » 

Revision 1334

Added by Dietmar over 14 years ago

Fixed bug in /modules/admin.php

View differences:

admin.php
14 14
 * @filesource		$HeadURL$
15 15
 * @lastmodified    $Date$
16 16
 *
17
*/
17
 */
18 18

  
19 19
// Stop this file being access directly
20 20
if(!defined('WB_URL')) {
......
23 23
}
24 24

  
25 25
// Get page id
26
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id'])) {
26
if(isset($_GET['page_id']) && is_numeric($_GET['page_id']))
27
{
27 28
	$page_id = $_GET['page_id'];
28
} elseif(isset($_POST['page_id']) AND is_numeric($_POST['page_id'])) {
29
} elseif(isset($_POST['page_id']) && is_numeric($_POST['page_id']))
30
{
29 31
	$page_id = $_POST['page_id'];
30 32
} else {
31 33
	header("Location: index.php");
......
33 35
}
34 36

  
35 37
// Get section id if there is one
36
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
38
if(isset($_GET['section_id']) && is_numeric($_GET['section_id']))
39
{
37 40
	$section_id = $_GET['section_id'];
38
} elseif(isset($_POST['section_id']) AND is_numeric($_POST['section_id'])) {
41
} elseif(isset($_POST['section_id']) && is_numeric($_POST['section_id']))
42
{
39 43
	$section_id = $_POST['section_id'];
40 44
} else {
41 45
	// Check if we should redirect the user if there is no section id
42
	if(!isset($section_required)) {
46
	if(!isset($section_required))
47
	{
43 48
		$section_id = 0;
44 49
	} else {
45 50
		header("Location: $section_required");
......
51 56
$js_back = 'javascript: history.go(-1);';
52 57

  
53 58
// Create new admin object
54
require(WB_PATH.'/framework/class.admin.php');
59
include(WB_PATH.'/framework/class.admin.php');
60
// header will be set here, see database->is_error
55 61
$admin = new admin('Pages', 'pages_modify');
56 62

  
57 63
// Get perms
58
$database = new database();
59
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
60
$results_array = $results->fetchRow();
61
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
62
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
64
// $database = new database();
65
$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
66
$sql .= 'WHERE `page_id` = '.intval($page_id);
63 67

  
68
$res_pages = $database->query($sql);
69
$rec_pages = $res_pages->fetchRow();
70

  
71
$old_admin_groups = explode(',', str_replace('_', '', $rec_pages['admin_groups']));
72
$old_admin_users  = explode(',', str_replace('_', '', $rec_pages['admin_users']));
73

  
64 74
$in_group = FALSE;
65
foreach($admin->get_groups_id() as $cur_gid){
66
    if (in_array($cur_gid, $old_admin_groups)) {
75
foreach($admin->get_groups_id() as $cur_gid)
76
{
77
    if (in_array($cur_gid, $old_admin_groups))
78
	{
67 79
        $in_group = TRUE;
68 80
    }
69 81
}
70
if((!$in_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
71
	echo $admin->get_group_id().$admin->get_user_id();
72
	print_r ($old_admin_groups);
82
if((!$in_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
83
{
73 84
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
74 85
}
75 86

  
76 87
// Workout if the developer wants to show the info banner
77
if(isset($print_info_banner) AND $print_info_banner == true) {
78
	
79
// Get page details
80
$database = new database();
81
$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
82
$results = $database->query($query);
83
if($database->is_error()) {
84
	$admin->print_header();
85
	$admin->print_error($database->get_error());
86
}
87
if($results->numRows() == 0) {
88
	$admin->print_header();
89
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
90
}
91
$results_array = $results->fetchRow();
88
if(isset($print_info_banner) && $print_info_banner == true)
89
{
90
	// Get page details
91
	// $database = new database(); not needed
92
	$sql  = 'SELECT `page_id`,`page_title`,`modified_by`,`modified_when` FROM `'.TABLE_PREFIX.'pages` ';
93
	$sql .= 'WHERE `page_id` = '.intval($page_id);
94
	$res_pages = $database->query($sql);
95
	if($database->is_error())
96
	{
97
		// $admin->print_header();  don't know why
98
		$admin->print_error($database->get_error());
99
	}
100
	if($results->numRows() == 0)
101
	{
102
		// $admin->print_header();   don't know why
103
		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
104
	} else {
105
		$res_pages = $results->fetchRow();
106
	}
92 107

  
93
// Get display name of person who last modified the page
94
$user=$admin->get_user_details($results_array['modified_by']);
108
	// Get display name of person who last modified the page
109
	$user = $admin->get_user_details($res_pages['modified_by']);
95 110

  
96
// Convert the unix ts for modified_when to human a readable form
97
if($results_array['modified_when'] != 0) {
98
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
99
} else {
100
	$modified_ts = 'Unknown';
101
}
111
	// Convert the unix ts for modified_when to human a readable form
112
	if($res_pages['modified_when'] != 0)
113
	{
114
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $res_pages['modified_when']+TIMEZONE);
115
	} else {
116
		$modified_ts = 'Unknown';
117
	}
102 118

  
103
// Include page info script
104
$template = new Template(THEME_PATH.'/templates');
105
$template->set_file('page', 'pages_modify.htt');
106
$template->set_block('page', 'main_block', 'main');
107
$template->set_var(array(
108
								'PAGE_ID' => $results_array['page_id'],
109
								'PAGE_TITLE' => ($results_array['page_title']),
110
								'MODIFIED_BY' => $user['display_name'],
111
								'MODIFIED_BY_USERNAME' => $user['username'],
112
								'MODIFIED_WHEN' => $modified_ts,
113
								'ADMIN_URL' => ADMIN_URL
114
								)
115
						);
116
if($modified_ts == 'Unknown') {
117
	$template->set_var('DISPLAY_MODIFIED', 'hide');
118
} else {
119
	$template->set_var('DISPLAY_MODIFIED', '');
120
}
119
	// Include page info script
120
	$template = new Template(THEME_PATH.'/templates');
121
	$template->set_file('page', 'pages_modify.htt');
122
	$template->set_block('page', 'main_block', 'main');
123
	$template->set_var(array(
124
				'PAGE_ID' => $res_pages['page_id'],
125
				'PAGE_TITLE' => ($res_pages['page_title']),
126
				'MODIFIED_BY' => $user['display_name'],
127
				'MODIFIED_BY_USERNAME' => $user['username'],
128
				'MODIFIED_WHEN' => $modified_ts,
129
				'ADMIN_URL' => ADMIN_URL
130
				));
121 131

  
122
// Work-out if we should show the "manage sections" link
123
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
124
if($query_sections->numRows() > 0) {
125
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
126
} elseif(MANAGE_SECTIONS == 'enabled') {
127
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
128
} else {
129
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
130
}
132
	if($modified_ts == 'Unknown')
133
	{
134
		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
135
	} else {
136
		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
137
	}
131 138

  
132
// Insert language TEXT
133
$template->set_var(array(
134
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
135
								'TEXT_CHANGE' => $TEXT['CHANGE'],
136
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
137
								'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
138
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
139
								)
140
						);
139
	// Work-out if we should show the "manage sections" link
140
    $sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
141
	$sql .= 'WHERE `page_id` = '.intval($page_id).' AND `module` = "menu_link"';
142
	if( ( $res_sections = $database->query($sql) ) && ($database->is_error() == false ) )
143
	{
144
		if($res_sections->numRows() > 0)
145
		{
146
			$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
147
		}elseif(MANAGE_SECTIONS == 'enabled')
148
		{
149
			$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
150
		}else {
151
			$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
152
		}
153
	} else {
154
		$admin->print_error($database->get_error());
155
	}
141 156

  
142
// Parse and print header template
143
$template->parse('main', 'main_block', false);
144
$template->pparse('output', 'page');
157
	// Insert language TEXT
158
	$template->set_var(array(
159
				'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
160
				'TEXT_CHANGE' => $TEXT['CHANGE'],
161
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
162
				'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
163
				'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
164
				));
145 165

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

  
148 171
// Work-out if the developer wants us to update the timestamp for when the page was last modified
149
if(isset($update_when_modified) AND $update_when_modified == true) {
150
	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".time()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
172
if(isset($update_when_modified) && $update_when_modified == true)
173
{
174
	$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` ';
175
	$sql .= 'SET `modified_when` = '.time().', ';
176
	$sql .=     '`modified_by`   = '.intval($admin->get_user_id()).' ';
177
	$sql .=     'WHERE page_id   = '.intval($page_id);
178
	$database->query($sql);
151 179
}
152 180

  
153 181
?>

Also available in: Unified diff