<?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'];
if ($_REQUEST['action'] == 'add') {
    $sql     = "insert into zht_profl2 (id,fl2,fl1ID,body) values ('','$_REQUEST[fl2]','$_REQUEST[fl1ID]','$_REQUEST[body]')";
    $result  = mysql_query($sql);
    $Message->setMessage("添加成功!","pro_fl2.php");
    $Message->showMessage();
}
if ($_REQUEST['action'] == 'update') {
 	$sql         = "update zht_profl2 set fl2='$_REQUEST[fl2]',fl1ID='$_REQUEST[fl1ID]',body='$_REQUEST[body]' where id='$_REQUEST[id]'";
    $result  = mysql_query($sql);
//	$sql1        = "update zht_products set fl1='$_REQUEST[fl1ID]',fl2='$_REQUEST[fl2]' where fl1='$_REQUEST[old_fl1ID]' && fl2='$_REQUEST[old_fl2]'";
//	mysql_query($sql1);
    $Message->setMessage("编辑成功!","pro_fl2.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.fl2.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 enctype="multipart/form-data" name=form  method="post" action="pro_fl2.php" onsubmit="return check_input()">
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=520>
  <tr>
    <td width="30%" bgColor=#EBF1F5><center><b>分类</b></center></td>
    <td width="70%" bgcolor=ffffff>
    <?php
      $sql    = "select * from zht_profl1 order by id asc;";
      $result = mysql_query($sql);
      echo " <select name=\"fl1ID\">";
	  while ($row = mysql_fetch_array($result) ) {
        echo "<option value=\"$row[id]\">$row[fl1]</option>";
      }
	  echo "</select>";
	?>
    </td>
  </tr>
  <tr>
    <td width="30%" bgColor=#EBF1F5><center><b>子分类名称</b></center></td>
    <td width="70%" bgcolor=ffffff>
      <input type="text" size="30" name="fl2" maxlength="28">
    </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="add" name="action">
<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?
    break;
	case "delete":
	     $query     = "delete from zht_profl2 where id='$_REQUEST[id]'";
         mysql_query($query);
         $Message->setMessage("删除成功!","pro_fl2.php");
         $Message->showMessage();
		 break;
	case "update":
         $sql       = "select * from zht_profl2 where id='$_REQUEST[id]'";
         $result    = mysql_query($sql);
         $row       = mysql_fetch_array($result);
?>
<form name=form  method="post" action="pro_fl2.php" onsubmit="return check_input()">
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=520>
  </tr>
    <td width="30%" bgColor=#EBF1F5><center><b>分类</b></center></td>
    <td width="70%" bgcolor=ffffff>
	 <select name="fl1ID">
     <?php
		$sql2    = "select fl1 from zht_profl1 where id='$row[fl1ID]'";
		$result2 = mysql_query($sql2);
		$row2    = mysql_fetch_array($result2);
	    echo "<option selected value=\"$row[fl1ID]\">$row2[fl1]</option>";
 	    $sql1    = "select * from zht_profl1 order by id asc;";
        $result1 = mysql_query($sql1);
	    while ($row1 = mysql_fetch_array($result1) ) {
           echo "<option value=\"$row1[id]\">$row1[fl1]</option>";
        }
	    echo "</select>";
	?>
    </td>
  </tr>
  </tr>
    <td width="30%" bgColor=#EBF1F5><center><b>子分类名称</b></center></td>
    <td width="70%" bgcolor=ffffff>
	<?php
      echo "<input type=text size=30 name=\"fl2\" value=\"$row[fl2]\">";
	?>
    </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=$row[id]><input type=hidden name=\"old_fl1\"  value=\"$row[fl1ID]\"><input type=hidden name=\"old_fl2\"  value=\"$row[fl2]\">"; ?>
<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_profl2 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=420>";
    echo "<tr>";
    echo "<td width=170 height=18 bgColor=#EBF1F5><div align=center><b>分类</b></div></td>";
    echo "<td width=170 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);
		if ( $row['id']) {
			echo "<tr bgColor=#ffffff>";
			$sql2    = "select fl1 from zht_profl1 where id='$row[fl1ID]'";
			$result2 = mysql_query($sql2);
			$row2    = mysql_fetch_array($result2);
			echo "<td width=170 height=18 bgColor=#ffffff><div align=center>$row2[fl1]</div></td>";
			echo "<td width=170 height=18 bgColor=#ffffff><div align=center>$row[fl2]</div></td>";
			echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=pro_fl2.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=pro_fl2.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><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=pro_fl2.php?page=1>第一页</a></td>";
              echo "<td align=center><a href=pro_fl2.php?page=".($page-1).">上一页</a></td>";
          }
          if ( $page <> $last ) {
              echo "<td align=center><a href=pro_fl2.php?page=".($page+1).">下一页</a></td>";
              echo "<td align=center><a href=pro_fl2.php?page=$last>最后一页</a></td>";
          }
          echo "</tbody>";
          echo "</tr>";
          echo "</table><br>";
		  echo "</center>";
   } else {
      echo "<center>对不起，您还没有添加记录,<a href=pro_fl2.php?page=add>我要添加</a>!</center>";
   }
	break;
}
?>
