<?php
include("../../db.php");
//header("Access-Control-Allow-Origin: * ");

header('Content-Type: application/json');
$session=$_REQUEST['session'];

$date=$_REQUEST['date'];

$myUid = $_GET['uid'];


// 	 $session=mysql_real_escape_string($session);

$result=$db->getRows("select * from staff where session='$session' ");

if($result)
{
    $emptyJson = new stdClass();
    foreach ($result as $rowc)
    {

        $thread_name = getChatThread($myUid, "A", $rowc['idno']);
        $rec = $db->getRow("SELECT * FROM recent_message WHERE thread = '$thread_name' ");

        if ($rec == null || $rec == ''){
            $rec = $emptyJson;
        }

        $jsonc[]=array("idno"=>$rowc['idno'],"name"=>$rowc['name'],"fname"=>$rowc['fname'],"subject"=>$rowc['experience'],"dob"=>$rowc['dob'],
            "qualification"=>$rowc['qualification'],"mobile"=>$rowc['mobile'],"address"=>$rowc['address'],
            "department"=>$rowc['department'],"photo"=>"$rowc[photo]","channel_id"=>$rowc['channel_id'],
            "recent_msg" => $rec);

        $json['status']=1;
        $json['msg']="Profile found Successfully..!";
        $json['data']=$jsonc;
    }
    echo json_encode($json);
}
else
{
    echo json_encode(array('status' => 0, 'msg'=>'detail not found..!'));
}



function getChatThread($myId, $myutype, $otherId){
    if($myId < $otherId){
        return $myutype.$myId."_T".$otherId;
    }else{
        return "T".$otherId."_".$myutype.$myId;
    }
}