<?php 	require_once('_approot.php');  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
	$ls=$_POST['ls'];
	//内链代码开始
	$in=$_GET['in'];
	$id=$_GET['id'];
	$modiid=$_POST['modiid'];
	$scanning=$_GET['scanning'];
	
	$oldstr=htmlspecialchars($_POST['oldstr'], ENT_QUOTES); //  
	$Num=$_POST['Num'];
	$newstr=htmlspecialchars($_POST['newstr'], ENT_QUOTES);
	$nowlinknum=$_GET['Num'];
	$startdir=trim($_POST['startdir']); //  
	 
	 
 

	switch ($in)
	{
		case "up":
			$down=$nowlinknum-1;
			$down_sql="update ls_replace set Num=".$nowlinknum." where Num=".$down." ";
			$down_sql2="update ls_replace set Num=Num-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";
			break;
		case "down":
			$up=$nowlinknum+1;
			$up_sql="update ls_replace set Num=".$nowlinknum." where Num=".$up."  ";
			$up_sql2="update ls_replace set Num=Num+1 where id=".$id." ";
			
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";

			break;
		case "insert":
			$select_sql2="select * from ls_replace where oldstr='".$oldstr."' and  startdir='".$startdir."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysqli_num_rows($select_query2); //总数
			if(trim($oldstr)!=""){
				if($select_rows2>0){
					$ls_msg="<script> alert('替换词已经存在，请重添加');</script>";
				}else{
					$select_sql2="select * from ls_replace ";
					$select_query2=$opendb->query($select_sql2);
					$select_rows2=mysqli_num_rows($select_query2); //总数
	
					$insert_sql="insert into ls_replace(oldstr,newstr,startdir,Num,enable) values ('".$oldstr."','".$newstr."','".$startdir."',".($select_rows2+1).",1)";
					//echo $insert_sql;
					$insert_query=$opendb->query($insert_sql);
	
					$ls_msg="添加操作成功！";
				}
			}
			break;
		case "modi":
			$modi_sql="update ls_replace set startdir='".$startdir."', oldstr='".$oldstr."',   newstr='". $newstr ."', startdir='".$startdir."'  where id=".$modiid." ";
			 
			$modi_query=$opendb->query($modi_sql);
			
			$ls_msg="修改操作成功！";
				
			break;
		case "del":
		 
			$link_sql2="select * from ls_replace where id=".$id." ";
			$link_query2=$opendb->query($link_sql2);
			$link_rows2=mysqli_fetch_assoc($link_query2);
			$num_sql2="update ls_replace set Num=Num-1 where Num>".$link_rows2['Num']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);
		
			$del_sql="delete from ls_replace where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			break;
		case "unenable":
			$unenable_sql="update ls_replace set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="禁止操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_replace set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="允许操作成功！";
			break;
	}
	
	if($scanning=="replace")
	{
		$totalfile=0; //function replmutilang +1
		$totalstr=0; //function replmutilang  

		$in_sql="SELECT * FROM ls_replace where enable=1 order by Num asc"; //count the error by searchtype
		$in_query=$opendb->query($in_sql);
		 
		while ($in_rows=mysqli_fetch_assoc($in_query)){
		 $oldstr1=htmlspecialchars_decode($in_rows['oldstr']);
		 $newstr1=htmlspecialchars_decode($in_rows['newstr']);
		 if(is_dir($in_rows['startdir']))
		 { 	treeoperatefiles($in_rows['startdir'], "noreplmutilang","replmutilang" ) 	; }
		 else
		 {
			 $ls_msg=$in_rows['startdir']." 文件夹不存在，";
		 }
		}
		
  		$ls_msg.=" 替换".$totalfile."个文件，".$totalstr."个词组";
		
	}elseif($scanning=="clear"){
		$in_sql="SELECT * FROM ls_replace where enable=1 order by Num asc"; //count the error by searchtype
		$in_query=$opendb->query($in_sql);
		$totalfile=0; //function replmutilang +1
		$totalstr=0; //function replmutilang 
		 
		while ($in_rows=mysqli_fetch_assoc($in_query)){
		 $oldstr1=htmlspecialchars_decode($in_rows['newstr']);
		 $newstr1=htmlspecialchars_decode($in_rows['oldstr']);
		 treeoperatefiles($in_rows['startdir'],"noreplmutilang","replmutilang" ) 	;
		}
		$ls_msg="清除"  .$totalfile."个文件，".$totalstr."个词组";
;
	}
		if($scanning=="delall"){
 			$in_sql="delete   from ls_replace where 1"; //count the error by searchtype
			$in_query=$opendb->query($in_sql);
		}
	
	$select_sql2="select * from ls_replace where enable=1 ";
	$select_query2=$opendb->query($select_sql2);
	$link_num=mysqli_num_rows($select_query2); //总数
	
	$in_sql="SELECT * FROM ls_replace order by Num asc"; //count the error by searchtype
	$in_query=$opendb->query($in_sql);
	//内链代码结束
	
	
	
