<!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">
<?php
	session_start();
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/ls_inccode.php');
	
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	
	$ls=$_GET['ls'];
	$mutiLangDomianFlag = $_POST['mutiLangDomianFlag']==""?$mutiLangDomianFlag:$_POST['mutiLangDomianFlag'];  //获取提交的URL前缀值
	if(substr($mutiLangDomianFlag,-1)!='/') $mutiLangDomianFlag=$mutiLangDomianFlag.'/';
	writeconstant("mutiLangDomianFlag", $mutiLangDomianFlag, "str");
	
	$scrDir="../";
	//$allcopyfiles="bootstrap,css";
	$allcopyfiles="bootstrap,css,images,jq22css,jq22js,js,ls_admin,motif,revolvingpics,Templates,Templates1,update,download";

	$allcopyfiles2="sendmail_inc.php,robots.txt";
	$arrtransFlags = explode(",",$transFlags );    
	$ls_msg="英文网站设计全部完成，方可转入多语 ";
	$transtpl=$_GET['transtpl'];
	$transdt=$_GET['transdt'];
	
 	if($ls=="createml")
	{
		for($j=0;$j< count($arrtransFlags);$j++){ 
			 $thisFlags=trim($arrtransFlags[$j]);
			 $lanDir= 	"../".$thisFlags;
			if(file_exists($lanDir)) {
				for($ii=1;$ii>0;$ii++){
					if(rename($lanDir,$lanDir.$ii) )break;
				}
			}
				
			if(!is_dir($lanDir)) {
				if(mkdir($lanDir)){
					$ls_msg.=$lanDir."已创建；";
					
					$arrtfiles = explode(",",$allcopyfiles );  // 复制文件夹
					for($i=0;$i< count($arrtfiles);$i++){ 
					 	$thisfiles=$scrDir.trim($arrtfiles[$i]);
						$destination=$lanDir."/".trim($arrtfiles[$i]);
						xCopy($thisfiles, $destination,$nocopyFile=array(), $child=true);
						//echo $thisfiles."==".$destination."<br/>";
					}
					 
					$arrtfiles2 = explode(",",$allcopyfiles2 );  // 复制文件
					for($i=0;$i< count($arrtfiles2);$i++){ 
					 	$thisfiles2=$scrDir.trim($arrtfiles2[$i]);
						$destination2=$lanDir."/".trim($arrtfiles2[$i]);
						copy($thisfiles2, $destination2 );
						//echo $thisfiles2."==".$destination2."<br/>";
					}
					
					$ls_msg.=$lanDir."已复制文件；";  
					//更新all.dwt模板;
					$srca= array('1' => 'all.dwt','2' => 'all2.dwt' ,'3' => '<html lang="en">'  );  //替换dwt  
					$obja= array('1' =>'all'.$thisFlags.'.dwt','2' =>'all2'.$thisFlags.'.dwt','3' =>'<html lang="'.$thisFlags.'">'   ); 
					
					$filetplold=$lanDir."/Templates/all.dwt";			  
					$filetplnew=$lanDir."/Templates/all".$thisFlags.".dwt";			  
					if(copy($filetplold,$filetplnew)) {unlink( $filetplold); $ls_msg.='模板  all'.$thisFlags.'.dwt 已替换 '; } else $ls_msg.='模板  all'.$thisFlags.'.dwt 修改失败 ';
					writereplacestr($filetplnew,$srca,$obja); // 替换 Template 下模板
					copy($filetplnew,str_replace("Templates","Templates1",$filetplnew)); //复制到 1 备份
					
					$filetplold=$lanDir."/Templates/all2.dwt";			  
					$filetplnew=$lanDir."/Templates/all2".$thisFlags.".dwt";			  
					if(copy($filetplold,$filetplnew)) {unlink( $filetplold); $ls_msg.='模板  all2'.$thisFlags.'.dwt 已替换 '; } else $ls_msg.='模板  all2'.$thisFlags.'.dwt 修改失败 ';
					writereplacestr($filetplnew,$srca,$obja); // 替换 Template 下模板
					copy($filetplnew,str_replace("Templates","Templates1",$filetplnew)); //复制到 1 备份
					 
					$filetpl1=$lanDir."/Templates1";
					
					// 递归操作
					$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filetpl1), RecursiveIteratorIterator::SELF_FIRST); 
					foreach($iterator as $item) { 
						if(substr($item,-1)==".") continue;
						writereplacestr($item,$srca,$obja); // 替换 Template1 下模板
					} 
					$ls_msg.='模板 $filetpl1 中 all'.$thisFlags.'.dwt，  all2'.$thisFlags.'.dwt 已替换 ';
					
					if(!file_exists("backupdb")){if(mkdir("backupdb"))$ls_msg.="backupdb"."建立成功！";} //建立多语数据库
					$thisbackupSQLFile="backupdb/backup_crtypedb.sql";
					include('inc/conn_var.php');
					$thishost=$host;
					$thisusername=$username;
					$thispassword=$password;
					$flmdbname=$dbname;
					$mlDBname=$dbname."_".$thisFlags;
					//echo $thishost."==".$mlDBname;
					backuplsdb($thishost,$thisusername,$thispassword,$flmdbname,$thisbackupSQLFile,false);
					restorelsdb($thishost,$thisusername,$thispassword,$mlDBname,$thisbackupSQLFile,false);   
	

		
					//更新conn数据
					$filename= "../".$thisFlags."/ls_admin/inc/conn_var.php";
					$fp = fopen($filename,"r");
					$conn_str  = fread($fp,filesize ($filename));
					$startconn_str=substr($conn_str,0,strpos($conn_str,"\$host"));
					$replconn_str="
					\$host='localhost';
					\$dbname='".$dbname."_".$thisFlags."';
					\$username='".$thisusername."';
					\$password='".$thispassword."';
					}";
					$dbn=substr($dbname,0,strpos($dbname,"."));
				 	$elseconn_str=substr($conn_str,strpos($conn_str,"else"));
					$elseconn_str=str_replace($dbn,$dbn."_".$thisFlags,$elseconn_str);
					$newconn_str=$startconn_str.$replconn_str.$elseconn_str;
				
					writegeneralfile($filename,$newconn_str);
					
					$srca= array('1' => '$picsrc=' ); 
					$obja= array('1' => '$picsrc="../../".' ); 
					writereplacestr("../".$thisFlags."/Templates1/search.php",$srca,$obja); //搜索产品图片路径
					//htaccess
					$filename= "../".$thisFlags."/.htaccess";
					if(file_exists($filename)) rename($filename,$filename."1");
					
		 			 

					
					$ls_msg.=" 数据库已经创建；".$mlDBname;
				}
				else
				{$ls_msg.=$lanDir."不能创建创建；";}
			}
			else
			
			{$ls_msg.=$lanDir."已存在；";}
		 } // end for
		
	}

	if($ls=="transalltpl")
	{
		for($j=0;$j< count($arrtransFlags);$j++){
			transtpl($arrtransFlags[$j]);  // 语言
		}
		$ls_msg.="模板已全部翻译；";
	}

	if($transtpl!="")
	{
		$transstr="";   //手工翻译
		transtpl($transtpl); // 语言
		echo $transstr; // 已拼合的翻译串，在 transtpl($transtpl);
		$ls_msg.=$transtpl."模板已翻译；";
	}


	if($ls=="transalldt")
	{
		for($j=0;$j< count($arrtransFlags);$j++){
			transdt($arrtransFlags[$j]); // 语言
		}
		$ls_msg.="内容已全部翻译；";
	}

	if($transdt!="")
	{
		transdt($transdt); // 语言
		$ls_msg.=$transdt."内容已翻译；";
	}

	$submitaddlang=$_POST['submitaddlang'];

	if($submitaddlang=="确定"){ //手工增加块表
		for($j=1;$j< 1000;$j++){  
			$thisenn=trim($_POST["en".$j]);
			//echo $thisenn."--";
			if($thisenn!=""&&$thisenn!="En".$j)
			{
				for($i=0;$i< count($arrtransFlags);$i++){ 
				echo "iii";
			 	 	$lang=trim($arrtransFlags[$i]);
					$thisnoen=trim($_POST[$lang.$j]);
 					if(addtransfast($thisenn,$lang,$thisnoen,"tpl"))
						$ls_msg.=$lang."--".$thisenn."--".$thisnoen."已添加, ";
				 }
			}
			else
			{
				$ls_msg.="";
				break;	
			} // 英文为空就退出
		}
		
	}	
	
	$selectdelfast=trim($_GET['selectdelfast']);

	if($selectdelfast!="")
	{
		$del_sql="delete   from ls_transfast where ID=$selectdelfast ";
		$config_query=$opendb->query($del_sql);
		$ls_msg.="快表 ID:$selectdelfast 已删除";
	}
	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_rows=mysql_fetch_assoc($config_query);
				 					

