<?php
include("../../common.php");
include(S_ROOT."_admin/security.php");
include(S_ROOT."blog/include/Cats.php");
include(S_ROOT."caching/robot.php");
$Para = new Cats();
$editor_type = "";
request($Para->fields,array("")); 
if($_POST["st"]=="add"){	
	$title = norm($title);
	$title = str_replace("\$","",$title);//for split with $ later
	$des = norm($des);
	$sql = sqlInsert($Para->table,$Para->fields,array(""));
	if($db->query($sql)){
		$msg = "<font color=red>You have added a new info successfully!</font><br>";
		cache_news_cats();
	?>
	<script language=javascript>parent.viewAll.document.location.href = "cats.php"</script>
	<?
	}
    else{
		$msg = "<font color=red>You have failed to add a new info.</font><br>";
	}
}
?>
<!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>
<title>calendar</title>
<? include(S_ROOT."_admin/elements/meta.inc.php");?>
<script type="text/javascript">
function check(thisForm){  
   var q =thisForm.title;
   var a =thisForm.des;
   var fields = new Array(q,a);
  //don't need to change the following lines 
  var error = false;
  var focusObj = null;
  var color1 = "#FF9900";
  var color2 = "#FFFFFF";
  
  for(i=0;i<fields.length;i++){
  	fields[i].style.background=color2;
	if(fields[i].value==""){
		fields[i].style.background=color1;
		if(!error)
			focusObj = fields[i];
		error=true;		
	}
  }  
  if(error){  
    alert("Please enter the required info in the highlight field.");
	focusObj.focus();
    return false;
  }
  else{ 
  	  document.form1.Submit.disabled = true; 
      return true;
  }  
}
</script>
</head>
<body onLoad="document.form1.title.focus()">
<?php echo $msg?> 
<form name=form1 method=post action="<?php echo $PHP_SELF?>" onSubmit=" return check(this)">
  <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr> 
      <td height="36" align="right">Title</td>
      <td><input name="title0" type="text" id="title0" style="width:500px" value="<?=$title0?>" maxlength=80> 
      </td>
    </tr>
    <tr> 
      <td align="right">Group to a Category</td>
      <td align="left"> 
        <?
echo "<select name='parentID'><option></option>";
$str = display_cat(0,"",0);
function display_cat($parentID,$dash,$deep){
	global $Para;
	$tpre = C_tpre;
	$re = "";
	$t = mysql_query("select * from $Para->table where parentID='{$parentID}' order by orderNum desc");
	$dash .= "_";
	$deep++;
	while($row=mysql_fetch_array($t)){
		$catTitle = $row["title0"];
		$catID = $row["ID"];
		$indexStr = "{$dash}|{$deep}|";	
		$re .= "<option value='{$catID}'>{$indexStr} {$catTitle}</option>";
		$re .= display_cat($catID,$dash,$deep);		
	}
	return $re;
}
$str .= "<option value=''></option>";
echo str_replace("value='".$parentID."'","selected='selected' value='".$parentID."'",$str);
echo "</select>";

$db->close();
?>
      </td>
    </tr>
    <tr> 
      <td align="right">Order Num</td>
      <td align="left"><input type="text" name="orderNum" value="<?=$orderNum?>">
        large order num displays first</td>
    </tr>
    <tr> 
      <td width="14%">&nbsp;</td>
      <td width="86%" align="center"><input type=hidden name=st value=add> <input type="submit" name="Submit" value="Add"></td>
    </tr>
  </table>
</form>
</body>
</html>
