<?php
function setutf8($strs){
  return iconv("gb2312", "UTF-8", $strs);
}

function getlanguage($lang){
   if($lang==''){
   return "NULL";
   }
   $sql="select language from etw_language where domain like '%".$lang."%'";
   $result=mysql_query($sql);
   $row=mysql_fetch_array($result);
   return $row['language'];
  }
  
function getdomain($lang){
   if($lang==''){
   return "";
   }
   $sql="select kuozhan from etw_language where domain like '%".$lang."%'";
   $result=mysql_query($sql);
   $row=mysql_fetch_array($result);
   return $row['kuozhan'];
  }

function childemail($id){
       $sql="select username from chat_user where id=".$id;
	   $result=mysql_query($sql);
	   $rs=mysql_fetch_array($result);
	   return $rs[username];
}

function maxchatid($uid){
       $maxid=sql_select("select max(yid) from etw_onlines where usernameid=".$uid);
	   return $maxid[0][0];	   
}


function isgototranslate($id){
        $sql="select * from etw_onlines where id=".$id;
		$result=mysql_query($sql);
		$rs=mysql_fetch_array($result);
		if($rs[translate]<>0){
		   return true;
		}else{
		  return false;
		}
		     
}

function isachivetranslate($id){
        $sql="select * from etw_translate where chatid=".$id;
		$result=mysql_query($sql);
		$rs=mysql_fetch_array($result);
		if($rs[achivetime]<>0){
		   return date('y-m-d H:i',$rs[achivetime]);
		}else{
		  return false;
		}
		     
}

function translatestatus($id){
       $sa;
       $sql="select * from etw_translate where chatid=".$id." order by type desc";
       $result=mysql_query($sql);
	   $rs=mysql_fetch_array($result);
	   $counts=count($rs);
	        if($rs['type']=='2' && $rs['achivetime']<>'0'){
			    $sa="完成";
			    return $sa;			
			}else if($rs['type']=='2' && $rs['achivetime']=='0'){
			    $sa="回复翻译中";
			    return $sa;			
			}else if($rs['type']=='1' && $rs['achivetime']<>'0'){
			    $sa="询盘已翻译";
			    return $sa;			
			}else if($rs['type']=='1' && $rs['achivetime']=='0'){
			    $sa="询盘转翻译";
			    return $sa;			
			}
	   $sa="未处理";
	   return $sa;
}

function getchildemail($id){
      $sql="select username from chat_user where id=".$id;
	  $result=mysql_query($sql);
	  $row=mysql_fetch_array($result);
	  return $row['username'];
}

function getday (){
        $n=date("N",time());
		 switch($n){
            case "1": $week="星期一";break;
            case "2": $week="星期二";break;
            case "3": $week="星期三";break;
            case "4": $week="星期四";break;
            case "5": $week="星期五";break;
            case "6": $week="星期六";break;
            case "7": $week="星期日";break;
		 }
	return $week." &nbsp;".date("Y 年 m 月 d 日",time());
}
  function showtitle($str,$len){
      if ( strlen($str) <= $len )
         {
                 return $str ;
         }else{
		//  $str= iconv("GB2312","UTF-8",$str);
		  if ( ord($str[$len-1]) < 128 ){return substr($str,0,$len);}
		  else{
		   $cur_count_ok = 0 ;
            for ( $i=0; $i<$len; $i++ )
               { if ( ord($str[$i]) < 128 )
                 {$cur_count_ok = $i + 1 ;}
                 else{ $i++ ;
                      $cur_count_ok = $i + 1 ;
                 }
            }
           return substr($str, 0, $cur_count_ok);

		  }
		 }
 
 }

function utf8Substr($str, $from, $len)
{
    return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
                       '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
                       '$1',$str);
}
 
 
 
 
 ?>