| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        admin
 | 
  
    | 5 |  * @package         pages
 | 
  
    | 6 |  * @author          WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2004-2009, Ryan Djurovich
 | 
  
    | 8 |  * @copyright       2009-2011, 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: settings2.php 1457 2011-06-25 17:18:50Z Luisehahne $
 | 
  
    | 14 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings2.php $
 | 
  
    | 15 |  * @lastmodified    $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
 | 
  
    | 16 |  *
 | 
  
    | 17 |  */
 | 
  
    | 18 | /* */
 | 
  
    | 19 | 
 | 
  
    | 20 | // Create new admin object and print admin header
 | 
  
    | 21 | require('../../config.php');
 | 
  
    | 22 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 23 | 
 | 
  
    | 24 | // suppress to print the header, so no new FTAN will be set
 | 
  
    | 25 | $admin = new admin('Pages', 'pages_settings',false);
 | 
  
    | 26 | 
 | 
  
    | 27 | // Get page id
 | 
  
    | 28 | if(!isset($_POST['page_id']) || !is_numeric($_POST['page_id']))
 | 
  
    | 29 | {
 | 
  
    | 30 | 	header("Location: index.php");
 | 
  
    | 31 | 	exit(0);
 | 
  
    | 32 | } else {
 | 
  
    | 33 | 	$page_id = (int)$_POST['page_id'];
 | 
  
    | 34 | }
 | 
  
    | 35 | 
 | 
  
    | 36 | /*
 | 
  
    | 37 | if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
 | 
  
    | 38 | {
 | 
  
    | 39 | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 | 
  
    | 40 | }
 | 
  
    | 41 | */
 | 
  
    | 42 | $pagetree_url = ADMIN_URL.'/pages/index.php';
 | 
  
    | 43 | $target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
 | 
  
    | 44 | 
 | 
  
    | 45 | if (!$admin->checkFTAN())
 | 
  
    | 46 | {
 | 
  
    | 47 | 	$admin->print_header();
 | 
  
    | 48 | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$target_url);
 | 
  
    | 49 | }
 | 
  
    | 50 | // After check print the header
 | 
  
    | 51 | $admin->print_header();
 | 
  
    | 52 | 
 | 
  
    | 53 | // Include the WB functions file
 | 
  
    | 54 | require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 55 | 
 | 
  
    | 56 | // Get values
 | 
  
    | 57 | $page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
 | 
  
    | 58 | $menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
 | 
  
    | 59 | $page_code = (int) $admin->get_post_escaped('page_code');
 | 
  
    | 60 | $description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
 | 
  
    | 61 | $keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
 | 
  
    | 62 | $parent = (int) $admin->get_post_escaped('parent'); // fix secunia 2010-91-3
 | 
  
    | 63 | $visibility = $admin->get_post_escaped('visibility');
 | 
  
    | 64 | if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
 | 
  
    | 65 | $template = preg_replace("/\W/", "", $admin->get_post_escaped('template')); // fix secunia 2010-93-3
 | 
  
    | 66 | $target = preg_replace("/\W/", "", $admin->get_post_escaped('target'));
 | 
  
    | 67 | $admin_groups = $admin->get_post_escaped('admin_groups');
 | 
  
    | 68 | $viewing_groups = $admin->get_post_escaped('viewing_groups');
 | 
  
    | 69 | $searching = (int) $admin->get_post_escaped('searching');
 | 
  
    | 70 | $language = strtoupper($admin->get_post('language'));
 | 
  
    | 71 | $language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
 | 
  
    | 72 | $menu = (int) $admin->get_post_escaped('menu'); // fix secunia 2010-91-3
 | 
  
    | 73 | 
 | 
  
    | 74 | // Validate data
 | 
  
    | 75 | if($page_title == '' || substr($page_title,0,1)=='.')
 | 
  
    | 76 | {
 | 
  
    | 77 | 	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
 | 
  
    | 78 | }
 | 
  
    | 79 | if($menu_title == '' || substr($menu_title,0,1)=='.')
 | 
  
    | 80 | {
 | 
  
    | 81 | 	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
 | 
  
    | 82 | }
 | 
  
    | 83 | 
 | 
  
    | 84 | // Get existing perms
 | 
  
    | 85 | // $database = new database();
 | 
  
    | 86 | 
 | 
  
    | 87 | $sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
 | 
  
    | 88 | $results = $database->query($sql);
 | 
  
    | 89 | 
 | 
  
    | 90 | $results_array = $results->fetchRow();
 | 
  
    | 91 | $old_parent = $results_array['parent'];
 | 
  
    | 92 | $old_link = $results_array['link'];
 | 
  
    | 93 | $old_position = $results_array['position'];
 | 
  
    | 94 | $old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
 | 
  
    | 95 | $old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
 | 
  
    | 96 | 
 | 
  
    | 97 | // Work-out if we should check for existing page_code
 | 
  
    | 98 | $field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
 | 
  
    | 99 | 
 | 
  
    | 100 | $in_old_group = FALSE;
 | 
  
    | 101 | foreach($admin->get_groups_id() as $cur_gid)
 | 
  
    | 102 | {
 | 
  
    | 103 |     if (in_array($cur_gid, $old_admin_groups))
 | 
  
    | 104 |     {
 | 
  
    | 105 | 	$in_old_group = TRUE;
 | 
  
    | 106 |     }
 | 
  
    | 107 | }
 | 
  
    | 108 | if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
 | 
  
    | 109 | {
 | 
  
    | 110 | 	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 | 
  
    | 111 | }
 | 
  
    | 112 | 
 | 
  
    | 113 | // Setup admin groups
 | 
  
    | 114 | $admin_groups[] = 1;
 | 
  
    | 115 | //if(!in_array(1, $admin->get_groups_id())) {
 | 
  
    | 116 | //	$admin_groups[] = implode(",",$admin->get_groups_id());
 | 
  
    | 117 | //}
 | 
  
    | 118 | $admin_groups = preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
 | 
  
    | 119 | // Setup viewing groups
 | 
  
    | 120 | $viewing_groups[] = 1;
 | 
  
    | 121 | //if(!in_array(1, $admin->get_groups_id())) {
 | 
  
    | 122 | //	$viewing_groups[] = implode(",",$admin->get_groups_id());
 | 
  
    | 123 | //}
 | 
  
    | 124 | $viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
 | 
  
    | 125 | 
 | 
  
    | 126 | // If needed, get new order
 | 
  
    | 127 | if($parent != $old_parent)
 | 
  
    | 128 | {
 | 
  
    | 129 | 	// Include ordering class
 | 
  
    | 130 | 	require(WB_PATH.'/framework/class.order.php');
 | 
  
    | 131 | 	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
 | 
  
    | 132 | 	// Get new order
 | 
  
    | 133 | 	$position = $order->get_new($parent);
 | 
  
    | 134 | 	// Clean new order
 | 
  
    | 135 | 	$order->clean($parent);
 | 
  
    | 136 | } else {
 | 
  
    | 137 | 	$position = $old_position;
 | 
  
    | 138 | }
 | 
  
    | 139 | 
 | 
  
    | 140 | // Work out level and root parent
 | 
  
    | 141 | if ($parent!='0')
 | 
  
    | 142 | {
 | 
  
    | 143 | 	$level = level_count($parent)+1;
 | 
  
    | 144 | 	$root_parent = root_parent($parent);
 | 
  
    | 145 | }
 | 
  
    | 146 | else {
 | 
  
    | 147 | 	$level = '0';
 | 
  
    | 148 | 	$root_parent = '0';
 | 
  
    | 149 | }
 | 
  
    | 150 | 
 | 
  
    | 151 | // Work-out what the link should be
 | 
  
    | 152 | if($parent == '0')
 | 
  
    | 153 | {
 | 
  
    | 154 | 	$link = '/'.page_filename($menu_title);
 | 
  
    | 155 | 	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
 | 
  
    | 156 | 	if($link == '/index' || $link == '/intro')
 | 
  
    | 157 |     {
 | 
  
    | 158 | 		$link .= '_' .$page_id;
 | 
  
    | 159 | 		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
 | 
  
    | 160 | 	} else {
 | 
  
    | 161 | 		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
 | 
  
    | 162 | 	}
 | 
  
    | 163 | } else {
 | 
  
    | 164 | 	$parent_section = '';
 | 
  
    | 165 | 	$parent_titles = array_reverse(get_parent_titles($parent));
 | 
  
    | 166 | 	foreach($parent_titles AS $parent_title)
 | 
  
    | 167 |     {
 | 
  
    | 168 | 		$parent_section .= page_filename($parent_title).'/';
 | 
  
    | 169 | 	}
 | 
  
    | 170 | 	if($parent_section == '/')
 | 
  
    | 171 |     {
 | 
  
    | 172 |       $parent_section = '';
 | 
  
    | 173 |     }
 | 
  
    | 174 | 	$link = '/'.$parent_section.page_filename($menu_title);
 | 
  
    | 175 | 	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
 | 
  
    | 176 | }
 | 
  
    | 177 | 
 | 
  
    | 178 | // Check if a page with same page filename exists
 | 
  
    | 179 | // $database = new database();
 | 
  
    | 180 | $sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
 | 
  
    | 181 | $get_same_page = $database->query($sql);
 | 
  
    | 182 | 
 | 
  
    | 183 | if($get_same_page->numRows() > 0)
 | 
  
    | 184 | {
 | 
  
    | 185 | 	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
 | 
  
    | 186 | }
 | 
  
    | 187 | 
 | 
  
    | 188 | // Update page with new order
 | 
  
    | 189 | $sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
 | 
  
    | 190 | // $database = new database();
 | 
  
    | 191 | $database->query($sql);
 | 
  
    | 192 | 
 | 
  
    | 193 | // Get page trail
 | 
  
    | 194 | $page_trail = get_page_trail($page_id);
 | 
  
    | 195 | 
 | 
  
    | 196 | // Update page settings in the pages table
 | 
  
    | 197 | $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
 | 
  
    | 198 | $sql .= '`parent` = '.$parent.', ';
 | 
  
    | 199 | $sql .= '`page_title` = "'.$page_title.'", ';
 | 
  
    | 200 | $sql .= '`menu_title` = "'.$menu_title.'", ';
 | 
  
    | 201 | $sql .= '`menu` = '.$menu.', ';
 | 
  
    | 202 | $sql .= '`level` = '.$level.', ';
 | 
  
    | 203 | $sql .= '`page_trail` = "'.$page_trail.'", ';
 | 
  
    | 204 | $sql .= '`root_parent` = '.$root_parent.', ';
 | 
  
    | 205 | $sql .= '`link` = "'.$link.'", ';
 | 
  
    | 206 | $sql .= '`template` = "'.$template.'", ';
 | 
  
    | 207 | $sql .= '`target` = "'.$target.'", ';
 | 
  
    | 208 | $sql .= '`description` = "'.$description.'", ';
 | 
  
    | 209 | $sql .= '`keywords` = "'.$keywords.'", ';
 | 
  
    | 210 | $sql .= '`position` = '.$position.', ';
 | 
  
    | 211 | $sql .= '`visibility` = "'.$visibility.'", ';
 | 
  
    | 212 | $sql .= '`searching` = '.$searching.', ';
 | 
  
    | 213 | $sql .= '`language` = "'.$language.'", ';
 | 
  
    | 214 | $sql .= '`admin_groups` = "'.$admin_groups.'", ';
 | 
  
    | 215 | $sql .= '`viewing_groups` = "'.$viewing_groups.'"';
 | 
  
    | 216 | $sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.(int)$page_code.' ' : ' ';
 | 
  
    | 217 | $sql .= 'WHERE `page_id` = '.$page_id;
 | 
  
    | 218 | $database->query($sql);
 | 
  
    | 219 | 
 | 
  
    | 220 | $target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
 | 
  
    | 221 | if($database->is_error())
 | 
  
    | 222 | {
 | 
  
    | 223 | 	$admin->print_error($database->get_error(), $target_url );
 | 
  
    | 224 | }
 | 
  
    | 225 | // Clean old order if needed
 | 
  
    | 226 | if($parent != $old_parent)
 | 
  
    | 227 | {
 | 
  
    | 228 | 	$order->clean($old_parent);
 | 
  
    | 229 | }
 | 
  
    | 230 | 
 | 
  
    | 231 | /* BEGIN page "access file" code */
 | 
  
    | 232 | 
 | 
  
    | 233 | // Create a new file in the /pages dir if title changed
 | 
  
    | 234 | if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
 | 
  
    | 235 | {
 | 
  
    | 236 | 	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
 | 
  
    | 237 | } else {
 | 
  
    | 238 |     $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
 | 
  
    | 239 | 	// First check if we need to create a new file
 | 
  
    | 240 | 	if(($old_link != $link) || (!file_exists($old_filename)))
 | 
  
    | 241 |     {
 | 
  
    | 242 | 		// Delete old file
 | 
  
    | 243 | 		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
 | 
  
    | 244 | 		if(file_exists($old_filename))
 | 
  
    | 245 |         {
 | 
  
    | 246 | 			unlink($old_filename);
 | 
  
    | 247 | 		}
 | 
  
    | 248 | 		// Create access file
 | 
  
    | 249 | 		create_access_file($filename,$page_id,$level);
 | 
  
    | 250 | 		// Move a directory for this page
 | 
  
    | 251 | 		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
 | 
  
    | 252 |         {
 | 
  
    | 253 | 			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
 | 
  
    | 254 | 		}
 | 
  
    | 255 | 		// Update any pages that had the old link with the new one
 | 
  
    | 256 | 		$old_link_len = strlen($old_link);
 | 
  
    | 257 |         $sql = '';
 | 
  
    | 258 | 		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
 | 
  
    | 259 | 
 | 
  
    | 260 | 		if($query_subs->numRows() > 0)
 | 
  
    | 261 |         {
 | 
  
    | 262 | 			while($sub = $query_subs->fetchRow())
 | 
  
    | 263 |             {
 | 
  
    | 264 | 				// Double-check to see if it contains old link
 | 
  
    | 265 | 				if(substr($sub['link'], 0, $old_link_len) == $old_link)
 | 
  
    | 266 |                 {
 | 
  
    | 267 | 					// Get new link
 | 
  
    | 268 | 					$replace_this = $old_link;
 | 
  
    | 269 | 					$old_sub_link_len =strlen($sub['link']);
 | 
  
    | 270 | 					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
 | 
  
    | 271 | 					// Work out level
 | 
  
    | 272 | 					$new_sub_level = level_count($sub['page_id']);
 | 
  
    | 273 | 					// Update level and link
 | 
  
    | 274 | 					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
 | 
  
    | 275 | 					// Re-write the access file for this page
 | 
  
    | 276 | 					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
 | 
  
    | 277 | 					if(file_exists($old_subpage_file))
 | 
  
    | 278 |                     {
 | 
  
    | 279 | 						unlink($old_subpage_file);
 | 
  
    | 280 | 					}
 | 
  
    | 281 | 					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
 | 
  
    | 282 | 				}
 | 
  
    | 283 | 			}
 | 
  
    | 284 | 		}
 | 
  
    | 285 | 	}
 | 
  
    | 286 | }
 | 
  
    | 287 | 
 | 
  
    | 288 | // Function to fix page trail of subs
 | 
  
    | 289 | function fix_page_trail($parent,$root_parent)
 | 
  
    | 290 | {
 | 
  
    | 291 | 	// Get objects and vars from outside this function
 | 
  
    | 292 | 	global $admin, $template, $database, $TEXT, $MESSAGE;
 | 
  
    | 293 | 	// Get page list from database
 | 
  
    | 294 | 	// $database = new database();
 | 
  
    | 295 | 	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
 | 
  
    | 296 | 	$get_pages = $database->query($query);
 | 
  
    | 297 | 	// Insert values into main page list
 | 
  
    | 298 | 	if($get_pages->numRows() > 0)
 | 
  
    | 299 |     {
 | 
  
    | 300 | 		while($page = $get_pages->fetchRow())
 | 
  
    | 301 |         {
 | 
  
    | 302 | 			// Fix page trail
 | 
  
    | 303 | 
 | 
  
    | 304 | 			$database->query("UPDATE ".TABLE_PREFIX."pages SET ".($root_parent != 0 ?"root_parent = '$root_parent', ":"")." page_trail = '".get_page_trail($page['page_id'])."' WHERE page_id = '".$page['page_id']."'");
 | 
  
    | 305 | 			// Run this query on subs
 | 
  
    | 306 | 			fix_page_trail($page['page_id'],$root_parent);
 | 
  
    | 307 | 		}
 | 
  
    | 308 | 	}
 | 
  
    | 309 | }
 | 
  
    | 310 | 
 | 
  
    | 311 | // Fix sub-pages page trail
 | 
  
    | 312 | fix_page_trail($page_id,$root_parent);
 | 
  
    | 313 | 
 | 
  
    | 314 | /* END page "access file" code */
 | 
  
    | 315 | 
 | 
  
    | 316 | //$pagetree_url = ADMIN_URL.'/pages/index.php';
 | 
  
    | 317 | //$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
 | 
  
    | 318 | // Check if there is a db error, otherwise say successful
 | 
  
    | 319 | if($database->is_error())
 | 
  
    | 320 | {
 | 
  
    | 321 | 	$admin->print_error($database->get_error(), $target_url );
 | 
  
    | 322 | } else {
 | 
  
    | 323 | 	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
 | 
  
    | 324 | }
 | 
  
    | 325 | 
 | 
  
    | 326 | // Print admin footer
 | 
  
    | 327 | $admin->print_footer();
 | 
  
    | 328 | 
 | 
  
    | 329 | ?>
 |