<?php
include("../../common.php");
include(S_ROOT."_admin/security.php");
include(S_ROOT."blog/include/Cats.php");
$Para = new Cats();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<? include(S_ROOT."_admin/elements/meta.inc.php");?>
</head>
<body> 
<div align=center>
  <table bgcolor="#FFFFFF" width="360" border="0" cellspacing="2" cellpadding="3">
    <tr align="center" bgcolor="#CCCCCC">
      <td width="127"><a target="main" href="categoryAdd.php?parentID=0">Add top category</a></td>
      <td width="88" height="21"><a href="search.php" target="main">All News</a></td>
      <td width="89"><a href="add.php" target="main">Add New</a></td>
    </tr>
    <tr align="center" bgcolor="#CCCCCC">
      <form action="search.php" method="post" name="form1" target="main" id="form1">
        <td colspan="3"><input name="keyword" type="text" value="<?=$keyword?>" style="width:150px" />
          <input type="submit" name="Submit" value="Go" /></td>
      </form>
    </tr>
  </table>
<a href="add.php" target="main"></a></div>

<!------- search result start ------>
<table width=100% height=66  border=0 cellpadding= cellspacing=8>
 
  <tr> 
    <td height=30 valign=middle> 
<?   
$condStr = " where ID>0 ";
$sortStr = "order by orderNum desc";
If($sortBy) $sortStr = " order by $sortBy"; else  $sortStr = " order by orderNum desc"; 	
if (!isset($step)) $step = 100;
if (!isset($from)) $from = 0;
//===========================================================================
$goto = $_REQUEST["goto"];
$count = $_REQUEST["count"];	
if($goto!=""){
	if($goto<=0) $from = 0;
	else if($goto>$count/$step)  $from = (int)(($count - 1) / $step) * $step;	
	else $from = ($step*$goto)-$step;		
}
//===========================================================================
$sql="SELECT * FROM $Para->table $condStr $sortStr limit ".$from.",".$step;
$tsql = "SELECT count(ID) as total from $Para->table $condStr";
$result = mysql_query($sql) or die(mysql_error());
$tquery = mysql_query($tsql) or die(mysql_error());
$trows = mysql_fetch_array($tquery);
$count = $trows['total'];
if($count == "0") die("Your search yielded no result.<br>");
$param="count=$count&sortBy=$sortBy";
$pageStr = pages($from,$step,$count,$param);
?>
      <div align=center><font class=head><?php echo $msg?></div>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td> 
                                    <?=search_results($from,$step,$count);?>
                                  </td>
                                  <td> 
                                    <?=$pageStr?>
                                  </td>
                                </tr>
                              </table></td>
  </tr>
  <tr>
    <td height=30  valign=middle>
<?php
$str = display_cat(0);			
function display_cat($parentID){
	global $db,$Para;
 	$re = "";
	$t = $db->query("select * from $Para->table where parentID='$parentID' order by orderNum desc,ID desc");
	while($row=$db->fetch($t)){
		$empStr = "";
		$addStr = "";
		if($parentID==0){
			$empStr = "font-weight:bold";
		}
		$addStr = "<a target='main' href='categoryAdd.php?parentID=".$row["ID"]."'><img src='/images/cool/add.gif' border='0' align='absmiddle' title='Add sub-cagetory for this'></a> ";
		//if(strlen($row["value"])<8 && $row["parentID"])
			//$value = ": <span class='red'>".$row["value"]."</span>";
		//else	
			$value = "";
		$leafStr = "";	
		if($row["near_leaf"])
			$leafStr = ". ";
		$re .="<div style='clear:left;padding-left:15px;border-bottom:#CCCCCC 1px solid'>
					<div style='float:left;{$empStr}'>".$leafStr.$row["title0"].$value." (".$row["ID"].", ".$row["orderNum"].")</div>
					<div style='float:left;text-align:right'>{$addStr} &nbsp; <a target='main' href='categoryEdit.php?ID=".$row["ID"]."'><img src='/images/cool/edit.gif' border='0' align='absmiddle' title='Edit this'></a> &nbsp;  
						<a target='main' href='search.php?catID=".$row["ID"]."'><img src='/images/cool/list.gif' border='0' align='absmiddle' title='List all info'></a></div>";
					$re .= display_cat($row["ID"]);
	    $re .="</div>";
	}
	return $re;
}
echo $str;
?>
    
	  </td>
  </tr>
</table>
<!------- search result end ------>
<p><br/>
  </p>
</body>
</html>