?>

<link href="css/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/style2.css" />
<script language="JavaScript" src="js/jquery.js"></script>
<script language="JavaScript" src="js/ls.js"></script>
<title>mutiLang</title>
</head>
<body bgcolor="#f4f4f4">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
	<tr>
        <td height="18" style="border-bottom: 5px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#666" style="font-size:16px;"><strong>多语种界面切换</strong></font></div>
	  </td>
	</tr>
	<tr>
		<td height="198" align="center" valign="top" bgcolor="#dee7ff">                    <form id="fmconfig" name="fmconfig" method="post" enctype="multipart/form-data"  action="<?php echo $PHP_SELF;?>">
                      <table width="99%" height="157" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                        <script>
								function plan01(){
									var str = '';
								   $(".plan01").each(function(){
										if($(this).is(':checked')){
											str += $(this).val();
										}
									});
								   return str;
								};
								
								function checkPlan01(){
									$(".plan01").each(function(){
										if($(".checkPlan01").is(':checked')){
											$(this).attr("checked",true);
										}else{
											$(this).attr("checked",false);
										}
									});
								}
								
								function unCheck01(){
									if($(".checkPlan01").is(':checked')){
										$(".checkPlan01").attr("checked",false);
									}
								}
								</script>
                        <tr>
                          <td height="48" align="left"  bgcolor='#eee' style='padding-left:5px;'>提示：
                            <?=$ls_msg;?></td>
                        </tr>
                        <tr>
                          <td height="46" align="center"  bgcolor='#eee' style='padding-left:5px;'>1、<a href="1addtranstag.php" target="_blank">加翻译标签</a>   &nbsp;&nbsp; 2、<a href="temp_ml.php?ls=createml">生成多语种结构</a></td>
                        </tr>
                        <tr>
                        <? if($manualTrans){  ?>  <td height="46" align="center"  bgcolor='#eee' style='padding-left:5px;'>
                            手工翻译: &nbsp;
                            <input id=" " type="button" value="模板，constant，数据表" onclick="window.open('tansbig.php','_blank');" />
                            &nbsp;&nbsp;</td> 
                        <? } ?>
                        </tr>
                        <tr>
                          <? if(!$manualTrans){  ?>   <td height="46" align="center"  bgcolor='#eee' style='padding-left:5px;'>
                       
                          <a href="temp_ml.php?ls=transalldt">翻译网站内容</a>: &nbsp;
                            <?php 
			$lan = $config_rows['language'];			 
             for($i=0;$i< count($arrtransFlags);$i++){ 
			 	 $thisFlags=trim($arrtransFlags[$i]);
			  	 foreach($translate_name as $k=>$val){ 
 					 if($val["translate_name"]==$thisFlags) $thiscountry= $val["name"];
				 }
			 ?>
                            <input id="<?=$thisFlags?>2" type="button" value="<?=$thiscountry?>" onclick="JavaScript:window.parent.location='?transdt=<?=$thisFlags?>';" />
                            &nbsp;&nbsp;
                            <? }?></td> <? }?>
                        </tr>
                        <tr>
                          <td align="center"  bgcolor='#eee' style='padding-left:5px;'>当前网站语言设置：
                            <input type="hidden" name="ls" value="modi" />
                            <img src="img/gq/en.jpg" alt="" height="16" />
                            <input id="en" type="button" value="回英语" onclick="JavaScript:window.parent.location='<?=($_SESSION['landir']==""?"": "../../ls_admin/")?>all.php';" />
                            &nbsp; &nbsp;
                            <?php 
			$lan = $config_rows['language'];			 
             for($i=0;$i< count($arrtransFlags);$i++){ 
			 	 $thisFlags=trim($arrtransFlags[$i]);
			  	 foreach($translate_name as $k=>$val){ 
 					 if($val["translate_name"]==$thisFlags) $thiscountry= $val["name"];
				 }
			 ?>
                            <img src="img/gq/<?=$thisFlags?>.jpg" alt="" height="16" />
                            <input id="<?=$thisFlags?>" type="button" value="<?=$thiscountry?>" onclick="window.open('<?= "../".($_SESSION['landir']==""?"": "../").$thisFlags."/ls_admin/"?>all.php?currLan=<?=$thisFlags?>&amp;currLanName=<?=$thiscountry?>','_parent');" />
                            &nbsp;&nbsp;
                            <? }
			   
		
							?></td>
                        </tr>
                        <script>
								function plan02(){
									var str2 = '';
								   $(".plan02").each(function(){
										if($(this).is(':checked')){
											str2 += $(this).val();
										}
									});
								   return str2;
								};
								function checkPlan02(){
									$(".plan02").each(function(){
										if($(".checkPlan02").is(':checked')){
											$(this).attr("checked",true);
										}else{
											$(this).attr("checked",false);
										}
									});
								}
								function unCheck02(){
									if($(".checkPlan02").is(':checked')){
										$(".checkPlan02").attr("checked",false);
									}
								}
								</script>
                        <script>
								function plan03(){
									var str3 = '';
								   $(".plan02").each(function(){
										if($(this).is(':checked')){
											str3 += $(this).val();
										}
									});
								   return str3;
								};
								function checkPlan03(){
									$(".plan03").each(function(){
										if($(".checkPlan03").is(':checked')){
											$(this).attr("checked",true);
										}else{
											$(this).attr("checked",false);
										}
									});
								}
								function unCheck03(){
									if($(".checkPlan03").is(':checked')){
										$(".checkPlan03").attr("checked",false);
									}
								}
								</script>
                        <script>
									function planAll(){
										var strAll = '';
										for(var i=1; i<=27; i++){
											if($("#lan"+i).is(':checked')){
												strAll += $("#lan"+i).val();
											}
										}
									   return strAll;
									};
									</script>
                      </table>
                    </form>
          <p>
            <script>  i=2 ;</script> 
          </p>
          <form id="adfastmanual" name="adfastmanual" method="post" enctype="multipart/form-data"  action="<?php echo $PHP_SELF;?>">
        
         <p><br/> </p>
         <p> </p>
           <select name="selectdelfast1" id="selectusername1"  onchange="window.open('?selectdelfast='+this.value,'right','');">
             <option value=" "> --------   删除快表翻译，选中即删除，请谨慎选择  ------- </option>
             <?
		 $select_sql="select * from ls_transfast where 1 order by en asc";
			 
			 
			$select_query=$opendb->query($select_sql);
			while($select_rows2=mysql_fetch_assoc($select_query))
		  	{
				$optstr="";
				$opttitle="  --------------   ".$select_rows2['en']."\r\n";
            	for($j=0;$j< count($arrtransFlags);$j++){  
					$thislang=trim($arrtransFlags[$j]); 
					$optstr.="  ----  $thislang  ----  ".substr($select_rows2[$thislang],0,16);
					$opttitle.="\r\n   --   $thislang   --   ".$select_rows2[$thislang];
					
				}
				echo "<option value=".$select_rows2['ID']." title='".$opttitle."'>【 ".substr($select_rows2['en'],0,16)." 】".$optstr."</option>";
            }
		 
		 ?>
           </select>         
         <p>                  
         <p>添加快表翻译项目<br>
		  <p>
		    <input type="text" name="en1" id="hiddenField2" value="En1"   onclick="this.value=(this.value=='En1'?'':this.value);"/>
		    <?php 
			 $inputstr="";

			for($j=0;$j< count($arrtransFlags);$j++){  
			 //$thislike.=" (".trim($arrtransFlags[$j])."  like '%ERROR%' or ".trim($arrtransFlags[$j])."='' )"; // 组合error 或者空的翻译结果
			 $inputlang=trim($arrtransFlags[$j]); ?>
		    <input type="text" name="<?=$inputlang?>1" id="<?=$j?>1" value="<?=$inputlang?>1" onclick="this.value=(this.value=='<?=$inputlang?>1'?'':this.value);" />
		    
		    <?php } ?>
		    <script>
			  
			  function addlang(langstr){
				 var strs= new Array(); //定义一数组 
				 
 				 var inputlang  = document.createElement('input');  //创建input节点
				inputlang .setAttribute('type', 'text');  //定义类型是文本输入
				inputlang .setAttribute('name', 'en'+""+i);  //定义类型是文本输入
				inputlang .setAttribute('value', 'En'+""+i);  //定义类型是文本输入
				inputlang .setAttribute('onclick', "this.value= (this.value==('En"+''+i+"')?'':this.value);" );  // 英文
				
				document.getElementById('adfastmanual').appendChild(inputlang  ); //添加到form中显示
				// alert(langstr);
				  strs=langstr.split(","); //字符分割 
				 
				  for (j=0;j<strs.length;j++ ) 
				  { 
				 	// alert(strs[j]);
				  	 var inputlang2 = document.createElement('input');  //其他语言
					  inputlang2 .setAttribute('type', 'text');  //定义类型是文本输入
					  inputlang2 .setAttribute('name', strs[j]+""+i);  //定义类型是文本输入
					  inputlang2 .setAttribute('value', strs[j]+""+i);  //定义类型是文本输入
					  inputlang2 .setAttribute('onclick', "this.value= (this.value=='"+strs[j]+""+i+"'?'':this.value);" );  //定义类型是文本输入
					  
					  document.getElementById('adfastmanual').appendChild(inputlang2 ); //添加到form中显示
				  } 
				  i++;
				  $("#adfastmanual").append("<br/>");
			  }</script>
	      <p><br>
          <button name="addbutton" type="button" value="确定" onClick=" addlang('<?=$transFlags?>');"/> 增加</button>
          <button name="submitaddlang" type="submit" value="确定" onClick=" "/> 确定</button>
		  <button type="reset" name="button" id="button" value="重置" />重置</button>
	      <br /><br />
	      </p>
        </form>   

      </p></td>
       
  </tr>
</table>
</body>
</html>