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

        if(ISSET($_POST)){

               $username = trim($_POST['username']);
               $pass1 = trim($_POST['password']);
               $pass=sha1($pass1);
               $salt="a1Bz20ydqelm8m1wqlxIseQ0zV";
               $password = $salt.$pass;

               $role = "Zone Leader";

            // ==========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 = "'Admin' will Add Account for 'Zone Leader' name is. '".$username ."'";    
            // ==========end audit trail==============

               $SAP->add_zoneleader($username, $password, $role, $user, $ip, $host,  $logdate, $action);
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function () { swal("Add Zone Leader Successfully!","Message!","success");';
                  echo '}, 1000);</script>';
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function(){';
                  echo 'window.location = "/SAP_Information_System/Dashboard/pages/Zone_leader.php"';
                  echo '},1000)';
                  echo '</script>';
             
        }
?>