ruạṛ
<?php /** * process page ordering * @version 0.9 * @author Robert Urquhart <programmer@activatedesign.co.nz> * @package WEP-CMS * @todo to bring this up to version 0.10 use {page} and {page}->load sub_pages() * instead of build_page_tree() */ require_once $_SERVER['DOCUMENT_ROOT'].'/admin/scripts-includes/universal.php'; session_start(); $conn_ID = connect_to_db(); //print_r($_POST); if(!is_array($_POST['page'])) { die('Invalid page array'); exit; } $message = ''; $pages = array(); $tree = build_page_tree(); //print_r($tree); assign_positions($tree); //recursive function function assign_positions($tree = array()) { global $pages, $message; $sort = array(); //$i = 0; // on first run forcing different numbers foreach($tree as $p) { $pid = $p['page_id']; if(isset($_POST['page']["$pid"])) { // validate submitted position if(!$pos = is_numeric_id($_POST['page']["$pid"],0)) { $message .= "Invalid value ".$_POST["$pid"]." for page $pid (".$p['name']."), this page has been placed at the top of the order.<br />"; $pos = -1000; } //subtree if(!empty($p['branches'])) { assign_positions($p['branches']); //recursive } } //end isset else { $message .= "Value not supplied for page $id (".$p['name']."), this page has been placed at the top of the order.<br />"; $pos = -1000; } $sort["p$pid"] = $pos;//+$i; //prefix with p because array_merge refuses to acknowledge strings consisting of solely numeric characters no matter how firmly defined. //$i++; // on first run forcing different numbers } //end foreach //echo 'unsorted ';print_r($sort); $sort = order_for_db($sort); //just this branch/tier //echo 'sorted '; print_r($sort); $pages = array_merge($pages,$sort); //echo 'pages '; print_r($pages); } //echo 'pages final '; print_r($pages); exit; //* foreach($pages as $id => $pos){ $pid = ltrim($id,'p'); mysql_query("update page_data set position = '$pos' where page_id = '$pid'"); } //*/ $message .= "Positions updated."; getout($message); exit; ?>
cải xoăn