<?
include(dirname(__FILE__)."/global.php");



set_time_limit(0);

header('Content-Type: text/html; charset=utf-8');

include("../../include/pinyin.php");

include("../../include/gbk2utf8.php");




/*
//由于编码不一样，所以重新连接
$cfg_dbcharset                               = "utf-8"; 

//连接数据库
$db = mysql_pconnect("$dbhost", "$dbuser", "$dbpasswd");
mysql_select_db("$dbname");
//连接数据库

		if( mysql_get_server_info() > '4.1' && $cfg_dbcharset){
			mysql_query("SET NAMES '".$cfg_dbcharset."'");
		}
		if( mysql_get_server_info() > '5.0' ){
			mysql_query("SET sql_mode=''");
		}

*/



	$fid = 26;//网站栏目
	$mid = 48;//栏目模块
	$zq_table = "w6_module_content_$mid";//保存数据的表格


$filename="../../data/fy_config.php"; //伪原创设置文件

if($webdb['NewsFY']=='0'){
exit("关键词站群功能已关闭！");
}

@$job = $submitted_vars["job"];

if($job == "modify"){
  $postdb = $_POST['postdb'];
  
  $writefile="<?php	\r\n";
  $i = 0;
  foreach($postdb AS $key=>$value){
  $i++;
  $value=addslashes($value);
  $writefile.="\$fydb['$key']='$value';\r\n";
  }
 
  $query    =   updatetofile("$filename","$writefile");
	  
  if ($query)
     {
       $showmsg = "翻译字段修改成功！";
	   $formurl = "fy.php";
     }
  else
     {
       $showmsg = "翻译字段修改失败！";
	   $formurl = "fy.php";
     }
	 
  include('showmsg.php');
  exit;


}elseif($job == "fy"){


	@$action = $submitted_vars["action"];

	$mid = $submitted_vars['mid'];

		if(!$action){//翻译前期工作

			$result=mysql_query("SELECT * FROM `w6_module_content_".$mid."` ORDER BY `id` DESC") or die("Could not connect: " . mysql_error());
			$num = mysql_num_rows($result);
				if( $num == 0 ){exit("此模块暂时没有内容！");}
				while($rs=mysql_fetch_array($result)){
					$list_str .= $rs['aid']."\n";
				}
			//$filename = "../../cache/fy.list.php";
			$query    =   updatetofile("../../cache/fy.list.php","$list_str");//写入索引数据
			
			//跳转到 翻译 处理
			echo "开始对文章进行  翻译 处理！<br> <meta http-equiv=\"refresh\" content=\"0;URL=?job=fy&action=fy2&pc=0&mid=".$mid."\">";
			exit;

		}elseif( $action == "fy2" ){//真正进行 翻译 处理
		
			$pc = $_GET['pc'] ? $_GET['pc'] : 0 ;

			$arr_aid = file("../../cache/fy.list.php");
			$aid = $arr_aid[$pc];

			require("$filename");
			  foreach($fydb AS $key=>$value){
			  $value=stripslashes($value);
			  $webdbs[$key]=$value;
			  }
			$fy_pole = explode ( "\r\n" , $fydb['fy_pole'] );
			$fy_num = count($fy_pole);
			
			//读取字段内容
			$query = "SELECT * FROM `w6_module_content_".$mid."` WHERE `aid` = '$aid'";
			$result=mysql_query( $query ) or die("Could not connect: " . mysql_error());
			
			for($i=0;$i<$fy_num;$i++){
				//$LabelArray[$fy_pole[$i]] = Translate ( stripslashes(mysql_result($result,"0",$fy_pole[$i])) );
				$LabelArray[$fy_pole[$i]] = stripslashes(mysql_result($result,"0",$fy_pole[$i])) ;
				$LabelArray[$fy_pole[$i]] = gbk2utf8 ( $LabelArray[$fy_pole[$i]] , '../../include/gbkcode/gbk2utf8.table' );//转换编码 gbk - utf8
				$LabelArray2[$fy_pole[$i]] = addslashes ( Translate ( $LabelArray[$fy_pole[$i]] ) );
			}
			
			//翻译好以后修改数据库 &#65279;
			for($i=0;$i<$fy_num;$i++){
				$update_str_a[] = "`$fy_pole[$i]` = '". utf8_decode ( $LabelArray2[$fy_pole[$i]] ) ."'";//utf-8前面老多出乱码的以围绕成 ISO-8859-1 
			}
			$update_str = implode( " , " , $update_str_a );
			$query="UPDATE `w6_module_content_".$mid."` SET ".$update_str." WHERE `aid`=".$aid ;
			//echo $query;exit;
			$result=mysql_query($query);
			
			if($result){
					echo "aid = $aid 文章翻译完成，继翻译下一篇文章！<hr><br>翻译前文章内容：<br>";print_r($LabelArray);echo '<br><br>翻译后文章内容：<br>';print_r($LabelArray2);
					echo "<meta http-equiv=\"refresh\" content=\"2;URL=?job=fy&action=fy2&mid=".$mid."&pc=".($pc+1)."\">";
			}
			
		exit;

		}

}

