<?php include('../dbconnect.php');
ob_start();
session_start();
$user = $_SESSION['user'];
$sqla = "SELECT * FROM account WHERE userid = '$user'";
$resulta = mysqli_query($conn, $sqla);
$rowa  = mysqli_fetch_assoc($resulta);

if( !isset($_SESSION['user']) ) {
 header("Location: ../index.php");
 exit;
}

 
 



$sql = "SELECT * FROM empinfo";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);


$curyear = date('y');

$rowcount=mysqli_num_rows($result);

$count = $rowcount + 1;

$strlength = strlen($count);

if($strlength = 1){
  $ATVID = str_pad($count, 2, '0', STR_PAD_LEFT);
 
}
else{
  $ATVID  = $count;
}
$empID = 'ATV'.$curyear.'-'.$ATVID;

/*
if($strlength = 1){
    $ATVID = str_pad($emp, 2, '0', STR_PAD_LEFT);
   
}
else{
    $ATVID = $emp;
}

$empID = 'ATV'.$curyear.'-'.$ATVID; */
$password= $empID; 


$imgFile = $_FILES['userpic']['name'];
$tmp_dir = $_FILES['userpic']['tmp_name'];
$imgSize = $_FILES['userpic']['size'];

$surname = $_POST['sname'];
$firstname = $_POST['fname'];
$middlename = $_POST['mname'];
$permanentadd = $_POST['permanentadd'];
$residentialadd = $_POST['residentialadd'];
$bday = $_POST['bday'];
$empage = $_POST['empage'];
$gender = $_POST['gender'];
$contactno = $_POST['contactno'];
$email = $_POST['email'];
$civilstat = $_POST['civilstat'];

$spouse = $_POST['spouse'];
$spousebday = $_POST['spousebday'];


$mothersname = $_POST['mothersname'];
$motheroccu = $_POST['motheroccu'];
$fathersname = $_POST['fathersname'];
$fatheroccu = $_POST['fatheroccu'];
$ename = $_POST['ename'];
$erelatioship = $_POST['erelationship'];
$eaddress = $_POST['eaddress'];
$econtactno = $_POST['econtact'];

$hireddate = $_POST['hireddate'];
$thirdmonth = $_POST['thirdmonth'];
$fifthmonth = $_POST['fifthmonth'];

$tenure = $_POST['tenure'];
$level = $_POST['level'];
$department = $_POST['department'];
$team = $_POST['team'];
$genpos = $_POST['genpos'];
$jobtitle =  $_POST['jobtitle'];
$supervisor = $_POST['supervisor'];
$salarycode = $_POST['salarycode'];
$effectdate = $_POST['effectdate'];

