<?php
session_start();
include "header.html";
require_once "../MessageBox.php";
include "../datasource.inc.php";
$Message = new MessageBox;
if ( empty($_SESSION["adminuser"]) and $_SESSION["userjs"] != "1") {
    $Message->setMessage("对不起，您没有权限进入后台管理!","index.html");
    $Message->showMessage();
}
$page      = $_REQUEST['page'];
$action    = $_REQUEST['action'];
$id        = $_REQUEST['id'];
if ($_REQUEST['action'] == 'add') {
	$file_name    = $_FILES['picpath']['name'];
    mt_srand((double)microtime()*1000000);
    $shpid = uniqid(mt_rand());
    $shpid = substr($shpid,0,6);
	$file_name1 = $shpid.$file_name;
	$picpath 	= $image_path.$file_name1;
	if ($file_name) {
		copy($_FILES['picpath']['tmp_name'],$picpath);
		$shpidimgname   = $shpid.".".substr($file_name,-3);
		@rename("$image_path/$file_name1","$image_path/$shpidimgname");
	}
    $sql     = "insert into zht_pro01fl1 values ('','$_REQUEST[fl1]','$shpidimgname','$_REQUEST[body]')";
    $result  = mysql_query($sql);
    $Message->setMessage("添加成功!","pro01_fl1.php");
    $Message->showMessage();
}
if ($_REQUEST['action'] == 'update') {
	$file_name    = $_FILES['picpath']['name'];
    mt_srand((double)microtime()*1000000);
    $shpid = uniqid(mt_rand());
    $shpid = substr($shpid,0,6);
	$file_name1 = $shpid.$file_name;
	$picpath 	= $image_path.$file_name1;
	if ($file_name) {
		copy($_FILES['picpath']['tmp_name'],$picpath);
		$shpidimgname   = $shpid.".".substr($file_name,-3);
		@rename("$image_path/$file_name1","$image_path/$shpidimgname");
	}
	if ($file_name){
		$sql  = "update zht_pro01fl1 set fl1='$_REQUEST[fl1]',picpath='$shpidimgname',body='$_REQUEST[body]' where id='$_REQUEST[id]'";
	}else{
		$sql  = "update zht_pro01fl1 set fl1='$_REQUEST[fl1]',body='$_REQUEST[body]' where id='$_REQUEST[id]'";
	}
	$sql1        = "update zht_profl2 set fl1='$_REQUEST[fl1]' where fl1='$_REQUEST[old_fl1]'";
	$sql2        = "update zht_products set fl1='$_REQUEST[fl1]' where fl1='$_REQUEST[old_fl1]'";
    mysql_query($sql);
	mysql_query($sql1);
	mysql_query($sql2);
    $Message->setMessage("编辑成功!","pro01_fl1.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.fl1.value=='') {
		alert("请输入主分类名称!");
		return false;
	}
 return true;
}
</script>
<?php
switch ($page){
	case "add":
?>
<center>
<form enctype="multipart/form-data" name=form  method="post" action="pro01_fl1.php" onsubmit="return check_input()">
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=400>
  <tr>
    <td width="30%" bgColor=#EBF1F5><center><b>主分类名称</b></center></td>
    <td width="70%" bgcolor=ffffff><input type="text" size="30" name="fl1"></td>
  </tr>
  
  <!--<tr>
    <td width="30%" bgColor=#EBF1F5><center><b>分类图片</b></center></td>
    <td width="70%" bgcolor=ffffff><input type="file" size="30" name="picpath"></td>
  </tr>
  <tr height=24>
    <td width="100%" bgColor=#EBF1F5 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="hidden" value="add" name="action">
<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 zht_pro01fl1 where id='$id'";
		mysql_query($query);
		$Message->setMessage("删除成功!","pro01_fl1.php");
		$Message->showMessage();
		break;
	case "update":
		$sql       = "select * from zht_pro01fl1 where id='$id'";
		$result    = mysql_query($sql);
		$row       = mysql_fetch_array($result);
		$id        = $row['id'];
		$name      = $row['name'];
		$body      = str_replace("<BR>", "\n", $row['body']);
?>
<form name=form enctype="multipart/form-data" method="post" action="pro01_fl1.php" onsubmit="return check_input()">
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=400>
  </tr>
    <td width="30%" bgColor=#EBF1F5><center><b>分类名称</b></center></td>
    <td width="70%" bgcolor=ffffff>
	<?php echo "<input type=text size=30 name=\"fl1\" value=\"$row[fl1]\">";?>
    </td>
  </tr>
  
  <!--<tr>
    <td width="30%" bgColor=#EBF1F5><center><b>分类图片</b></center></td>
    <td width="70%" bgcolor=ffffff><input type="file" size="30" name="picpath"></td>
  </tr>
  <tr height=24>
    <td width="100%" bgColor=#EBF1F5 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>
  </tr>-->
  
</table><br>
<input type="hidden" value="update" name="action">
<?php echo "<input type=hidden name=id  value=$id><input type=hidden name=\"old_fl1\"  value=\"$row[fl1]\">"; ?>
<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 zht_pro01fl1 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=500>";
		echo "<tr>";
		//echo "<td width=160 height=18 bgColor=#EBF1F5><div align=center><b>图片</b></div></td>";
		echo "<td width=260 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=160 height=18 bgColor=#ffffff><div align=center><img src=\"../upload-images/$row[picpath]\" width=151 height=89></div></td>";
				echo "<td width=260 height=18 bgColor=#ffffff><div align=center>$row[fl1]</div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=pro01_fl1.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=pro01_fl1.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=pro01_fl1.php?page=1>第一页</a></td>";
			echo "<td align=center><a href=pro01_fl1.php?page=".($page-1).">上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=pro01_fl1.php?page=".($page+1).">下一页</a></td>";
			echo "<td align=center><a href=pro01_fl1.php?page=$last>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，您还没有添加记录,<a href=pro01_fl1.php?page=add>我要添加</a>!</center>";
	}
	break;
}
?>
