Project

General

Profile

1 1224 Luisehahne
<?php
2
/**
3
 *
4 1269 Luisehahne
 * @category        backend
5
 * @package         modules
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id$
14 1270 Luisehahne
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16 1224 Luisehahne
 *
17 1334 Luisehahne
 */
18 1224 Luisehahne
19
// Stop this file being access directly
20
if(!defined('WB_URL')) {
21
	header('Location: ../index.php');
22
	exit(0);
23
}
24
25
// Get page id
26 1334 Luisehahne
if(isset($_GET['page_id']) && is_numeric($_GET['page_id']))
27
{
28 1224 Luisehahne
	$page_id = $_GET['page_id'];
29 1334 Luisehahne
} elseif(isset($_POST['page_id']) && is_numeric($_POST['page_id']))
30
{
31 1224 Luisehahne
	$page_id = $_POST['page_id'];
32
} else {
33
	header("Location: index.php");
34
	exit(0);
35
}
36
37
// Get section id if there is one
38 1334 Luisehahne
if(isset($_GET['section_id']) && is_numeric($_GET['section_id']))
39
{
40 1224 Luisehahne
	$section_id = $_GET['section_id'];
41 1334 Luisehahne
} elseif(isset($_POST['section_id']) && is_numeric($_POST['section_id']))
42
{
43 1224 Luisehahne
	$section_id = $_POST['section_id'];
44
} else {
45
	// Check if we should redirect the user if there is no section id
46 1334 Luisehahne
	if(!isset($section_required))
47
	{
48 1224 Luisehahne
		$section_id = 0;
49
	} else {
50
		header("Location: $section_required");
51
		exit(0);
52
	}
53
}
54
55
// Create js back link
56
$js_back = 'javascript: history.go(-1);';
57
58
// Create new admin object
59 1334 Luisehahne
include(WB_PATH.'/framework/class.admin.php');
60
// header will be set here, see database->is_error
61 1224 Luisehahne
$admin = new admin('Pages', 'pages_modify');
62
63
// Get perms
64 1334 Luisehahne
// $database = new database();
65
$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
66
$sql .= 'WHERE `page_id` = '.intval($page_id);
67 1224 Luisehahne
68 1334 Luisehahne
$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
74 1224 Luisehahne
$in_group = FALSE;
75 1334 Luisehahne
foreach($admin->get_groups_id() as $cur_gid)
76
{
77
    if (in_array($cur_gid, $old_admin_groups))
78
	{
79 1224 Luisehahne
        $in_group = TRUE;
80
    }
81
}
82 1334 Luisehahne
if((!$in_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
83
{
84 1224 Luisehahne
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
85
}
86
87
// Workout if the developer wants to show the info banner
88 1334 Luisehahne
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 1335 Luisehahne
	if($res_pages->numRows() == 0)
101 1334 Luisehahne
	{
102
		// $admin->print_header();   don't know why
103
		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
104
	} else {
105 1335 Luisehahne
		$rec_pages = $res_pages->fetchRow();
106 1334 Luisehahne
	}
107 1224 Luisehahne
108 1334 Luisehahne
	// Get display name of person who last modified the page
109 1335 Luisehahne
	$user = $admin->get_user_details($rec_pages['modified_by']);
110 1224 Luisehahne
111 1334 Luisehahne
	// Convert the unix ts for modified_when to human a readable form
112 1335 Luisehahne
	if($rec_pages['modified_when'] != 0)
113 1334 Luisehahne
	{
114 1335 Luisehahne
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $rec_pages['modified_when']+TIMEZONE);
115 1334 Luisehahne
	} else {
116
		$modified_ts = 'Unknown';
117
	}
118 1224 Luisehahne
119 1334 Luisehahne
	// 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 1335 Luisehahne
				'PAGE_ID' => $rec_pages['page_id'],
125
				'PAGE_TITLE' => ($rec_pages['page_title']),
126 1334 Luisehahne
				'MODIFIED_BY' => $user['display_name'],
127
				'MODIFIED_BY_USERNAME' => $user['username'],
128
				'MODIFIED_WHEN' => $modified_ts,
129
				'ADMIN_URL' => ADMIN_URL
130
				));
131 1224 Luisehahne
132 1335 Luisehahne
	$template->set_block('main_block', 'show_modify_block', 'show_modify');
133 1334 Luisehahne
	if($modified_ts == 'Unknown')
134
	{
135 1335 Luisehahne
    	$template->set_block('show_modify', '');
136 1334 Luisehahne
		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
137
	} else {
138
		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
139 1335 Luisehahne
    	$template->parse('show_modify', 'show_modify_block', true);
140 1334 Luisehahne
	}
141 1224 Luisehahne
142 1335 Luisehahne
	$template->set_block('main_block', 'show_section_block', 'show_section');
143 1334 Luisehahne
	// Work-out if we should show the "manage sections" link
144
    $sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
145
	$sql .= 'WHERE `page_id` = '.intval($page_id).' AND `module` = "menu_link"';
146
	if( ( $res_sections = $database->query($sql) ) && ($database->is_error() == false ) )
147
	{
148
		if($res_sections->numRows() > 0)
149
		{
150 1335 Luisehahne
			$template->set_block('show_section', '');
151 1334 Luisehahne
			$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
152
		}elseif(MANAGE_SECTIONS == 'enabled')
153
		{
154
			$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
155 1335 Luisehahne
    		$template->parse('show_section', 'show_section_block', true);
156 1334 Luisehahne
		}else {
157 1335 Luisehahne
			$template->set_block('show_section', '');
158 1334 Luisehahne
			$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
159
		}
160
	} else {
161
		$admin->print_error($database->get_error());
162
	}
163 1224 Luisehahne
164 1334 Luisehahne
	// Insert language TEXT
165
	$template->set_var(array(
166
				'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
167
				'TEXT_CHANGE' => $TEXT['CHANGE'],
168
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
169
				'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
170
				'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
171
				));
172 1224 Luisehahne
173 1334 Luisehahne
	// Parse and print header template
174
	$template->parse('main', 'main_block', false);
175
	$template->pparse('output', 'page');
176 1224 Luisehahne
}
177
178
// Work-out if the developer wants us to update the timestamp for when the page was last modified
179 1334 Luisehahne
if(isset($update_when_modified) && $update_when_modified == true)
180
{
181
	$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` ';
182
	$sql .= 'SET `modified_when` = '.time().', ';
183
	$sql .=     '`modified_by`   = '.intval($admin->get_user_id()).' ';
184
	$sql .=     'WHERE page_id   = '.intval($page_id);
185
	$database->query($sql);
186 1224 Luisehahne
}
187
188 4 ryan
?>