<?php
include("../../common.php");
include(S_ROOT."_admin/security.php");
include(S_ROOT."blog/include/Cats.php");
include(S_ROOT."caching/robot.php");
//============================
$disableStr = '';
if(get_para(11,"_value")=="yes")
	$disableStr = 'disabled="disabled"';
//============================
$Para = new Cats();
$ID = $_REQUEST["ID"];
if($_POST["Submit"]=="Update"){
	request($Para->fields,array(""));
	$title0 = norm($title0);
	$title1 = norm($title1);
	$title2 = norm($title2);
	$title3 = norm($title3);
	$title0 = str_replace("\$","",$title0);//for split with $ later
	$pDate = $pTime;
	$sql = sqlUpdate($Para->table,$Para->fields,array(""),"where ID=$ID");
	if($db->query($sql)){
		$msg = "<font color=red>You have updated the 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 update the info.</font><br>";
	}
}
else if($_POST["Submit"]=="Delete"){
   $sql = "delete from $Para->table where ID=$ID";
   if($db->query($sql)){
			$msg = "<font color=red>You have deleted the info successfully!</font><br>";
			cache_news_cats();
	?>
	<script language=javascript>parent.viewAll.document.location.href = "cats.php"</script>
	<?php
	}
    else{
		$msg = "<font color=red>You have failed to delete the info.</font><br>";
	}
}
//retrieve from database --------------------
$Para->setID($ID);
sql_row($Para->fields,$Para->row);
?>
<!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 remind(){
		var agree=confirm("Are you sure to delete this info?  Press OK to confirm.");
		if (agree)
			return true ;
		else
			return false ;
	}
function check(thisForm){
    var q =thisForm.title0;
   var fields = new Array(q);
  //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{
      return true;
  }
}
</script>
<script type="text/javascript" src="/include/js/jquery-ui.js"></script>
<script type="text/javascript" src="/include/js/sprinkle.js"></script>
<link rel="stylesheet" href="/include/css/tabs_style.css" type="text/css">
</head>
<body>
<div class="msg"><?php echo $msg?></div>
<form method="post" action="<?=$_SERVER["PHP_SELF"]?>" onSubmit=" return check(this)">
  <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr> 
      <td colspan="2" align="left" valign="top"><strong>1) Title </strong>
        <!--widget start-->
        <div id="tabvanilla" class="widget">
          <ul class="tabnav">
            <li><a href="#tab0">English</a></li>
            <li><a href="#tab1">Chinese</a></li>
            <li><a href="#tab2">Japanese</a></li>
            <li><a href="#tab3">Korean</a></li>
            </ul>  
          
          <div id="tab0" class="tabdiv"><input name="title0" type="text" value="<?=$title0?>" style="width:500px" maxlength=80></div>          
          <div id="tab1" class="tabdiv" style="display:none;"><input name="title1" type="text" value="<?=$title1?>" style="width:500px" maxlength=80></div>
          
          <div id="tab2" class="tabdiv"  style="display:none;"><input name="title2" type="text" value="<?=$title2?>" style="width:500px" maxlength=80></div>
          
          <div id="tab3" class="tabdiv"  style="display:none;"><input name="title3" type="text" value="<?=$title3?>" style="width:500px" maxlength=80></div>
          
        </div>
        <!--widget end-->
              </td>
    </tr>
    <tr> 
      <td width="14%"><strong>2) Category</strong></td>
      <td width="86%" align="left"> 
<?
echo "<select name='parentID'><option></option>";
$str = display_cat(0,"",0);
function display_cat($parentID,$dash,$deep){
	global $db,$Para;
	$tpre = C_tpre;
	$re = "";
	$t = $db->query("select * from $Para->table where parentID='{$parentID}' order by orderNum desc");
	$dash .= "_";
	$deep++;
	while($row=$db->fetch($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='".$Para->row["parentID"]."'","selected='selected' value='".$Para->row["parentID"]."'",$str);
echo "</select>";
?>
      </td>
    </tr>
    <tr>
      <td><strong>3) Number of post</strong></td>
      <td align="left"><input name="posts" type="text" id="posts" value="<?=$posts?>" /></td>
    </tr>
    <tr> 
      <td><strong>4) Order Num</strong></td>
      <td align="left"><input type="text" name="orderNum" value="<?=$orderNum?>">
        large order num displays first</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="left">
        <input type="checkbox" <? echo $Para->row["near_leaf"]?> name="near_leaf" id="near_leaf" value="checked">
      <label for="near_leaf">next to detailed page</label></td>
    </tr>
    <tr> 
      <td align="left"><input  <?=$disableStr?> name="Submit" type="submit" id="Submit" onClick="return remind()" value="Delete"></td>
      <td align="center"><input type=hidden name=ID value="<?=$ID?>"> <input type="submit" name="Submit" value="Update"> 
      </td>
    </tr>
  </table>
</form>
</body>
</html>
<?
$db->close();
?>
