| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        admin
 | 
  
    | 5 |  * @package         pages
 | 
  
    | 6 |  * @author          Ryan Djurovich, 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: sections.php 1758 2012-09-16 08:46:13Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/sections.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2012-09-16 10:46:13 +0200 (Sun, 16 Sep 2012) $
 | 
  
    | 15 |  *
 | 
  
    | 16 |  */
 | 
  
    | 17 | 
 | 
  
    | 18 | // Include config file
 | 
  
    | 19 | require('../../config.php');
 | 
  
    | 20 | 
 | 
  
    | 21 | // Make sure people are allowed to access this page
 | 
  
    | 22 | if(MANAGE_SECTIONS != 'enabled')
 | 
  
    | 23 | {
 | 
  
    | 24 | 	header('Location: '.ADMIN_URL.'/pages/index.php');
 | 
  
    | 25 | 	exit(0);
 | 
  
    | 26 | }
 | 
  
    | 27 | /* */
 | 
  
    | 28 | $debug = false; // to show position and section_id
 | 
  
    | 29 | If(!defined('DEBUG')) { define('DEBUG',$debug);}
 | 
  
    | 30 | // Include the WB functions file
 | 
  
    | 31 | require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 32 | // Create new admin object
 | 
  
    | 33 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 34 | $admin = new admin('Pages', 'pages_view', false);
 | 
  
    | 35 | 
 | 
  
    | 36 | $action = 'show';
 | 
  
    | 37 | // Get page id
 | 
  
    | 38 | $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
 | 
  
    | 39 | $page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
 | 
  
    | 40 | $action = ($page_id ? 'show' : $action);
 | 
  
    | 41 | // Get section id if there is one
 | 
  
    | 42 | $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
 | 
  
    | 43 | $section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
 | 
  
    | 44 | $action = ($section_id ? 'delete' : $action);
 | 
  
    | 45 | // Get module if there is one
 | 
  
    | 46 | $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
 | 
  
    | 47 | $module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
 | 
  
    | 48 | $action = ($module != '' ? 'add' : $action);
 | 
  
    | 49 | $admin_header = true;
 | 
  
    | 50 | $backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
 | 
  
    | 51 | 
 | 
  
    | 52 | switch ($action):
 | 
  
    | 53 | 	case 'delete' :
 | 
  
    | 54 |         if($admin->get_permission('pages_delete') == false)
 | 
  
    | 55 |         {
 | 
  
    | 56 | 			$admin->print_header();
 | 
  
    | 57 | 			$admin->print_error($module.' '.strtolower($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']),$backlink);
 | 
  
    | 58 |         }
 | 
  
    | 59 | 
 | 
  
    | 60 | 		if( ( !($section_id = intval($admin->checkIDKEY('section_id', 0, $_SERVER['REQUEST_METHOD'])) )) )
 | 
  
    | 61 | 		{
 | 
  
    | 62 | 			if($admin_header) { $admin->print_header(); }
 | 
  
    | 63 | 			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
 | 
  
    | 64 | 		}
 | 
  
    | 65 | 
 | 
  
    | 66 | 		$action = 'show';
 | 
  
    | 67 | 	    $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 68 | 	    $sql .= 'WHERE `section_id` ='.$section_id;
 | 
  
    | 69 |         if( ( ($modulname = $database->get_one($sql)) == $module) && ($section_id > 0 ) ) {
 | 
  
    | 70 | 			// Include the modules delete file if it exists
 | 
  
    | 71 | 			if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
 | 
  
    | 72 | 		    {
 | 
  
    | 73 | 				require(WB_PATH.'/modules/'.$modulname.'/delete.php');
 | 
  
    | 74 | 			}
 | 
  
    | 75 | 		    $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 76 | 		    $sql .= 'WHERE `section_id` ='.(int)$section_id.' LIMIT 1';
 | 
  
    | 77 | 			if( !$database->query($sql) ) {
 | 
  
    | 78 | 				if($admin_header) { $admin->print_header(); }
 | 
  
    | 79 | 				$admin->print_error($database->get_error(),$backlink);
 | 
  
    | 80 | 			}  else {
 | 
  
    | 81 | 				require_once(WB_PATH.'/framework/class.order.php');
 | 
  
    | 82 | 				$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
 | 
  
    | 83 | 				$order->clean($page_id);
 | 
  
    | 84 | 				$format = $TEXT['SECTION'].' %d  %s %s '.strtolower( $TEXT['DELETED']);
 | 
  
    | 85 | 				$message = sprintf ($format,$section_id,strtoupper($modulname),strtolower($TEXT['SUCCESS']));
 | 
  
    | 86 | 				if($admin_header) { $admin->print_header(); }
 | 
  
    | 87 | 				$admin_header = false;
 | 
  
    | 88 | 				unset($_POST);
 | 
  
    | 89 | 				$admin->print_success($message, $backlink );
 | 
  
    | 90 | 			}
 | 
  
    | 91 |         } else {
 | 
  
    | 92 | 			if($admin_header) { $admin->print_header(); }
 | 
  
    | 93 | 			$admin->print_error($module.' '.strtolower($TEXT['NOT_FOUND']),$backlink);
 | 
  
    | 94 |         }
 | 
  
    | 95 | 
 | 
  
    | 96 | 		break;
 | 
  
    | 97 | 	case 'add' :
 | 
  
    | 98 |         if($admin->get_permission('pages_add') == false)
 | 
  
    | 99 |         {
 | 
  
    | 100 | 			$admin->print_header();
 | 
  
    | 101 | 			$admin->print_error($module.' '.strtolower($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']),$backlink);
 | 
  
    | 102 |         }
 | 
  
    | 103 | 		if (!$admin->checkFTAN())
 | 
  
    | 104 | 		{
 | 
  
    | 105 | 			$admin->print_header();
 | 
  
    | 106 | 			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
 | 
  
    | 107 | 		}
 | 
  
    | 108 | 		$action = 'show';
 | 
  
    | 109 | 		$module = preg_replace('/\W/', '', $module );  // fix secunia 2010-91-4
 | 
  
    | 110 | 		require_once(WB_PATH.'/framework/class.order.php');
 | 
  
    | 111 | 		// Get new order
 | 
  
    | 112 | 		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
 | 
  
    | 113 | 		$position = $order->get_new($page_id);
 | 
  
    | 114 | 		// Insert module into DB
 | 
  
    | 115 | 	    $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
 | 
  
    | 116 | 	    $sql .= '`page_id` = '.(int)$page_id.', ';
 | 
  
    | 117 | 	    $sql .= '`module` = \''.$module.'\', ';
 | 
  
    | 118 | 	    $sql .= '`position` = '.(int)$position.', ';
 | 
  
    | 119 | 	    $sql .= '`block` = \'1\', ';
 | 
  
    | 120 |         $sql .= '`publ_start` = \'0\',';
 | 
  
    | 121 |         $sql .= '`publ_end` = \'0\' ';
 | 
  
    | 122 | 
 | 
  
    | 123 |         if($database->query($sql)) {
 | 
  
    | 124 | 			// Get the section id
 | 
  
    | 125 | 			$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
 | 
  
    | 126 | 			// Include the selected modules add file if it exists
 | 
  
    | 127 | 			if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
 | 
  
    | 128 | 		    {
 | 
  
    | 129 | 				require(WB_PATH.'/modules/'.$module.'/add.php');
 | 
  
    | 130 | 			}
 | 
  
    | 131 |         } elseif ($database->is_error())  {
 | 
  
    | 132 | 			if($admin_header) { $admin->print_header(); }
 | 
  
    | 133 | 			$admin->print_error($database->get_error());
 | 
  
    | 134 | 		}
 | 
  
    | 135 | 		break;
 | 
  
    | 136 | 	default:
 | 
  
    | 137 | 		break;
 | 
  
    | 138 | endswitch;
 | 
  
    | 139 | 
 | 
  
    | 140 | switch ($action):
 | 
  
    | 141 | 	default:
 | 
  
    | 142 | 
 | 
  
    | 143 | 		if($admin_header) { $admin->print_header(); }
 | 
  
    | 144 | 		// Get perms
 | 
  
    | 145 | 		$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
 | 
  
    | 146 | 		$sql .= 'WHERE `page_id` = '.$page_id;
 | 
  
    | 147 | 		$results = $database->query($sql);
 | 
  
    | 148 | 
 | 
  
    | 149 | 		$results_array = $results->fetchRow();
 | 
  
    | 150 | 		$old_admin_groups = explode(',', $results_array['admin_groups']);
 | 
  
    | 151 | 		$old_admin_users = explode(',', $results_array['admin_users']);
 | 
  
    | 152 | 		$in_old_group = FALSE;
 | 
  
    | 153 | 		foreach($admin->get_groups_id() as $cur_gid)
 | 
  
    | 154 | 		{
 | 
  
    | 155 | 			if (in_array($cur_gid, $old_admin_groups))
 | 
  
    | 156 | 		    {
 | 
  
    | 157 | 				$in_old_group = TRUE;
 | 
  
    | 158 | 			}
 | 
  
    | 159 | 		}
 | 
  
    | 160 | 		if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
 | 
  
    | 161 | 		{
 | 
  
    | 162 | 			$admin->print_header();
 | 
  
    | 163 | 			$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
 | 
  
    | 164 | 		}
 | 
  
    | 165 | 
 | 
  
    | 166 | 		// Get page details
 | 
  
    | 167 | 		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
 | 
  
    | 168 | 		$sql .= 'WHERE `page_id` = '.$page_id;
 | 
  
    | 169 | 		$results = $database->query($sql);
 | 
  
    | 170 | 
 | 
  
    | 171 | 		if($database->is_error())
 | 
  
    | 172 | 		{
 | 
  
    | 173 | 			// $admin->print_header();
 | 
  
    | 174 | 			$admin->print_error($database->get_error());
 | 
  
    | 175 | 		}
 | 
  
    | 176 | 		if($results->numRows() == 0)
 | 
  
    | 177 | 		{
 | 
  
    | 178 | 			// $admin->print_header();
 | 
  
    | 179 | 			$admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
 | 
  
    | 180 | 		}
 | 
  
    | 181 | 		$results_array = $results->fetchRow();
 | 
  
    | 182 | 
 | 
  
    | 183 | 		// Get display name of person who last modified the page
 | 
  
    | 184 | 			$user=$admin->get_user_details($results_array['modified_by']);
 | 
  
    | 185 | 		// Convert the unix ts for modified_when to human a readable form
 | 
  
    | 186 | 			if($results_array['modified_when'] != 0) {
 | 
  
    | 187 | 				$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
 | 
  
    | 188 | 			} else {
 | 
  
    | 189 | 				$modified_ts = 'Unknown';
 | 
  
    | 190 | 			}
 | 
  
    | 191 | 
 | 
  
    | 192 | 		// Set module permissions
 | 
  
    | 193 | 		$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
 | 
  
    | 194 | 
 | 
  
    | 195 | 		// Unset block var
 | 
  
    | 196 | 		unset($block);
 | 
  
    | 197 | 		// Include template info file (if it exists)
 | 
  
    | 198 | 		if($results_array['template'] != '')
 | 
  
    | 199 | 		{
 | 
  
    | 200 | 			$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
 | 
  
    | 201 | 		} else {
 | 
  
    | 202 | 			$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
 | 
  
    | 203 | 		}
 | 
  
    | 204 | 		if(file_exists($template_location))
 | 
  
    | 205 | 		{
 | 
  
    | 206 | 			require($template_location);
 | 
  
    | 207 | 		}
 | 
  
    | 208 | 		// Check if $menu is set
 | 
  
    | 209 | 		if(!isset($block[1]) || $block[1] == '')
 | 
  
    | 210 | 		{
 | 
  
    | 211 | 			// Make our own menu list
 | 
  
    | 212 | 			$block[1] = $TEXT['MAIN'];
 | 
  
    | 213 | 		}
 | 
  
    | 214 | 
 | 
  
    | 215 | 		/*-- load css files with jquery --*/
 | 
  
    | 216 | 		// include jscalendar-setup
 | 
  
    | 217 | 		$jscal_use_time = true; // whether to use a clock, too
 | 
  
    | 218 | 		require_once(WB_PATH."/include/jscalendar/wb-setup.php");
 | 
  
    | 219 | 
 | 
  
    | 220 | 		// Setup template object, parse vars to it, then parse it
 | 
  
    | 221 | 		// Create new template object
 | 
  
    | 222 | 		$tpl = new Template(dirname($admin->correct_theme_source('pages_sections.htt')));
 | 
  
    | 223 | 		// $template->debug = true;
 | 
  
    | 224 | 		$tpl->set_file('page', 'pages_sections.htt');
 | 
  
    | 225 | 		$tpl->set_block('page', 'main_block', 'main');
 | 
  
    | 226 | 		$tpl->set_block('main_block', 'module_block', 'module_list');
 | 
  
    | 227 | 		$tpl->set_block('main_block', 'section_block', 'section_list');
 | 
  
    | 228 | 		$tpl->set_block('section_block', 'block_block', 'block_list');
 | 
  
    | 229 | 		$tpl->set_block('main_block', 'calendar_block', 'calendar_list');
 | 
  
    | 230 | 		$tpl->set_var('FTAN', $admin->getFTAN());
 | 
  
    | 231 | 
 | 
  
    | 232 | 		// set first defaults and messages
 | 
  
    | 233 | 		$tpl->set_var(array(
 | 
  
    | 234 | 						'PAGE_ID' => $results_array['page_id'],
 | 
  
    | 235 | 						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
 | 
  
    | 236 | 						'PAGE_IDKEY' => $results_array['page_id'],
 | 
  
    | 237 | 						'TEXT_PAGE' => $TEXT['PAGE'],
 | 
  
    | 238 | 						'PAGE_TITLE' => ($results_array['page_title']),
 | 
  
    | 239 | 						'MENU_TITLE' => ($results_array['menu_title']),
 | 
  
    | 240 | 						'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
 | 
  
    | 241 | 						'TEXT_LAST_MODIFIED' => $TEXT['LAST_UPDATED_BY'],
 | 
  
    | 242 | 						'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
 | 
  
    | 243 | 						'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
 | 
  
    | 244 | 						'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
 | 
  
    | 245 | 						'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
 | 
  
    | 246 | 						'TEXT_ID' => 'ID',
 | 
  
    | 247 | 						'TEXT_TYPE' => $TEXT['TYPE'],
 | 
  
    | 248 | 						'TEXT_BLOCK' => $TEXT['BLOCK'],
 | 
  
    | 249 | 						'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
 | 
  
    | 250 | 						'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
 | 
  
    | 251 | 						'TEXT_ACTIONS' => $TEXT['ACTIONS'],
 | 
  
    | 252 | 						'MODIFIED_BY'          => $user['display_name'],
 | 
  
    | 253 | 						'MODIFIED_BY_USERNAME' => $user['username'],
 | 
  
    | 254 | 						'MODIFIED_WHEN'        => $modified_ts,
 | 
  
    | 255 | 						'ADMIN_URL' => ADMIN_URL,
 | 
  
    | 256 | 						'WB_URL' => WB_URL,
 | 
  
    | 257 | 						'THEME_URL' => THEME_URL
 | 
  
    | 258 | 						)
 | 
  
    | 259 | 					);
 | 
  
    | 260 | // check modify page permission
 | 
  
    | 261 | 	if( $admin->get_permission('pages_modify') )
 | 
  
    | 262 | 	{
 | 
  
    | 263 | 		$tpl->set_var(array(
 | 
  
    | 264 | 				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'].'">',
 | 
  
    | 265 | 				'MODIFY_LINK_AFTER' => '</a>',
 | 
  
    | 266 | 				'DISPLAY_MANAGE_MODIFY' => 'link',
 | 
  
    | 267 | 				));
 | 
  
    | 268 | 	} else {
 | 
  
    | 269 | 		$tpl->set_var(array(
 | 
  
    | 270 | 				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
 | 
  
    | 271 | 				'MODIFY_LINK_AFTER' => '</span>',
 | 
  
    | 272 | 				'DISPLAY_MANAGE_MODIFY' => 'link',
 | 
  
    | 273 | 				));
 | 
  
    | 274 | 	}
 | 
  
    | 275 | 
 | 
  
    | 276 | // check settings page permission
 | 
  
    | 277 | 	if( $admin->get_permission('pages_settings') )
 | 
  
    | 278 | 	{
 | 
  
    | 279 | 		$tpl->set_var(array(
 | 
  
    | 280 | 				'SETTINGS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'].'">',
 | 
  
    | 281 | 				'SETTINGS_LINK_AFTER' => '</a>',
 | 
  
    | 282 | 				'DISPLAY_MANAGE_SETTINGS' => 'link',
 | 
  
    | 283 | 				));
 | 
  
    | 284 | 	} else {
 | 
  
    | 285 | 		$tpl->set_var(array(
 | 
  
    | 286 | 				'SETTINGS_LINK_BEFORE' => '<span class="bold grey">',
 | 
  
    | 287 | 				'SETTINGS_LINK_AFTER' => '</span>',
 | 
  
    | 288 | 				'DISPLAY_MANAGE_SECTIONS' => 'link',
 | 
  
    | 289 | 				));
 | 
  
    | 290 | 	}
 | 
  
    | 291 | 
 | 
  
    | 292 | 		// Insert variables
 | 
  
    | 293 | 		$tpl->set_var(array(
 | 
  
    | 294 | 						'PAGE_ID' => $results_array['page_id'],
 | 
  
    | 295 | 						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
 | 
  
    | 296 | 						'PAGE_IDKEY' => $results_array['page_id'],
 | 
  
    | 297 | 						'VAR_PAGE_TITLE' => $results_array['page_title'],
 | 
  
    | 298 | 						'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
 | 
  
    | 299 | 						'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
 | 
  
    | 300 | 						)
 | 
  
    | 301 | 					);
 | 
  
    | 302 | 
 | 
  
    | 303 | 		$sql  = 'SELECT `section_id`,`module`,`position`,`block`,`publ_start`,`publ_end` ';
 | 
  
    | 304 | 		$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 305 | 		$sql .= 'WHERE `page_id` = '.$page_id.' ';
 | 
  
    | 306 | 		$sql .= 'ORDER BY `position` ASC';
 | 
  
    | 307 | 		$query_sections = $database->query($sql);
 | 
  
    | 308 | 
 | 
  
    | 309 | 		if($query_sections->numRows() > 0)
 | 
  
    | 310 | 		{
 | 
  
    | 311 | 			$num_sections = $query_sections->numRows();
 | 
  
    | 312 | 			while($section = $query_sections->fetchRow())
 | 
  
    | 313 | 		    {
 | 
  
    | 314 | 				if(!is_numeric(array_search($section['module'], $module_permissions)))
 | 
  
    | 315 | 		        {
 | 
  
    | 316 | 					// Get the modules real name
 | 
  
    | 317 | 		            $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
 | 
  
    | 318 | 		            $sql .= 'WHERE `directory` = "'.$section['module'].'"';
 | 
  
    | 319 | 		            if(!$database->get_one($sql) || !file_exists(WB_PATH.'/modules/'.$section['module']))
 | 
  
    | 320 | 					{
 | 
  
    | 321 | 						$edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
 | 
  
    | 322 | 					}else
 | 
  
    | 323 | 					{
 | 
  
    | 324 | 						$edit_page = '';
 | 
  
    | 325 | 					}
 | 
  
    | 326 | 					$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : 'section_');
 | 
  
    | 327 | 					$edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
 | 
  
    | 328 | 					$edit_page_1  = ($sec_anchor!='') ? '#'.$sec_anchor.$section['section_id'].'">' : '">';
 | 
  
    | 329 | 					$edit_page_1 .= $section['module'].'</a>';
 | 
  
    | 330 | 					if(SECTION_BLOCKS)
 | 
  
    | 331 | 		            {
 | 
  
    | 332 | 						if($edit_page == '')
 | 
  
    | 333 | 						{
 | 
  
    | 334 | 							if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
 | 
  
    | 335 | 							{
 | 
  
    | 336 | 								$edit_page = $edit_page_0.'&wysiwyg='.$section['section_id'].$edit_page_1;
 | 
  
    | 337 | 							} else {
 | 
  
    | 338 | 								$edit_page = $edit_page_0.$edit_page_1;
 | 
  
    | 339 | 							}
 | 
  
    | 340 | 						}
 | 
  
    | 341 | 						$input_attribute = 'input_normal';
 | 
  
    | 342 | 						$tpl->set_var(array(
 | 
  
    | 343 | 								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
 | 
  
    | 344 | 								'NAME_SIZE' => 300,
 | 
  
    | 345 | 								'INPUT_ATTRIBUTE' => $input_attribute,
 | 
  
    | 346 | 								'VAR_SECTION_ID' => $section['section_id'],
 | 
  
    | 347 | 								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
 | 
  
    | 348 | 								// 'VAR_SECTION_IDKEY' => $section['section_id'],
 | 
  
    | 349 | 								'VAR_POSITION' => $section['position'],
 | 
  
    | 350 | 								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
 | 
  
    | 351 | 								'SELECT' => '',
 | 
  
    | 352 | 								'SET_NONE_DISPLAY_OPTION' => ''
 | 
  
    | 353 | 								)
 | 
  
    | 354 | 							);
 | 
  
    | 355 | 						// Add block options to the section_list
 | 
  
    | 356 | 						$tpl->clear_var('block_list');
 | 
  
    | 357 | 						foreach($block AS $number => $name)
 | 
  
    | 358 | 		                {
 | 
  
    | 359 | 							$tpl->set_var('NAME', htmlentities(strip_tags($name)));
 | 
  
    | 360 | 							$tpl->set_var('VALUE', $number);
 | 
  
    | 361 | 							$tpl->set_var('SIZE', 1);
 | 
  
    | 362 | 							if($section['block'] == $number)
 | 
  
    | 363 | 		                    {
 | 
  
    | 364 | 								$tpl->set_var('SELECTED', ' selected="selected"');
 | 
  
    | 365 | 							} else {
 | 
  
    | 366 | 								$tpl->set_var('SELECTED', '');
 | 
  
    | 367 | 							}
 | 
  
    | 368 | 							$tpl->parse('block_list', 'block_block', true);
 | 
  
    | 369 | 						}
 | 
  
    | 370 | 					} else {
 | 
  
    | 371 | 						if($edit_page == '')
 | 
  
    | 372 | 						{
 | 
  
    | 373 | 							$edit_page = $edit_page_0.'#wb_'.$edit_page_1;
 | 
  
    | 374 | 						}
 | 
  
    | 375 | 						$input_attribute = 'input_normal';
 | 
  
    | 376 | 						$tpl->set_var(array(
 | 
  
    | 377 | 								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:hidden;"',
 | 
  
    | 378 | 								'NAME_SIZE' => 300,
 | 
  
    | 379 | 								'INPUT_ATTRIBUTE' => $input_attribute,
 | 
  
    | 380 | 								'VAR_SECTION_ID' => $section['section_id'],
 | 
  
    | 381 | 								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
 | 
  
    | 382 | 								// 'VAR_SECTION_IDKEY' => $section['section_id'],
 | 
  
    | 383 | 								'VAR_POSITION' => $section['position'],
 | 
  
    | 384 | 								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
 | 
  
    | 385 | 								'NAME' => htmlentities(strip_tags($block[1])),
 | 
  
    | 386 | 								'VALUE' => 1,
 | 
  
    | 387 | 								'SET_NONE_DISPLAY_OPTION' => ''
 | 
  
    | 388 | 								)
 | 
  
    | 389 | 							);
 | 
  
    | 390 | 					}
 | 
  
    | 391 | 					// Insert icon and images
 | 
  
    | 392 | 					$tpl->set_var(array(
 | 
  
    | 393 | 								'CLOCK_16_PNG' => 'clock_16.png',
 | 
  
    | 394 | 								'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
 | 
  
    | 395 | 								'DELETE_16_PNG' => 'delete_16.png'
 | 
  
    | 396 | 								)
 | 
  
    | 397 | 							);
 | 
  
    | 398 | 					// set calendar start values
 | 
  
    | 399 | 					if($section['publ_start']==0)
 | 
  
    | 400 | 		            {
 | 
  
    | 401 | 						$tpl->set_var('VALUE_PUBL_START', '');
 | 
  
    | 402 | 					} else {
 | 
  
    | 403 | 						$tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']));
 | 
  
    | 404 | 					}
 | 
  
    | 405 | 					// set calendar start values
 | 
  
    | 406 | 					if($section['publ_end']==0)
 | 
  
    | 407 | 		            {
 | 
  
    | 408 | 						$tpl->set_var('VALUE_PUBL_END', '');
 | 
  
    | 409 | 					} else {
 | 
  
    | 410 | 						$tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']));
 | 
  
    | 411 | 					}
 | 
  
    | 412 | 					// Insert icons up and down
 | 
  
    | 413 | 					if($section['position'] != 1 )
 | 
  
    | 414 | 		            {
 | 
  
    | 415 | 						$tpl->set_var(
 | 
  
    | 416 | 									'VAR_MOVE_UP_URL',
 | 
  
    | 417 | 									'<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&section_id='.$section['section_id'].'">
 | 
  
    | 418 | 									<img src="'.THEME_URL.'/images/up_16.png" alt="{TEXT_MOVE_UP}" />
 | 
  
    | 419 | 									</a>' );
 | 
  
    | 420 | 					} else {
 | 
  
    | 421 | 						$tpl->set_var(array(
 | 
  
    | 422 | 									'VAR_MOVE_UP_URL' => ''
 | 
  
    | 423 | 									)
 | 
  
    | 424 | 								);
 | 
  
    | 425 | 					}
 | 
  
    | 426 | 					if($section['position'] != $num_sections ) {
 | 
  
    | 427 | 						$tpl->set_var(
 | 
  
    | 428 | 									'VAR_MOVE_DOWN_URL',
 | 
  
    | 429 | 									'<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&section_id='.$section['section_id'].'">
 | 
  
    | 430 | 									<img src="'.THEME_URL.'/images/down_16.png" alt="{TEXT_MOVE_DOWN}" />
 | 
  
    | 431 | 									</a>' );
 | 
  
    | 432 | 					} else {
 | 
  
    | 433 | 						$tpl->set_var(array(
 | 
  
    | 434 | 									'VAR_MOVE_DOWN_URL' => ''
 | 
  
    | 435 | 									)
 | 
  
    | 436 | 								);
 | 
  
    | 437 | 					}
 | 
  
    | 438 | 				} else {
 | 
  
    | 439 | 				  continue;
 | 
  
    | 440 | 				}
 | 
  
    | 441 | 
 | 
  
    | 442 | 					$tpl->set_var(array(
 | 
  
    | 443 | 									'DISPLAY_DEBUG' => ' style="visibility="visible;"',
 | 
  
    | 444 | 									'TEXT_SID' => 'SID',
 | 
  
    | 445 | 									'DEBUG_COLSPAN_SIZE' => 9
 | 
  
    | 446 | 									)
 | 
  
    | 447 | 								);
 | 
  
    | 448 | 				if($debug)
 | 
  
    | 449 | 		        {
 | 
  
    | 450 | 					$tpl->set_var(array(
 | 
  
    | 451 | 									'DISPLAY_DEBUG' => ' style="visibility="visible;"',
 | 
  
    | 452 | 									'TEXT_PID' => 'PID',
 | 
  
    | 453 | 									'TEXT_SID' => 'SID',
 | 
  
    | 454 | 									'POSITION' => $section['position']
 | 
  
    | 455 | 									)
 | 
  
    | 456 | 								);
 | 
  
    | 457 | 				} else {
 | 
  
    | 458 | 					$tpl->set_var(array(
 | 
  
    | 459 | 									'DISPLAY_DEBUG' => ' style="display:none;"',
 | 
  
    | 460 | 									'TEXT_PID' => '',
 | 
  
    | 461 | 									'POSITION' => ''
 | 
  
    | 462 | 									)
 | 
  
    | 463 | 								);
 | 
  
    | 464 | 				}
 | 
  
    | 465 | 				$tpl->parse('section_list', 'section_block', true);
 | 
  
    | 466 | 			}
 | 
  
    | 467 | 		}
 | 
  
    | 468 | 
 | 
  
    | 469 | 		// now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
 | 
  
    | 470 | 		// the loop is simply a copy from above.
 | 
  
    | 471 | 		$sql  = 'SELECT `section_id`,`module` FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 472 | 		$sql .= 'WHERE page_id = '.$page_id.' ';
 | 
  
    | 473 | 		$sql .= 'ORDER BY `position` ASC';
 | 
  
    | 474 | 		$query_sections = $database->query($sql);
 | 
  
    | 475 | 
 | 
  
    | 476 | 		if($query_sections->numRows() > 0)
 | 
  
    | 477 | 		{
 | 
  
    | 478 | 			$num_sections = $query_sections->numRows();
 | 
  
    | 479 | 			while($section = $query_sections->fetchRow())
 | 
  
    | 480 | 		    {
 | 
  
    | 481 | 				// Get the modules real name
 | 
  
    | 482 | 		        $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
 | 
  
    | 483 | 		        $sql .= 'WHERE `directory` = "'.$section['module'].'"';
 | 
  
    | 484 | 		        $module_name = $database->get_one($sql);
 | 
  
    | 485 | 
 | 
  
    | 486 | 				if(!is_numeric(array_search($section['module'], $module_permissions)))
 | 
  
    | 487 | 		        {
 | 
  
    | 488 | 					$tpl->set_var(array(
 | 
  
    | 489 | 								'jscal_ifformat' => $jscal_ifformat,
 | 
  
    | 490 | 								'jscal_firstday' => $jscal_firstday,
 | 
  
    | 491 | 								'jscal_today' => $jscal_today,
 | 
  
    | 492 | 								'start_date' => 'start_date'.$section['section_id'],
 | 
  
    | 493 | 								'end_date' => 'end_date'.$section['section_id'],
 | 
  
    | 494 | 								'trigger_start' => 'trigger_start'.$section['section_id'],
 | 
  
    | 495 | 								'trigger_end' => 'trigger_stop'.$section['section_id']
 | 
  
    | 496 | 								)
 | 
  
    | 497 | 							);
 | 
  
    | 498 | 					if(isset($jscal_use_time) && $jscal_use_time==TRUE) {
 | 
  
    | 499 | 						$tpl->set_var(array(
 | 
  
    | 500 | 								'showsTime' => "true",
 | 
  
    | 501 | 								'timeFormat' => "24"
 | 
  
    | 502 | 								)
 | 
  
    | 503 | 							);
 | 
  
    | 504 | 					}  else {
 | 
  
    | 505 | 						$tpl->set_var(array(
 | 
  
    | 506 | 								'showsTime' => "false",
 | 
  
    | 507 | 								'timeFormat' => "24"
 | 
  
    | 508 | 								)
 | 
  
    | 509 | 							);
 | 
  
    | 510 | 					}
 | 
  
    | 511 | 				}
 | 
  
    | 512 | 				$tpl->parse('calendar_list', 'calendar_block', true);
 | 
  
    | 513 | 			}
 | 
  
    | 514 | 		}
 | 
  
    | 515 | 
 | 
  
    | 516 | 		// Work-out if we should show the "Add Section" form
 | 
  
    | 517 | 		$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 518 | 		$sql .= 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
 | 
  
    | 519 | 		$query_sections = $database->query($sql);
 | 
  
    | 520 | 		if($query_sections->numRows() == 0)
 | 
  
    | 521 | 		{
 | 
  
    | 522 | 			// Modules list
 | 
  
    | 523 | 		    $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` ';
 | 
  
    | 524 | 		    $sql .= 'WHERE `type` = "module" AND `function` = "page" AND `directory` != "menu_link" ';
 | 
  
    | 525 | 		    $sql .= 'ORDER BY `name`';
 | 
  
    | 526 | 		    $result = $database->query($sql);
 | 
  
    | 527 | 		// if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
 | 
  
    | 528 | 
 | 
  
    | 529 | 			if($result->numRows() > 0)
 | 
  
    | 530 | 		    {
 | 
  
    | 531 | 				while ($module = $result->fetchRow())
 | 
  
    | 532 | 		        {
 | 
  
    | 533 | 					// Check if user is allowed to use this module   echo  $module['directory'],'<br />';
 | 
  
    | 534 | 					if(!is_numeric(array_search($module['directory'], $module_permissions)))
 | 
  
    | 535 | 		            {
 | 
  
    | 536 | 						$tpl->set_var('VALUE', $module['directory']);
 | 
  
    | 537 | 						$tpl->set_var('NAME', $module['name']);
 | 
  
    | 538 | 						if($module['directory'] == 'wysiwyg')
 | 
  
    | 539 | 		                {
 | 
  
    | 540 | 							$tpl->set_var('SELECTED', ' selected="selected"');
 | 
  
    | 541 | 						} else {
 | 
  
    | 542 | 							$tpl->set_var('SELECTED', '');
 | 
  
    | 543 | 						}
 | 
  
    | 544 | 						$tpl->parse('module_list', 'module_block', true);
 | 
  
    | 545 | 					} else {
 | 
  
    | 546 | 					  continue;
 | 
  
    | 547 | 					}
 | 
  
    | 548 | 				}
 | 
  
    | 549 | 			}
 | 
  
    | 550 | 		}
 | 
  
    | 551 | 		// Insert language text and messages
 | 
  
    | 552 | 		$tpl->set_var(array(
 | 
  
    | 553 | 							'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
 | 
  
    | 554 | 							'TEXT_ARE_YOU_SURE' => $TEXT['ARE_YOU_SURE'],
 | 
  
    | 555 | 							'TEXT_TYPE' => $TEXT['TYPE'],
 | 
  
    | 556 | 							'TEXT_ADD' => $TEXT['ADD'],
 | 
  
    | 557 | 							'TEXT_SAVE' =>  $TEXT['SAVE'],
 | 
  
    | 558 | 							'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
 | 
  
    | 559 | 							'TEXT_CALENDAR' => $TEXT['CALENDAR'],
 | 
  
    | 560 | 							'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
 | 
  
    | 561 | 							'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
 | 
  
    | 562 | 							'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
 | 
  
    | 563 | 							'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
 | 
  
    | 564 | 							)
 | 
  
    | 565 | 						);
 | 
  
    | 566 | 		$tpl->parse('main', 'main_block', false);
 | 
  
    | 567 | 		$tpl->pparse('output', 'page');
 | 
  
    | 568 | 		// include the required file for Javascript admin
 | 
  
    | 569 | 		if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'))
 | 
  
    | 570 | 		{
 | 
  
    | 571 | 			include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
 | 
  
    | 572 | 		}
 | 
  
    | 573 | 		break;
 | 
  
    | 574 | endswitch;
 | 
  
    | 575 | 
 | 
  
    | 576 | // Print admin footer
 | 
  
    | 577 | $admin->print_footer();
 |