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

        if(ISSET($_POST)){

               $lastname = trim($_POST['lastname']);
               $firstname = trim($_POST['firstname']);
               $middlename = trim($_POST['middlename']);
               $name = ucfirst($lastname) .', '.ucfirst($firstname).' '. ucfirst($middlename);
               $full_name = "'".$name."'";
               $age = trim($_POST['age']);
               $birthdate = trim($_POST['birthdate']);
               $gender = trim($_POST['gender']);
               $household_number = trim($_POST['household_number']);
               $birthplace = trim($_POST['birthplace']);
               $differently_abledperson = trim($_POST['differently_abledperson']);
               $gcash_number = trim($_POST['gcash_number']);
               $blood_type = trim($_POST['blood_type']);
               $purok_no = trim($_POST['purok_no']);
               $civil_status = trim($_POST['civil_status']);
               $total_householdmember = trim($_POST['total_householdmember']);
               $religion = trim($_POST['religion']);
               $occupation = trim($_POST['occupation']);
               $contact_number = trim($_POST['contact_number']);
               $monthly_income = trim($_POST['monthly_income']);
               $educational_attainment = trim($_POST['educational_attainment']);
               $nationality = trim($_POST['nationality']);
               $philhealth_number = trim($_POST['philhealth_number']);
               $skills = trim($_POST['skills']);
               $water_usage = trim($_POST['water_usage']);
               $land_ownershipstatus = trim($_POST['land_ownershipstatus']);
               $sektor = trim($_POST['sektor']);
               $benificiaries_of = trim($_POST['benificiaries_of']);
               $light_facilities = trim($_POST['light_facilities']);
               $remark = trim($_POST['remark']);
               $former_address = trim($_POST['former_address']);           
               $username = trim($_POST['username']);
               $pass1 = trim($_POST['password']);
               $pass=sha1($pass1);
               $salt="a1Bz20ydqelm8m1wqlxIseQ0zV";
               $password = $salt.$pass;
               $role = "Member";

              $image = addslashes(file_get_contents($_FILES['image_profile']['tmp_name']));
              $images ="uploads/". addslashes($_FILES['image_profile']['name']);
              $image_size = getimagesize($_FILES['image_profile']['tmp_name']);
             // move_uploaded_file($_FILES["images"]["tmp_name"], $images);

              move_uploaded_file($_FILES["image_profile"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/SAP_Information_System/uploads/" .   addslashes($_FILES["image_profile"]["name"]));


              // ==========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 Beneficiaries Info. for ".$full_name;    
            // ==========end audit trail==============


               $SAP->add_beneficiaries($lastname, $firstname, $middlename, $age, $birthdate, $gender, $household_number, $birthplace, $differently_abledperson, $gcash_number, $blood_type, $purok_no, $civil_status, $total_householdmember, $religion, $occupation, $contact_number, $monthly_income,  $educational_attainment, $nationality, $philhealth_number, $skills, $water_usage, $land_ownershipstatus, $sektor, $benificiaries_of, $light_facilities, $remark, $former_address, $username, $password, $role, $images, $user, $ip, $host,  $logdate, $action);
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function () { swal("Add Beneficiaries Successfully!","Message!","success");';
                  echo '}, 1000);</script>';
                  echo '<script type="text/javascript">';
                  echo 'setTimeout(function(){';
                  echo 'window.location = "/SAP_Information_System/Dashboard/pages/Beneficiaries.php"';
                  echo '},1000)';
                  echo '</script>';
             
        }
?>