<?php
	include_once("check_login.php");
	include_once("include/config.php");
	$action = trim($_GET["action"]);
	$page = trim($_GET["page"]);
	$page = $page ? $page : 1;
	$max_per_page = 10;
	if($action == "save"){
		//check_site_url();
		//array_pop($_POST);//表单提交上来的数据都存入$_POST数组中，现在弹出最后一个数组值，因为最后一个是按纽
		extract($_POST);//把数组名作为变量名，数组值作为变量值
		if(is_array($p_order)){
			//更新排序数字
			foreach($p_order as $key => $val){
				if(check_is_numb($val))
					mysql_query("update hmcss_product set p_order = $val where p_id = $key")
						or show_err("更新产品排序出错，请联系管理员");
				else
					show_err("排序只能是数字");
			}
			show_err("产品显示顺序已成功修改","set_product_list.php");
		}
		else
			header("location:set_product_list.php");
	}
	else{
		$t_id = trim($_POST["select_small"]);
		$f_id = trim($_POST["select_big"]);
		$filter_arr[0] = array("2",0,false);
		if($hm_arr = get_product_t($filter_arr)){
			$op_str = "";
			$op_str .= "<option value=\"0\">查询所有产品</option>\n\r";
			foreach ($hm_arr as $key => $val)
				if(check_is_numb($f_id) && $f_id !=0 && $f_id == $val[0])
					$op_str .= "<option value=\"$val[0]\" selected=\"selected\">$val[2]</option>\n\r";
				else
					$op_str .= "<option value=\"$val[0]\">$val[2]</option>\n\r";
		}
		else
			$op_str .= "<option value=\"0\">请先添加产品分类</option>\n\r";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品列表</title>
<script language = "javascript" src="include/jquery.min.js" type="text/javascript"></script>
<script language = "javaScript" src = "include/hmcss_ajax.js" type="text/javascript"></script>
<script language="javascript">
$(function(){
	show_small_type($("#select_big"),"t");
	$(".set_main_list li").bind({
		mouseover:function(){
			$("." + $(this).attr("class")).css("background-color","#DDD");
		},
		mouseout:function(){
			$("." + $(this).attr("class")).css("background-color","");
		}
	});
}); 
function get_t()
{
	$("#select_small").prepend("<option value=\"0\" selected=\"selected\">查询该大类下所有产品</option>");
	$("#select_small").val("0");
}

function show_img(obj)
{
	if($("#" + obj).css("display") == "none")
		$("#" + obj).css("display","block");
	else
		$("#" + obj).css("display","none");
}

function set_order()
{
	$("#form1").submit();
}
</script>
<style type="text/css">
.set_main_list{width:906px; overflow:hidden; margin:0px auto; border-left:#CCC 1px solid;}
 ul{list-style:none; margin:0px; padding:0px;}
.set_main_list li{list-style:none; height:30px; line-height:30px; overflow:hidden; float:left; border-right:#CCC 1px solid; border-bottom:#CCC 1px solid;}
.set_main_title{width:906px; overflow:hidden; margin:0px auto; border-left:#CCC 1px solid; border-top:#CCC 1px solid; background-color:#DDD;}
.set_main_title li{list-style:none; height:30px; line-height:30px; float:left; padding:0px; text-align:center; border-right:#CCC 1px solid; border-bottom:#CCC 1px solid;}
.img_span{display:none; margin:0px; padding:0px; height:150px; width:200px; position:absolute; background-color:#DDD;}
</style>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div class="head_menu"><span class="head_menu_on"><a href="set_product_list.php">产品列表</a></span><a href="set_product_new.php">添加产品</a><a href="set_product_type.php">产品分类</a><a href="set_product_img.php">产品图片</a><a href="set_img_upload.php">图片上传</a></div>
<form id="form_select" name="form_select" method="post" action="set_product_list.php?action=list">
<div style="width:800px; height:30px; margin:20px auto; padding:0px; line-height:30px; text-align:center;">请选择分类：&nbsp;&nbsp;<select name="select_big" id="select_big" onchange="show_small_type($('#select_big'),'t')">
            <?php echo $op_str; ?>
          </select>&nbsp;&nbsp;<span id="floading"></span>&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="submit" name="button" id="button" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="button" id="button" value="  设 置  " title="设置产品显示顺序" onclick="set_order()" />
</div>
</form>

<div class="set_main_out">
  <form id="form1" name="form1" method="post" action="set_product_list.php?action=save">
    <div class="set_main_title">
      <ul>
      	<li style="width:50px;">ID</li>
      	<li style="width:100px;">显示顺序</li>
        <li style="width:150px;">产品分类</li>
        <li style="width:150px;">产品名称</li>
        <li style="width:300px;">产品介绍</li>
        <li style="width:150px;">产品操作</li>
      </ul>
    </div>
    <div class="set_main_list">
      <ul>
      <?php
	  	unset($filter_arr);
	  	check_is_numb($f_id) && $f_id > 0 ? (check_is_numb($t_id) && $t_id > 0 ? $filter_arr[] = array("1",$t_id,false) : $filter_arr[] = array("2",$f_id,false)) : $filter_arr = "";
		if(!$hm_arr = get_product($filter_arr))
			show_err("该分类下暂无产品，请添加产品","set_product_new.php");
		else{
			//计算总页数
			$all_page = ceil(count($hm_arr)/$max_per_page);
			if($page > $all_page)
				$page = $all_page;
			$start = $page ? (($page - 1) * $max_per_page) : 0;
			$filter_arr[] = array("4","$start,$max_per_page",false);
			$hm_arr = get_product($filter_arr);
			//把分类查出来放入数组
			if(!$hm_type_arr = get_product_t(""))
				show_err("系统中暂无分类，请先添加分类");
			else{
				foreach($hm_type_arr as $key => $val)
					$t_arr[$val[0]] = $val[2];
			}
			foreach($hm_arr as $key => $val){
				$ab_top = 160+($key*31) . "px";
				if($val[7])
					$img_str = "<span id=\"img_$val[0]\" class=\"img_span\" style =\"background:url(../product/small/$val[7]) center no-repeat #DDD; top:$ab_top;\"></span>\n";
				else
					$img_str = "<span id=\"img_$val[0]\" class=\"img_span\" style=\"height:30px; line-height:30px; width:250px; top:$ab_top;\">暂无产品主图，<a onclick=\"location.href='set_product_img.php?p_id=$val[0]'\" class=\"do_style\">点击这里设置</a></span>\n";
				echo "<li class=\"li_$val[0]\" style=\"width:50px; text-align:center;\">$val[0]</li>\n";
				echo "<li class=\"li_$val[0]\" style=\"width:100px; text-align:center;\"><input name=\"p_order[$val[0]]\" type=\"text\" id=\"p_order[$val[0]]\" maxlength=\"3\"  style=\"width:50px; margin:4px auto;\" value=\"$val[9]\" /></li>\n";
				$fl_str = "[" . $t_arr[$val[2]] . "]" . $t_arr[$val[1]];
				echo "<li class=\"li_$val[0]\" style=\"width:150px; text-align:center;\" title=\"$fl_str\">$fl_str</li>\n";
				echo "<li class=\"li_$val[0]\" style=\"width:150px; text-align:center; cursor:pointer;\" onclick=\"show_img('img_$val[0]')\" title=\"点击查看该产品图片\">$val[3]$img_str</li>\n";
				echo "<li class=\"li_$val[0]\" style=\"width:300px; text-align:center;\" title=\"$val[6]\">" . strip_tags($val[6]) . "</li>\n";
				echo "<li class=\"li_$val[0]\" style=\"width:150px; text-align:center;\"><span class=\"do_style\" style=\"width:50px;\" onclick=\"location.href='set_product_edit.php?p_id=$val[0]'\">修改</span><span class=\"do_style\" style=\"width:50px;\" onclick=\"if(confirm('确定要删除该产品吗？')) location.href='DEL.php?type=product&id=$val[0]'; else return;\">删除</span></li>";
			}
		}
	  ?>
      </ul>
    </div>
  </form>
<div id="page" style="width:906px;">
<?php
	for($i = 1;$i <= $all_page;$i++)
		echo $i - $page == 0 ? "<a class=\"now_page\">$i</a>" : "<a class=\"page_span\" href=\"set_product_list.php?page=$i\">$i</a>";
?>
</div>
</div>
</body>
</html>