<?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'];
$body    = str_replace("\n", "<BR>", $_REQUEST['body']);
$date    = Date("Y-m-d");
if ( $_REQUEST['action'] == "insert") {

	$sql    = "insert into pic_title values ('','$_REQUEST[fl]','$_REQUEST[title]','$body','$date')";
	$result = mysql_query($sql);
	ShowMessage(3,"添加成功！","");
}
if ( $_REQUEST['action'] == 'update') {
	$sql     = "update pic_title set fl='$_REQUEST[fl]',title='$_REQUEST[title]',body='$body' where id='$_REQUEST[id]'";
	mysql_query($sql);
	ShowMessage(4,"编辑成功！","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="news.php?action=insert" enctype="multipart/form-data" 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>
      <select name="fl">
     <option value="清纯美女">清纯美女</option>     
	 <option value="性感美女">性感美女</option>
     <option value="美女写真">美女写真</option>
     <option value="美女自拍">美女自拍</option>	
	 <option value="丝袜美女">丝袜美女</option>     
	 <option value="明星八卦">明星八卦</option>
     <option value="网络红人">网络红人</option>
     <option value="日韩美女">日韩美女</option>	 	 
      </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><input type=file size="30" name="picpath1">

</td>
  </tr>
  -->
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>内容</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="body" rows="3" cols=60></textarea></td>
  </tr>
</table>
<br>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?
		break;
	case "delete":
		$query    = "delete from pic_title where id='$_REQUEST[id]'";
		mysql_query($query);
		ShowMessage(3,"删除成功！","");
		break;
	case "update":
		$sql      = "select * from pic_title 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="news.php?action=update" method="post" enctype="multipart/form-data" 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>
      <select name="fl">
     <option value="<?php echo $row['fl']?>"><?php echo $row['fl']?></option>     	  
     <option value="清纯美女">清纯美女</option>     
	 <option value="性感美女">性感美女</option>
     <option value="美女写真">美女写真</option>
     <option value="美女自拍">美女自拍</option>	 
	 <option value="丝袜美女">丝袜美女</option>	 
	 <option value="明星八卦">明星八卦</option>	 
	 <option value="网络红人">网络红人</option>	 
	 <option value="日韩美女">日韩美女</option>	 	 
      </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" value="<?php echo $row['title']?>"></td>
  </tr>
<!--  
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>主题图片</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=file size="30" name="picpath1">

</td>
  </tr>
  -->
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>内容</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="body" rows="3" cols=60><?php echo $row['title']?></textarea></td>
  </tr>
</table>
<br>
<?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 pic_title where id='$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 
	if ($row['picpath1']){
	?>
	<img src=../upload-images/<?php echo $row['picpath1']?>>
	<?php
	}
	?>
	
	<?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="news.php">返回</a>
</center>
<?php
		break;
	default:
    echo "<center>";
    echo "<table border=0 width=520>";
    echo "<form action=\"news.php\" method=post><tr>";
    echo "<td bgColor=#ffffff>分类：<select name=\"fl\">";
	$sql1    = "select * from pic_titlefl 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 pic_title where fl='$_REQUEST[fl]' && title like '%$_REQUEST[search]%' order by id desc;";
	} elseif ( $_REQUEST['fl']) {
		$sql    = "select * from pic_title where fl='$_REQUEST[fl]' order by id desc;";
	} elseif ( $_REQUEST['search']){
		$sql    = "select * from pic_title where title like '%$_REQUEST[search]%' order by id desc;";
	} else{
	   	$sql    = "select * from pic_title 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=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=80 height=18 bgColor=#EBF1F5><div align=center><b>添加图片</b></div></td>";		
    	echo "<td width=80 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=100 height=18 bgColor=#ffffff><div align=center>$row[fl]</div></td>";
				echo "<td width=340 height=18 bgColor=#ffffff><div align=center>$row[title]</div></td>";
				echo "<td width=170 height=18 bgColor=#ffffff><div align=center><a href=cs_pic.php?id=$row[id]&page=add>添加图片</a></div></td>";
				echo "<td width=170 height=18 bgColor=#ffffff><div align=center><a href=cs_pic.php?id=$row[id]>管理图片</a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=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=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=news.php?page=1&fl=$_REQUEST[fl]&search=$_REQUEST[search]>第一页</a></td>";
			echo "<td align=center><a href=news.php?page=".($page-1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=news.php?page=".($page+1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>下一页</a></td>";
			echo "<td align=center><a href=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;
}
?>
