<?php
require_once '../../library/config.php';


if (isset($_POST['item'])){
	$col_name = $_POST['item'];
	$id = $_POST['p_id'];
	if($col_name == 'dimension'){
		$height = $_POST['height'];
		$width = $_POST['width'];
		$lenght = $_POST['lenght'];
		mysql_query("UPDATE product_list SET height = '$height', width = '$width', lenght = '$lenght' WHERE p_id = '$id'", $connePaper);
	} elseif ($col_name == 'cate'){
		$cate = $_POST['p_cat_id'];
		$subcate = $_POST['p_subcat_id'];
		mysql_query("UPDATE product_list SET p_cat_id = '$cate', p_subcat_id = '$subcate'  WHERE p_id = '$id'", $connePaper);
		
	} elseif ($col_name == 'album_id'){
		$album_id = $_POST['input_val'];
		mysql_query("UPDATE product_list SET p_album_id = '$album_id'  WHERE p_id = '$id'", $connePaper);
		
	} elseif ($col_name == 'p_more_photo'){
		if ($_POST['post_photo']){
			$post_photo = implode(",", $_POST['post_photo']);
			mysql_query("UPDATE product_list SET p_image_more = '$post_photo' WHERE p_id = '$id'", $connePaper);
		} else {
			mysql_query("UPDATE product_list SET p_image_more = '' WHERE p_id = '$id'", $connePaper);
		}
		if ($_POST['del_photo']){
			
			$del_photo = implode(",", $_POST['del_photo']);
			$del_img = explode(",", $del_photo);
			
			foreach ($del_img  as $img_link) : 
			$deleteImage = '../upload/product_images/'.$img_link;
			unlink($deleteImage);
			endforeach;
		} 
		
	} elseif ($col_name == 'ep_p_name'){
		$value = $_POST['input_val'];
		mysql_query("UPDATE product_list SET p_name = '$value' WHERE p_id = '$id'", $connePaper);
		
		$code = strtolower($value);
		$code = trim($code);
		$code = str_replace(" ","-",$code);
		$code = str_replace("'","",$code);
		
		mysql_query("UPDATE product_list SET p_code = '$code' WHERE p_id = '$id'", $connePaper);
	} else {
		$value = $_POST['input_val'];
		mysql_query("UPDATE product_list SET `$col_name` = '$value' WHERE p_id = '$id'", $connePaper);
		
	}
}
if (isset($_POST['del_cover'])){
	$deleteCover = '../upload/cover_images/'.$_POST['del_cover'];
	unlink($deleteCover);
}
if (isset($_POST['del_p_image'])){
	$deletePimage = '../upload/product_images/'.$_POST['del_p_image'];
	unlink($deletePimage);
}
mysql_close($connePaper);

?>
<b style="color:red;">更新成功!!</b>

<script type="text/javascript">
	setTimeout(function(){location.reload()}, 100);
</script>