?>
<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 href="css/newui.css" rel="stylesheet" type="text/css">
   <link rel="stylesheet" href="css/style2.css" />
<SCRIPT type=text/javascript src="js/ls2.js"></SCRIPT>
<style type="text/css"> 
div,ul,li {margin:0;padding:0;}
ul{list-style-type:none;}
#fo li{ width:350px;}
#tul{list-style-type:none;width:240px;background:#D6DFF7;margin-bottom:30px;}
#tul:after{content:".";display:block;clear:both;line-height:0px;height:0;visibility:hidden;}
.tul li { width:50%; height:30px; line-height:30px; text-align:center; color:#0c3d66;background:#e3e6ed; font-size:14px; float:left;  color:#2064ae;cursor: hand;!important;cursor: pointer}
.tul .check { background:white;font-weight: bold; } 
.slist { width:350px; height:170px;margin:auto;}
#cont{
	width:380px;
	height:250px;
	border:1px solid gray;
}
#nei{
	clear:both;
	width:360px;
	height:100px;
	padding:10px;
}
</style> 
<script type="text/javascript" src="js/jquery.js"></script>
<script language="JavaScript" src="js/ls.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' />";
	}
    
    jQuery(document).ready(function(){
        jQuery('.tul li').click(
                function(){
                        jQuery(this).siblings().removeClass("check");
                        jQuery(this).addClass("check");
                        var tid = "#" + jQuery(this).attr('id') + "_cont";
                        jQuery(tid).siblings().hide();
                        jQuery(tid).show();
                        
                },
                function(){}
        );
});
	
</script>

<script type="text/javascript">
function internal(operation){
	var action = "ls_replace.php?action="+operation;
	$.ajax({
		type: "POST",
		newstr: action,
		error: function(request) {
		},
		success: function(response)
		{
			if(response == "repeat"){
				alert("链接已经存在 或链接文字为空。");
			}else{
				if(response == "fail"){
					//alert("自动添加失败");
				}else{
					//alert("自动添加成功");
					window.location.href="ls_replace.php";
				}
			}
		}
	});
}
</script>
</head>
<body>
<?php echo $msg_er;?>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
	<tr>
        <td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc">多语言内容替换</font></div>
				</td>
	</tr>
	<tr>
		<td align="center" ><form name="fmconfig" method="post" enctype="multipart/form-data"  action="ls_config.php">
			<input type="hidden" name="ls" value="modi" />
			<table width="98%" 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>
		</form>
</td>
</tr>
	<tr>
        <td style="padding-top:10px;" ><table width="98%" border="0" align="center" cellpadding="1" cellspacing="1"style="background-color: #f0f0ee;">
          <tr bgcolor="#f0f0ee">
            <td align="center" colspan="9" height="37"><b>多级目录替换</b></td>
          </tr>
          <tr bgcolor="#f0f0ee" height="37">
            <td align="center" width="39" height="28">序号</td>
            <td align="center" width="264" height="28">旧词（被替换词）</td>
            <td width="351" align="center">新词</td>
            <td width="162" align="center">起始目录</td>
            <td colspan="2" align="center">排序</td>
            <td width="40" align="center" >操作</td>
            <td width="40" align="center" >删除</td>
            <td  width="40" align="center">允许</td>
          </tr>
          <?php 
		  $i=1;
		  while ($link_rows=mysqli_fetch_assoc($in_query))
		  { ?>
          <tbody id='ZH_<?=$link_rows['ID']?>' >
            <tr bgcolor='#f9f9f9' height='37'
						onMouseOver=
						 	this.style.backgroundColor='#e5e5e5' 
						onMouseOut=
						 	this.style.backgroundColor='#f9f9f9' 
						>
              <td align='left' style='padding-left:10px;' height='25' ><?=$i?></td>
              <td align='left' style='padding-left:10px;' height='25' ><?= htmlspecialchars_decode($link_rows['oldstr'])?></td>
              <td align='left' style='padding-left:10px;' height='25'> <?= htmlspecialchars_decode($link_rows['newstr'])?> </td>
              <td align='left' style='padding-left:10px;' height='25'><?=trim($link_rows['startdir'])?></td>
              <td width="50" align='center'><?php 						if($i!=1)// not start up
						{?>
                <a href='?page=<?=$page?>&id=<?=$link_rows['ID']?>&Num=<?=$link_rows['Num']?>&in=up&selectcate=<?=$selectcate?>' title='向上移动'><img src='images/up.gif' border='0'></a>
                <?php } ?></td>
              <td width="51" align='center'><?php 
						if($i!=$link_num)// not end down
						{ ?>
                <a href='?page=<?=$page?>&id=<?=$link_rows['ID']?>&Num=<?=$link_rows['Num']?>&in=down&selectcate=<?=$selectcate?>' title='向下移动'><img src='images/down.gif' border='0'></a>
                <?php } ?></td>
              <td align='center'><a href='javascript:secBoard(<?=$link_rows['ID']?>)' title='编辑'><img src='images/b_edit.png' border='0' /></a></td>
              <td align='center'> 
                <a href='?page=<?=$page?>&id=<?=$link_rows['ID']?>&in=del&selectcate=<?=$selectcate?>' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>
               </td>
              <td align='center'><?php   if($link_rows['enable']==1)
							{ ?>
                <a href='?page=<?=$page?>&id=<?=$link_rows['ID']?>&in=unenable&selectcate=<?=$selectcate?>' title='显示'><img src='images/enable.gif' border='0'></a>
                <?php }
						  if($link_rows['enable']==0)
						  	{ ?>
                <a href='?page=<?=$page?>&id=<?=$link_rows['ID']?>&in=enable&selectcate=<?=$selectcate?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
                <?php } ?></td>
            </tr>
          </tbody>
          <tbody id='Z_<?=$link_rows['ID']?>' style='display:none;'>
      <form name='fm_link' action='?in=modi' enctype='multipart/form-data' method='post'>
        <tr bgcolor='#f4f4f4'>
            <td align='left' style='padding-left:10px;' height='25' ><?=$i?></td>
            <td align='left' style='padding-left:10px;' height='25' ><textarea name="oldstr" rows="6" class="inp" style="width:100%;"><?=$link_rows['oldstr']?></textarea></td>
            <td align='left' style='padding-left:5px;' height='25'><textarea name="newstr" rows="6" class="inp" style="width:100%;"><?=$link_rows['newstr']?></textarea></td>
            <td align='left' style='padding-left:5px;' height='25'><input name='startdir' type='text' class='inp' value='<?=$link_rows['startdir']?>' style="width:50%;" />
              <select name="selecttype_<?=$link_rows['ID']?>" id="selecttype_<?=$link_rows['ID']?>"  onchange="this.form.startdir.value= this.value">
                <?php  file_exists("widget/menulangs.php")?include "widget/menulangs.php":""  ?>
            </select></td>
            <td colspan='5' align='center'><input value='<?=$link_rows['ID']?>' name='modiid' type='hidden'>
              <button type='submit' value='保存'>保存</button>
              <button type='button' onclick='javascript:secBoard2(<?=$link_rows['ID']?>)' value='放弃'>放弃</button></td>
          </tr>
      </form>
      </tbody>
      <?php       $i++;
	  }
	 ?>
