<?php
    session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
?>
<!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">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<title>无标题文档</title>
	</head>

	<body>
<?PHP

			
	$ls=$_POST['ls'];
	$id=$_POST['id'];
	
	$workshopText=$_POST['workshopText'];
	$ChangecatePagePic=$_POST['ChangecatePagePic'];
	$image=$_FILES['productPic']['name'];   
  $size=$_FILES['productPic']['size'];   
  $type=$_FILES['productPic']['type'];
	
	switch ($ls)
	{
		case "insert":
			if ($type == "image/gif" || $type == "image/png" || $type == "image/pjpeg" )
				{
				 if($size < $PicSize) //开始判断图像大小
					{
															$pathBigPic="../".$WorkShopFolders."/".$BigFoldersProducts;
															//echo $pathBigPic."<br>";
															//创建大图文件夹
															createFolder($pathBigPic);
															$pathSmallPic="../".$WorkShopFolders."/".$SmallFoldersProducts;
															//echo $pathSmallPic."<br>";
															//创建小图文件夹
															createFolder($pathSmallPic);
													  	
													  	$arr=array(" ",".");   
													  	//产生文件名   
													  	$productPic=str_replace($arr ,"",time()).".".substr($image,-3);
													  	
													  	$pathBigPic=$pathBigPic."/".$productPic;
													  	//echo $pathBigPic."<br>";
													  	//上传文件
													  	move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
													  	
													  	$srcFile=$pathBigPic; //源地址
													  	$toW=$SmallPicW;			//宽度
													  	$toH=$SmallPicH;			//高度
													  	$toFile=$pathSmallPic."/".$productPic; //目标地址
													  	//生成缩略图
													  	ImageResize($srcFile,$toW,$toH,$toFile);
													  	
													  	$insert_sql=sprintf("insert into ls_management(Pic,Text,Num,enable) values(%s,%s,%s,%s)",
													  										GetSQLValueString($productPic, "text"),
													  										GetSQLValueString($workshopText, "text"),
													  										GetSQLValueString($SortingNum, "int"),
													  										GetSQLValueString("1", "int")
													  										);
													  	$insert_query=$opendb->query($insert_sql);
													  	echo "
																		<form name=\"fm\" method=\"post\" action=\"addmanagement.php\">
																		<input type=\"hidden\" value=\"".$workshopText."\" name=\"workshopText\">
																		<table width='96%' border='0' align='center' cellpadding='1' cellspacing='1' bgcolor='#6396d6'>
																			<tr>
																				<td height='18' background='images/admin_bg.gif'><div align='center'><font color='#ffffff'><strong>添加信息</strong></font></div>
																				</td>
																			</tr>
																			<tr>
																				<td height='213' valign='top' bgcolor='#dee7ff'><br>
																					<table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
					 
																					  <tr bgcolor=\"#B9DAFF\"> 
																						<td height=\"28\" colspan=\"2\"></td>
																					  </tr>
																					  <tr bgcolor=\"#f4f4f4\"> 
																						<td style=\"padding-left:50px;\" >*缩略图：</td>
																						<td style=\"padding-left:5px;\" >
																							<img src=\" ".$toFile." \" width=\"".$toW."\" height=\"".$toH."\" border=\"1\" >
																							
																						</td>
																					  </tr>
																					  <tr bgcolor=\"#f4f4f4\"> 
																						<td style=\"padding-left:50px;\" width=\"30%\">简介：</td>
																						<td>
																						".$workshopText."
																						</td>
																					  </tr>
																					  <tr bgcolor=\"#B9DAFF\"> 
																						<td height=\"28\" colspan=\"2\" align=\"center\">
																						<input type=\"submit\" value=\"继续添加\">
																						<input type=\"button\" value=\"返回列表\" onclick=\"javascript:location='management.php';\">
																						</td>
																					  </tr>
																					
																					</table>
																				</td>
																			</tr>
																			</table>
																			</form>
																		";
					}						
				 else
					{
						echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
					}
				}
			else
				{
					 echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
				}
			
			break;
		
	
		case "update":
					
					  if($ChangecatePagePic=="yes")
	  				 	{
	  				 		//判断图像格式
	  				 		if ($type == "image/gif" || $type == "image/png" || $type == "image/pjpeg" )
										{
											if($size < $PicSize) //开始判断图像大小
											{
													  $pathBigPic="../".$WorkShopFolders."/".$BigFoldersProducts;
															$pathSmallPic="../".$WorkShopFolders."/".$SmallFoldersProducts;
															
															$arr=array(" ",".");   
													  	//产生文件名   
													  	$pic=$_POST['Pic'];
													  	$pic=trim(str_replace(substr($image,-4),"",$pic));
													  	//echo $pic;
													  	$productPic=str_replace($arr ,"",$pic).".".substr($image,-3);
													  														  	
													  	$pathBigPic=$pathBigPic."/".$productPic;
													  	//echo $pathBigPic;
													  	//上传文件
													  	move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
													  	
													  	$srcFile=$pathBigPic; //源地址
													  	$toW=$SmallPicW;			//宽度
													  	$toH=$SmallPicH;			//高度
													  	$toFile=$pathSmallPic."/".$productPic; //目标地址
													  	//生成缩略图
													  	ImageResize($srcFile,$toW,$toH,$toFile);			
								}
											else
											{
												echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
											}
										}
										else
										{
											 echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
										}
	  				 	} 
	  				 	
															$update_sql=sprintf("update ls_management set Text=%s where ID=%s",
																									  GetSQLValueString($workshopText, "text"),
																										GetSQLValueString($id, "int")
																								);
														  //echo $update_sql;
														  //更新数据
														  $update_query=$opendb->query($update_sql);
														  echo "<script>alert('数据更新成功!\\n请刷新本页！');location='modimanagement.php?id=".$id."';</script>";
				
		break;	
	}
?>
	</body>
</html>