<?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
        
        
         $Tribe_ID =  mysqli_real_escape_string($link, trim(isset($_POST['tribe_id']) ? $_POST['tribe_id'] : ''));
         $userID =  mysqli_real_escape_string($link, trim(isset($_POST['UserID']) ? $_POST['UserID'] : ''));
         $UserType =  mysqli_real_escape_string($link, trim(isset($_POST['UserType']) ? $_POST['UserType'] : ''));
       
         
         
             $pros_get_tribe = mysqli_query($link," SELECT * FROM `event` WHERE  `TribeID`='$Tribe_ID' ORDER BY EventTitle ASC");
            
            $pros_get_tribe_cnt = mysqli_num_rows($pros_get_tribe);
            
                                  
              if($pros_get_tribe_cnt > 0)
              {
                  
                  
                   $prosload_user_array = [];
                
                     while($pros_get_tribe_cnt_row = mysqli_fetch_assoc($pros_get_tribe))
                     {
                         
                         
                          $TribeID_new =  $pros_get_tribe_cnt_row['TribeID'];
                          $MeetingTitle =  $pros_get_tribe_cnt_row['EventTitle'];
                          $TribeMeetingID =  $pros_get_tribe_cnt_row['EventID'];
                          $EventDate =  $pros_get_tribe_cnt_row['EventDate'];
                          
                          
                          $prosload_user_array[] = array(
                                'tribe_id' => $TribeID_new,
                                'meet_title' => $MeetingTitle,
                                'tribe_meetingid'=> $TribeMeetingID,
                                'date_id'=> $EventDate
                                           
                            );
          
                          
                       
                     }
                       
                     $response = array(
                                "requestSuccessful" => true, // Assuming the request was successful
                                "responseMessage" => "success",
                                "responseDescription" => "no event found",
                                 "responseBody" => $prosload_user_array
                                );
                     
                     
                  
              }else
              {
                  
                  
                    $response = array(
                        "requestSuccessful" => true, // Assuming the request was successful
                        "responseMessage" => "failed",
                        "responseDescription" => "no event found",
                         "responseBody" => array(
                                'tribe_id' => '',
                                'meet_title' => '',
                                'tribe_meetingid'=> '',
                                 'date_id'=> ''
                                 
                            )
                        );
                  
              }
       
       
       
        $utf8_string = mb_convert_encoding($response, 'UTF-8', 'UTF-8');
        
        $json_response = json_encode($utf8_string, JSON_UNESCAPED_UNICODE);
    
         // Output the JSON response
        echo $json_response;

        
      
        
       

?>