<?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();
}
$page    = $_REQUEST['page'];
$body    = $_REQUEST['body'];
$commet  = str_replace("\n", "<BR>", $_REQUEST['commet']);
$date     = Date("Y-m-d");
$datetime = Date("Y-m-d H:i:s");
$page     = $_REQUEST['page'];
$body     = $_REQUEST['body'];
if ( $_REQUEST['action'] == "insert") {
	$sql    = "insert into en_zht_news values ('','','$_REQUEST[fl]','$_REQUEST[title]','$description','$keywords','$body','$datetime')";
	$result = mysql_query($sql);
	ShowMessage(4,"添加成功！","en_news.php");
}
if ( $_REQUEST['action'] == 'update') {
	$sql     = "update en_zht_news set bx='$_REQUEST[bx]',fl='$_REQUEST[fl]',title='$_REQUEST[title]',description='$description',keywords='$keywords',body='$body' where id='$_REQUEST[id]'";
	mysql_query($sql);
	ShowMessage(4,"编辑成功！","en_news.php");
}
?>
<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 chin()
{
	if (document.form1.title.value=='') {
		alert("请输入文章标题！");
		return false;
	}
 return true;
}
</script>
<?php
switch ($page){
	case "add":
?>
<center>
<p align="center">&nbsp;<b><font size="3">请输入新闻内容</font></b></p>
<form action="en_news.php?action=insert" method="post" name="form1" onsubmit="return chin()">
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#6795B4" width=550>
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>分类</b></center></td>
    <td width="80%" bgcolor=ffffff>
    <?php
      $sql    = "select * from en_zht_newsfl order by id asc";
      $result = mysql_query($sql);
      echo " <select name=\"fl\">";
	  while ($row = mysql_fetch_array($result) ) {
        echo "<option value=\"$row[fl]\">$row[fl]</option>"; 
      }
	  echo "</select>";
	?>
    </td>
  </tr>
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>新闻标题</b></center></td>
    <td width="80%" bgcolor=ffffff><input type="text" size="60" name="title"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>网页描述</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="description" rows="3" cols=60></textarea></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>关键词</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="keywords" rows="3" cols=60></textarea></td>
  </tr>
  <tr>
    <td width="100%" bgcolor=ffffff colspan=2><textarea name="body" style="display:none"></textarea><IFRAME ID="eWebEditor1" SRC="eWebEditor/ewebeditor.htm?id=body&style=gray" FRAMEBORDER="0" SCROLLING="no" WIDTH="550" HEIGHT="350"></IFRAME></td>
  </tr>
</table>
<br>
<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?
		break;
	case "delete":
		$query    = "delete from en_zht_news where id='$_REQUEST[id]'";
		mysql_query($query);
		ShowMessage(3,"删除成功！","");
		break;
	case "update":
		$sql      = "select * from en_zht_news where id='$_REQUEST[id]'";
		$result   = mysql_query($sql);
		$row      = mysql_fetch_array($result);
		$body     = str_replace("<BR>", "\n", $row['body']);
		$description  = str_replace("<BR>", "\n", $row['description']);
		$keywords  = str_replace("<BR>", "\n", $row['keywords']);
?>
<center>
<p align="center">&nbsp;<b><font size="3">请修改新闻内容</font></b></p>
<form action="en_news.php?action=update" method="post" name="form" onsubmit="return chin()">
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=550>
<!--  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>显示顺序</b></center></td>
    <td width="80%" bgColor=#ffffff>
	<?php echo "<input type=text size=5 name=\"bx\" value=\"$row[bx]\">"; ?>
    </td>
  </tr>-->
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>分类</b></center></td>
    <td width="80%" bgcolor=ffffff>
	<select name="fl">
    <?php
	echo "<option selected value=\"$row[fl]\">$row[fl]</option>";
	$sql1    = "select * from zht_newsfl order by id asc";
	$result1 = mysql_query($sql1);
	while ($row1 = mysql_fetch_array($result1)) {
		echo "<option value=\"$row1[fl]\">$row1[fl]</option>";
	}
	?>
	</select>
    </td>
  </tr>
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>标题</b></center></td>
    <td width="80%" bgColor=#ffffff>
     <?php echo "<input type=text size=60 name=\"title\" value=\"$row[title]\">";?>
    </td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>网页描述</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="description" rows="3" cols=60><? echo $description?></textarea></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>关键词</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="keywords" rows="3" cols=60><? echo $keywords?></textarea></td>
  </tr>
<!--  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>发布时间</b></center></td>
    <td width="80%" bgColor=#ffffff>
     <?php echo "<input type=text size=10 name=\"date\" value=\"$row[date]\">";?>(格式：2007-04-11)
    </td>
  </tr>-->
  <tr>
    <td width="100%" bgcolor=ffffff colspan=2><textarea name="body" style="display:none"><? echo $row['body'] ?></textarea><IFRAME ID="eWebEditor1" SRC="eWebEditor/ewebeditor.htm?id=body&style=gray" FRAMEBORDER="0" SCROLLING="no" WIDTH="550" HEIGHT="350"></IFRAME></td>
	</td>
  </tr>
</table>
<br>
<input type="hidden" value="update" name="action">
<?php echo "<input type=hidden name=id  value=$row[id]>"; ?>
<input type="submit" value="编 辑" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?php
		break;
	case "text":
		$sql     = "select * from en_zht_news where id='$_REQUEST[id]'";
		$result  = mysql_query($sql);
		$row     = mysql_fetch_array($result);
		$imagetype = ( substr($row['picpath'],-3,3));
		if ( $imagetype=="gif" or $imagetype=="GIF" or $imagetype=="jpg" or $imagetype=="JPG" or $imagetype=="png" or $imagetype=="PNG" or $imagetype=="bmp" or $imagetype=="BMP" or $imagetype=="jpe" or $imagetype=="JPE") {
			$size    = getimagesize ("../upload-images/$row[picpath]");
			$arr     = imgspec( 400, $size[0], $size[1]);
			$imgwidth  = $arr[0];
			$imgheight = $arr[1];
			$pic       = "<img src=../upload-images/$row[picpath] width=$imgwidth height=$imgheight align=center>";
		} else {
			$pic       = "";
		}
?>
<br>
<center>
<table border=0 cellpadding=0 cellspacing=0 width=620>
  <tr height=22> 
    <td><b>类型：</b><?php echo $row['fl']; ?></td>
  </tr>
  <tr> 
    <td align="center"><font size=3><b><?php echo $row['title']?></b></font><br><hr><?php echo "发布时间：<font color=red>$row[date]</font><br>"; ?></td>
  </tr>
  <tr>
    <td height=10></td>
  </tr>
  <tr>
    <td align="center"><?php echo $pic?></td>
  </tr>
  <tr>
    <td height=10></td>
  </tr>
  <tr> 
    <td style="line-height:150%"><?php echo $row['body']?></td>
  </tr>
</table>
<br><a href="en_news.php">返回</a>
</center>
<?php
		break;
	default:
    echo "<center>";
    echo "<table border=0 width=520>";
    echo "<form action=\"en_news.php\" method=post><tr>";
    echo "<td bgColor=#ffffff>分类：<select name=\"fl\">";
	$sql1    = "select * from zht_newsfl order by id asc";
	$result1 = mysql_query($sql1);
	echo "<option value=\"\">请选择</option>";
	while ($row1 = mysql_fetch_array($result1) ) {
		echo "<option value=\"$row1[fl]\">$row1[fl]</option>"; 
	}
	echo "</select>";
    echo "</td>";
    echo "<td bgColor=#ffffff>";
	echo "信息标题：<input type=text size=20 name=\"search\" maxlength=20>";
    echo "&nbsp;<input type=submit value=搜索>";
    echo "</td>";
    echo "</tr>";
    echo "</form>";
    echo "</table>";
	if ( $_REQUEST['fl'] && $_REQUEST['search']){
	   	$sql    = "select * from en_zht_news where fl='$_REQUEST[fl]' && title like '%$_REQUEST[search]%' order by id desc;";
	} elseif ( $_REQUEST['fl']) {
		$sql    = "select * from en_zht_news where fl='$_REQUEST[fl]' order by id desc;";
	} elseif ( $_REQUEST['search']){
		$sql    = "select * from en_zht_news where title like '%$_REQUEST[search]%' order by id desc;";
	} else{
	   	$sql    = "select * from en_zht_news order by id desc;";
	}	
    $result = mysql_query($sql);
	$num    = mysql_num_rows($result);		
    if ( $num>0 ){
    	$last   = intval(($num-1)/30)+1;
    	if ( $page < 1 ) $page=1;
    	if ( $page > $last ) $page=$last;
    	mysql_data_seek($result,($page-1)*30);
		echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=520>";
    	echo "<tr>";
//		echo "<td width=80 height=18 bgColor=#EBF1F5><div align=center><b>显示顺序</b></div></td>";
    	echo "<td width=100 height=18 bgColor=#EBF1F5><div align=center><b>分类</b></div></td>";    	
    	echo "<td width=340 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<30;$i++ ) {
        	$row     = mysql_fetch_array($result);
	     	$id      = $row['id'];
		 	$body    = substr($row['body'],0,30);
		 	if ( $id ) {
				echo "<tr bgColor=#ffffff>";
//				echo "<td width=80 height=18 bgColor=#ffffff><div align=center>$row[bx]</div></td>";
				echo "<td width=100 height=18 bgColor=#ffffff><div align=center>$row[fl]</div></td>";
				echo "<td width=340 height=18 bgColor=#ffffff><div align=center><a href=en_news.php?page=text&id=$row[id]>$row[title]</a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=en_news.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_news.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_news.php?page=1&fl=$_REQUEST[fl]&search=$_REQUEST[search]>第一页</a></td>";
			echo "<td align=center><a href=en_news.php?page=".($page-1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=en_news.php?page=".($page+1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>下一页</a></td>";
			echo "<td align=center><a href=en_news.php?page=$last&fl=$_REQUEST[fl]&search=$_REQUEST[search]>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，找不到符合条件的记录,<a href=javascript:history.go(-1)>重新查询</a>!</center>";
	}
	break;
}
?>
