<?php
	include_once("check_login.php");
	include_once("include/config.php");
	$action = trim($_GET["action"]);
	if($action == "save"){
		check_site_url();
		array_pop($_POST);//表单提交上来的数据都存入$_POST数组中，现在弹出最后一个数组值，因为最后一个是按纽
		extract($_POST);//把数组名作为变量名，数组值作为变量值
		//先检查小分类有没有选择
		if(!check_is_numb($select_small))
			show_err("请选择小分类，如果没有请添加");
		//查大分类
		if(!check_is_numb($select_big))
			show_err("请选择大分类，或选择大分类出错");
		//查产品名
		$p_name = trim($p_name);
		(strlen($p_name) <0 || check_bad_str($p_name)) ? show_err("请输入产品名，或产品名中有非法字符") : $p_name = addslashes($p_name);
		$p_model = trim($p_model);
		check_bad_str($p_model) ? show_err("产品型号中有非法字符") : $p_model = addslashes($p_model);
		$p_standar = trim($p_standar);
		check_bad_str($p_standar) ? show_err("产规格中有非法字符") : $p_standar = addslashes($p_standar);
		//查产品介绍
		strlen($p_content) < 9 ? show_err("请输入至少10个英文字符或5个中文字的产品介绍") : $p_content = addslashes($p_content);
		mysql_query("insert into hmcss_product (t_id,f_id,p_name,p_model,p_standar,p_content) values ($select_small,$select_big,'$p_name','$p_model','$p_standar','$p_content')")
			or show_err("添加新产品出错，请联系管理员");
		show_err("新产品已成功添加","set_product_new.php");
	}
	else{
		$filter_arr[0] = array("2",0,false);
		if($hm_arr = get_product_t($filter_arr)){
			$op_str = "";
			foreach ($hm_arr as $key => $val)
				$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 type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<script language="javascript">
$(function(){
	show_small_type($("#select_big"),"t");
	}); 
</script>
<style type="text/css"></style>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div class="head_menu"><a href="set_product_list.php">产品列表</a><span class="head_menu_on"><a href="set_product_new.php">添加产品</a></span><a href="set_product_type.php">产品分类</a><a href="set_product_img.php">产品图片</a><a href="set_img_upload.php">图片上传</a></div>
<div class="set_main_out">
  <form id="form1" name="form1" method="post" action="set_product_new.php?action=save">
    <div class="set_main">
      <ul>
        <li style="width:140px; color:#C03;">产品大类:</li>
        <li style="width:638px;">
          <select name="select_big" id="select_big" onchange="show_small_type($('#select_big'),'t')">
            <?php echo $op_str; ?>
          </select>
          <span style="font-size: 12px; color: #999"> 请选择产品大类</span> </li>
        <li style="width:140px; color:#C03;">产品小类:</li>
        <li style="width:638px;"><span id="floading"></span> <span style="font-size: 12px; color: #999"> 请选择产品小类</span> </li>
        <li style="width:140px; color:#C03;">产品名称:</li>
        <li style="width:638px;">
          <input name="p_name" type="text" id="p_name" size="50" maxlength="20" />
          <span style="color:#999; font-size:12px;">请填写产品的名称</span></li>
        <li style="width:140px;">产品型号:</li>
        <li style="width:638px;"><span id="floading"></span> <span style="font-size: 12px; color: #999"> 
          <input name="p_model" type="text" id="p_model" size="50" maxlength="20" />
        请填写产品的型号</span> </li>
        <li style="width:140px;">产品规格:</li>
        <li style="width:638px;"><span id="floading"></span> <span style="font-size: 12px; color: #999"> 
          <input name="p_standar" type="text" id="p_standar" size="50" maxlength="20" />
        请填写产品的规格</span> </li>
        <li style="width:140px; height:400px; color:#C03;">产品介绍:</li>
        <li style="width:638px; height:400px;"><textarea cols="80" id="p_content" name="p_content" rows="10" style="margin:0px auto;"></textarea>
            <script type="text/javascript">
            if (typeof CKEDITOR == 'undefined') {
            	document.write('加载CKEditor失败');
            	}
            	else {
            	var editor = CKEDITOR.replace('p_content');
            	CKFinder.SetupCKEditor(editor, 'ckfinder'); //ckfinder总目录的相对路径.
            	}
                CKEDITOR.config.height = 310;
				CKEDITOR.config.width = 630;
            </script></li>
        <li style="width:789px; text-indent:0px; text-align:center;">
          <input type="submit" name="button" id="button" value="  提 交  " />
        </li>
      </ul>
    </div>
  </form>
</div>
</body>
</html>