<?php include("parent/callMe.php"); ?>
  
 <?php


 //==================================For Authentication ============================================

if ($_REQUEST['email']!=NULL && $_REQUEST['pass']!=NULL ) {

    // Set the appropriate HTTP headers
header('Content-Type: application/json');
    
$email = $_REQUEST['email'];
$password = $_REQUEST['pass'];

$sql = "SELECT branch_id FROM  edu_user_config  WHERE user_email='$email' and user_password='$password' ";
$userData = $m->query($sql);

$brID=$userData[0]['branch_id'];
$sql = "SELECT branch_id as id, Branch_Name as title FROM  edu_branch_config  WHERE branch_id='$brID' ";
$branchData = $m->query($sql);

$jsonData = json_encode($branchData);

$jsonArray = json_decode($jsonData, true);
$object = $jsonArray[0];
// You can now work with the extracted object separately
$id = $object['id'];
$title = $object['title'];
// Print the extracted object
echo json_encode($object);

}




//==================================For Not Sent Messages ============================================

if ($_REQUEST['id']!=NULL) {

$brID=$_REQUEST['id'];

$sql="SELECT msg_from,msg_details,msg_id FROM edu_messages_details where msg_status='1' and branch_Id='$brID' ";

$msgData = $m->query($sql);

$jsonDataMessage = json_encode($msgData);

// Output the JSON data
 echo $jsonDataMessage;


}


//==================================For Update Message Status ============================================

if ($_REQUEST['msg_id']!=NULL && $_REQUEST['msg_from']!=NULL) {

$msgFrom=$_REQUEST['msg_from'];
$msgID=$_REQUEST['msg_id'];

$data = array(

'msg_status' => 0               

);

$m->where ("msg_id", $msgID);

$result =  $m->update ('edu_messages_details', $data);

// Create an associative array representing the message
$message = array(    
    "Status" => "Sender: ".$msgFrom." >>> Message status has been successfully updated...!"
);

// Convert the array to JSON format
$json_message = json_encode($message);

// Print the JSON-formatted message
echo $json_message;

}

 ?>