| 1 | <?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: admin.php 1529 2011-11-25 05:03:32Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/admin.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2011-11-25 06:03:32 +0100 (Fri, 25 Nov 2011) $
 | 
  
    | 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 | // 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 | 		header("Location: index.php");
 | 
  
    | 29 | 		exit(0);
 | 
  
    | 30 | 	}
 | 
  
    | 31 | 
 | 
  
    | 32 | // Get section id if there is one
 | 
  
    | 33 | 	$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 | 	}
 | 
  
    | 39 | /*
 | 
  
    | 40 | // be sure is is numeric
 | 
  
    | 41 | $page_id = intval($page_id);
 | 
  
    | 42 | $section_id = intval($section_id);
 | 
  
    | 43 | */
 | 
  
    | 44 | // Create js back link
 | 
  
    | 45 | // $js_back = 'javascript: history.go(-1);';
 | 
  
    | 46 | $js_back = ADMIN_URL.'/pages/sections.php?page_id='.$page_id;
 | 
  
    | 47 | // 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 | 	// print_r ($old_admin_groups);
 | 
  
    | 71 | 	$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 | 	}
 | 
  
    | 82 | }
 | 
  
    | 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 | 	// Setup template object, parse vars to it, then parse it
 | 
  
    | 99 | 	$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('pages_modify.htt'));
 | 
  
    | 100 | 	// Create new template object
 | 
  
    | 101 | 	$template = new Template($ThemePath);
 | 
  
    | 102 | 	// $template->debug = true;
 | 
  
    | 103 | 	$template->set_file('page', 'pages_modify.htt');
 | 
  
    | 104 | 	$template->set_block('page', 'main_block', 'main');
 | 
  
    | 105 | 	$template->set_block('main_block', 'section_block', 'section_list');
 | 
  
    | 106 | 	$template->set_block('section_block', 'block_block', 'block_list');
 | 
  
    | 107 | 	$template->set_var(array(
 | 
  
    | 108 | 				'PAGE_ID' => $page['page_id'],
 | 
  
    | 109 | 				// 'PAGE_IDKEY' => $admin->getIDKEY($page['page_id']),
 | 
  
    | 110 | 				'PAGE_IDKEY' => $page['page_id'],
 | 
  
    | 111 | 				'PAGE_TITLE' => ($page['page_title']),
 | 
  
    | 112 | 				'MENU_TITLE' => ($page['menu_title']),
 | 
  
    | 113 | 				'ADMIN_URL' => ADMIN_URL,
 | 
  
    | 114 | 				'WB_URL' => WB_URL,
 | 
  
    | 115 | 				'THEME_URL' => THEME_URL
 | 
  
    | 116 | 				));
 | 
  
    | 117 | 
 | 
  
    | 118 | 	$template->set_var(array(
 | 
  
    | 119 | 				'MODIFIED_BY' => $user['display_name'],
 | 
  
    | 120 | 				'MODIFIED_BY_USERNAME' => $user['username'],
 | 
  
    | 121 | 				'MODIFIED_WHEN' => $modified_ts,
 | 
  
    | 122 | 				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
 | 
  
    | 123 | 				));
 | 
  
    | 124 | 
 | 
  
    | 125 | 	$template->set_block('main_block', 'show_modify_block', 'show_modify');
 | 
  
    | 126 | 	if($modified_ts == 'Unknown')
 | 
  
    | 127 | 	{
 | 
  
    | 128 | 	    $template->set_block('show_modify', '');
 | 
  
    | 129 | 		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
 | 
  
    | 130 | 
 | 
  
    | 131 | 	} else {
 | 
  
    | 132 | 		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
 | 
  
    | 133 | 	    $template->parse('show_modify', 'show_modify_block', true);
 | 
  
    | 134 | 	}
 | 
  
    | 135 | 
 | 
  
    | 136 | 	// Work-out if we should show the "manage sections" link
 | 
  
    | 137 | 	$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.(int)$page_id.' ';
 | 
  
    | 138 | 	$sql .= 'AND `module` = "menu_link"';
 | 
  
    | 139 | 	$query_sections = $database->query($sql);
 | 
  
    | 140 | 
 | 
  
    | 141 | 	$template->set_block('main_block', 'show_section_block', 'show_section');
 | 
  
    | 142 | 	if($query_sections->numRows() > 0)
 | 
  
    | 143 | 	{
 | 
  
    | 144 | 		$template->set_block('show_section', '');
 | 
  
    | 145 | 		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
 | 
  
    | 146 | 
 | 
  
    | 147 | 	} elseif(MANAGE_SECTIONS == 'enabled')
 | 
  
    | 148 | 	{
 | 
  
    | 149 | 
 | 
  
    | 150 | 		$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
 | 
  
    | 151 | 	    $template->parse('show_section', 'show_section_block', true);
 | 
  
    | 152 | 
 | 
  
    | 153 | 	} else {
 | 
  
    | 154 | 		$template->set_block('show_section', '');
 | 
  
    | 155 | 		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
 | 
  
    | 156 | 
 | 
  
    | 157 | 	}
 | 
  
    | 158 | 
 | 
  
    | 159 | 	// Insert language TEXT
 | 
  
    | 160 | 	$template->set_var(array(
 | 
  
    | 161 | 					'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
 | 
  
    | 162 | 					'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
 | 
  
    | 163 | 					'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
 | 
  
    | 164 | 					));
 | 
  
    | 165 | 
 | 
  
    | 166 | 	// Parse and print header template
 | 
  
    | 167 | 	$template->parse('main', 'main_block', false);
 | 
  
    | 168 | 	$template->pparse('output', 'page');
 | 
  
    | 169 | 	// unset($print_info_banner);
 | 
  
    | 170 | 	unset($template);
 | 
  
    | 171 | 
 | 
  
    | 172 | 	if (SECTION_BLOCKS) {
 | 
  
    | 173 | 		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
 | 
  
    | 174 |                  {
 | 
  
    | 175 | 			$block_name = htmlentities(strip_tags($block[$section['block']]));
 | 
  
    | 176 | 		} else {
 | 
  
    | 177 | 			if ($section['block'] == 1)
 | 
  
    | 178 |                      {
 | 
  
    | 179 | 				$block_name = $TEXT['MAIN'];
 | 
  
    | 180 | 			} else {
 | 
  
    | 181 | 				$block_name = '#' . (int) $section['block'];
 | 
  
    | 182 | 			}
 | 
  
    | 183 | 		}
 | 
  
    | 184 | 
 | 
  
    | 185 | 		$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : '');
 | 
  
    | 186 | 		print '<div class="section-info" '.$sec_anchor.' ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
 | 
  
    | 187 | 		print '<b>  Modul: </b>' . $section['module']." ";
 | 
  
    | 188 | 		print '<b>  ID: </b>' . $section_id."</div>\n";
 | 
  
    | 189 | 	}
 | 
  
    | 190 | 
 | 
  
    | 191 | } //
 | 
  
    | 192 | 
 | 
  
    | 193 | // Work-out if the developer wants us to update the timestamp for when the page was last modified
 | 
  
    | 194 | if(isset($update_when_modified) && $update_when_modified == true) {
 | 
  
    | 195 | 	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".time()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
 | 
  
    | 196 | }
 |