<?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
        
        
        $pros_title =  mysqli_real_escape_string($link, trim(isset($_POST['pros_title']) ? $_POST['pros_title'] : ''));
        $date_cont =  mysqli_real_escape_string($link, trim(isset($_POST['date_cont']) ? $_POST['date_cont'] : ''));
        $UserID =  mysqli_real_escape_string($link, trim(isset($_POST['UserID']) ? $_POST['UserID'] : ''));
        $UserType =  mysqli_real_escape_string($link, trim(isset($_POST['UserType']) ? $_POST['UserType'] : ''));
        $tribe_id =  mysqli_real_escape_string($link, trim(isset($_POST['tribe_id']) ? $_POST['tribe_id'] : ''));
        
        
        $pros_verify_tribe = mysqli_query($link, "SELECT * FROM `event` WHERE `TribeID`='$tribe_id' AND `EventTitle`='$pros_title' AND `EventDate`='$date_cont'");
        $pros_verify_tribe_cnt = mysqli_num_rows($pros_verify_tribe);
        
        
        if($pros_verify_tribe_cnt > 0)
        {
            
                $response = array(
                    "requestSuccessful" => true, // Assuming the request was successful
                    "responseMessage" => "failed",
                    "responseDescription" => "This meeting has been set already"
                     
                 );
                               
            
            
            
        }else
        {
            
            
                //  $member_nickname
                
                            
                             $insert_event = mysqli_query($link, "INSERT INTO `event`(`EventID`, `TribeID`, `EventTitle`, `EventDate`) 
                             VALUES (NULL,'$tribe_id','$pros_title','$date_cont')");
                            
                            
                            
                 
        
                           if($insert_event == true)
                           
                          $response = array(
                            "requestSuccessful" => true, // Assuming the request was successful
                            "responseMessage" => "success",
                            "responseDescription" => "Event set successfully"
                             
                             );
                        
                   
            
            
            
        }
              
        
      
         $json_response = json_encode($response);
    
        // // Output the JSON response
        echo $json_response;
       

?>