if(isset($_POST['createemp']))
{
     
    if(isset($_POST['cb'])){
        
        $empID = $_POST['empid'];
    }
    
    $sql = "SELECT firstname, surname, middlename, mothersmaiden FROM empinfo WHERE firstname='$firstname' && surname='$surname' && middlename='$middlename' && mothersmaiden ='$mothersname'";
    $result = $conn->query($sql);
    $sqlid = "SELECT * FROM empinfo WHERE empid='$empID'";
    $resultid = $conn->query($sqlid);
    
    if ($resultid->num_rows > 0) {

        $error = '<div class="alert alert-warning">
         Employee ID already exist.
      </div>
      ';

    }

    if ($result->num_rows > 0) {

        $error = '<div class="alert alert-warning">
         Employee already exist.
      </div>
      ';
    
    }
    if($empage < 15){
        $error = '<div class="alert alert-warning">
         Age must be 15 and above
      </div>
      ';
    }
 

  
    if(empty($imgFile)){

      $userpic = 'profile.png';
    }
    else{
            $upload_dir = '../files/pictures/'; // upload directory
       
           $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
           $valid_extensions = array('jpeg', 'jpg', 'png', 'gif');
           $userpic = $empID.".".$imgExt;

           if(in_array($imgExt, $valid_extensions)){			
            // Check file size '5MB'
            if($imgSize < 5000000 )				{
              move_uploaded_file($tmp_dir,$upload_dir.$userpic);
              
            }
            else{
              $error="<div class='alert alert-warning'>
              <strong style='font-size:12pt;'>Sorry, your file is too large</strong> 
            </div>";
            }
        }
        else
        {
            $error="<div class='alert alert-warning'>
            <strong style='font-size:12pt;'>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</strong> 
          </div>";
          }
        

    }

         
    if(!isset($error)){
        
    date_default_timezone_set('Asia/Manila');
    $datetime = date('Y/m/d g:i:s');

    //$sampledate = date_create($thirdmonth);

    //$formatdate = date_format($sampledate, "Y/m/d");
  
    $tdate = date_create($thirdmonth);

    $fdate = date_create($fifthmonth);

 

    $formatt = date_format($tdate, "Y/m/d");
    $formatd = date_format($fdate, "Y/m/d");

    $password = hash('sha256', $empID);

   
        


        //governmentinfo
        $govsql ="INSERT INTO `governmentinfo`(`gid`, `sss`, `pagibig`, `tin`, `philhealth`) 
        VALUES ('$empID','none','none','none','none')";
        //Employee account
        $sql1 = "INSERT INTO `account`(`userid`, `password`, `level`, `status`) VALUES ('$empID','$password','user','active')";
        //Employee Info
        $sql = "INSERT INTO `empinfo`(`empid`, `surname`, `firstname`, `middlename`, `permanentadd`, `residentialadd`, `bday`, `age`, `gender`, `contactno`,
         `email`, `civilstat`, `mothersmaiden`, `fathersname`, `mothersoccu`, `fathersoccu`, `ename`, `erel`, `eadd`, `econtactno`, `userid`,`dateadded`,`picture`,`spouse`,`spousebday`,`gid`)
          VALUES ('$empID','$surname','$firstname','$middlename','$permanentadd','$residentialadd','$bday','$empage','$gender','$contactno','$email','$civilstat','$mothersname',
          '$fathersname', '$motheroccu','$fatheroccu','$ename','$erelatioship','$eaddress','$econtactno','$empID','$datetime','$userpic','$spouse','$spousebday','$empID')";
        //Employee details
        $sql2 = "INSERT INTO `empdetails`(`detailid`, `hireddate`, `thirdmonth`, `fourthmonth`, `tenure`, `level`, `department`, `team`, `generalpos`, `jobtitle`, `supervisor`,`status`,`date`,`empid`) 
        VALUES ('$empID','$hireddate','$formatt','$formatd','$tenure','$level','$department','$team','$genpos','$jobtitle','$supervisor','Active','$hireddate','$empID')";

        $sqlsal ="INSERT INTO `salaryemp`(`salarycode`, `effectivitydate`, `empid`) VALUES ('$salarycode','$effectdate','$empID')";

        if($civilstat == 'Single'){
            $docstat = 'N/A';
            }
            else{
                $docstat ='none';
            }

        //documents
         
        $acid = $empID.'Account Opening Form';
        $birid = $empID.'BIR 1905 and 2305';
        $ceid = $empID.'Certificate of Employment';
        $cbc = $empID.'Children Birth Certificate';
        $itrid = $empID.'ITR';
        $mciid = $empID.'Marriage Certificate';
        $nbiid = $empID.'NBI Clearance';
        $nsoid = $empID.'NSO PSA Birth Certificate';
        $peid = $empID.'Pre Employement Medical Exam';
        $torid = $empID.'TOR DIPLOMA';
        $mdfid = $empID.'Updated MDF';
        $mdrid = $empID.'Updated MDR';
        $vid = $empID.'Valid ID';
  
       
   

       $docsql ="INSERT INTO `documents`(`docid`, `name`, `document`, `status`, `empid`) 
       VALUES ('$acid','Account Opening Form','none','none','$empID'),
       ('$birid','BIR 1905 and 2305','none','none','$empID'),
       ('$ceid','Certificate of Employment','none','none','$empID'),
       ('$cbc','Children Birth Certificate','none','none','$empID'),
       ('$itrid','ITR','none','none','$empID'),
       ('$mciid','Marriage Certificate','none','$docstat','$empID'),
       ('$nbiid','NBI Clearance','none','none','$empID'),
       ('$nsoid','NSO PSA Birth Certificate','none','none','$empID'),
       ('$peid','Pre Employement Medical Exam','none','none','$empID'),
       ('$torid','TOR DIPLOMA','none','none','$empID'),
       ('$mdfid','Updated MDF','none','none','$empID'),
       ('$mdrid','Updated MDR','none','none','$empID'),
       ('$vid','Valid ID','none','none','$empID')

       
       
       ";
       
      
        /*
       $docsql="INSERT INTO `checklist`(`document`, `date`, `status`, `empid`)
      VALUES ('Account Opening Form','none','Not Submitted','$empID'),
       ('BIR 1905 and 2305','none','Not Submitted','$empID'),
       ('Certificate of Employment','none','Not Submitted','$empID'),
       ('Children Birth Certificate','none','Not Submitted','$empID'),
       ('ITR','none','Not Submitted','$empID'),
       ('Marriage Certificate','none','$docstat','$empID'),
       ('NBI Clearance','none','Not Submitted','$empID'),
       ('NSO/PSA Birth Certificate','none','Not Submitted','$empID'),
       ('Pre Employement Medical Exam','none','Not Submitted','$empID'),
       ('TOR/DIPLOMA','none','Not Submitted','$empID'),
       ('Updated MDF','none','Not Submitted','$empID'),
       ('Updated MDR','none','Not Submitted','$empID'),
       ('Valid ID','none','Not Submitted','$empID')";
        */
        
        if (mysqli_query($conn, $sql1) && mysqli_query($conn, $govsql) && mysqli_query($conn, $sql) && mysqli_query($conn, $sql2) && mysqli_query($conn, $sqlsal) && mysqli_query($conn, $docsql)) {
            
          $alert='<div class="alert alert-success" role="alert">
          Employee Successfully Added!
            </div>';
            header('location: employee.php');

            
        } 
        else {
            $error='<div class="alert alert-danger" role="alert">
            Theres Error Adding Employee
              '.mysqli_error($conn).'</div>';
            
        }
        

    }  
    


}





