<?php
function unreadetwtrans($uid,$wherechild){
     $sql="select count(*) from etw_onlines where usernameid=".$uid.$wherechild." and (translate<>0 or reply<>0) and readed=0";
     $rs=sql_select($sql);
	 if($rs[0][0]==0){
	  echo $rs[0][0];
	 }else{
	  echo "<font color='#ff0000'>".$rs[0][0]."</font>";
	 }

}
function unreadinquery($uid,$wherechild){
    $ids=sql_select("select max(id) as id from etw_onlines where usernameid=".$uid.$wherechild." group by title,contacter,email,address,content");
	 $id="";
	for($i=0;$i<count($ids)-1;$i++){
	   $id=$id."'".$ids[$i][0]."',";
	  }
	$id=$id."'".$ids[count($ids)-1][0]."'";
    $sql="select id from etw_onlines where id in(".$id.") and translate=0 and reply=0 and readed=0";
	
    // $sql="select a.* from etw_onlines a right join (select max(id) id from etw_onlines group by title,contacter,email,address,content) b on b.id = a.id where usernameid=".$uid.$wherechild." and translate=0 and reply=0 and readed=0";
     $result=mysql_query($sql);
	 $count=mysql_num_rows($result);

	 if($count==0){
	  echo $count;
	 }else{
	  echo "<font color='#ff0000'>".$count."</font>";
	 }
}

function unreadmessage($uid,$wherechild){
     $sql="select count(*) from etw_onlines where usernameid=".$uid.$wherechild." and (translate<>0 or reply<>0) and readed=0";
     $rs=sql_select($sql);
	 
    $ids=sql_select("select max(id) as id from etw_onlines where usernameid=".$uid.$wherechild." group by title,contacter,email,address,content");
	 $id="";
	for($i=0;$i<count($ids)-1;$i++){
	   $id=$id."'".$ids[$i][0]."',";
	  }
	 $id=$id."'".$ids[count($ids)-1][0]."'";
     $sql="select id from etw_onlines where id in(".$id.") and translate=0 and reply=0 and readed=0";
     $result=mysql_query($sql);
	 $count=mysql_num_rows($result);
	 $all= $rs[0][0]+$count;
	 if($all==0){
	  echo $all;
	 }else{
	  echo "<font color='#ff0000'>".$all."</font>";
	 }
	 
	 
}

function allchats($uid,$wherechild){
     // $sql="select max(id) as id from etw_onlines where  usernameid=".$uid.$wherechild." and isdelete=0 and readed=1 group by title,contacter,email,address,content";
 	 
    $ids=sql_select("select max(id) as id from etw_onlines where usernameid=".$uid.$wherechild." group by title,contacter,email,address,content");
	 $id="";
	for($i=0;$i<count($ids)-1;$i++){
	   $id=$id."'".$ids[$i][0]."',";
	  }
	 $id=$id."'".$ids[count($ids)-1][0]."'";
     $sql="select id from etw_onlines where id in(".$id.") and  readed=1";
	
	  $result=mysql_query($sql);
	  $count=0;
	  while($counts=mysql_fetch_array($result)){
			 $count= $count+1;
		}
	  echo $count;
}

function totalchats($uid,$wherechild){
      $sql="select max(id) as id from etw_onlines where  usernameid=".$uid.$wherechild." group by title,contacter,email,address,content";
	
	  $result=mysql_query($sql);
	  $count=0;
	  while($counts=mysql_fetch_array($result)){
			 $count= $count+1;
		}
	  echo $count;
}

function lajichats($uid,$wherechild){
      $sql="select count(*) as counts from etw_onlines where isdelete=1 and usernameid=".$uid.$wherechild;
	  $result=mysql_query($sql);
	  $rs=mysql_fetch_array($result);
	  echo  $rs['counts'];
}

function lastlogintime($uid){
    $sql="select logintime from etw_loginlog where userid=".$uid." order by logintime desc";
	$rs=sql_select($sql);
	if($rs[1][0]==''){
	echo  date('Y-m-d H:i',time());
	}else{
	echo  date('Y-m-d H:i',$rs[1][0]);
	}
}

function logincount($uid){
    $sql="select count(*) from etw_loginlog where userid=".$uid;
	$rs=sql_select($sql);
	
	echo $rs[0][0];
}

function servicecout($uid){
   $sql="select count(*) from etw_suggest where  userid=".$uid;
	$rs=sql_select($sql);
	echo $rs[0][0];
}

function noticecout(){
   $sql="select count(*) from etw_gonggao";
	$rs=sql_select($sql);
	echo $rs[0][0];
}

 ?>