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




// API URL
$url = 'https://smartcampus.pk/Production/get_data_sms_api.php?id=1';

// Create a new cURL resource
$curl = curl_init($url);

// Set the cURL options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

// Execute the cURL request
$response = curl_exec($curl);

// Check for errors
if (curl_errno($curl)) {
    $error = curl_error($curl);
    // Handle the error accordingly
    // ...
} else {
    // Process the API response
    $Messages = json_decode($response, true);

    // Output the JSON data
   /* echo '<pre>';
    print_r($Messages);
    echo '</pre>';*/
}

// Close cURL resource
curl_close($curl);



  // Iterate over each message using a foreach loop
        foreach ($Messages as $message) {
            $msg_from = $message['msg_from'];
            $msg_details = $message['msg_details'];
            $msg_id = $message['msg_id'];

            // Output the message details
            /*echo "From: $msg_from<br>";
            echo "Details: $msg_details<br>";
            echo "ID: $msg_id<br><br>";*/


// now update record


$data = array(

'msg_status' => 0               

);

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

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

// Create an associative array representing the message
$message = array(    
"Status" => "Sender: ".$msg_from." >>> 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."<br>";






        } 



?>



