<?php	
define('IN_OUN', true);
include_once( "includes/command.php");

if($Aconf['priveMessage'] != '')
{
   echo showMessage($Aconf['priveMessage']);
   exit;
}

$db_table = $pre."tjcat";
//post
if( $_POST['action'] == 'add'  )
{
	$Afields=array('name'=>$_POST['name'],'imgwidth'=>$_POST['imgwidth'],'imgheight'=>$_POST['imgheight'],'limits'=>$_POST['limits'],'domain_id'=>$_SESSION[$un_domain_id]);
    $tid = $oPub->install($db_table,$Afields);
	unset($Anorm);
}

if( $_POST['action'] == 'edit'){
	$_POST["id"] = $_POST["id"] + 0;
	 $Afields=array('name'=>$_POST['name'],'imgwidth'=>$_POST['imgwidth'],'imgheight'=>$_POST['imgheight'],'limits'=>$_POST['limits']);
	 $condition = 'id='.$_POST["id"].' AND domain_id='.$_SESSION[$un_domain_id];
     $oPub->update($db_table,$Afields,$condition);
	 unset($Anorm);
	 unset($_GET);
}

//get
if( $_GET['action'] == 'edit'){
	$sql = "SELECT * FROM ".$db_table." where id = ".$_GET['id']." AND domain_id=".$_SESSION[$un_domain_id];
	$Anorm = $oPub->selectrow($sql);
}

if( $_GET['action'] == 'del'){
	/*还有子属性将不能删除*/
	$condition = 'id='.$_GET['id'].' AND domain_id='.$_SESSION[$un_domain_id];
    $oPub->delete($db_table,$condition);
}


 
$sql = "SELECT * FROM ".$db_table." WHERE domain_id='".$_SESSION[$un_domain_id]."' ORDER BY id ASC";
$AnormAll = $oPub->select($sql);
$StrtypeAll = '';
$n = 0;
while( @list( $key, $value ) = @each( $AnormAll) )
{
	  $n ++;
	   $tmpstr = ($n % 2 == 0)?"even":"odd";
       $StrtypeAll .= '<TR class='.$tmpstr.'>';
	   $StrtypeAll .= '<TD align=left>'.$value['id'].'</TD>';
       $StrtypeAll .= '<TD align=left>'.$value['name'].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.$value['imgwidth'].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.$value['imgheight'].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.$value['limits'].'</TD>';
       $StrtypeAll .= '<TD align=left><a href="'.$_SERVER["PHP_SELF"].'?id='.$value["id"].'&fid=0&action=edit"><IMG SRC="images/b_edit.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="编辑"></a> ';
	   $StrtypeAll .= ' _ <a href="'.$_SERVER["PHP_SELF"].'?id='.$value["id"].'&fid=0&action=del"><IMG SRC="images/b_drop.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="删除"></a></TD>'; 
       $StrtypeAll .= '</TR>';     
}

?>

<?php
   include_once( "header.php");
	if ($strMessage != '')
	{
		 echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>';
	}
?>
<DIV class=content>
<TABLE width="99%" border=0>
  <TR class="odd" >
  <form name="form1" method="post" action=""> 
    <TD width="13%" align="left" colspan="6">
        <span>推荐分类:</span>
     	<input name="name" type="text" value="<?php echo ($Anorm['id'])?$Anorm['name']:''?>" />	
		<span>图片宽度:</span>
		<input name="imgwidth" type="text" value="<?php echo ($Anorm['id'])?$Anorm['imgwidth']:''?>" />px
		<span>图片高度:</span>
		<input name="imgheight" type="text" value="<?php echo ($Anorm['id'])?$Anorm['imgheight']:''?>" />px	
		<span>前台推荐显示的条数:</span>
		<input name="limits" type="text" value="<?php echo ($Anorm['id'])?$Anorm['limits']:5;?>" size="2"/>	
        <input type="hidden" name="action" value="<?php echo ($Anorm['id'])?'edit':'add'?>" />
        <input type="submit" name="Submit" value="<?php echo ($Anorm['id'])?'编辑':'增加' ?>" style="background-color: #FFCC66"/>
		<input type="hidden" name="id" value="<?php echo ($Anorm['id'])?$Anorm['id']:'0'?>" />  
    </TD>
    </form>
  </TR>	
  <TR class=bg5>
    <TD align=left>ID</TD>
    <TD align=left>推荐分类</TD>
	<TD align=left>图片宽度</TD>
	<TD align=left>图片高度</TD>
	<TD align=left>显示条数</TD>
    <TD align=left>操作</TD> 
  </TR>
  <?php echo $StrtypeAll?>
 
</TABLE>
 
</DIV>
<BR/> 

<?php
include_once( "footer.php");
?>