<?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');
	
	$statistics=$_POST['statistics'];
	$onlines=$_POST['onlines'];
	$maps=$_POST['maps'];
	$share=$_POST['share'];
	$shield=$_POST['shield'];
	$aboutLenght=$_POST['aboutLenght'];
	$indexPassword=$_POST['indexPassword'];
	$htaccess=$_POST['htaccess'];
	$robot=$_POST['robot'];
	$statisticsUrl=$_POST['statisticsUrl'];
	
	$onlinechartUrl=$_POST['onlinechartUrl'];
	$onlinechartName=$_POST['onlinechartName'];
	$onlinechartPsd=$_POST['onlinechartPsd'];
	
	$code2=$_POST['code2'];
	$onlinechart=$_POST['onlinechart'];
	$reserve1=$_POST['reserve1'];
	$reserve2=$_POST['reserve2'];
	$reserve3=$_POST['reserve3'];
	$ls=$_POST['ls']; 
	
	//二维码参数  开始
	$data=$_POST['data'];
	$olddata=$_POST['olddata'];
	$level=$_POST['level'];
	$size=$_POST['size'];
	
	$logo_name=$_FILES['logoFile']['name'];
	$logo_size=$_FILES['logoFile']['size'];
	$logo_type=$_FILES['logoFile']['type'];
	$ChangecatePagePic=$_POST['ChangecatePagePic'];
	$ChangecatePage=$_POST['ChangecatePage'];
	//二维码参数  结束
	
	switch($ls)
	{
		case "insert":
			$update_sql=sprintf("update ls_config set statistics=%s, onlines=%s, maps=%s,onlinechart=%s, share=%s, shield=%s, aboutLenght=%s, indexPassword=%s, qr_data=%s, htaccess=%s, robot=%s, statisticsUrl=%s, onlinechartUrl=%s, onlinechartName=%s, onlinechartPsd=%s", 
							GetSQLValueString($statistics, "text"),
							GetSQLValueString($onlines, "text"), 
							GetSQLValueString($maps, "text"),
							GetSQLValueString($onlinechart, "text"),
							GetSQLValueString($share, "text"),
							GetSQLValueString($shield, "text"),
							GetSQLValueString($aboutLenght, "text"),
							GetSQLValueString($indexPassword, "text"),
							GetSQLValueString($data, "text"),
							GetSQLValueString($htaccess, "text"),
							GetSQLValueString($robot, "text"),
							GetSQLValueString($statisticsUrl, "text"),
							GetSQLValueString($onlinechartUrl, "text"),
							GetSQLValueString($onlinechartName, "text"),
							GetSQLValueString($onlinechartPsd, "text")
							);
			if($update_query=$opendb->query($update_sql)){
				$ls_msg="修改操作成功！";
			}else{
				$ls_msg="修改操作失败！";
			}
			
			break;
	}
	
	$select_sql="select * from ls_config ";
	$select_query=$opendb->query($select_sql);
	$select_rows=mysql_fetch_assoc($select_query);
	
	$statistics2 = $select_rows['statistics'];
	$onlines2 = $select_rows['onlines'];
	$maps2 = $select_rows['maps'];
	$share2 = $select_rows['share'];
	$shield2 = $select_rows['shield'];
	$indexPassword2 = $select_rows['indexPassword'];
	$aboutLenght2 = $select_rows['aboutLenght'];
	$qr_data = $select_rows['qr_data'];
	$htaccess2 = $select_rows['htaccess'];
	$robot2 = $select_rows['robot'];

	$ls_msg="功能代码操作";
	
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);
}
	$replacedir=trim($_POST['replacedir']);
	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="已经进行了目录整理操作";
	}
	
	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_rows=mysql_fetch_assoc($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']);
	
	$htaccess_path = "../.htaccess";
	$robots_path = "../robots.txt";
	
	if(file_exists($htaccess_path)){
		if (is_file ($htaccess_path)){ 
			@unlink ($htaccess_path); //若文件已存在，则删除
		}
	}
	$fp = fopen($htaccess_path,"w");
	fwrite($fp,$htaccess2);
	fclose($fp);
	
	if(file_exists($robots_path)){
		if (is_file ($robots_path)){ 
			@unlink ($robots_path); //若文件已存在，则删除
		}
	}
	$fp = fopen($robots_path,"w");
	fwrite($fp,$robot2);
	fclose($fp);
?>
<!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>
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="../themes/default/default.css" />
		<script language="JavaScript" src="js/ls.js"></script>
</head>
<body>
		<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>
				 <form name="newsform" enctype="multipart/form-data" method="post" action="ls_functioncode.php" >
					<input type="hidden" value="insert" name="ls">
                    <input type="hidden" value="<?=$code?>" name="code2">
                    <input type="hidden" name="ChangecatePagePic" value="no">
                    <input type="hidden" name="ChangecatePage" value="no">
				   <table border="0" width="98%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right">&nbsp;</td>
						</tr>
					</table>
					<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					  <tr bgcolor="#B9DAFF"> 
						<td width="10%" height="28" ></td>
                        <td height="28" colspan="3"  style="padding-left:30px;" ></td>
                      </tr>
                      <tr bgcolor="#f4f4f4">
                        <td width="10%">&nbsp;</td>
                        <td style="padding-left:30px;">
                        	首页“关于我们”长度：                       	    <input type="text" value="<?php echo $select_rows['aboutLenght'];?>" name="aboutLenght" class="ifinfoinputshort"  >
                        </td>
                        <td width="12%">&nbsp;</td>
                        <td width="35%" align="right"><input type="submit" value="提交" /></td>
                      </tr>
					  <tr bgcolor="#f4f4f4"> 
                      	<td width="10%" rowspan="2" align="right">统计代码：</td>
						<td colspan="3" valign="middle"  style="padding-left:30px;">
                        <textarea name="statistics" style="width:85%;height:120px;"><?php echo htmlspecialchars($statistics2); ?></textarea>
                        启用
                        <label>
                          <input name="checkbox" type="checkbox" id="checkbox" checked="checked" />
                        </label></td>
						</tr>
                      <tr bgcolor="#f4f4f4">
                      	<td style="padding-left:30px;">
                        	访问统计网址：                       	    <input type="text" value="<?php echo $select_rows['statisticsUrl'];?>" name="statisticsUrl" style="width:230px;" >
                        </td>
                        <td width="12%"><input type="button" onclick="window.open('<?=$select_rows['statisticsUrl']?>')" value="查看统计" /></td>
                        <td width="35%" align="right"><input type="submit" value="提交" /></td>
                      </tr>
                        <tr bgcolor="#f4f4f4">
                        <td align="right">在线联系代码<br />
                          （QQ）：</td>
						<td colspan="3"  style="padding-left:30px;">
                        <textarea name="onlines" style="width:85%;height:120px;"><?php echo htmlspecialchars($onlines2); ?></textarea>
                        启用
                        <label>
                          <input name="checkbox2" type="checkbox" id="checkbox2" checked="checked" />
                        </label></td>
						</tr>
                        <tr bgcolor="#f4f4f4">
                          <td width="10%" rowspan="2" align="right">在线客服：</td>
                          <td colspan="3"  style="padding-left:30px;"><textarea name="onlinechart" style="width:85%;height:120px;"><?php echo htmlspecialchars($onlinechart); ?></textarea>
                            启用
                            <label>
                              <input name="checkbox3" type="checkbox" id="checkbox3" />
                          </label></td>
                        </tr>
                          <tr bgcolor="#f4f4f4">
                            <td style="padding-left:30px;">
                                在线客服登录地址： 
                                  <input type="text" value="<?php echo $select_rows['onlinechartUrl'];?>" name="onlinechartUrl" style="width:230px;" >
                            </td>
                            <td width="12%"><input type="button" onclick="window.open('<?=$select_rows['onlinechartUrl']?>')" value="登录客服" /></td>
                            <td width="35%" align="right"><input type="submit" value="提交" /></td>
                          </tr>
                        <tr bgcolor="#f4f4f4">
                      	<td align="right">地图代码：</td>
						<td colspan="3"  style="padding-left:30px;">
                        <textarea name="maps" style="width:85%;height:120px;"><?php echo htmlspecialchars($maps2); ?></textarea>
                        启用
                        <label>
                          <input name="checkbox4" type="checkbox" id="checkbox4" checked="checked" />
                        </label></td>
						</tr>
                        <tr bgcolor="#f4f4f4"> 
                        <td align="right">社交网站分享<br />代码：</td>
						<td colspan="3"  style="padding-left:30px;">
                        <textarea name="share" style="width:85%;height:120px;"><?php echo htmlspecialchars($share2); ?></textarea>
                        启用
                        <label>
                          <input name="checkbox5" type="checkbox" id="checkbox5" checked="checked" />
                        </label></td>
						</tr>
                      <tr bgcolor="#f4f4f4">
                      	<td align="right">.htaccess：</td>
						<td colspan="3"  style="padding-left:30px;">
                        <textarea name="htaccess" style="width:85%;height:120px;"><?php echo htmlspecialchars($htaccess2); ?></textarea>
						</td>
						</tr>
                        <tr bgcolor="#f4f4f4"> 
                        <td align="right">robots.txt：</td>
						<td colspan="3"  style="padding-left:30px;">
                        <textarea name="robot" style="width:85%;height:120px;"><?php echo htmlspecialchars($robot2); ?></textarea>
						</td>
						</tr>
                        <tr bgcolor="#f4f4f4">
                        <td width="10%">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td width="12%">&nbsp;</td>
                        <td width="35%" align="right" style="padding-right:10px;"><input type="submit" value="提交" /></td>
                      </tr>
                        <tr bgcolor="#f4f4f4">
                        <td align="right">屏蔽代码：<br /></td>
						<td style="padding-left:30px;">
                        <textarea name="shield" style="width:100%;height:120px;"><?php echo $shield2; ?></textarea>
						</td>
                        <td width="12%" align="left" valign="bottom"><p><span style="">启用
                              <label>
                                <input name="checkbox6" type="checkbox" id="checkbox6" checked="checked" />
                              </label>
                        </span></p></td>
                        <td width="35%"><p>访问密码：
                          <input type="text" value="<?php echo $select_rows['indexPassword'];?>" name="indexPassword" class="ifinfoinputshort"  >
                        </p></td>
						</tr>
<?php
include 'phpqrcode/phpqrcode.php';

$value = $data; //二维码内容 
$errorCorrectionLevel = $level;//容错级别  
$matrixPointSize = $size;//生成图片大小  //生成二维码图片
if($value != $olddata || $ChangecatePage=="yes")
	QRcode::png($value, 'qr/qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
if($ChangecatePagePic=="yes"){
	if ($logo_type == "image/gif" || $logo_type == "image/png" || $logo_type == "image/x-png" || $logo_type == "image/pjpeg" || $logo_type == "image/jpeg" ){
		if($logo_size < $PicSize){
			
			$pathBigPic="company_logo";

			//echo $pic;
			$productPic="logo.".substr($logo_name,-3);																			
			$pathBigPic=$pathBigPic."/".$productPic;
			//echo $pathBigPic;
			//上传文件
			move_uploaded_file($_FILES['logoFile']['tmp_name'], $pathBigPic);
			$toW=60;			//宽度
			$toH=60;			//高度
			$toFile=$pathBigPic;		//目标地址
			$srcFile=$pathBigPic;	//目标地址
			if(!$_POST['automationGif'])  //是动画则不缩小
			{
				ImageResize($srcFile,$toW,$toH,$toFile);	//resize the big pic width & height to stand size
			}
			chmod($toFile,0644);

			$logo = $pathBigPic;//准备好的logo图片  
			$QR = 'qr/qrcode.png';//已经生成的原始二维码图     
			if ($logo !== FALSE) {   
				$QR = imagecreatefromstring(file_get_contents($QR));   
				$logo = imagecreatefromstring(file_get_contents($logo));   
				$QR_width = imagesx($QR);//二维码图片宽度   
				$QR_height = imagesy($QR);//二维码图片高度   
				$logo_width = imagesx($logo);//logo图片宽度   
				$logo_height = imagesy($logo);//logo图片高度
				$logo_qr_width = $QR_width / 5;
				$scale = $logo_width/$logo_qr_width;
				$logo_qr_height = $logo_height/$scale;
				$from_width = ($QR_width - $logo_qr_width) / 2;   //重新组合图片并调整大小   
				imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,   $logo_qr_height, $logo_width, $logo_height);  
			}  //输出图片  
			imagepng($QR, 'qr/qrcode.png');
		}else{
			echo "	<script>alert('图片最大为".$PicSize."！');history.go(-1);</script>";
		}
	}else{
		echo "	<script>alert('请选择图片上传，或者你选择的文件不符合要求!\\n只允许格式 .gif .png .jpeg');history.go(-1);</script>";
	}
}
?>
                        <tr bgcolor="#f4f4f4"> 
                        <td align="right">二维码生成：</td>
						<td colspan="3"  style="padding-left:30px;">
               	    <table width="93%" border="0" align="left" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                              <tr bgcolor="#f4f4f4">
                                <td width="34%">&nbsp;</td>
                                <td width="12%">&nbsp;</td>
                                <td width="54%">&nbsp;</td>
                              </tr>
                              <tr bgcolor="#f4f4f4">
                                <td rowspan="4" align="center">
                                <img src="qr/qrcode.png<?php echo "?t=".rand();?>">
                                </td>
                                <td align="right">文本内容：</td>
                                <td>
                                    <textarea name="data" style="width:90%;height:120px;"><?php echo (isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):$qr_data)?></textarea>
                                </td>
                              </tr>
                              <tr bgcolor="#f4f4f4">
                                <td align="right">质量：</td>
                                <td><select name="level" onChange="newsform.ChangecatePage.value='yes';">
                                        <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>
                                        <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option>
                                        <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option>
                                        <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
                                    </select></td>
                              </tr>
                              <tr bgcolor="#f4f4f4">
                                <td align="right">尺寸：</td>
                                <td>
                                <select name="size" onChange="newsform.ChangecatePage.value='yes';">;
                                <?php 
								$matrixPointSize = 4;
								for($i=1;$i<=10;$i++)
                                    echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
                                ?>
                                </select>
                                </td>
                              </tr>
                              <tr bgcolor="#f4f4f4">
                                <td align="right">Logo:</td>
                                <td><input type="file" name="logoFile" style="width:400px;" onChange="newsform.ChangecatePagePic.value='yes';"></td>
                              </tr>
                              <tr bgcolor="#f4f4f4">
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>修改二维码信息后，点击“提交”按钮生成。
                                  <input type="hidden" name="olddata" value="<?=$qr_data?>" /></td>
                              </tr>
                            </table>
                        </td>
                        <tr bgcolor="#c4cfff">
                            <td colspan="4" align="center"><?php file_exists("widget/ls_config_replacedir.php")?include "widget/ls_config_replacedir.php":""?></td>
                        </tr>
					  <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="4" align="center"><input type="submit" value="提交">
						    <input type="reset" name="button" id="button" value="重置" /></td>
					  </tr>
					</table>
				</form>
				</td>
			</tr>
		</table>
	</body>
</html>

