<?php

// require_once("../../../bigbluebutton-default/mentor/db_connect.php");

$meetingId=$_GET['meetingId'];

$moderatorPw=$_GET['moderatorPw'];

$meetingendtime=time();

//$update_meeting="UPDATE meeting_information SET meetingended=$meetingendtime
//WHERE meetingid_created=$meetingId ";

// mysqli_query($conn, $update_meeting);

//  $fp = fopen('lidn.txt', 'w');
// fwrite($fp, $meetingId.' '.$moderatorPw.'  '.$update_meeting);
// fclose($fp);



//update meeting information when meeting ends

// $update_meeting="UPDATE meeting_information SET meetingended=$meetingendtime
// WHERE meetingid_created=$meetingId ";
// mysqli_query($conn, $query);



$apiUrl = "https://rest.ifieldsmart.com/api/Meeting/EndMeetingStatus";
$queryParams = http_build_query([
    'MeetingID'   => $meetingId,
//    'moderatorPw' => 'no password required!' 
]);
$fullUrl = $apiUrl . "?" . $queryParams;
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $fullUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Stop waiting after 10 seconds

// If your API requires a specific header (like an API Key)
// curl_setopt($ch, CURLOPT_HTTPHEADER, [
//     'Authorization: Bearer YOUR_SECRET_TOKEN'
// ]);

// 5. Execute the request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// 6. Error Handling
if (curl_errno($ch)) {
    echo 'Connection Error: ' . curl_error($ch);
} else {
    if ($httpCode === 200) {
        echo "Meeting status updated successfully via API.";
    } else {
        echo "API returned an error (Status Code: $httpCode). Response: " . $response;
    }
}

curl_close($ch);



?>