Project

General

Profile

1 1441 Luisehahne
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         modules
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2010, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
*/
17
18
// Stop this file being access directly
19
if(defined('WB_PATH') == false)
20
{
21
	die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
22
}
23
24 1457 Luisehahne
// Get page id
25
	$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
26
	$page_id = intval(isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : (isset($page_id) ? intval($page_id) : 0);
27
	if(	($page_id == 0)) {
28 1441 Luisehahne
		header("Location: index.php");
29
		exit(0);
30
	}
31
32
// Get section id if there is one
33 1457 Luisehahne
	$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
34
	$section_id = intval(isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id'] : (isset($section_id) ? intval($section_id) : 0);
35
	if(	($section_id == 0) && isset($section_required)) {
36
		header("Location: $section_required");
37
		exit(0);
38 1441 Luisehahne
	}
39 1457 Luisehahne
/*
40 1441 Luisehahne
// be sure is is numeric
41
$page_id = intval($page_id);
42
$section_id = intval($section_id);
43 1457 Luisehahne
*/
44 1441 Luisehahne
// Create js back link
45
// $js_back = 'javascript: history.go(-1);';
46 1457 Luisehahne
$js_back = ADMIN_URL.'/pages/sections.php?page_id='.$page_id;
47 1441 Luisehahne
// Create new admin object, you can set the next variable in your module
48
// to print with or without header, default is with header
49
// it is recommed to set the variable before including the /modules/admin.php
50
$admin_header = (!isset($admin_header)) ? true : $admin_header;
51
require_once(WB_PATH.'/framework/class.admin.php');
52
$admin = new admin('Pages', 'pages_modify',(bool)$admin_header);
53
// Get perms
54
// unset($admin_header);
55
56
$page = $admin->get_page_details($page_id,ADMIN_URL.'/pages/index.php' );
57
58
$old_admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
59
$old_admin_users = explode(',', str_replace('_', '', $page['admin_users']));
60
61
$in_group = false;
62
foreach($admin->get_groups_id() as $cur_gid){
63
    if (in_array($cur_gid, $old_admin_groups)) {
64
        $in_group = true;
65
    }
66
}
67
68
if((!$in_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
69
	print $admin->get_group_id().$admin->get_user_id();
70 1457 Luisehahne
	// print_r ($old_admin_groups);
71 1441 Luisehahne
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
72
}
73
74
// some additional security checks:
75
// Check whether the section_id belongs to the page_id at all
76
if ($section_id != 0) {
77
	$section = $admin->get_section_details($section_id,ADMIN_URL.'/pages/index.php');
78
	if (!$admin->get_permission($section['module'], 'module'))
79
	{
80
		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
81 1457 Luisehahne
	}
82 1441 Luisehahne
}
83
84
// Workout if the developer wants to show the info banner
85
if(isset($print_info_banner) && $print_info_banner == true) {
86
	// Get page details already defined
87
88
	// Get display name of person who last modified the page
89
	$user = $admin->get_user_details($page['modified_by']);
90
91
	// Convert the unix ts for modified_when to human a readable form
92
	if($page['modified_when'] != 0) {
93
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $page['modified_when']+TIMEZONE);
94
	} else {
95
		$modified_ts = 'Unknown';
96
	}
97
98 1529 Luisehahne
	// Setup template object, parse vars to it, then parse it
99
	// Create new template object
100 1625 Luisehahne
	$template = new Template(dirname($admin->correct_theme_source('pages_modify.htt')));
101 1529 Luisehahne
	// $template->debug = true;
102 1441 Luisehahne
	$template->set_file('page', 'pages_modify.htt');
103
	$template->set_block('page', 'main_block', 'main');
104
	$template->set_block('main_block', 'section_block', 'section_list');
105
	$template->set_block('section_block', 'block_block', 'block_list');
106
	$template->set_var(array(
107
				'PAGE_ID' => $page['page_id'],
108
				// 'PAGE_IDKEY' => $admin->getIDKEY($page['page_id']),
109
				'PAGE_IDKEY' => $page['page_id'],
110
				'PAGE_TITLE' => ($page['page_title']),
111
				'MENU_TITLE' => ($page['menu_title']),
112
				'ADMIN_URL' => ADMIN_URL,
113
				'WB_URL' => WB_URL,
114
				'THEME_URL' => THEME_URL
115
				));
116
117
	$template->set_var(array(
118
				'MODIFIED_BY' => $user['display_name'],
119
				'MODIFIED_BY_USERNAME' => $user['username'],
120
				'MODIFIED_WHEN' => $modified_ts,
121
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
122
				));
123
124
	$template->set_block('main_block', 'show_modify_block', 'show_modify');
125
	if($modified_ts == 'Unknown')
126
	{
127
	    $template->set_block('show_modify', '');
128
		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
129
130
	} else {
131
		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
132
	    $template->parse('show_modify', 'show_modify_block', true);
133
	}
134
135
	// Work-out if we should show the "manage sections" link
136
	$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.(int)$page_id.' ';
137
	$sql .= 'AND `module` = "menu_link"';
138
	$query_sections = $database->query($sql);
139
140
	$template->set_block('main_block', 'show_section_block', 'show_section');
141
	if($query_sections->numRows() > 0)
142
	{
143
		$template->set_block('show_section', '');
144
		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
145
146
	} elseif(MANAGE_SECTIONS == 'enabled')
147
	{
148
149
		$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
150
	    $template->parse('show_section', 'show_section_block', true);
151
152
	} else {
153
		$template->set_block('show_section', '');
154
		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
155
156
	}
157
158
	// Insert language TEXT
159
	$template->set_var(array(
160
					'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
161
					'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
162
					'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
163
					));
164
165
	// Parse and print header template
166
	$template->parse('main', 'main_block', false);
167
	$template->pparse('output', 'page');
168
	// unset($print_info_banner);
169
	unset($template);
170
171 1457 Luisehahne
	if (SECTION_BLOCKS) {
172
		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
173
                 {
174
			$block_name = htmlentities(strip_tags($block[$section['block']]));
175
		} else {
176
			if ($section['block'] == 1)
177
                     {
178
				$block_name = $TEXT['MAIN'];
179
			} else {
180
				$block_name = '#' . (int) $section['block'];
181
			}
182
		}
183
184
		$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : '');
185
		print '<div class="section-info" '.$sec_anchor.' ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
186
		print '<b>  Modul: </b>' . $section['module']." ";
187
		print '<b>  ID: </b>' . $section_id."</div>\n";
188
	}
189
190 1441 Luisehahne
} //
191
192
// Work-out if the developer wants us to update the timestamp for when the page was last modified
193
if(isset($update_when_modified) && $update_when_modified == true) {
194
	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".time()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
195
}