//从设置文件读取内容
require("$filename");

  foreach($fydb AS $key=>$value){
  $value=stripslashes($value);
  $webdbs[$key]=$value;
  }


?><!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.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	text-decoration: none;
	color: #000000;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #000000;
}
.red {color: #FF0000}
-->
</style>
<script language="Javascript1.2">
<!-- // load htmlarea
_editor_url = "../../htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// -->
</script>

<SCRIPT LANGUAGE="JavaScript">
<!--
function get_obj(obj){
   return document.getElementById(obj);
}
//-->
</SCRIPT>
</head>

<body>
<div align="center" class="font12">
  <table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#A4B6D7">
    <tr>
      <td width="100%" height="22" align="center" background="images/titlebg.jpg">&nbsp;</td>
    </tr>
  </table>
  <br />
  <table width="100%" height="25" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td align="left" bgcolor="#FFFFFF"> [<a 
      href="../../index.php?job=makeIndexHtml" target="_blank" class="a_bt">首页静态</a>]      [<a 
      href="MakeHtml.php" class="a_bt">栏目静态</a>]      [<a 
      href="../../index.php?job=delIndexHtml" class="a_bt">删除静态首页</a>]
	  
	  <?
	  if($webdb['NewsWYC']=='1'){
	  ?>
	  [<a href="wyc.php" class="a_bt">文章伪原创处理</a>]
	  <?
	  }
	  ?>
	  
	  <?
	  if($webdb['KeyZQ']=='1'){
	  ?>
	  [<a href="zq.php" class="a_bt">关键词站群功能</a>]
	  <?
	  }
	  ?>
	  
	  <?
	  if($webdb['NewsFY']=='1'){
	  ?>
	  [<a href="fy.php" class="a_bt">英文翻译功能</a>]
	  <?
	  }
	  ?>
	  
    </tr>
  </table>
  <br />
  <br />
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">基本设置</td>
    </tr>
    <tr>
      <td height="24" align="left">
	  <form id="form1" name="form1" method="post" action="">
	  <table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" class="table2">
        <tr>
          <td width="21%" height="28" bgcolor="#FFFFFF">翻译字段设置:</td>
          <td width="79%" bgcolor="#FFFFFF"><textarea name="postdb[fy_pole]" cols="30" rows="8" id="postdb[fy_pole]"><?=$fydb['fy_pole']?></textarea>
            多个字段请换行</td>
        </tr>
        <tr>
          <td height="28" bgcolor="#FFFFFF">&nbsp;</td>
          <td bgcolor="#FFFFFF"><input type="submit" value="提交" name="Submit" />
            <input name="job" type="hidden" id="job" value="modify" /></td>
        </tr>
      </table>
        </form>
      </td>
    </tr>
  </table><br />
<br />
<br />
<br />
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">选择模块进行翻译</td>
    </tr>
    <tr>
      <td height="24" align="left">
	  <br />
</td>
    </tr>
    <tr>
      <td align="center">
  <table width="90%" border="0" cellpadding="1" cellspacing="1" bgcolor="#A4B6D7">
      <tr>
        <td width="12%" align="center" bgcolor="#FFFFFF"><strong>排 序</strong></td>
        <td width="30%" align="center" bgcolor="#FFFFFF"><strong>模块名称</strong></td>
        <td width="25%" align="center" bgcolor="#FFFFFF"><span class="head">选择模块进行翻译</span></td>
        </tr>
      <?
                $query="SELECT * FROM `w6_module` ORDER BY `module_taxis` ASC";
                $result=mysql_query($query);
                $i=0;
                while($row=mysql_fetch_array($result))
                  {
                  $module_id            =    stripslashes($row["module_id"]);
				  $module_taxis       =    stripslashes($row["module_taxis"]);
                  $module_name     =    stripslashes( $row["module_name"] );
                ?>
      <form id="form2" name="form2" method="post" action="">
        <tr>
          <td height="34" align="center" bgcolor="#FFFFFF"><input name="module_taxis" type="text" id="module_taxis" value="<?=$module_taxis?>" size="3" />
            <input name="id" type="hidden" id="id" value="<?=$id?>" />
            <input name="job" type="hidden" id="job" value="modify" /></td>
          <td align="center" bgcolor="#FFFFFF">【<?=$module_name?>】</td>
          <td align="center" bgcolor="#FFFFFF"><a href="?mid=45&amp;job=fy" target="_blank">对“ 
            <?=$module_name?> 
            ”栏目内容进行翻译</a><a href="?mid=<?=$module_id;?>&amp;job=scmkdata" target="_blank" onclick="return MM_popupMsg('确定要删除吗“<?=$module_name?>”！！')"></a></td>
          </tr>
      </form>
      <?
		$i++;
		}
		?>
    </table>
	  </td>
    </tr>
  </table>
</div>

<SCRIPT LANGUAGE="JavaScript">
<!--
function show_help(di){
	if(document.getElementById(di).style.display==''){
		document.getElementById(di).style.display='none';
	}else{
		document.getElementById(di).style.display='';
	}
}
function get_help(){
	obj=document.body.getElementsByTagName("span");
	for(var i=0;i< obj.length;i++ ){
		if(obj[i].getAttribute("help")=='1'){
			obj[i].className='Help';
			obj[i].style.display='none';
			var vid=Math.random()*1000000000000000000;
			obj[i].id='a'+vid;

			obj2=document.createElement("font");
			obj2.innerHTML="<A href=\"javascript:show_help('a'+"+vid+");\" style='margin-left:5px;' title='点击查看更多帮助信息'><img src='../images/help_icon.gif' border=0></A>";
			obj[i].parentNode.insertBefore(obj2, obj[i]);
		}
	}
}
get_help();

function set_class(){
	obj=document.body.getElementsByTagName("input");
	for(var i=0;i< obj.length;i++ ){
		if(obj[i].type=='submit'||obj[i].type=='button'){
			obj[i].className='submit';
		}else if (obj[i].type=='radio'||obj[i].type=='checkbox'){
			obj[i].style.border='0px;';
		}else if(obj[i].type=='text'){
			obj[i].className='input_text';
		}
	}
	obj=document.body.getElementsByTagName("textarea");
	for(var i=0;i< obj.length;i++ ){
		obj[i].className='input_textarea';
	}
	if(document.getElementById("top_menu")!=null)
	{
		obj2=get_obj('top_menu').getElementsByTagName("td");
	
		for(var i=0;i< obj2.length;i++ ){
			s=obj2[i].innerHTML;
			s=s.replace(/\[</g, "<");
			s=s.replace(/>\]/g, ">");
			obj2[0].innerHTML=s;	
		}
	}
	
}
set_class();



//-->
</SCRIPT>

</body>
</html>
