<?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'] : ''));
        $password =  mysqli_real_escape_string($link, trim(isset($_POST['password']) ? $_POST['password'] : ''));
        
         $hashedPassword = md5($password);
        
        $currentDateTime = date('Y-m-d H:i:s');
        
        
        
          $sql = ("SELECT * FROM `Users` WHERE UserID='$userID'");
          $result = mysqli_query($link, $sql);
          $row = mysqli_fetch_assoc($result);
          $row_cnt = mysqli_num_rows($result);
    
          if ($row_cnt > 0) 
          {
              
              
              
          
                  $updatepwd = mysqli_query($link, "UPDATE `userlogin` SET `Password`='$hashedPassword' WHERE `UserID`='$userID'");
                  
                  
                  if($updatepwd == true)
                  {
                      
                      
                       $response = array(
                        "requestSuccessful" => true, // Assuming the request was successful
                        "responseMessage" => "success",
                        "responseDescription" => "Password set successfull"
                        
                      );
                      
                      
                  }else
                  {
                      
                      
                       $response = array(
                        "requestSuccessful" => true, // Assuming the request was successful
                        "responseMessage" => "failed",
                        "responseDescription" => "Error!! Password could not be chnaged please try again later"
                        
                      );
                      
                      
                  }
                    
                     
          }
          else
          {
              
             
                   $response = array(
                        "requestSuccessful" => true, // Assuming the request was successful
                        "responseMessage" => "failed",
                        "responseDescription" => "User not found"
                        
                        
                      );
              
          }
      
      
         $json_response = json_encode($response);
    
        // // Output the JSON response
        echo $json_response;
       

?>