Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @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 5.2.2 and higher
13
 * @version         $Id: admin.php 1457 2011-06-25 17:18:50Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/admin.php $
15
 * @lastmodified    $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
16
 *
17
*/
18

    
19
// Stop this file being access directly
20
if(defined('WB_PATH') == false)
21
{
22
	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>');
23
}
24

    
25
// Get page id
26
	$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
27
	$page_id = intval(isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : (isset($page_id) ? intval($page_id) : 0);
28
	if(	($page_id == 0)) {
29
		header("Location: index.php");
30
		exit(0);
31
	}
32

    
33
// Get section id if there is one
34
	$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
35
	$section_id = intval(isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id'] : (isset($section_id) ? intval($section_id) : 0);
36
	if(	($section_id == 0) && isset($section_required)) {
37
		header("Location: $section_required");
38
		exit(0);
39
	}
40
/*
41
// be sure is is numeric
42
$page_id = intval($page_id);
43
$section_id = intval($section_id);
44
*/
45
// Create js back link
46
// $js_back = 'javascript: history.go(-1);';
47
$js_back = ADMIN_URL.'/pages/sections.php?page_id='.$page_id;
48
// Create new admin object, you can set the next variable in your module
49
// to print with or without header, default is with header
50
// it is recommed to set the variable before including the /modules/admin.php
51
$admin_header = (!isset($admin_header)) ? true : $admin_header;
52
require_once(WB_PATH.'/framework/class.admin.php');
53
$admin = new admin('Pages', 'pages_modify',(bool)$admin_header);
54
// Get perms
55
// unset($admin_header);
56

    
57
$page = $admin->get_page_details($page_id,ADMIN_URL.'/pages/index.php' );
58

    
59
$old_admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
60
$old_admin_users = explode(',', str_replace('_', '', $page['admin_users']));
61

    
62
$in_group = false;
63
foreach($admin->get_groups_id() as $cur_gid){
64
    if (in_array($cur_gid, $old_admin_groups)) {
65
        $in_group = true;
66
    }
67
}
68

    
69
if((!$in_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
70
	print $admin->get_group_id().$admin->get_user_id();
71
	// print_r ($old_admin_groups);
72
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
73
}
74

    
75
// some additional security checks:
76
// Check whether the section_id belongs to the page_id at all
77
if ($section_id != 0) {
78
	$section = $admin->get_section_details($section_id,ADMIN_URL.'/pages/index.php');
79
	if (!$admin->get_permission($section['module'], 'module'))
80
	{
81
		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
82
	}
83
}
84

    
85
// Workout if the developer wants to show the info banner
86
if(isset($print_info_banner) && $print_info_banner == true) {
87
	// Get page details already defined
88

    
89
	// Get display name of person who last modified the page
90
	$user = $admin->get_user_details($page['modified_by']);
91

    
92
	// Convert the unix ts for modified_when to human a readable form
93
	if($page['modified_when'] != 0) {
94
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $page['modified_when']+TIMEZONE);
95
	} else {
96
		$modified_ts = 'Unknown';
97
	}
98

    
99
	// Include page info script
100
	$template = new Template(THEME_PATH.'/templates');
101
	$template->set_file('page', 'pages_modify.htt');
102
	$template->set_block('page', 'main_block', 'main');
103
	$template->set_block('main_block', 'section_block', 'section_list');
104
	$template->set_block('section_block', 'block_block', 'block_list');
105
	$template->set_var(array(
106
				'PAGE_ID' => $page['page_id'],
107
				// 'PAGE_IDKEY' => $admin->getIDKEY($page['page_id']),
108
				'PAGE_IDKEY' => $page['page_id'],
109
				'PAGE_TITLE' => ($page['page_title']),
110
				'MENU_TITLE' => ($page['menu_title']),
111
				'ADMIN_URL' => ADMIN_URL,
112
				'WB_URL' => WB_URL,
113
				'THEME_URL' => THEME_URL
114
				));
115

    
116
	$template->set_var(array(
117
				'MODIFIED_BY' => $user['display_name'],
118
				'MODIFIED_BY_USERNAME' => $user['username'],
119
				'MODIFIED_WHEN' => $modified_ts,
120
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
121
				));
122

    
123
	$template->set_block('main_block', 'show_modify_block', 'show_modify');
124
	if($modified_ts == 'Unknown')
125
	{
126
	    $template->set_block('show_modify', '');
127
		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
128

    
129
	} else {
130
		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
131
	    $template->parse('show_modify', 'show_modify_block', true);
132
	}
133

    
134
	// Work-out if we should show the "manage sections" link
135
	$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.(int)$page_id.' ';
136
	$sql .= 'AND `module` = "menu_link"';
137
	$query_sections = $database->query($sql);
138

    
139
	$template->set_block('main_block', 'show_section_block', 'show_section');
140
	if($query_sections->numRows() > 0)
141
	{
142
		$template->set_block('show_section', '');
143
		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
144

    
145
	} elseif(MANAGE_SECTIONS == 'enabled')
146
	{
147

    
148
		$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
149
	    $template->parse('show_section', 'show_section_block', true);
150

    
151
	} else {
152
		$template->set_block('show_section', '');
153
		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
154

    
155
	}
156

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

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

    
170
	if (SECTION_BLOCKS) {
171
		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
172
                 {
173
			$block_name = htmlentities(strip_tags($block[$section['block']]));
174
		} else {
175
			if ($section['block'] == 1)
176
                     {
177
				$block_name = $TEXT['MAIN'];
178
			} else {
179
				$block_name = '#' . (int) $section['block'];
180
			}
181
		}
182

    
183
		$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : '');
184
		print '<div class="section-info" '.$sec_anchor.' ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
185
		print '<b>  Modul: </b>' . $section['module']." ";
186
		print '<b>  ID: </b>' . $section_id."</div>\n";
187
	}
188

    
189
} //
190

    
191
// Work-out if the developer wants us to update the timestamp for when the page was last modified
192
if(isset($update_when_modified) && $update_when_modified == true) {
193
	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".time()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
194
}
(1-1/3)