<?php
//图片中,img_type的类型设置,1:表示企业荣誉图片,2:表示企业实力图片,3:表示首页幻灯图片
	include_once("check_login.php");
	include_once("include/config.php");
	if(@$_GET["action"]) {
		check_site_url();
		$img_type=trim($_POST["img_type"]);
		switch($img_type)
		{
			case "0":
				show_err("请选择要上传的图片类型");
				break;
			case "1":
				$annexFolder = ROOT_PATH . "honner/big";//大图所在目录
				$smallFolder = ROOT_PATH . "honner/small";//小图所在目录
				$resize = true;
				$s_width = 180;
				$s_height = 150;
				//查出现在的最大顺序
				if(!$hm_arr=get_img_order("honner"))
					show_err("查询企业荣誉最大顺序号出错");
				$this_order=$hm_arr[0][0]+1;
				$my_sql1="insert into hmcss_img (img_pic,img_type,img_time,img_order) values ('";
				$my_sql2="',1,'" . date("Y-m-d H:i:s",time()) . "',$this_order)";
				$str_sql="企业荣誉";
				break;
			case "2":
				$annexFolder = ROOT_PATH . "best/big";//大图所在目录
				$smallFolder = ROOT_PATH . "best/small";//小图所在目录
				$resize = true;
				$s_width = 380;
				$s_height = 300;
				//查出现在的最大顺序
				if(!$hm_arr=get_img_order("best"))
					show_err("查询实力展示最大顺序号出错");
				$this_order=$hm_arr[0][0];
				is_null($this_order) ? $this_order = 1 : $this_order = $this_order+1;
				$my_sql1="insert into hmcss_img (img_pic,img_type,img_time,img_order) values ('";
				$my_sql2="',2,'" . date("Y-m-d H:i:s",time()) . "',$this_order)";
				$str_sql="实力图片";
				break;
			case "3":
				$annexFolder = ROOT_PATH . "product/big";//大图所在目录
				$smallFolder = ROOT_PATH . "product/small";//小图所在目录
				$resize = true;
				$s_width = 180;
				$s_height = 130;
				//查该产品相关信息
				$p_id = trim($_POST["p_id"]);
				if(!check_is_numb($p_id) || $p_id < 1)
					show_err("请选择对应的产品");
				$filter_arr[0] = array("0",$p_id,false);
				if(!$hm_arr = get_product($filter_arr))
					show_err("系统中没有对应的产品，请联系管理员");
				$p_pics = $hm_arr[0][8] ? $hm_arr[0][8] . "|" : "";
				$p_pics = str_ireplace("||","|",$p_pics);
				$my_sql1="update hmcss_product set p_pics = '" . $p_pics;
				$my_sql2="' where p_id = $p_id";
				$str_sql="产品图片";
				break;
			case "4":
				$annexFolder = ROOT_PATH . "flash_pic";//所在目录
				$resize = false;
				$my_sql1="insert into hmcss_img (img_pic,img_type,img_time,img_order) values ('";
				$my_sql2="',3,'" . date("Y-m-d H:i:s",time()) . "',0)";
				$str_sql="幻灯图片";
				break;
			case "5":
				$annexFolder = ROOT_PATH . "upload_file/images";//所在目录
				$smallFolder = ROOT_PATH . "upload_file/images";//所在目录
				$resize = true;
				$s_width = 600;
				$s_height = 500;
				$my_sql1="update hmcss_config set config_content = '";
				$my_sql2="' where config_name = 'com_intro_pic'";
				$str_sql="企业简介图片";
				break;
		}
		require("upfile.php");
		$img = new UPImages($annexFolder,$smallFolder);
		//$img->maxWidth = 800;
		//$img->maxHeight = 600;
        $photo = $img->upLoad("upfile");
		//图片文件名入数据库
		if(!mysql_query($my_sql1 . $photo . $my_sql2))
			show_err("新加入图片[$str_sql]失败");
        $img->toFile = true;//设置为true表示生成新的文件，为false则表示不生成新文件，但显示新文件
		if($resize)
        	$newImg = $img->ResizeImg($photo,$smallFolder,$s_width,$s_height);
		//$newImg = $img->ResizeImg($photo,$annexFolder,800,600);
		if($img_type == "4")
			set_flash_xml();
        show_err("已成功上传了图片","set_img_upload.php");
	} else {
?>
<!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">
$(function(){
	$("#img_type").val("0");
	$("#img_type").bind({
		change:function(){
			if($(this).val() == 3){
				$("#p_name1").css("display","");
				$("#p_name2").css("display","");
			}
			else{
				$("#p_name1").css("display","none");
				$("#p_name2").css("display","none");
			}
		}
	});
	}); 
</script>
<style type="text/css"></style>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div class="head_menu"><a href="set_img_flash.php">首页幻灯图</a><a href="set_img_honner.php">企业荣誉图片</a><a href="set_img_best.php">实力展示图片</a><a href="set_product_img.php">产品图片</a><span class="head_menu_on"><a href="set_img_upload.php">图片上传</a></span></div>
<div class="set_main_out">
	<form method="post" action="set_img_upload.php?action=go" enctype="multipart/form-data">
	<div class="set_main">
		<ul>
        	<li style="width:140px;">选择图片类型:</li>
          <li style="width:638px;">
            <select name="img_type" id="img_type">
              <option value="0" selected="selected">请选择</option>
              <option value="1">荣誉图片</option>
              <option value="2">实力展示</option>
              <option value="3">产品图片</option>
              <option value="4">幻灯图片</option>
              <option value="5">简介图片</option>
            </select>
            <span style="font-size: 12px; color: #999"> 请您选择上传图片的类型</span>
          </li>
          <li id="p_name1" style="width:140px; display:none;">选择对应产品:</li>
          <li id="p_name2" style="width:638px; display:none; overflow:hidden;">
            <select name="p_id" id="p_id">
            <?php
            	if($hm_arr = get_product()){
					foreach($hm_arr as $key => $val)
						echo " <option value=\"$val[0]\">$val[3]</option>\n\r";
				}
				else
					echo " <option value=\"0\">请先添加产品</option>\n\r";
			?>
            </select>
          </li>
        	<li style="width:789px;"><input type="file" name="upfile" size="50"><input type="submit" value="上传">
            <span style="font-size: 12px; color: #999"> 请上传图片(jpg,gif,png格式，大小不超过1M)</span>
          </li>
    	</ul>
	</div>
   </form>
</div>
</body>
</html>
<?php
}
?>