<?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']);
$description  = str_replace("\n", "<BR>", $_REQUEST['description']);
$keywords  = str_replace("\n", "<BR>", $_REQUEST['keywords']);
$date     = Date("Y-m-d");
$datetime = Date("Y-m-d H:i:s");
if ( $_REQUEST['action'] == "tj" ) {
	$file_name    = $_FILES['picpath']['name'];
	$file_name2    = $_FILES['picpath2']['name'];
    mt_srand((double)microtime()*1000000);
    $shpid = uniqid(mt_rand());
    $shpid = substr($shpid,0,6);
	$file_name1 = $shpid.$file_name;
	$file_name3 = $shpid."_2".$file_name2;
	$picpath 	= $image_path.$file_name1;
	$picpath2 	= $image_path.$file_name3;
	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_name2) {
		copy($_FILES['picpath2']['tmp_name'],$picpath2);
		$shpidimgname2   = $shpid."_2".".".substr($file_name2,-3);
		@rename("$image_path/$file_name3","$image_path/$shpidimgname2");
	}
    $query = "insert into tz_pic values ('','$_REQUEST[fl1]','$_REQUEST[fl2]','$_REQUEST[name]','$_REQUEST[style]','$_REQUEST[medium]','$_REQUEST[number]','$shpidimgname','$shpidimgname2','$commet','$body','$description','$keywords','$datetime')";
	mysql_query($query);
    $Message->setMessage("添加成功!","tz_pic.php");
    $Message->showMessage();
}
if ($_REQUEST['action'] == 'update') {
	$file_name    = $_FILES['picpath']['name'];
	$file_name2    = $_FILES['picpath2']['name'];
    mt_srand((double)microtime()*1000000);
    $shpid = uniqid(mt_rand());
    $shpid = substr($shpid,0,6);
	$file_name1 = $shpid.$file_name;
	$file_name3 = $shpid."_2".$file_name2;
	$picpath 	= $image_path.$file_name1;
	$picpath2 	= $image_path.$file_name3;
	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_name2) {
		copy($_FILES['picpath2']['tmp_name'],$picpath2);
		$shpidimgname2   = $shpid."_2".".".substr($file_name2,-3);
		@rename("$image_path/$file_name3","$image_path/$shpidimgname2");
	}
	if ($file_name && $file_name2){
		$sql  = "update tz_pic set fl1='$_REQUEST[fl1]',fl2='$_REQUEST[fl2]',name='$_REQUEST[name]',style='$_REQUEST[style]',medium='$_REQUEST[medium]',number='$_REQUEST[number]',picpath='$shpidimgname',picpath2='$shpidimgname2',commet='$commet',body='$body',description='$description',keywords='$keywords' where id='$_REQUEST[id]'";
	} elseif ($file_name) {
		$sql  = "update tz_pic set fl1='$_REQUEST[fl1]',fl2='$_REQUEST[fl2]',name='$_REQUEST[name]',style='$_REQUEST[style]',medium='$_REQUEST[medium]',number='$_REQUEST[number]',picpath='$shpidimgname',commet='$commet',body='$body',description='$description',keywords='$keywords' where id='$_REQUEST[id]'";
	} elseif ($file_name2){
		$sql  = "update tz_pic set fl1='$_REQUEST[fl1]',fl2='$_REQUEST[fl2]',name='$_REQUEST[name]',style='$_REQUEST[style]',medium='$_REQUEST[medium]',number='$_REQUEST[number]',picpath2='$shpidimgname2',commet='$commet',body='$body',description='$description',keywords='$keywords' where id='$_REQUEST[id]'";
	} else {
		$sql  = "update tz_pic set fl1='$_REQUEST[fl1]',fl2='$_REQUEST[fl2]',name='$_REQUEST[name]',style='$_REQUEST[style]',medium='$_REQUEST[medium]',number='$_REQUEST[number]',commet='$commet',body='$body',description='$description',keywords='$keywords' where id='$_REQUEST[id]'";
	}
    $result  = mysql_query($sql);
   $Message->setMessage("编辑成功!","tz_pic.php?id=$_REQUEST[id]");
    $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>
