/* 
判断表中某行字段有变化没， 记录到ls_change, 并翻译 
如果有语言手工修改过，返回 相关语言数组
更新成功 返回true，否则 返回已经手工优化的 语种
 */
function ifchange($tbname,$ID,$posta,$lang='en') 
{ 
	require_once('conn.php');
	require_once('conn_var.php');
	require_once('constant.php');
	
	
	$opendb=new mydb();
	require_once('char_set.php');
	$sql="select * from ".$tbname." where ID=".$ID." ";
	$query1=$opendb->query($sql);
	$rows=mysql_fetch_assoc($query1);
	$sql2="select COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.COLUMNS where table_name = '".$tbname."' and table_schema = '".$dbname."' ";
	$query2=$opendb->query($sql2);
	$rows2=mysql_fetch_assoc($query2);
	
	for($i=1;$i<= count($rows2);$i++){ 
          if($rows2['DATA_TYPE']=="varchar"||!(strpos($rows2['DATA_TYPE'],'text')===false)){
          	if(!(trim($rows[$rows2['COLUMN_NAME']])==trim($posta[$rows2['COLUMN_NAME']]))){ //POST 字段有变化,记录
				
				$select_sql2="select * from ls_change where tbname='".$tbname."' and  tbID='".$ID."' and  lang='".$lang."' and    tbField='". $rows2['COLUMN_NAME']."' ";
	 
				$select_query2=$opendb->query($select_sql2);
				$select_rows2_num=mysql_num_rows($select_query2); //总数
				if($select_rows2_num==0){ //没有
			
					$sql3="insert into ls_change (tbname,tbID,tbField,lang,	date1)  values(".$tbname.",".$ID.",". $rows2['COLUMN_NAME'] .".".$lang.",".date('Y-m-d').") ";
					$query3=$opendb->query($sql3);
				}else{
					$sql3="update ls_change set	date1=".date('Y-m-d')." where tbname='".$tbname."' and  tbID='".$ID."' and  lang='".$lang."' and    tbField='". $rows2['COLUMN_NAME']."' ";
					$query3=$opendb->query($sql3);
					
				}

			
			}
//英文有变化，若无其他语种手工修改，更新其他语种 对应内容

          	if(!(trim($rows[$rows2['COLUMN_NAME']])==trim($posta[ $rows2['COLUMN_NAME']]))&&$lang=="en"){ //POST 字段有变化,记录
				
				$select_sql2="select * from ls_change where tbname='".$tbname."' and  tbID='".$ID."' and  lang!='en' and    tbField='". $rows2['COLUMN_NAME']."' ";
	 
				$select_query2=$opendb->query($select_sql2);
				$str=""; // return str
				$a=array();

				$needtrans=$transFlags; //constant
				while(	$select_rows2=mysql_fetch_assoc($select_query2)){
					 
						//$str.=$rows2['lang']."语".$tbname."表的".$rows2['COLUMN_NAME']."已经手工翻译\r\n";
						array_push($a,$select_rows2['lang']);
						$needtrans=str_replace($select_rows2['lang'],"", $needtrans);
				}
				
				$na=explode(",",$needtrans);
				for($i=1;$i<= count($na);$i++){ //没有人工处理过的，直接翻译，替换
					$thislang=(trim($na[$i]));
					if($thislang!=""){
						//tranlstext
						$transstr=tranlstext($posta[$rows2['COLUMN_NAME']],$thislang);
						updatelang($tbname,$ID,$rows2['COLUMN_NAME'],$transstr,$thislang) ;
						
					}
					

				}
			}

          }   
     }
	 return isset($a)?$a:true;
} 

/* 更新某语言$tbname表$ID行 $field字段,成功返回true */
function updatelang($tbname,$ID,$field,$str,$lang) 
{ 
	require_once("../../".$lang.'inc/conn.php');
	$opendb=new mydb();
	require_once('char_set.php');
	$sql3="update ".$tbname." set	".$field."=".$str." where ID=".$ID." ";
	$query3=$opendb->query($sql3);	
	if($query3) return true; else  return false; 
}