
<?php 
@session_start();
include('../inc/conn.php');
include('../inc/function.php');
$uid=$_GET['uid'];
       $ids=sql_select("select max(id) as id from etw_onlines where usernameid=".$uid." 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 * 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." and translate=0 and reply=0 and readed=0";
     $result=mysql_query($sql);
	 $count=mysql_num_rows($result);

$nums=0;
if($_SESSION['vote']=="father"){
      $allid=allchatid($uid);	
      $filename="http://data.etwservice.com/etw_xml/".$uid.".xml";
     // if(remote_file_exists($filename)){
      $xml=''; 
	  if($f = @fopen( $filename, 'r' )){ 
      while( $data = fread( $f, 4096 ) ) { $xml .= $data; } 
      fclose( $f ); 
	  preg_match_all( "/\<item\>(.*?)\<\/item\>/s",$xml, $items ); 
      
	  foreach( $items[0] as $item )  { 
	      $flat=1;
		  preg_match_all( "/\<id\>(.*?)\<\/id\>/", $item, $chatid ); 
		  for($i=0;$i<count($allid);$i++){
		     if($chatid[1][0]==$allid[$i]){
			    $flat=0;
				break;
			   }
			 }
		  if($flat==1){ 
			       preg_match_all( "/\<title\>(.*?)\<\/title\>/", $item, $title ); 
                   preg_match_all( "/\<contacter\>(.*?)\<\/contacter\>/", $item, $contacter ); 
                   preg_match_all( "/\<telephone\>(.*?)\<\/telephone\>/", $item, $telephone ); 
                   preg_match_all( "/\<fax\>(.*?)\<\/fax\>/", $item, $fax ); 
                   preg_match_all( "/\<email\>(.*?)\<\/email\>/", $item, $email ); 
                   preg_match_all( "/\<address\>(.*?)\<\/address\>/", $item, $address ); 
                   preg_match_all( "/\<content\>(.*?)\<\/content\>/", $item, $content ); 
                   preg_match_all( "/\<languages\>(.*?)\<\/languages\>/", $item, $languages ); 
                   preg_match_all( "/\<senddate\>(.*?)\<\/senddate\>/", $item, $senddate ); 
                   preg_match_all( "/\<ip\>(.*?)\<\/ip\>/", $item, $ip ); 
                   preg_match_all( "/\<url\>(.*?)\<\/url\>/", $item, $url );
				   
				   $mysql="insert into etw_onlines(yid,title,contacter,telephone,fax,email,address,content,language,senddate,url,usernameid,ip,readed) value('".$chatid[1][0]."','".$title[1][0]."','".$contacter[1][0]."','".$telephone[1][0]."','".$fax[1][0]."','".$email[1][0]."','".$address[1][0]."','".$content[1][0]."','".$languages[1][0]."','".$senddate[1][0]."','".$url[1][0]."','".$uid."','".$ip[1][0]."','0' )";
	    
		           mysql_query($mysql) or die("error");
			       $nums=$nums+1;

		  }
	  }	  
  } 
 
 } 
 $counts=$nums+$count;

 if($counts<>0){
   $str="<a href='unread.php' class='red'>(<span id='newmsg'>".$counts."</span>)</a>";
   }else{
   $str="(<span id='newmsg'>0</span>)";
   }
   echo $str;

 ?>