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

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

$db_table = $pre."support";
//post
if( $_POST['action'] == 'add' )
{
   $sql = "INSERT INTO " . $db_table . " ( descs ,  ip , name,tel,pos,addrs,email ,  dateadd ,orderdate, states , `domain_id` )" .
           "VALUES ('$_POST[descs]', '".real_ip()."', '$_POST[name]','$_POST[tel]','$_POST[pos]','$_POST[addrs]','$_POST[email]','".gmtime()."', '".gmtime()."','3','$_SESSION[$un_domain_id]')"; 
   $oPub->query($sql);
   $strMessage =  "添加成功!";

}

if( $_POST['action'] == 'edit')
{
	$_POST[spid] = $_POST[spid] + 0;

	$sql = "UPDATE " . $db_table . " SET 
    name  = '$_POST[name]',
	tel   = '$_POST[tel]',
	pos   = '$_POST[pos]',
	addrs = '$_POST[addrs]',
	descs = '$_POST[descs]',
	email='$_POST[email]',
	states=3 
	WHERE domain_id = ".$_SESSION[$un_domain_id]." and spid = ".$_POST[spid];
    $oPub->query($sql);  
	$strMessage = "编辑回复成功";
	unset($_GET);
}

//get
if( $_GET['action'] == 'edit'){
	$_GET['spid'] = $_GET['spid'] + 0;
	$sql = "SELECT * FROM ".$db_table." 
	       WHERE spid = ".$_GET['spid'].
		   " AND domain_id=".$_SESSION[$un_domain_id];
	$Aspp = $oPub->selectrow($sql);
}

if( $_GET['action'] == 'del'){
	$_GET['spid'] + 0;
    $condition = 'spid='.$_GET['spid'];
    $oPub->delete($db_table,$condition);	
}
/* 批量删除 */
if ($_REQUEST['action'] == 'del_checkbox')
{
    if (isset($_POST['checkboxes']))
    {
        $count = 0;
        foreach ($_POST['checkboxes'] AS $key => $id)
        {
			$id = $id +0; 
			$condition = 'spid='.$id;
			$oPub->delete($db_table,$condition); 
		}
	}
}


//page
$strWhere = " WHERE states <> 1 AND domain_id=".$_SESSION[$un_domain_id];
$sql = "SELECT count( * ) AS count FROM ".$db_table.$strWhere;
$row = $oPub->selectrow($sql);
$count = $row['count'];
unset($row);
$page = new ShowPage;
$page->PageSize = 40;
$page->Total = $count;
$pagenew = $page->PageNum();
$page->LinkAry = array(); 
$strOffSet = $page->OffSet();

$sql = "SELECT * FROM ".$db_table.$strWhere." ORDER BY spid desc limit ".$strOffSet;
$AsppAll = $oPub->select($sql);

$StrtypeAll = '';
$n = 0;
while( @list( $key, $value ) = @each( $AsppAll) ) {
	   $tmpstr = ($n % 2 == 0)?"even":"odd";
	   $n ++ ;
       $StrtypeAll .= '<TR class='.$tmpstr.'>';
	   $StrtypeAll .= '<TD align=left>';
	   $StrtypeAll .= '<input type="checkbox" name="checkboxes['.$value["spid"].']" value="'.$value["spid"].'" />';
	   $StrtypeAll .= '</TD>';
	   $descs = sub_str(clean_html($value["descs"]),30);
       $StrtypeAll .= '<TD align=left>'.$descs.'</TD>';
       $StrtypeAll .= '<TD align=left>'.$value["name"].':'.$value["tel"].'/'.$value["email"].'<br/>邮编:'.$value["pos"].'/地址:'.$value["addrs"].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.$value["ip"].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.date("m-d h:i", $value[dateadd]).'</TD>';
	   $states = ($value[states]==3)?'已审':'';
	   $StrtypeAll .= '<TD align=left>'.$states.'</TD>';
       $StrtypeAll .= '<TD align=left><a href="'.$_SERVER["PHP_SELF"].'?spid='.$value["spid"].'&action=edit&page='.$pagenew.'"><IMG SRC="images/b_edit.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="编辑"></a> _ ';
	   $StrtypeAll .= '<a href="'.$_SERVER["PHP_SELF"].'?spid='.$value["spid"].'&action=del&page='.$pagenew.'"><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="100%" border=0>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>" name="listForm" target="_self">
  <TR class=bg5>
    <TD width="5%" align=left>序号</TD>
    <TD width="35%" align=left>内容</TD>
	<TD width="30%" align=left>EMAIL/姓名</TD>
	<TD width="5%" align=left>ip</TD>
	<TD width="12%" align=left>日期</TD>
	<TD width="5%" align=left>状态</TD>
    <TD width="8%" align=left>操作</TD>
  </TR>
  <?php echo $StrtypeAll?>
  <TR class=bg5>
    <TD colspan="7" align=right>
    <span style="float: left">
	全选删除:<input onclick=selectAll() type="checkbox" name="check_all"/>
	<INPUT TYPE="submit" name="submit" value="确认删除" style="background-color: #FF9900">
	<INPUT TYPE="reset" name="reset" value="恢复" style="background-color: #CCFF99"> 
	<INPUT TYPE="hidden" name="action" value="del_checkbox"> 
    </span>
	<?php echo $showpage = $page->ShowLink();?>
	</TD>
  </TR>
  </FORM>
</TABLE>
<TABLE width="900" border=0>
  <TR class="odd" >
  <form name="form1" method="post" action=""> 
    <TD width="900" align="left" colspan="7">
        <span>姓名:</span>
		<input name="name" type="text" size="10" value="<?php echo ($Aspp['spid'])?$Aspp['name']:''?>" />
        <span>电话:</span>
		<input name="tel" type="text" size="16" value="<?php echo ($Aspp['spid'])?$Aspp['tel']:''?>" />
        <span>EMAIL:</span>
		<input name="email" type="text" size="30" value="<?php echo ($Aspp['spid'])?$Aspp['email']:''?>" />
		<br/>
        <span>邮编:</span>
		<input name="pos" type="text" size="7" value="<?php echo ($Aspp['spid'])?$Aspp['pos']:''?>" />
        <span>地址:</span>
		<input name="addrs" type="text" size="40" value="<?php echo ($Aspp['spid'])?$Aspp['addrs']:''?>" />
        <br/>
       <?php
		$descs1 = ($Aspp[states]==0 AND $Aspp['spid'] > 0)?$Aspp['descs'].'<div style="border: 1px solid #DADADA;clear: left;width:500px"><B>回复:</B></div>':$Aspp['descs'];
		echo create_html_ck('descs',$descs1);
	   ?>			
		<br/>
		<input type="submit" name="Submit" value="<?php echo ($Aspp['spid'])?'编辑回复':'增加留言'?>" style="background-color: #FFCC66"/>
        <input type="hidden" name="action" value="<?php echo ($Aspp['spid'])?'edit':'add'?>" />        
		<input type="hidden" name="spid" value="<?php echo ($Aspp['spid'])?$Aspp['spid']:'0'?>" />
		<input type="hidden" name="re_spid" value="<?php echo ($Aspp['spid'])?$Aspp['spid']:'0'?>" />
		<br/>
    </TD>
    </form>
  </TR>	
</TABLE> 
</DIV>
<script type="text/javascript" language="JavaScript">

function selectAll(){
	xx = listForm.check_all.checked
	for(var i=0;i<listForm.length;i++)
	{
		if(listForm.elements[i].type=="checkbox")
			listForm.elements[i].checked=xx;
	}
}

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