<?php
require dirname(__FILE__) . "/dzsck.php";

/*$upfile = $_FILES['upfile'];  本地视频上传
function upload_file($files, $path = "../shootingimg/video",$imagesExt=['jpg','png','jpeg','gif','mp4']){
    // 判断错误号
    if (@$files['error'] == 00) {
        // 判断文件类型
        $ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));
        if (!in_array($ext,$imagesExt)){
            return "非法文件类型";
        }
        // 判断是否存在上传到的目录
        if (!is_dir($path)){
            mkdir($path,0777,true);
        }
        // 生成唯一的文件名
        $fileName = md5(uniqid(microtime(true),true)).'.'.$ext;
        // 将文件名拼接到指定的目录下
        $destName = $path."/".$fileName;
        // 进行文件移动
        if (!move_uploaded_file($files['tmp_name'],$destName)){
            return "文件上传失败！";
        }
        return $destName;
    } else {
        // 根据错误号返回提示信息
        switch (@$files['error']) {
            case 1:
                echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
                break;
            case 2:
                echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
                break;
            case 3:
                echo "文件只有部分被上传";
                break;
            case 6:
            case 7:
                echo "系统错误";
                break;
        }

    }

}*/

/** 本地图片上传 **/
$file = $_FILES['file'];
function upload_file2($files, $path = "../shootingimg/images",$imagesExt=['jpg','png','jpeg','gif']){
    // 判断错误号
    if (@$files['error'] == 00) {
        // 判断文件类型
        $ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));
        if (!in_array($ext,$imagesExt)){
            return "非法文件类型";
        }
        // 判断是否存在上传到的目录
        if (!is_dir($path)){
            mkdir($path,0777,true);
        }
        // 生成唯一的文件名
        $fileName = md5(uniqid(microtime(true),true)).'.'.$ext;
        // 将文件名拼接到指定的目录下
        $destName = $path."/".$fileName;
        // 进行文件移动
        if (!move_uploaded_file($files['tmp_name'],$destName)){
            return "文件上传失败！";
        }
        return $destName;
    } else {
        // 根据错误号返回提示信息
        switch (@$files['error']) {
            case 1:
                echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
                break;
            case 2:
                echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
                break;
            case 3:
                echo "文件只有部分被上传";
                break;
            case 6:
            case 7:
                echo "系统错误";
                break;
        }

    }

}

$s_id = $_GET['s_id'];

$cm->query("SELECT * FROM d_shooting where s_id=".$s_id);
$row = $cm->fetch_array($rs);

if (($_GET["type"] == "edit")) {
		$pic = upload_file2($file);
		if($pic == null){
			$cm->query("SELECT * FROM d_shooting where s_id=".$_POST['id']);
			$hh = $cm->fetch_array($rs);
			if($hh['s_pic'] != ""){
				$pic = $hh['s_pic'];
			}else{
				$pic = $_POST["s_pic2"];
			}
		}
		$url2 = $_POST["upfile2"];
		$date = array(
			"s_name" => $_POST["s_name"],
			"s_pic" => $pic,
			"s_url" => $url2,
			"s_content" => $_POST["s_content"]
		);
		
		$updates = $cm->cmupdate($date,"s_id='" . $_POST["id"]."'", "d_shooting");
		if($updates){
			echo tiao("修改成功！", "shooting.php");
			exit();
		}else{
			echo tiao("修改失败,请重新修改！", "editshooting.php?id=" . $_POST["id"]);
			exit();
		} 
		
}
?>
<!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="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改商品</title>
<link href="public/css/base.css" rel="stylesheet" type="text/css" />
<link href="public/css/style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
        #myEditor{
            width: 600px;
            height: 180px;
        }
		#myEditor1{
            width: 600px;
            height: 180px;
        }
</style>
</head>
<body>
<div class="tab" id="tab"> <a class="selected" href="#">修改用户</a></div>
<div class="page_form">
<form name="form2" method="post" action="?type=edit" enctype="multipart/form-data">
<div class="page_table form_table">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <input type="hidden" name="id" value="<?php echo $row['s_id']?>" />
        <tr>
			<td width="132" align="right">影视名</td>
			<td width="500">
				<input type="text" name="s_name" value="<?=$row['s_name']?>" />
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视封面图</td>
			<td width="385">
				<input type="hidden" name="MAX_FILE_SIZE" value="2000000000">
				<?php if($row['s_pic']!==""){?>
				<img src="<?=$row['s_pic']?>" width="100px" height="100px" />
				<?php } ?>
				<input type="file" name="file" id="image-input" />   
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视外部封面图</td>
			<td width="385">
				<input type="text" name="s_pic2" value="<?=$row['s_pic']?>" style="width:500px;">最初添加为外部图片的条件下修改，否则请点上面上传
			</td>
		</tr>
		<tr>
			<td width="132" align="right">影视外部链接</td>
			<td width="385">
				<input type="text" name="upfile2" value="<?=$row['s_url']?>" style="width:500px;">
			</td>
		</tr>
		
		<tr>
			<td width="132" align="right">影视简介</td>
			<td width="385">
				<textarea name="s_content"><?=$row['s_content']?></textarea>
			</td>
		</tr>
    </table>
</div>
<!--普通提交-->
<div class="form_submit">
<button type="submit" class="button">修改</button> 
</div>
</form>
</div>
</div>
<div class="fn_clear"></div>
</body>
</html>