<?php
session_start();
include "header.html";
require_once "../MessageBox.php";
include "../datasource.inc.php";
include "../Function.php";
$Message = new MessageBox;
if ( empty($_SESSION["usernumber"]) and $_SESSION["userjs"] != "1") {
    $Message->setMessage("对不起，您没有权限进入后台管理!","logout.php");
    $Message->showMessage();
	EXIT;
}
$page      = $_REQUEST['page'];
if ($_REQUEST['action'] == 'add') {
	$sql     = "insert into en_zht_newsfl (id,fl) values ('','$_REQUEST[fl]');";
	$result  = mysql_query($sql);
	$Message->setMessage("添加成功！","en_newsfl.php");
	$Message->showMessage();
}
if ($_REQUEST['action'] == 'update') {
 	$sql         = "update en_zht_newsfl set fl='$_REQUEST[fl]' where id='$_REQUEST[id]'";
	$sql1        = "update en_zht_news set fl='$_REQUEST[fl]' where fl='$_REQUEST[old_fl]'";
    mysql_query($sql);
	mysql_query($sql1);
    $Message->setMessage("编辑成功！","en_newsfl.php");
	$Message->showMessage();
}
?>
<table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <TD vAlign=top><FONT color=#565656><IMG height=14 
      src="../images/closedfold.gif" width=14>&nbsp;&nbsp;您当前的位置<BR><IMG 
      height=15 src="../images/bar.gif" width=15><IMG height=14 
      src="../images/openfold.gif" width=14>&nbsp;&nbsp;新闻分类管理(英文版)</FONT></TD>
        </tr>
</table>
<script language=javascript>
function check_input()
{
	if (document.form.fl.value=='') {
		alert("请输入分类!");
		return false;
	}
 return true;
}
</script>
<?php
switch ($page){
    case "add":

?>
<center>
<form enctype="multipart/form-data" name=form  method="post" action="en_newsfl.php" onsubmit="return check_input()">
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=460>
  <tr> 
    <td width="30%" bgColor=#EBF1F5><center><b>分类</b></center></td>
    <td width="70%" bgcolor=ffffff> 
      <input type="text" size="30" name="fl">
    </td>
  </tr>
</table><br>
<input type="hidden" value="add" name="action">
<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?
    break;
	case "delete":
	     $query     = "delete from en_zht_newsfl where id='$_REQUEST[id]';";
         mysql_query($query);
         $Message->setMessage("删除成功！","en_newsfl.php");
		 $Message->showMessage();
		 break;
	case "update":
         $sql       = "select * from en_zht_newsfl where id='$_REQUEST[id]';";
         $result    = mysql_query($sql);
         $row       = mysql_fetch_array($result);

?>
<form name=form  method="post" action="en_newsfl.php" onsubmit="return check_input()">
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=460>
  <tr>
    <td width="30%" bgColor=#EBF1F5><center><b>信息分类</b></center></td>
    <td width="70%" bgcolor=ffffff>
	<?php echo "<input type=text size=30 name=\"fl\" value=\"$row[fl]\">";?>
    </td>
  </tr>
</table><br>
<input type="hidden" value="update" name="action">
<?php echo "<input type=hidden name=\"id\"  value=$row[id]><input type=hidden name=\"old_fl\"  value=\"$row[fl]\">"; ?>  
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="submit" value="编 辑" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?php
		break;
	default:
	$sql    = "select * from en_zht_newsfl order by id asc";
	$result = mysql_query($sql);
	$num    = mysql_num_rows($result);		
	if ( $num>0 ){
		$last   = intval(($num-1)/20)+1;
		if ( $page < 1 ) $page=1;
		if ( $page > $last ) $page=$last;
		mysql_data_seek($result,($page-1)*20);
		echo "<center>";
		echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=280>";
		echo "<tr>";
		echo "<td width=200 height=18 bgColor=#EBF1F5><div align=center><b>信息分类</b></div></td>";    	
		echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>编辑</b></div></td>";		
		echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>删除</b></div></td>";		 		 	 		 
		echo "</tr>"; 		 	
		for ( $i=0;$i<20;$i++ ) {
			$row     = mysql_fetch_array($result);
			$id      = $row['id'];
			$body    = substr($row['body'],0,30);
			if ( $id ) {
				echo "<tr bgColor=#ffffff>";
				echo "<td width=200 height=18 bgColor=#ffffff><div align=center>$row[fl]</div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=en_newsfl.php?page=update&id=$row[id]><img src=../images/edit.gif border=0></a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击删除本条记录 href=en_newsfl.php?page=delete&id=$row[id] onclick=\"return confirm('确定要删除吗？')\"><img src=../images/clearicon.gif border=0></a></div></td>";
				echo "</tr>";
			}
		}
		echo "</table><br>";
		echo "<table width=500 border=0 cellspacing=0 cellpadding=0 height=24>";
		echo "<tbody>";
		echo "<tr><td colspan=4><center>";
		echo "总共找到<font color=red>$num</font>条记录,第<font color=red>$page</font>页,共<font color=red>$last</font>页。";
		echo "</center></td></tr><tr>";
		if ( $page <> 1 ) {
			echo "<td align=center>&nbsp;&nbsp;&nbsp;<a href=en_newsfl.php?page=1>第一页</a></td>";
			echo "<td align=center><a href=en_newsfl.php?page=".($page-1).">上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=en_newsfl.php?page=".($page+1).">下一页</a></td>";
			echo "<td align=center><a href=en_newsfl.php?page=$last>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，您还没有添加记录,<a href=en_newsfl.php?page=add>我要添加</a>!</center>";
	}
	break;
}
?>