</center>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<?
$sql = "select * from zht_profl2 order by id desc";
$result = mysql_query( $sql);
$count = 0;
while($res = mysql_fetch_row($result)){
?>
subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");
<?
$count++;
}
echo "onecount=$count;";
?>
//联动函数
function changelocation(locationid)
    {
    document.myform.fl2.length = 0; 
    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][2] == locationid)
            { 
       //var newOption1=new Option(subcat[i][1], subcat[i][0]);
                //document.all.ctype.add(newOption1);
                document.myform.fl2.options[document.myform.fl2.length] = new Option(subcat[i][1], subcat[i][0]);
            }        
        }
        
    }    
</script>
<script language=javascript>
function check_input()
{
	if (document.form.name.value=='') {
		alert("请输入图片名称!");
		return false;
	}
 return true;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<?php
switch ($page){
    case "add":
?>
<center>
<p align="center">&nbsp;<b><font size="3">请输入图片信息</font></b></p>
<form action="tz_pic.php?page=add" enctype="multipart/form-data"  method="post" name="myform" onsubmit="return check_input()">
<table width="550"  border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4>
 <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center>
      <b>图片ID</b>
    </center></td>
    <td width="80%" bgcolor=ffffff>
	<select name="fl1" size="1">
	<option value="<?php echo $_REQUEST[id]?>"><?php echo $_REQUEST[id]?></option>
    </select> 
    </td>
  </tr>
  <!--
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片小分类</b></center></td>
    <td width="80%" bgcolor=ffffff>
    <select name="fl2">                  
	<option selected value="">请指定小分类</option>
    </select>
    </td>
  </tr>

  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片名称</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="40" name="name"></td>
  </tr> 
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>排序</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="5" name="style"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>推荐</b></center></td>
    <td width="80%" bgColor=#ffffff><input type="radio" name="medium" value="是">
      是 <input name="medium" type="radio" value="否" checked="checked">
      否</td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>型号</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="20" name="number"></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="picpath"></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="picpath2"></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 height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>摘要</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="commet" rows="4" cols=60></textarea></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5 colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;<b>特性</b></td>
  </tr>-->
  <tr height=24>
    <td width="100%" bgColor=#EBF1F5 colspan=2><textarea name="body" style="display:none"><? echo $row['body']?></textarea><iframe id="body___Frame" src="../fckeditor/editor/fckeditor.html?InstanceName=body&amp;Toolbar=Basic" width="760px" height="560px" frameborder="0" scrolling="no"></iframe></td>
  </tr>
</table><br>
<input type="hidden" value="tj" name="action">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
<?php
		break;
	case "delete":
		$sql   = "delete from tz_pic where id='$_REQUEST[id]'";
		mysql_query($sql);
		$Message->setMessage("删除成功!","javascript:history.go(-1)");
		$Message->showMessage();
		break;
    case "update":
		$sql     = "select * from tz_pic where id='$_REQUEST[id]';";
		$result  = mysql_query($sql);
		$row     = mysql_fetch_array($result);
		$body    = $row['body'];
		$commet  = str_replace("<BR>", "\n", $row['commet']);
		$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="tz_pic.php" enctype="multipart/form-data" method=post name=form onsubmit="return check_input()">
<table width="550"  border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4>
<tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片ID</b></center></td>
    <td width="80%" bgcolor=ffffff>
	<select name="fl1" size="1">
	<option value="<?php echo $row['fl1']?>"><?php echo $row['fl1']?></option>
    </select> 

    </td>
  </tr><!--  
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片小分类</b></center></td>
    <td width="80%" bgcolor=ffffff>
    <select name="fl2">
    <?php
	$sql3    = "select * from zht_profl2 where id='$row[fl2]'";
	$result3 = mysql_query($sql3);
	$row3    = mysql_fetch_array($result3);
	echo "<option selected value=\"$row[fl2]\">$row3[fl2]</option>";
	$sql4    = "select * from zht_profl2 order by id desc";
    $result4 = mysql_query($sql4);
	while ($row4 = mysql_fetch_array($result4) ) {
       echo "<option value=\"$row4[id]\">$row4[fl2]</option>";
    }
	?>
	</select>
    </td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片名称</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="40" name="name" value="<? echo $row['name']?>"></td>
  </tr><tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>排序</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="5" name="style" value="<? echo $row['style']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>推荐</b></center></td>
    <td width="80%" bgColor=#ffffff>
	<?php
	if ($row['medium']=="是") {
		echo "<input type=\"radio\" name=\"medium\" value=\"是\" checked=\"checked\" />
      是 <input name=\"medium\" type=\"radio\" value=\"否\" />
      否";
	} else {
		echo "<input type=\"radio\" name=\"medium\" value=\"是\" />
      是 <input name=\"medium\" type=\"radio\" value=\"否\" checked=\"checked\" />
      否";
	}
	?>
	</td>
  </tr>-->
  <!--
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>型号</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="20" name="number" value="<? echo $row['number']?>"></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="picpath"></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="picpath2"></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 height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>摘要</b></center></td>
    <td width="80%" bgColor=#ffffff><textarea name="commet" rows="4" cols=60><? echo $commet?></textarea></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5 colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;<b>特性</b></td>
  </tr>-->
  <tr height=24>
    <td width="100%" bgColor=#EBF1F5 colspan=2><textarea name="body" style="display:none"><? echo $row['body']?></textarea><iframe id="body___Frame" src="../fckeditor/editor/fckeditor.html?InstanceName=body&amp;Toolbar=Basic" width="760px" height="560px" frameborder="0" scrolling="no"></iframe></td>
  </tr>
</table><br>
<?php echo "<input type=hidden name=id value=$row[id]>";?>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="hidden" value="update" name="action">
<input type="submit" value="编 辑" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
<?php
    	break;
    case "text":
		if ( $_REQUEST['actionsed']=="savesize") {
			if (!empty($_REQUEST['size']) && !empty($_REQUEST['price'])) {
				$query = "insert into zht_size values ('','$_REQUEST[id]','$_REQUEST[size]','$_REQUEST[price]')";
				mysql_query($query);
				$Message->setMessage("规格增加成功!","tz_pic.php?page=text&id=$_REQUEST[id]");
				$Message->showMessage();
			} else {
				$Message->setMessage("Sorry!规格增加失败!","javascript:history.go(-1)");
				$Message->showMessage();
			}
		}
		if ( $_REQUEST['actionsed']=="saveedit") {
			if (!empty($_REQUEST['size']) or !empty($_REQUEST['price'])) {
				$query = "update zht_size set size='$_REQUEST[size]',price='$_REQUEST[price]' where id='$_REQUEST[sid]'";
				mysql_query($query);
				$Message->setMessage("规格修改成功!","tz_pic.php?page=text&id=$_REQUEST[id]");
				$Message->showMessage();
			} else {
				$Message->setMessage("Sorry!规格修改失败!","javascript:history.go(-1)");
				$Message->showMessage();
			}
		}
		if ( $_REQUEST['actionsed']=="del") {
			if (!empty($_REQUEST['sizeid'])) {
				$sql   = "delete from zht_size where id='$_REQUEST[sizeid]'";
			    mysql_query($sql);
				$Message->setMessage("规格删除成功!","tz_pic.php?page=text&id=$_REQUEST[id]");
				$Message->showMessage();
			} else {
				$Message->setMessage("Sorry!规格删除失败!","javascript:history.go(-1)");
				$Message->showMessage();
			}
		}
		$sql    = "select * from tz_pic where id='$_REQUEST[id]'";
        $result = mysql_query($sql);
        $row    = mysql_fetch_array($result);
		$imagetype = ( substr($row['picpath2'],-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[picpath2]");
			$arr     = imgspec( 300, $size[0], $size[1]);
			$pic       = "<img src=../upload-images/$row[picpath2] width=$arr[0] height=$arr[1] align=center>";
		} else {
			$pic       = "";
		}
		$body    = str_replace("<BR>", "\n", $row['body']);

		$sql1    = "select * from zht_profl1 where id='$row[fl1]'";
		$result1 = mysql_query($sql1);
		$row1    = mysql_fetch_array($result1);
		$sql2    = "select * from zht_profl2 where id='$row[fl2]'";
		$result2 = mysql_query($sql2);
		$row2    = mysql_fetch_array($result2);
?>
<center>
<script language=javascript>  
	function sm(sname)
	{ 
		if(sname.style.display=='none') 
		{ 
			sname.style.display=''; 
		} 
		else 
		{ 
			sname.style.display='none'; 
		} 
	
	} 
</script>
<p><font size=3><b>图片详细信息</b></font></p>
<table width="560"  border=0 cellpadding=3 cellspacing=1 bgcolor=#6795B4>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>主分类</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row1['fl1'];?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>小分类</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row2['fl2'];?></td>
  </tr>
 <!-- <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片名称</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row['name'];?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>排序</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row['style'];?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>推荐</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row['medium'];?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>型号</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $row['number'];?></td>
  </tr>
 <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>规格</b></center></td>
    <td width="80%" bgColor=#ffffff style="line-height:160%">
	<?php
	$sql3    = "select * from zht_size where pid='$row[id]'";
	$result3 = mysql_query($sql3);
	while ($row3 = mysql_fetch_array($result3)) {
		if ($row3['id']) {
			if ($_REQUEST['textsed']=="edit" && $row3['id']==$_REQUEST['sizeid']) {
	?>
      <table width="300" border="0" cellspacing="0" cellpadding="0">
        <tr><form action="tz_pic.php?page=text" method=post name=form>
          <td width="140"><input name="size" type="text" size="20" value="<? echo  $row3['size']?>"></td>
          <td width="16" align="center"><b>=</b></td>
          <td width="14" align="right"><font color=red>$</font></td>
          <td width="65" align="center"><input name="price" type="text" size="6" value="<? echo  $row3['price']?>"></td>
          <td width="65" align="center"><input type="hidden" value="<? echo $row3['pid']?>" name="id"><input type="hidden" value="<? echo $row3['id']?>" name="sid"><input type="hidden" value="saveedit" name="actionsed"><input type="submit" name="Submit" value="确定" /></td></form>
        </tr>
      </table>
	<?php
			} else {
				echo $row3['size']." <b>=</b> <font color=red>$</font>".$row3['price']." [<a href=\"tz_pic.php?page=text&textsed=edit&id=$row3[pid]&sizeid=$row3[id]\">修改</a>][<a href=\"tz_pic.php?page=text&actionsed=del&id=$row3[pid]&sizeid=$row3[id]\">删除</a>]<br>";
			}
		}
	}
	echo "<u onClick=sm(ClassN1)>增加</u>";
	?>
      <table width="300" border="0" cellspacing="0" cellpadding="0" id="ClassN1" style="display:none">
        <tr><form action="tz_pic.php?page=text" method=post name=form>
          <td width="140"><input name="size" type="text" size="20"></td>
          <td width="16" align="center"><b>=</b></td>
          <td width="14" align="right"><font color=red>$</font></td>
          <td width="65" align="center"><input name="price" type="text" size="6"></td>
          <td width="65" align="center"><input type="hidden" value="<? echo $_REQUEST['id']?>" name="id"><input type="hidden" value="savesize" name="actionsed"><input type="submit" name="Submit" value="确定" /></td></form>
        </tr>
      </table></td>
  </tr>-->
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片图片</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo "<img src=\"../upload-images/$row[picpath]\" width=100 height=60>";?></td>
  </tr>
  <!--<tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>图片图片(大)</b></center></td>
    <td width="80%" bgColor=#ffffff><?php echo $pic;?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>网页描述</b></center></td>
    <td width="80%" bgColor=#ffffff><? echo $row['description']?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>关键词</b></center></td>
    <td width="80%" bgColor=#ffffff><? echo $row['keywords']?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>摘要</b></center></td>
    <td width="80%" bgColor=#ffffff><? echo $row['commet']?></td>
  </tr>-->
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5 colspan=2><?php echo $body;?></td>
  </tr>
</table>
<br>
<?php
	echo "<div align=center><a href=javascript:history.go(-1)>返回</a></div></center>";
		break;
	default:
    $sql1    = "select * from zht_profl1 order by id desc;";
    $result1 = mysql_query($sql1);
    $sql2    = "select * from zht_profl1 order by id desc;";
    $result2 = mysql_query($sql2);
	echo "<form action=tz_pic.php name=myform>";
    echo "<table width=680 align=center cellpadding=0 cellspacing=0 border=0><tr><td>";
	echo "图片主分类：</td><td>";
?>
	<select name="fl1" onChange="changelocation(document.myform.fl1.options[document.myform.fl1.selectedIndex].value)" size="1">
	<option selected value="">请指定主分类</option>
	<?php
	$sql4 = "select * from zht_profl1 order by id desc";
	$result4 = mysql_query( $sql4);
	while($res4 = mysql_fetch_row($result4)){
	?>
	<option value="<? echo $res4[0]; ?>"><? echo $res4[1]; ?></option>
	<? } ?>
    </select> 
<?php
	echo "</td><td>";
	echo "图片子分类：</td><td>";
?>
    <select name="fl2">                  
	<option selected value="">请指定小分类</option>
    </select>
<?php
	echo "</td><td>商品名称：<td>";
	echo "<td><input type=text name=\"title\" size=10></td><td><input type=submit value=\"查 询\"></td></tr></table></form>";

	if ( !empty( $_REQUEST['fl1']) and !empty( $_REQUEST['fl2']) and  !empty( $_REQUEST['title'])) {
		$sql    = "select * from tz_pic where fl1='$_REQUEST[fl1]' and fl2='$_REQUEST[fl2]' and title like '%$_REQUEST[title]%' order by id desc;";
	}elseif ( !empty($_REQUEST['fl1']) and !empty( $_REQUEST['fl2'])){
		$sql    = "select * from tz_pic where fl1='$_REQUEST[fl1]' and fl2='$_REQUEST[fl2]' order by id desc;";
	}elseif ( !empty($_REQUEST['fl1']) and !empty( $_REQUEST['title'])){
		$sql    = "select * from tz_pic where fl1='$_REQUEST[fl1]' and title like '%$_REQUEST[title]%' order by id desc;";
	}elseif ( !empty($_REQUEST['fl2']) and !empty( $_REQUEST['title'])){
		$sql    = "select * from tz_pic where fl2='$_REQUEST[fl2]' and title like '%$_REQUEST[title]%' order by id desc;";
	}elseif ( !empty($_REQUEST['fl1'])){
		$sql    = "select * from tz_pic where fl1='$_REQUEST[fl1]' order by id desc;";
	}elseif ( !empty($_REQUEST['fl2'])){
		$sql    = "select * from tz_pic where fl2='$_REQUEST[fl2]' order by id desc;";
	}elseif ( !empty($_REQUEST['title'])){
		$sql    = "select * from tz_pic where title like '%$_REQUEST[title]%' order by id desc;";
	} else {
		$sql    = "select * from tz_pic order by id desc;";
	}

	$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=720>";
		echo "<tr>";
		echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>排序</b></div></td>";
		echo "<td width=160 height=18 bgColor=#EBF1F5><div align=center><b>分类ID</b></div></td>";
		//echo "<td width=160 height=18 bgColor=#EBF1F5><div align=center><b>小分类</b></div></td>";
		echo "<td width=120 height=18 bgColor=#EBF1F5><div align=center><b>图片</b></div></td>";
		//echo "<td width=60 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']) {
				$sql1    = "select * from zht_profl1 where id='$row[fl1]'";
				$result1 = mysql_query($sql1);
				$row1    = mysql_fetch_array($result1);
				$sql2    = "select * from zht_profl2 where id='$row[fl2]'";
				$result2 = mysql_query($sql2);
				$row2    = mysql_fetch_array($result2);
				echo "<tr bgColor=#ffffff>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center>$row[style]</div></td>";
				echo "<td width=160 height=18 bgColor=#ffffff><div align=center>$row[fl1]</div></td>";
				//echo "<td width=160 height=18 bgColor=#ffffff><div align=center>$row2[fl2]</div></td>";
				echo "<td width=120 height=18 bgColor=#ffffff><div align=center><img src=../upload-images/$row[picpath] width=80 height=80 border=0></div></td>";
				//echo "<td width=60 height=18 bgColor=#ffffff><div align=center>$row[number]</div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=tz_pic.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=tz_pic.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=tz_pic.php?page=1&title=$_REQUEST[title]&fl1=$_REQUEST[fl1]&fl2=$_REQUEST[fl2]>第一页</a></td>";
			echo "<td align=center><a href=tz_pic.php?page=".($page-1)."&title=$_REQUEST[title]&fl1=$_REQUEST[fl1]&fl2=$_REQUEST[fl2]>上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=tz_pic.php?page=".($page+1)."&title=$_REQUEST[title]&fl1=$_REQUEST[fl1]&fl2=$_REQUEST[fl2]>下一页</a></td>";
			echo "<td align=center><a href=tz_pic.php?page=$last&title=$_REQUEST[title]&fl1=$_REQUEST[fl1]&fl2=$_REQUEST[fl2]>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，您还没有添加图片,<a href=tz_pic.php?page=add>我要添加</a>!</center>";
	}
	break;
}
?>