
<?php
   // session_start();
    include_once('../config/conn/db-connection.php');
    include_once('../config/class/sap_model.php');
    $SAP = new SAP_infosytem();

        if(ISSET($_POST)){

               $sapform_no = trim($_POST['sapform_no']);
               $purpose = trim($_POST['purpose']);
               $financial_serviceprovider = trim($_POST['financial_serviceprovider']);
               $status = "Approve";
               $recordedBy = trim($_POST['recordedBy']);
               $full_name = trim($_POST['full_name']);
               $sapform_id = trim($_POST['sapform_id']);


              // ==========audit trail==================
              //$user = trim($_POST['user']);
               if(!empty($_SERVER["HTTP_CLIENT_IP"])){
                     $ip = $_SERVER["HTTP_CLIENT_IP"];
                  }elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ 
                     $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
                  }else{
                     $ip = $_SERVER["REMOTE_ADDR"];
                }
               $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
               date_default_timezone_set("asia/manila");
               $logdate =  date('M-d-Y h:i A', strtotime("+0 HOURS"));
               $action = "'Zone Leader' has already Approved '".ucfirst($full_name)."'";    
            // ==========end audit trail==============


               $SAP->approve_sapform($sapform_no, $purpose, $financial_serviceprovider,  $status,  $recordedBy, $sapform_id,  $ip, $host,  $logdate, $action);
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function () { swal("Approve SAP Form Successfully!","Message!","success");';
                  echo '}, 1000);</script>';
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function(){';
                  echo 'window.location = "/SAP_Information_System/Zoneleader/dashboard.php"';
                  echo '},1000)';
                  echo '</script>';
             
        }
?>