?>
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin | Add Employee</title>

    <!-- Bootstrap core CSS-->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Page level plugin CSS-->
    <link href="../vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

    <!-- Custom styles for this template-->
        <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link rel="icon" href="../images/logo.jpg" type="image/gif" sizes="16x16">

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="../js/jquery-1.7.2.js"></script>
    <script src="../js/jquery.masked-input.js"></script>

    

    <script>
        function checkb() {
                   
             
                    if (document.getElementById("cb").checked == true) {
                        document.getElementById("dtext").disabled = false;
                    } else {
                        document.getElementById("dtext").disabled = true;
                    }
            
        }
       
        function csdiv(){
        
            var cs = document.getElementById("civilstat").value;
            if(cs == 'Married' || cs == 'Widowed' || cs == 'Divorced'){
                document.getElementById("civilstatbox").style.display ="block";
            }
            else if(cs == 'Single'){
               
                document.getElementById("civilstatbox").style.display ="none";
        }

        }

        function preview_image(event) 
        {
        var reader = new FileReader();
        reader.onload = function()
        {
        var output = document.getElementById('output_image');
        output.src = reader.result;
        }
        reader.readAsDataURL(event.target.files[0]);
        }

                
        function computedate(){
            //thirdmonth 
        var hdate = document.getElementById("hireddate").value;
        var tdate = new Date(hdate);
        tdate.setMonth(tdate.getMonth()+3,tdate.getDate()+1);
        var tdate1 = tdate.toLocaleDateString("en-US");
        document.getElementById("thirdmonth").value = tdate1;
        document.getElementById("hdate").value = hdate;
        //5th month

        var fdate = new Date(hdate);
        fdate.setMonth(fdate.getMonth()+5,fdate.getDate()+1);
        var fdate1 = fdate.toLocaleDateString("en-US");
        document.getElementById("fifthmonth").value = fdate1;


       

        } 
        function computeage(){
            var bday = document.getElementById("bday").value;
            var getbday = new Date(bday);
            var today = new Date();
            var age = today.getFullYear() - getbday.getFullYear();
            var  m = today.getMonth() - getbday.getMonth();
            document.getElementById("age").value = age;

            

        }

        function preview_image(event) 
        {
        var reader = new FileReader();
        reader.onload = function()
        {
        var output = document.getElementById('output_image');
        output.src = reader.result;
        }
        reader.readAsDataURL(event.target.files[0]);
        }
        
        
    </script>
    <style>
    .form-group.required .control-label:after {
    content:"*";
    color:#dc3545;
    font-weight: bold;
  }
    </style>

  </head>

   <body id="page-top">
	<div id="preloader">
   		<img src="../images/loaderS.gif" alt="processing..." height="150px" width="200px"/>
	</div>

  <div id="pageloader">
   <img src="../images/loaderS.gif" alt="processing..." height="150px" width="200px"/>
