<?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');

function getolddir($content)
{	
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$olddir_sql="select * from ls_products where position('ls_admin' IN ".$content.")>0 ";
	$olddir_query=$opendb->query($olddir_sql);
	$olddir_rows=mysql_fetch_assoc($olddir_query); 
	$olddirstr=$olddir_rows[$content];
	$olddir=substr($olddirstr,0,strpos($olddirstr,'ls_admin'));
	$olddir=substr($olddir,strrpos($olddir,'"')+1).'ls_admin';
	
	return($olddir);
}

	$ls=$_POST['ls'];
	$replacedir=$_POST['replacedir'];
	$ChangecatePagePic=$_POST['ChangecatePagePic'];
	$ChangecatePagePic2=$_POST['ChangecatePagePic2'];
	
	$image=$_FILES['productPic']['name'];   
	$size=$_FILES['productPic']['size'];   
	$type=$_FILES['productPic']['type'];
	$image2=$_FILES['productPic2']['name'];   
	$size2=$_FILES['productPic2']['size'];   
	$type2=$_FILES['productPic2']['type'];
	
	$con_sql="SELECT * FROM `ls_mobiconfig`";
	$con_query=$opendb->query($con_sql);
	$con_rows=mysql_fetch_assoc($con_query);
	
	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_rows=mysql_fetch_assoc($config_query);
	
	$path = "../m/images";
	$picName = "";
	
	if($con_rows['logo'] == null){
		$classPath="images/picture.gif";
	}else{
		$classPath=$path."/".$con_rows['logo'];
	}
	if($con_rows['qr_code'] == null){
		$classPath2="images/picture.gif";
	}else{
		$classPath2=$path."/".$con_rows['qr_code'];
	}
	
	if ($con_rows)
	{
		if($ls=="modi"){ 
			createFolder($path);
			if($ChangecatePagePic=="yes"){
				//判断图像格式
				if ($type == "image/gif" || $type == "image/png" || $type == "image/pjpeg" || $type == "image/jpeg" )
					{
						if($size < $PicSize) //开始判断图像大小
						{
							$oldbigpic=$path."/".$con_rows['logo'];
							if(file_exists($oldbigpic)){
								
								unlink($oldbigpic);		//delete old big pic
							}
							
							$randomnum=NULL;
							for($j=0;$j<=5;$j++)//随机数字的长度，本例随机数长度为6
							{
							srand((double)microtime()*1000000);
							$randomnumber=rand(!$j ? 1: 0,9);//产生随机数，不以0为第一个数，有些特殊的地方0开头被系统省略
							$randomnum.=$randomnumber;
							}
							
							$dest=date("Ymd").time().$randomnum;//设置文件名为时间戳加上随机数避免重复
	
							$pic = $_FILES['productPic']['name'];
							$pic=substr($pic,(strlen($pic)-4),strlen($pic));
							$picName = $dest.$pic;
							$pathBigPic = $path."/".$picName;
							$classPath=$path."/".$picName;
							//上传文件
							move_uploaded_file($_FILES['productPic']['tmp_name'], $pathBigPic);
						}
						else
						{
							echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
						}
					}else{
						echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
					}
				$update_pic_sql=sprintf("update ls_mobiconfig set logo=%s ",
				GetSQLValueString($picName, "text")
				);
				//更新产品图片
				$update_query=$opendb->query($update_pic_sql);
				//echo $update_sql;
				//更新数据
			}
			if($ChangecatePagePic2=="yes"){
				//判断图像格式
				if ($type2 == "image/gif" || $type2 == "image/png" || $type2 == "image/pjpeg" || $type2 == "image/jpeg" )
					{
						if($size2 < $PicSize) //开始判断图像大小
						{
							if($con_rows['qr_code']!=null){
								$oldbigpic2=$path."/".$con_rows['qr_code'];
								unlink($oldbigpic2);		//delete old big pic
							}
							
							$randomnum2=NULL;
							for($j=0;$j<=5;$j++)//随机数字的长度，本例随机数长度为6
							{
							srand((double)microtime()*1000000);
							$randomnumber2=rand(!$j ? 1: 0,9);//产生随机数，不以0为第一个数，有些特殊的地方0开头被系统省略
							$randomnum2.=$randomnumber2;
							}
							
							$dest2=date("Ymd").time().$randomnum2;//设置文件名为时间戳加上随机数避免重复
	
							$pic2 = $_FILES['productPic2']['name'];
							$pic2=substr($pic2,(strlen($pic2)-4),strlen($pic2));
							$picName2 = $dest2.$pic2;
							$pathBigPic2 = $path."/".$picName2;
							$classPath2=$path."/".$picName2;
							//上传文件
							move_uploaded_file($_FILES['productPic2']['tmp_name'], $pathBigPic2);
						}
						else
						{
							echo "	<script>alert('图像最大为".$PicSize."！');history.go(-1);</script>";
						}
					}
					else
					{
						echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
					}
					
				$update_pic_sql=sprintf("update ls_mobiconfig set qr_code=%s ",
				GetSQLValueString($picName2, "text")
				);
				//更新产品图片
				$update_query=$opendb->query($update_pic_sql);
				//echo $update_sql;
				//更新数据
			}
			$modi_sql="update ls_mobiconfig set 
						companyNameCn =  '".$_POST['companyNameCn']."'  ,
						companyName   =  '".$_POST['companyName']."'	,
						siteKeywords  =  '".$_POST['siteKeywords']."'   ,
						siteDescription = '".$_POST['siteDescription']."'
					  ";
			if($modi_query=$opendb->query($modi_sql)){
				$ls_msg = "修改配制操作成功！";
			}
		}
	}else{
		$templates_m = "Templates_m1";
		$insert_sql=sprintf("INSERT INTO ls_mobiconfig (companyNameCn, companyName, manager, siteKeywords, siteDescription, aboutus, bottomMenu, templates) VALUES(%s,%s,%s,%s,%s,%s,%s,%s) ",
			GetSQLValueString($config_rows['companyNameCn'], "text"),
			GetSQLValueString($config_rows['companyName'], "text"),
			GetSQLValueString($config_rows['manager'], "text"),
			GetSQLValueString($config_rows['siteKeywords'], "text"),
			GetSQLValueString($config_rows['siteDescription'], "text"),
			GetSQLValueString($config_rows['aboutus'], "text"),
			GetSQLValueString($config_rows['bottomMenu'], "text"),
			GetSQLValueString($templates_m, "text")
		 );
		$insert_query=$opendb->query($insert_sql);
	}
	
	if($replacedir=="进行目录整理")
	{
		$currentdir=trim($_POST['currentdir']);
		$olddir=trim($_POST['olddir']);
		$replacedir_sql="update  ls_products set productSpecification=replace(productSpecification,'".$olddir."','".$currentdir."'),   cateBrief=replace(cateBrief,'".$olddir."','".$currentdir."'), cateDetail=replace(cateDetail,'".$olddir."','".$currentdir."'), midcateBrief=replace(midcateBrief,'".$olddir."','".$currentdir."'), midcateDetail=replace(midcateDetail,'".$olddir."','".$currentdir."'), subcateBrief=replace(subcateBrief,'".$olddir."','".$currentdir."'), subcateDetail=replace(subcateDetail,'".$olddir."','".$currentdir."') where 1 ";
		$replacedir_query=$opendb->query($replacedir_sql);  //产品表目录整理
		
		$replacedir_sql="update  ls_singlepages set pageText=replace(pageText,'".$olddir."','".$currentdir."') where 1 ";
		$replacedir_query=$opendb->query($replacedir_sql);  //singlepage目录整理
		
		$replacedir_sql="update  ls_article  set articleText =replace(articleText ,'".$olddir."','".$currentdir."') where 1 ";
		$replacedir_query=$opendb->query($replacedir_sql);  //article目录整理
		
		$replacedir_sql="update   ls_news   set newsText =replace(newsText ,'".$olddir."','".$currentdir."') where 1 ";
		$replacedir_query=$opendb->query($replacedir_sql);  //news目录整理
		
		 $ls_msg="已经进行了目录整理操作";
	}
	
	$mobi_config_sql="select * from ls_mobiconfig ";
	$mobi_config_query=$opendb->query($mobi_config_sql);
	$mobi_config_rows=mysql_fetch_assoc($mobi_config_query);
	
	$olddir=getolddir('productSpecification');
	if($olddir=='ls_admin'){$olddir=getolddir('cateBrief');}
	if($olddir=='ls_admin'){$olddir=getolddir('cateDetail');}
	if($olddir=='ls_admin'){$olddir=getolddir('midcateBrief');}
	if($olddir=='ls_admin'){$olddir=getolddir('midcateDetail');}
	if($olddir=='ls_admin'){$olddir=getolddir('subcateBrief');}
	if($olddir=='ls_admin'){$olddir=getolddir('subcateDetail');}
	//echo $olddir;
	$currentdir=dirname($_SERVER['HTTP_REFERER']);
