Location: PHPKode > projects > PHP Manual Creator > adm/page_sort.php
<?php
require_once("../includes/config.php");
require_once("../includes/functions/func.global.php");
require_once("../includes/functions/loggincheck.php");
require_once("class.menu.php");

// Connect to database
db_connect($config);

if(isset($_POST['Submit']))
{
	if(isset($_COOKIE['pageord-pageord']))
	{
		$page_sort = explode('|',$_COOKIE['pageord-pageord']);
		$num_pages = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."pages WHERE parent_id='0'"));
		$sorts = array();
		
		$sort_val = (($num_pages * 10)+20);
	
		foreach ($page_sort as $key => $value)
		{
			$sorts[$value] = $sort_val;
			$sort_val = ($sort_val-10);
		}

		$query = "SELECT page_id,sort FROM ".$config['db']['pre']."pages";
		$query_result = mysql_query($query);
		while ($info = @mysql_fetch_array($query_result))
		{
			if(isset($sorts[$info['page_id']]))
			{
				mysql_query("UPDATE `man_pages` SET `sort` = '".addslashes($sorts[$info['page_id']])."' WHERE `page_id` =".addslashes($info['page_id'])." LIMIT 1 ;");
			}
			else
			{
				if($info['sort'] != 0)
				{
					mysql_query("UPDATE `man_pages` SET `sort` = '0' WHERE `page_id` =".addslashes($info['page_id'])." LIMIT 1 ;");
				}
			}
		}
		
		header("Location: page_sort.php");
		exit;
	}
}

$obj = new Menu();
$nav = $obj->get_js_menu(0,$config);

$manuals = array();

