<?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 =  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'] : ''));
        $newmemerd =  mysqli_real_escape_string($link, trim(isset($_POST['member_id']) ? $_POST['member_id'] : ''));
         $minitribe =  mysqli_real_escape_string($link, trim(isset($_POST['minitribe']) ? $_POST['minitribe'] : ''));
        
         
        
          if($minitribe == 'NULL' || $minitribe == '0' || $minitribe == '')
          {
              
              $newmmini_tribe = 0;
              
              $new_tribe = $Tribe_ID;
          }else
          {
              $newmmini_tribe =$minitribe;
              
              $new_tribe = 0;
              
          }
        
      
        
       
            
            
                    $insert_tribe = mysqli_query($link, "UPDATE `Users` SET TribeAssigenedID='$new_tribe',`MiniTribeAssigenedID`='$newmmini_tribe' WHERE UserID='$newmemerd'");
                    
                    if($insert_tribe == true)
                    {
                        
                            
                           
                           
                          $response = array(
                            "requestSuccessful" => true, // Assuming the request was successful
                            "responseMessage" => "success",
                            "responseDescription" => "tribe assigned successfully"
                             
                             );
                        
                    }else
                    {
                        
                          $response = array(
                                "requestSuccessful" => true, // Assuming the request was successful
                                "responseMessage" => "failed",
                                "responseDescription" => "Error!! member could not be assigned to tribe, kindly try again later."
                                 
                             );
                        
                    }
            
            
            
      
              
        
      
         $json_response = json_encode($response);
    
        // // Output the JSON response
        echo $json_response;
       

?>