| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        backend
 | 
  
    | 5 |  * @package         modules
 | 
  
    | 6 |  * @author          WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2009-2012, WebsiteBaker 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 1718 2012-08-29 14:25:15Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/admin.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2012-08-29 16:25:15 +0200 (Wed, 29 Aug 2012) $
 | 
  
    | 15 |  *
 | 
  
    | 16 |  */
 | 
  
    | 17 | 
 | 
  
    | 18 | // Stop this file being access directly
 | 
  
    | 19 | if(defined('WB_PATH') == false)
 | 
  
    | 20 | {
 | 
  
    | 21 | 	die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
 | 
  
    | 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 | 	// Create new template object
 | 
  
    | 100 | 	$template = new Template(dirname($admin->correct_theme_source('pages_modify.htt')),'keep');
 | 
  
    | 101 | 	// $template->debug = true;
 | 
  
    | 102 | 	$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 | 				'TEXT_LAST_MODIFIED' => $TEXT['LAST_UPDATED_BY'],
 | 
  
    | 120 | 				'MODIFIED_BY_USERNAME' => $user['username'],
 | 
  
    | 121 | 				'MODIFIED_WHEN' => $modified_ts,
 | 
  
    | 122 | 				'LAST_MODIFIED' => $MESSAGE['PAGES_LAST_MODIFIED'],
 | 
  
    | 123 | 				'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS']
 | 
  
    | 124 | 			));
 | 
  
    | 125 | 
 | 
  
    | 126 | 	$template->set_block('main_block', 'show_modify_block', 'show_modify');
 | 
  
    | 127 | 	if($modified_ts == 'Unknown')
 | 
  
    | 128 | 	{
 | 
  
    | 129 | 	    $template->set_block('show_modify', '');
 | 
  
    | 130 | 		$template->set_var('CLASS_DISPLAY_MODIFIED', 'hide');
 | 
  
    | 131 | 
 | 
  
    | 132 | 	} else {
 | 
  
    | 133 | 		$template->set_var('CLASS_DISPLAY_MODIFIED', '');
 | 
  
    | 134 | 	    $template->parse('show_modify', 'show_modify_block', true);
 | 
  
    | 135 | 	}
 | 
  
    | 136 | 
 | 
  
    | 137 | 	// Work-out if we should show the "manage sections" link
 | 
  
    | 138 | //	$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.(int)$page_id.' ';
 | 
  
    | 139 | //	$sql .= 'AND `module` = "menu_link"';
 | 
  
    | 140 | //	$query_sections = $database->query($sql);
 | 
  
    | 141 | /*-- workout if we should show the "manage sections" link ------------------------------*/
 | 
  
    | 142 | 	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
 | 
  
    | 143 | 	     . 'WHERE `page_id`='.$page_id.' AND `module`=\'menu_link\'';
 | 
  
    | 144 | 	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
 | 
  
    | 145 | //	if(!$bIsMenuLink && (MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
 | 
  
    | 146 | 	if((MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
 | 
  
    | 147 | 	{
 | 
  
    | 148 | 		$template->set_var(array(
 | 
  
    | 149 | 				'SECTIONS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/sections.php?page_id='.$page['page_id'].'">',
 | 
  
    | 150 | 				'SECTIONS_LINK_AFTER' => '</a>',
 | 
  
    | 151 | 				'DISPLAY_MANAGE_SECTIONS' => 'link',
 | 
  
    | 152 | 				));
 | 
  
    | 153 | 	}else {
 | 
  
    | 154 | //		$oTpl->set_block('show_manage_sections', '');
 | 
  
    | 155 | 		$template->set_var(array(
 | 
  
    | 156 | 				'SECTIONS_LINK_BEFORE' => '<span class="bold grey">',
 | 
  
    | 157 | 				'SECTIONS_LINK_AFTER' => '</span>',
 | 
  
    | 158 | 				'DISPLAY_MANAGE_SECTIONS' => 'link',
 | 
  
    | 159 | 				));
 | 
  
    | 160 | 	}
 | 
  
    | 161 | 
 | 
  
    | 162 | 	if( $admin->get_permission('pages_settings') )
 | 
  
    | 163 | 	{
 | 
  
    | 164 | 		$template->set_var(array(
 | 
  
    | 165 | 				'SETTINGS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/settings.php?page_id='.$page['page_id'].'">',
 | 
  
    | 166 | 				'SETTINGS_LINK_AFTER' => '</a>',
 | 
  
    | 167 | 				'DISPLAY_MANAGE_SETTINGS' => 'link',
 | 
  
    | 168 | 				));
 | 
  
    | 169 | 	} else {
 | 
  
    | 170 | 		$template->set_var(array(
 | 
  
    | 171 | 				'SETTINGS_LINK_BEFORE' => '<span class="bold grey">',
 | 
  
    | 172 | 				'SETTINGS_LINK_AFTER' => '</span>',
 | 
  
    | 173 | 				'DISPLAY_MANAGE_SECTIONS' => 'link',
 | 
  
    | 174 | 				));
 | 
  
    | 175 | 	}
 | 
  
    | 176 | /*
 | 
  
    | 177 | 	$template->set_block('main_block', 'show_section_block', 'show_section');
 | 
  
    | 178 | 	if($query_sections->numRows() > 0)
 | 
  
    | 179 | 	{
 | 
  
    | 180 | 		$template->set_block('show_section', '');
 | 
  
    | 181 | 		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
 | 
  
    | 182 | 
 | 
  
    | 183 | 	} elseif(MANAGE_SECTIONS == 'enabled')
 | 
  
    | 184 | 	{
 | 
  
    | 185 | 
 | 
  
    | 186 | 		$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
 | 
  
    | 187 | 	    $template->parse('show_section', 'show_section_block', true);
 | 
  
    | 188 | 
 | 
  
    | 189 | 	} else {
 | 
  
    | 190 | 		$template->set_block('show_section', '');
 | 
  
    | 191 | 		$template->set_var('DISPLAY_MANAGE_SECTIONS', 'display:none;');
 | 
  
    | 192 | 
 | 
  
    | 193 | 	}
 | 
  
    | 194 | */
 | 
  
    | 195 | 	// Insert language TEXT
 | 
  
    | 196 | 	$template->set_var(array(
 | 
  
    | 197 | 					'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
 | 
  
    | 198 | 					'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
 | 
  
    | 199 | 					'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
 | 
  
    | 200 | 					));
 | 
  
    | 201 | 
 | 
  
    | 202 | 	// Parse and print header template
 | 
  
    | 203 | 	$template->parse('main', 'main_block', false);
 | 
  
    | 204 | 	$template->pparse('output', 'page');
 | 
  
    | 205 | 	// unset($print_info_banner);
 | 
  
    | 206 | 	unset($template);
 | 
  
    | 207 | 
 | 
  
    | 208 | 	if (SECTION_BLOCKS) {
 | 
  
    | 209 | 		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
 | 
  
    | 210 |                  {
 | 
  
    | 211 | 			$block_name = htmlentities(strip_tags($block[$section['block']]));
 | 
  
    | 212 | 		} else {
 | 
  
    | 213 | 			if ($section['block'] == 1) {
 | 
  
    | 214 | 				$block_name = $TEXT['MAIN'];
 | 
  
    | 215 | 			} else {
 | 
  
    | 216 | 				$block_name = '#' . (int) $section['block'];
 | 
  
    | 217 | 			}
 | 
  
    | 218 | 		}
 | 
  
    | 219 | 
 | 
  
    | 220 | 		$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : '');
 | 
  
    | 221 | 		print '<div class="section-info" ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
 | 
  
    | 222 | 		print '<b>  Modul: </b>' . $section['module']." ";
 | 
  
    | 223 | 		print '<b>  ID: </b><a' . $section_id."></a></div>\n";
 | 
  
    | 224 | 	}
 | 
  
    | 225 | 
 | 
  
    | 226 | } //
 | 
  
    | 227 | 
 | 
  
    | 228 | // Work-out if the developer wants us to update the timestamp for when the page was last modified
 | 
  
    | 229 | if(isset($update_when_modified) && $update_when_modified == true) {
 | 
  
    | 230 | 	$database->query("UPDATE ".TABLE_PREFIX."pages SET modified_when = '".time()."', modified_by = '".$admin->get_user_id()."' WHERE page_id = '$page_id'");
 | 
  
    | 231 | }
 |