<?php
$path="../../";
include("../../map.php");
$musers = array();
$sql1=mysqli_query($conn, "select s1,s2,ts1 from t2 where ne='mesaj' and (s1='".$_SESSION["user_id"]."' or s2='".$_SESSION["user_id"]."') order by id desc"); while($message=mysqli_fetch_assoc($sql1)){
	if(($_GET["ts1"]=="" and $_GET["ts2"]=="" and ($message["ts1"] >= date('Y-m-d'))) or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($message["ts1"]>=$_GET["ts1"] and $message["ts1"]<=$_GET["ts2"])){
		if($message["s1"]<>$_SESSION["user_id"]){
			$musers[] = $message["s1"];
		}
		if($message["s2"]<>$_SESSION["user_id"]){
			$musers[] = $message["s2"];
		}
	}
}
//Print_r($musers);
?>
	<ul class="v3-list-group" style="margin:0px;">
<?php if($_GET["q"]==""){?>
	<?php
		foreach(array_unique($musers) as $key=>$value){
		$sqlc=mysqli_query($conn, "select id,t1 from t5 where id=".$value.""); $rsc=mysqli_fetch_assoc($sqlc);
		if(mysqli_num_rows($sqlc)>0){$user=$rsc["t1"];}else{$user="Admin";}
		$sql=mysqli_query($conn, "select id,n1,n12,n6,ts1 from t2 where ne='mesaj' and ((s1=".$_SESSION['user_id']." and s2=".$value.") or (s1=".$value." and s2=".$_SESSION['user_id'].")) order by id desc"); $message=mysqli_fetch_assoc($sql); $jsi = json_decode($message["n6"],true);$jsn=json_decode($message["n12"],true);	//bildirim
	?>
		<li class="v3-list-group-item cp v3-list-group-item-<?php if($jsn["notification".$_SESSION['user_id'].""]<>1){echo "success";}else{echo "warning";}?>" onclick="Load_Message_Form('<?php echo $value;?>');">
			<div class="v3-row">
				<div class="v3-col-md-2 v3-col-xs-3"> <i class="fa fa-user-circle" aria-hidden="true" style="font-size: 50px;"></i></div>
				<div class="v3-col-md-10 v3-col-xs-9">
				<b><?php echo $user;?></b><br>
				<?php echo kisalt($message["n1"],10)?><br>
				<?php if($message["n6"]<>""){?>
					<div class="v3-row">
					<?php foreach($jsi as $key=>$value){ ?>
					<div class="v3-col-md-2 v3-col-xs-3" style="padding: 5px;">
						<a data-fancybox="gallery" href="<?php echo $media_path_slash?>deppo/dosya/<?php echo $value;?>" class="v3-thumbnail">
							<img src="<?php echo $weburl?>/deppo/dosya/<?php echo $value;?>">
						</a>
					</div>
				<?php }echo "</div>";}?>
				<div style="font-size:10px;"><?php echo timeago($message["ts1"])?></div>
			</div>
		</li>
	<?php }?>
<?php }else{?>
	<?php
		$sqlc=mysqli_query($conn, "select id,t1 from t5 where t1 LIKE '%".$_GET["q"]."%' $luye"); while($rsc=mysqli_fetch_assoc($sqlc)){		
		if(mysqli_num_rows($sqli)>0){$user=$rsc["t1"];}else{$user="Admin";}
		$sql=mysqli_query($conn, "select id,n1,n12,n6,ts1 from t2 where ne='mesaj' and ((s1=".$_SESSION['user_id']." and s2=".$rsc["id"].") or (s1=".$rsc["id"]." and s2=".$_SESSION['user_id'].")) order by id desc"); $message=mysqli_fetch_assoc($sql); $jsi = json_decode($message["n6"],true);$jsn=json_decode($message["n12"],true);	//bildirim
	?>
		<li class="v3-list-group-item cp v3-list-group-item-<?php if($jsn["notification".$_SESSION['user_id'].""]<>1){echo "success";}else{echo "warning";}?>" onclick="Load_Message_Form('<?php echo $rsc["id"];?>');">
			<div class="v3-row">
				<div class="v3-col-md-2 v3-col-xs-3"> <i class="fa fa-user-circle" aria-hidden="true" style="font-size: 50px;"></i></div>
				<div class="v3-col-md-10 v3-col-xs-9">
				<b><?php echo $rsc["t1"];?></b><br>
				<?php echo kisalt($message["n1"],10)?><br>
				<?php if($message["n6"]<>""){?>
					<div class="v3-row">
					<?php foreach($jsi as $key=>$fvalue){ ?>
					<div class="v3-col-md-2 v3-col-xs-3" style="padding: 5px;">
						<a data-fancybox="gallery" href="<?php echo $media_path_slash?>deppo/dosya/<?php echo $fvalue;?>" class="v3-thumbnail">
							<img src="<?php echo $weburl?>/deppo/dosya/<?php echo $fvalue;?>">
						</a>
					</div>
				<?php }echo "</div>";}?>
				<div style="font-size:10px;"><?php echo timeago($message["ts1"])?></div>
			</div>
		</li>
	<?php }?>
<?php }?>
	</ul>