<?php

            include('../../config/config.php');
            date_default_timezone_set('Africa/Lagos');
            
            include('../messaging/whatsapp/index.php');
            
            // Set CORS headers to allow requests from any origin (*)
            header("Access-Control-Allow-Origin: *");
            
            // Allow specific HTTP methods
            header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
            
            // Allow specific HTTP headers
            header("Access-Control-Allow-Headers: Content-Type, Authorization");
            
            // Allow cookies to be included in the request (if needed)
            header("Access-Control-Allow-Credentials: true");
            
            // Retrieve the raw POST data
            $UserID = isset($_POST['UserID']) ? mysqli_real_escape_string($link, trim($_POST['UserID'])) : '';
            $UserType = isset($_POST['UserType']) ? mysqli_real_escape_string($link, trim($_POST['UserType'])) : '';
            $base64Image = isset($_POST['image']) ? mysqli_real_escape_string($link, trim($_POST['image'])) : '';
            
            $pros_verify_tribe = mysqli_query($link, "UPDATE `Users` SET `Photo`='$base64Image' WHERE `UserID`='$UserID'");
            
            if ($pros_verify_tribe) {
                $response = array(
                    "requestSuccessful" => true,
                    "responseMessage" => "success",
                    "responseDescription" => "Image uploaded successfully"
                );
            } else {
                $response = array(
                    "requestSuccessful" => false, // Assuming the request was not successful
                    "responseMessage" => "failed",
                    "responseDescription" => "Image could not be uploaded, please try again later"
                );
            }
            
            $json_response = json_encode($response);
            
            // Output the JSON response
            echo $json_response;

?>