</table>
<form name="fmaddlink" action="?in=insert" enctype="multipart/form-data" method="post" onSubmit="return Checkaddlink();" style="margin-bottom:0px;">
 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="0"style="background-color: #f0f0ee;">
            <tr bgcolor="#f4f4f4" height="47">
              <td width="5%" align="right" >旧词</td>
              <td width="28%" height="28" ><textarea name="oldstr" cols="40" rows="6" style="width:99%;"></textarea></td>
              <td width="5%" align="right" >新词</td>
              <td width="25%" align="right" ><textarea name="newstr" rows="6" style="width:99%;"></textarea></td>
              <td width="8%" height="28" align="right" >起始路径</td>
              <td width="21%" ><input name="startdir" type="text"    value="all" size="4" />
               <select name="selecttype3" id="selecttype2"  onchange="this.form.startdir.value= this.value">
                       <?php  file_exists("widget/menulangs.php")?include "widget/menulangs.php":""  ?>

                </select>
              </td>
              <td width="8%" height="28" align="center" ><button type="submit" value="增加" />增加</button></td>
            </tr>
          </table>
          </form>
          <br />
         
          <form name="fmin" method="post" action="">
          <table width="98%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
    	<tr>
           <td colspan="5" align="center" height="60"><input type="button" name="subscanning2" value="替换全部内容" style="height:40px;background-color:#090; color:#FFF; border:0px; cursor:pointer;"  onclick="
              if(confirm('您确定要扫描网站内容，替换相关目录下的所有对应词吗？')){
                window.location.href='?scanning=replace';
            }else{
                return false;
            }"/>
             &nbsp;
<input type="button" name="subscanning" value="还原全部替换内容" style="height:40px;background-color:#C30; color:#FFF; border:0px; cursor:pointer;"  onclick="
              if(confirm('您确定要扫描全部网站，还原全部替换内容吗？')){
                window.location.href='?scanning=clear';
            }else{
                return false;
            }"/>
&nbsp;
<input type="button" name="button2" id="button2" value="清除上述替换词" style="height:40px;background-color:#C33; color:#FFF; border:0px; cursor:pointer;" onclick="
if(confirm('您确定要清除这些词吗？')){
                window.location.href='?scanning=delall';
            }else{
                return false;
            }" 
          /></td>
         </tr>
         <tr >
              <td height='25' colspan="5" align='center' style='padding-left:10px;' >&nbsp;</td>
          </tr>
    </table>
  	<br />
  </form>
</td>
</tr>
</table>
</body>
</html>