?>
<!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; content="no-cache, must-revalidate" charset=utf-8">
<link href="css/admin.css" rel="stylesheet" type="text/css">
<link href="css/newui.css" rel="stylesheet" type="text/css">
<title>移动终端配置</title>
</head>
<SCRIPT type=text/javascript src="js/ls2.js"></SCRIPT>
<script type="text/javascript">
	
	function setInnerHTML(){
		var path1 = document.getElementById("select2").value;
		document.getElementById("img1").innerHTML="<img src='../"+path1+"/"+path1+".jpg' width='400' />";
	}
</script>

<body>
<table width="880" border="0" cellpadding="3" cellspacing="1" bgcolor="#6396d6">
	<tr bgcolor="#6396d6">
		<td colspan="4" bgcolor="#6396d6" align="center" height="18"><font color="#FFFFFF"><strong>移动终端系统配置</strong></font></td>
	</tr>
	<tr bgcolor="#6396d6">
		<td align="left" bgcolor="#D6DFF7" >
		<form name="fmconfig" enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF;?>">
			<input type="hidden" name="ls" value="modi" />
			<input type="hidden" name="ChangecatePagePic" value="no">
			<input type="hidden" name="ChangecatePagePic2" value="no">
			<table width="829" style="margin-top:16px;">
				<tr>
					<td colspan="2" align="left">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
					<td width="402" colspan="2">&nbsp;</td>
					</tr>
				<tr>
			</table>
			<table width="829" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF" style=" margin-bottom:20px;">
					<td colspan="3" bgcolor="#B9DAFF">&nbsp;</td>
					</tr>
				<tr bgcolor="#f4f4f4" >
					<td>
						<fieldset class="infofield" >
							<legend>基本信息</legend>
							<table width="380" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="100" align="right">网站首页标题：</td>
									<td width="280"><textarea name="companyName" class="inputareashort2"  ><?php echo $mobi_config_rows['companyName'];?></textarea>
									</td>
								</tr>
							</table>
							<div style="height:6px;"></div>
							<table width="380" border="0" cellspacing="0" cellpadding="0">
							  <tr>
							    <td width="100" align="right">logo图片：</td>
							    <td width="280"><img src="<?php echo $classPath ?>" height="70" border="1" name="pic" style="float:left;"></td>
						      </tr>
							  <tr>
							    <td align="right">选择图片：</td>
							    <td><input type="file" name="productPic" style="width:270px;" onchange="ChangecatePagePic.value='yes';"><br />
					图片宽度应在275点、高度在70点，格式为jpg/gif，大小不要超过<?php echo $PicSize/1000; ?>KB</td>
						      </tr>
						  </table>
                        </fieldset>
					</td>
					<td>
						<fieldset class="infofield"  >
							<legend>SEO优化</legend>
							<table width="380" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="93" align="right"><br />
							      网站关键字<br />
							      Keywords：</td>
									<td width="287"><textarea name="siteKeywords" class="inputareashort2" ><?php echo $mobi_config_rows['siteKeywords'];?></textarea>
									</td>
								</tr>
								<tr>
									<td align="right">网站描述<br />
								    Description：</td>
									<td><textarea name="siteDescription" class="inputareashort2" ><?php echo $mobi_config_rows['siteDescription'];?></textarea>
									</td>
								</tr>
							</table>
						</fieldset>
					</td>
					</tr>
				<tr bgcolor="#f4f4f4">
					<td colspan="3">
						<fieldset class="communfield"  >
						  <table width="800" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="160" height="32" align="right">&nbsp;</td>
									<td width="240">&nbsp;</td>
									<td width="160">&nbsp;</td>
									<td width="240" align="left"><div class="ifproverbutton"  >
										<input type="submit"  value="修改配置" class="submitbuttonsf4">
									  </div>
								  </td>
								</tr>
							</table>
                        </fieldset>
					</td>
				</tr>
				<tr bgcolor="#f4f4f4">
					<td colspan="2">
						<fieldset class="communfield2"  >
							<legend>移动终端链接</legend>
							<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
								<tr bgcolor="#f4f4f4">
									<td width="18%" style="padding-left:12px;" >网站二维码图片：</td>
									<td style="padding-left:3em;" ><img src="<?php echo $classPath2 ?>" width="<?=(isset($thisPicW)?$thisPicW:$SmallPicW)?>" height="<?=(isset($thisPicH)?$thisPicH:$SmallPicH)?>" border="1" name="pic" style="float:left;"><br>
										<br></td>
								</tr>
								<tr bgcolor="#f4f4f4">
									<td style="padding-left:15px;" >选择二维码图片：</td>
									<td style="padding-left:3em;" ><input type="file" name="productPic2" style="width:300px;" onchange="ChangecatePagePic2.value='yes';">
									  <br />
									图片宽度应在200-600点、高度在200-600点，格式为jpg/gif，大小不要超过<?php echo $PicSize/1000; ?>KB</td>
								</tr>
							</table>
						</fieldset>
					</td>
				</tr>
				<tr bgcolor="#f4f4f4">
					<td colspan="3">
						<fieldset class="communfield"  >
						  <table width="800" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="160" height="32" align="right">&nbsp;</td>
									<td width="240">&nbsp;</td>
									<td width="160">&nbsp;</td>
									<td width="240" align="left"><div class="ifproverbutton"  >
										<input type="submit"  value="修改配置" class="submitbuttonsf4">
									  </div>
								  </td>
								</tr>
							</table>
                        </fieldset>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
</table>

</body>
</html>