</div>

<div id="preloader">
   <img src="../images/loaderS.gif" alt="processing..." height="150px" width="200px"/>
</div>

      <?php include('uppernav.php')?>

    <div id="wrapper">

      <!-- Sidebar -->
      
      <?php 
      $employee = 'active';
      $addemp = "active";
      include('sidebar.php');
      $dashboard="active"; ?>
      <div id="content-wrapper">

        <div class="container-fluid">
            <form method="post" enctype="multipart/form-data">  

            <!-- Breadcrumbs-->
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                    <a href="employee.php">Employee</a>
                    </li>
                    <li class="breadcrumb-item active">Add Employee</li>
                </ol>
                <div class="col-sm-12 form-group ">
                <?php echo $error.$alert?>
                    <h4>Employee Information</h4>
                </div>
                <div class="row justify-content-lg-center"  >
                    <img id="output_image" style="height: 150px; width: 150px; border-radius:100px;" src="../images/profile.png" alt="hello"/> 
                </div>
                <div class="row justify-content-lg-center">
                    

                    <label class="btn btn-primary btn-sm"> <i class="fa fa-upload"></i>  Upload Profile Picture
                    <input type="file" name="userpic" style="display: none;" onchange="preview_image(event)"  accept="image/*" alt="PROFILE PICTURE" />
                    </label>
                </div>
                <div class="row justify-content-lg-center">
                    
                        <div style="margin:0 auto;" class="form-inline">
                            
                            <input type="checkbox" id="cb" name="cb" onclick="checkb()"> &nbsp &nbsp
                            <input type="text" id="dtext" name="empid" class="form-control" value="<?php echo $empID;?>" data-masked-input="ATV99-9999999999999" placeholder="Employee ID" disabled/>

                        </div>
                       
                       
                </div>

                    <div class="row p-3" >
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Surname </label> <br>
                            <input type="text" class="form-control" name="sname"  placeholder="Surname" value="<?php echo $surname?>" required >
                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">First Name </label> <br>
                            <input type="text" class="form-control" name="fname"  placeholder="First Name" value="<?php echo $firstname?>" required>
                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Middle Name </label> <br>
                            <input type="text" class="form-control" name="mname"  placeholder="Middle Name" value="<?php echo $middlename?>" required>
                        </div>
                
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Permanent Address </label> <br>
                            <input type="text" class="form-control" name="permanentadd"  placeholder="Permanent Address" value="<?php echo $permanentadd?>" required>
                        </div>
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Residential Address </label> <br>
                            <input type="text" class="form-control" name="residentialadd"  placeholder="Residential Address" value="<?php echo $residentialadd?>" required>
                        </div>

                        
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Birthdate </label> <br>
                            <input type="date" id="bday" onchange="computeage()" class="form-control" name="bday"  placeholder="Birthdate" value="<?php echo $bday?>" required >
                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Age </label> <br>
                            <input type="number" id="age" class="form-control" name="empage"  placeholder="Age" value="<?php echo $empage?>" readonly>
                        </div>

                            
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Gender</label> <br>
                            <select name="gender" class="form-control" required>
                             <?php 
                             switch($gender){
                                 case 'Male': 
                                 $male = 'selected';
                                 break;
                                 case 'Female':
                                 $female = 'selected';
                                 break;
                             }
                             ?>
                                <option value="" selected disabled> Gender </option>
                                <option value="Male" <?php echo $male?>> Male </option>
                                <option value="Female" <?php echo $female?>>Female </option>
                            
                            </select>
                        </div>

                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Contact Number </label> <br>
                            <input type="number" class="form-control" name="contactno"  placeholder="Contact No." value="<?php echo $contactno?>" required>
                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">Personal Email </label> <br>
                            <input type="email" class="form-control" name="email"  placeholder="Personal Email" value="<?php echo $email?>" required>
                        </div>

                        <div class="col-sm-4 form-group required">
                        <label  class="control-label">Civil Status </label> <br>
                            <select name="civilstat" id="civilstat" class="form-control" onchange=csdiv() required>
                            <?php 
                             switch($civilstat){
                                 case 'Single': 
                                 $single = 'selected';
                                 break;
                                 case 'Married':
                                 $married = 'selected';
                                 break;
                                 case 'Widowed':
                                 $widowed = 'selected';
                                 break;
                                 case 'Divorced':
                                 $divorced = 'selected';
                                 break;

                             }
                             ?> <option value="" selected disabled> Civil Status </option>
                                <option value="Single" <?php echo $single?>> Single </option>
                                <option value="Married" <?php echo $married?>> Married </option>
                                <option value="Widowed" <?php echo $widowed?>> Widowed </option>
                                <option value="Divorced" <?php echo $divorced?>> Divorced </option>
                            </select>
                        </div>
                        <div id="civilstatbox" style="width:98%; margin: 0 auto; display:none;">
                            <div class="row">
                                <div class="col-sm-6">
                                    <label class="control-label">Spouse's Name </label> <br>
                                    <input type="text" class="form-control" name="spouse"  placeholder="Spouse Name"  value="<?php echo $spouse?>">
                                    </div>
                                    <div class="col-sm-6">
                                    <label class="control-label">Date of Birth</label> <br>
                                    <input type="date" class="form-control" name="spousebday"  placeholder="Spouse Birthdate" value="<?php echo $spousebday?>" >
                                </div>
                            </div>
                        </div>
                        
                    


                        
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Mother's Maiden Name </label> <br>
                            <input type="text" class="form-control" name="mothersname"  placeholder="Mother's Maiden Name"  value="<?php echo $mothersname?>" required>
                        </div>

                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Occupation </label> <br>
                            <input type="text" class="form-control" name="motheroccu"  placeholder="Occupation" value="<?php echo $motheroccu?>" required>
                        </div>

                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Father's Name </label> <br>
                            <input type="text" class="form-control" name="fathersname"  placeholder="Father's Name" value="<?php echo $fathersname?>" required>
                        </div>
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Occupation </label> <br>
                            <input type="text" class="form-control" name="fatheroccu"  placeholder="Occupation" value="<?php echo $fatheroccu?>" required>
                        </div>

                        <div class="col-sm-12 form-group required">
                            <h5> <b> EMERGENCY CONTACT </b></h5>
                        </div>
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Name</label> <br>
                            <input type="text" class="form-control" name="ename"  placeholder="Name" value="<?php echo $ename?>"required>
                        </div>
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Relationship </label> <br>
                            <input type="text" class="form-control" name="erelationship"  placeholder="Relationship" value="<?php echo $erelatioship?>" required>
                        </div>

                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Complete Address</label> <br>
                            <input type="text" class="form-control" name="eaddress"  placeholder="Address" value="<?php echo $eaddress?>"required>
                        </div>
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Contact Number</label> <br>
                            <input type="number" class="form-control" name="econtact"  maxlength="12" placeholder="Contact Number" value="<?php echo $contactno?>"  required>
                        </div>
                        <div class="col-sm-12 form-group required">
                            <h5> <b> EMPLOYEE DETAILS</b></h5>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Hired Date</label> <br>
                        <input type="date" id="hireddate" onchange = computedate() class="form-control" name="hireddate"  placeholder="Hired Date" value="<?php echo $hireddate?>" required>

                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">3rd Month</label> <br>
                            <input type="text" id="thirdmonth"  class="form-control" name="thirdmonth"  placeholder="3rd Month" value="<?php echo $thirdmonth?>" readonly>
                        </div>
                        <div class="col-sm-4 form-group required">
                            <label class="control-label">5th Month</label> <br>
                            <input type="text" id="fifthmonth" class="form-control" name="fifthmonth"  placeholder="5th Month" value="<?php echo $fifthmonth?>" readonly>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Tenure </label> <br>
                                        <select name="tenure" class="form-control" required>
                                            <?php switch ($tenure) {
                                                    case "Regular":
                                                        $regular = 'selected';
                                                        break;
                                                    case "Probationary":
                                                        $prob = 'selected';
                                                        break;
                                                        case "Intern":
                                                        $int= 'selected';
                                                        break;
                                                        case "Casual":
                                                        $cas = 'selected';
                                                        break;
                                                
                                                }

                                            ?>
                                            <option value="" disabled selected>Tenure</option>
                                            <option value="Regular" <?php echo $regular?>>Regular</option>
                                            <option value="Probationary" <?php echo $prob?>>Probationary </option>
                                            <option value="Intern" <?php echo $int?>>Intern </option>
                                            <option value="Casual" <?php echo $cas?>>Casual </option>
                                        
                                        </select>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Level </label> <br>
                            <select name="level" class="form-control" required>
                                <?php switch ($level) {
                                    case "Executive":
                                    $exe= 'selected';
                                    break;
                                    case "Supervisor":
                                    $super = 'selected';
                                    break;
                                    case "Rank and File":
                                    $rf = 'selected';
                                     break;
                                        
                                            
                                }

                                    ?>
                            <option value="" disabled selected>Level</option>
                            <option value="Executive" <?php echo $exe?>>Executive</option>
                            <option value="Supervisor" <?php echo $super?>>Supervisor</option>
                            <option value="Rank and File" <?php echo $rf?>>Rank and File</option>
                                        
                             </select>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Department </label> <br>
                            <select name="department" class="form-control" required>
                                <?php switch ($department) {
                                    case "Operation":
                                    $op= 'selected';
                                    break;
                                    case "Support":
                                    $sup= 'selected';
                                    break;
                                } ?>
                                <option value="" disabled selected>Department</option>
                                <option value="Operation"<?php echo $op?>>Operation</option>
                                <option value="Support"<?php echo $sup ?>>Support</option>
                                
                            </select>
                    
                            </select>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Team</label> <br>
                            <?php 
                                        $query = "SELECT * FROM team";                                                
                                        $result = mysqli_query ($conn,$query); 
                                        echo "<select name='team'  class='form-control'>"; 
                                        echo "<option value='' disabled selected> Team </option>";
                                        while($r = mysqli_fetch_array($result)) {
                                            if($team==$r['name']){
                                                echo "<option value='".$r['name']."' selected='selected'>".$r['name']."</option>";
                                         
                                            }
                                           else{
                                            echo "<option value='".$r['name']."' >".$r['name']."</option>";
                                           }
                                            
                                        }
                                        echo "</select>"; ?>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">General Position </label> <br>
                        <?php 
                                        $query = "SELECT * FROM generalpos";                                                
                                        $result = mysqli_query ($conn,$query); 
                                        echo "<select name='genpos'  class='form-control'>"; 
                                        echo "<option value='' disabled selected> General Position </option>";
                                        while($r = mysqli_fetch_array($result)) {
                                            if($genpos==$r['name']){
                                                echo "<option value='".$r['name']."' selected='selected'>".$r['name']."</option>";
                                         
                                            }
                                           else{
                                            echo "<option value='".$r['name']."' >".$r['name']."</option>";
                                           }
                                            
                                        }
                                        echo "</select>"; ?>
                        </div>
                        <div class="col-sm-4 form-group required">
                        <label class="control-label">Job Title</label> <br>
                        <?php 
                                        $query = "SELECT * FROM jobtitle";                                                
                                        $result = mysqli_query ($conn,$query); 
                                        echo "<select name='jobtitle'  class='form-control'>"; 
                                        echo "<option value='' disabled selected> Job Title </option>";
                                        while($r = mysqli_fetch_array($result)) {
                                            if($jobtitle==$r['name']){
                                                echo "<option value='".$r['name']."' selected='selected'>".$r['name']."</option>";
                                         
                                            }
                                           else{
                                            echo "<option value='".$r['name']."' >".$r['name']."</option>";
                                           }
                                            
                                        }
                                        echo "</select>"; ?>
                          
                        </div>

                        
                        <div class="col-sm-6 form-group required">
                            <label class="control-label">Immediate Supervisor</label> <br>
                           
                                        <?php 
                                        $query = "SELECT * FROM supervisor";                                                
                                        $result = mysqli_query ($conn,$query); 
                                        echo "<select name='supervisor'  class='form-control'>
                                        <option value='' selected disabled> Immediate Supervisor </option>
                                        "; 
                                        while($r = mysqli_fetch_array($result)) {
                                            if($supervisor==$r['supervisors']){
                                                echo "<option value='".$r['supervisors']."' selected='selected'>".$r['supervisors']."</option>";
                                         
                                            }
                                           else{
                                            echo "<option value='".$r['supervisors']."' >".$r['supervisors']."</option>";
                                           }
                                            
                                        }
                                        echo "</select>"; ?>
                          
                            
                        </div>
                        <div class="col-sm-3 form-group required">
                        <label class="control-label">Status</label> <br>
                                    <select name="status" class="form-control" required >
                                        <?php switch ($status) {
                                                case "Active":
                                                $act= 'selected';
                                                    break;
                                                case "Inactive":
                                                $iact= 'selected';
                                                        break; }
                                                    ?>
                                                    <option value="" selected disabled> Status </option>
                                                <option value="Active" <?php echo $act?>>Active</option>
                                                <option value="Inactive" <?php echo $iact?>>Inactive</option>
                                        
                                    </select>

                        </div>
                        <div class="col-sm-3 form-group required">
                        <label class="control-label">Date</label> <br>
                        <input type="date" id="hdate" class="form-control" name="hireddate"  placeholder="Hired Date" value="<?php echo $hireddate?>" required readonly>

                        </div>
                        <div class="col-sm-6 form-group required">
                        <label class="control-label">Salary Code</label> <br>
                            <?php 
                                        $query = "SELECT * FROM salarypackage";                                                
                                        $result = mysqli_query ($conn,$query); 
                                        echo "<select name='salarycode' value='' class='form-control'>
                                        <option value='' selected disabled> Salary Code </option>
                                        "; 
                                        while($r = mysqli_fetch_array($result)) {
                                            if($salarycode==$r['salarycode']){
                                                echo "<option value='".$r['salarycode']."' selected='selected'>".$r['salarycode']."</option>";
                                         
                                            }
                                           else{
                                            echo "<option value='".$r['salarycode']."' >".$r['salarycode']."</option>";
                                           }
                                            
                                        }
                                        echo "</select>"; ?>
                        </div>
                        <div class="col-sm-6 form-group required">
                        <label class="control-label">Effectivity Date</label> <br>
                        <input type="date" id="effectdate" class="form-control" name="effectdate"  placeholder="Hired Date"  value="<?php echo $effectdate?>"  required >
                        </div>
                        <div class="col-sm-12 form-group required">
                            <div class="row justify-content-end">
                                
                                
                                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#createemp"><i class="fa fa-check"></i> Submit </button> &nbsp
                                <button type="reset" class="btn btn-primary" value="Reset" style="margin-right: 5px;"><i class="fa fa-refresh"></i> Reset </button> 
                                <a href="employee.php" class="btn btn-danger" role="button" style="margin-right: 5px;"> <i class="fa fa-close"></i> Cancel </a>
                            </div>
                        </div>

                        <!--MODAL MODAL MODAL-->
                        <div class="modal fade" id="createemp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered" role="document">
                                    <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Confirm Employee</h5>
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">Are you sure you want to submit employee registration<?php echo $firstname.' '.$surname?>?</div>
                                    <div class="modal-footer">
                                       <input type="submit" class="btn btn-success" name="createemp" value=" ✓ Yes" style="margin-right: 5px;" > 
                                        <button class="btn btn-danger" type="button" data-dismiss="modal"><i class="fa fa-close"></i> No</button>
                                        
                                    </div>
                                    </div>
                            </div>
                        </div>
                    </form>

        

                </div>
            

            </div>
        <script>
       // Date Validation for Date Effectivity effectdate.min = new Date().toISOString().split("T")[0];
        </script>
        

          

         

        <!-- Sticky Footer -->
          

        
      <!-- /.content-wrapper -->

    
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            <a class="btn btn-primary" href="login.html">Logout</a>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Page level plugin JavaScript-->
    <script src="../vendor/chart.js/Chart.min.js"></script>
    <script src="../vendor/datatables/jquery.dataTables.js"></script>
    <script src="../vendor/datatables/dataTables.bootstrap4.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin.min.js"></script>

    <!-- Demo scripts for this page-->
    <script src="../js/demo/datatables-demo.js"></script>
    <script src="../js/demo/chart-area-demo.js"></script>

          <script language="javascript" type="text/javascript">
            $(document).ready(function(){
            $("form").on("submit", function(){
                $("#pageloader").fadeIn();
            });//submit

             $('#preloader').fadeOut();
            });//document ready



        </script>
</body>

</html>