$query = "SELECT manual_id,manual_title FROM ".$config['db']['pre']."manuals";
$query_result = mysql_query($query);
while ($info = @mysql_fetch_array($query_result))
{
	$manuals[$info['manual_id']] = $info['manual_title'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHP Manual Creator Admin - Sort Pages</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="images/style.css">
<script language="JavaScript" type="text/javascript" src="images/core.js"></script>
<script language="JavaScript" type="text/javascript"><!--
	var dragsort = ToolMan.dragsort()
	var junkdrawer = ToolMan.junkdrawer()

	window.onload = function() {
		//junkdrawer.restoreListOrder("clorder")

		dragsort.makeListSortable(document.getElementById("pageord"),
				verticalOnly, saveOrder);
				
		pageloaded();
	}

	function verticalOnly(item) {
		item.toolManDragGroup.verticalOnly()
	}

	function saveOrder(item) 
	{
		var group = item.toolManDragGroup
		var list = group.element.parentNode
		var id = list.getAttribute("id")
		if (id == null) return
		group.register('dragend', function() {
			ToolMan.cookies().set("pageord-" + id, 
					junkdrawer.serializeList(list), 365)
		})
	}
	
	function pageloaded()
	{
		document.getElementById('loading').style.visibility = "hidden";
		document.getElementById('loading').style.display = "none";
		document.getElementById('loaded').style.visibility = "visible";
	}
	//-->
</script>
<SCRIPT LANGUAGE="JavaScript" SRC="menu/JSCookMenu.js"></SCRIPT>
<LINK REL="stylesheet" HREF="menu/themes/Office/theme.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="menu/themes/Office/theme.js"></SCRIPT>
<LINK REL="stylesheet" HREF="menu/themes/Office/theme.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="menu/themes/Office/theme.js"></SCRIPT>
<script language="JavaScript"><!--
function checkBox(theBox){
  var aBox = theBox.form["list[]"];
  var selAll = false;
  var i;
  for(i=0;i<aBox.length;i++){
    if(aBox[i].checked==false) selAll=true;
  }
  if(theBox.name=="selall"){
    for(i=0;i<aBox.length;i++){
      aBox[i].checked = selAll;
    }
    selAll = !selAll;
  }
  //theBox.form.selall.checked = selAll;
}
function init(){
  var theForm = document.f1;
  var aBox = theForm["list[]"];
  var selAll = false;
  var i;
  for(i=0;i<aBox.length;i++){
    if(aBox[i].checked==false) selAll=true;
    aBox[i].onclick = function(){checkBox(this)};
  }
  //theForm.selall.checked = selAll;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//--></script>
<style>
ul.sortable li {
	position: relative;
}

ul.boxy {
	list-style-type: none;
	padding: 0px;
	margin: 0px;
	width: 800px;
	font-size: 13px;
	font-family: Arial, sans-serif;
}
ul.boxy li {
	cursor:move;
	padding: 3px 3px;
	margin-bottom: 4px;
	border: 1px solid #941406;
	background-color: #FFFFFF;
}
.clickable a {
	display: block;
	text-decoration: none;
	cursor: pointer;
	cursor: hand;
}
.clickable li:hover {
	background-color: #f6f6f6;
}
</style>
</head>
<body>
<!--Start top-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="100%" height="42" align="left" background="images/bg_top.gif"><a href="index.php"><img src="images/logo.gif" width="207" height="17" hspace="10" border="0"></a></td>
  </tr>
  <tr>
    <td><img src="images/dot.gif" width="1" height="1" alt=""></td>
  </tr>
</table>
<!--End top-->
<!--Start topmenu-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#F0F0F0" height="25" style="padding-left:20px;" id="menu"><SCRIPT language="JavaScript" type="text/javascript">
			var myMenu =
				
			// Start the menu
[
<?php echo $nav; ?>
];				

			// Output the menu
			cmDraw ('menu', myMenu, 'hbr', cmThemeOffice, 'ThemeOffice');
			</SCRIPT></td>
  </tr>
  <tr>
    <td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
  </tr>
</table>
<br>

<!--End topmenu-->
<!--Start heading page-->
<table width="850" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td class="heading"><img src="images/icons/icon_editrule.gif" width="21" height="22" alt="" align="absmiddle" hspace="5">Sort Pages</td>
</tr>
<tr>
<td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
</tr>
</table>
<!--End heading page-->
<!--Start form-->
<br>
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #CCCCCC;">
  <tr>
    <td align="left" bgcolor="#F6F6F6" style="padding:15px;">
	<br>
      <div align="right"> 
            <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
              <option value="page_sort.php">View All</option>
			  <?
			  foreach ($manuals as $key => $value) 
			  {
			  	$selected = '';
				
				if(isset($_GET['manual']))
				{
					if($_GET['manual'] == $key)
					{
						$selected = ' selected';
					}
				}
              ?>
			  <option value="page_sort.php?manual=<?=$key;?>"<?=$selected;?>><?=stripslashes($value);?></option>
			  <?
			  }
			  ?>
            </select>
			<br>
            <br>
          </div>
	<br>
<strong>Drag and drop the Pages below to sort them in the order you want.</strong><Br><Br>
        <form action="page_sort.php<? if(isset($_GET['manual'])){ echo '?manual='.$_GET['manual']; } ?>" method="post" name="f1" id="f1">
<br>
			<div id="loading" align="center"><span style="font-size:14px;font-family:Verdana;">Loading Pages</span></div>
		  <div id="loaded" style="visibility:hidden;">
			<ul id="pageord" class="boxy">
<?php
if(isset($_GET['manual']))
{
	$query = "SELECT page_id,page_title FROM ".$config['db']['pre']."pages WHERE parent_id='0' AND manual_id='".addslashes($_GET['manual'])."' ORDER BY sort DESC";
}
else
{
	$query = "SELECT page_id,page_title FROM ".$config['db']['pre']."pages WHERE parent_id='0' ORDER BY sort DESC";
}
$query_result = mysql_query($query);
while ($info = @mysql_fetch_array($query_result))
{
?>
<li id="<?php echo $info['page_id']; ?>">
<?php echo $info['page_title']; ?>
</li>
<?php
}
?>
</ul>
<br><Br><Br>
<input name="Submit" type="submit" class="button" value="Save Page Order">
</div>
        </form></td>
  </tr>
</table>
<!--End form-->
<br><br>
<!--Start bottom-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
</tr>
<tr>
<td style="padding:15px;" align="center">
<span class="copyright">Copyright &copy; 2007 <a href="http://www.kubelabs.com/phpmanualcreator.php" class="copyright" target="_blank">Kubelabs.com</a> All Rights Reserved.</span></td>
</tr>
</table>
<!--End bottom-->
</body>
</html>
Return current item: PHP Manual Creator