<?php 
set_time_limit(10000);
include('../dbconnect.php');
include('../phps.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 ORDER BY empid DESC LIMIT 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);


$curyear = date('y');

$rowcount=mysqli_num_rows($result);

$row['empid'];

 $rowcount = substr($row['empid'], 6);


$count = $rowcount + 1;

$strlength = strlen($count);


if($strlength <= 2){
  $ATVID = str_pad($count, 3, '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 = phps($_POST['sname']);
$firstname = phps($_POST['fname']);
$middlename = phps($_POST['mname']);
$permanentadd = phps($_POST['permanentadd']);
$residentialadd = phps($_POST['residentialadd']);
$bday = phps($_POST['bday']);
$empage = phps($_POST['empage']);
$gender = phps($_POST['gender']);
$contactno = phps($_POST['contactno']);
$email = phps($_POST['email']);
$civilstat = phps($_POST['civilstat']);

$spouse = phps($_POST['spouse']);
$spousebday = phps($_POST['spousebday']);


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

$hireddate = phps($_POST['hireddate']);
$thirdmonth = phps($_POST['thirdmonth']);
$fifthmonth = phps($_POST['fifthmonth']);

$tenure = phps($_POST['tenure']);
$level = phps($_POST['level']);
$department = phps($_POST['department']);
$team = phps($_POST['team']);
$team = str_replace("&amp;","&",$team);
$genpos = phps($_POST['genpos']);
$jobtitle = phps( $_POST['jobtitle']);
$supervisor = phps($_POST['supervisor']);
$salarycode = phps($_POST['salarycode']);
$effectdate = phps($_POST['effectdate']);

//MYSQLI ESCAPE STRING

$surname = phps($_POST['sname']);
$surname = mysqli_real_escape_string($conn, $surname);


$firstname = mysqli_real_escape_string($conn, $firstname);  
$middlename = mysqli_real_escape_string($conn, $middlename);   
$permanentadd = mysqli_real_escape_string($conn, $permanentadd);  
$residentialadd = mysqli_real_escape_string($conn, $residentialadd);  
$bday = mysqli_real_escape_string($conn, $bday); 
$empage = mysqli_real_escape_string($conn, $empage);  
$gender = mysqli_real_escape_string($conn, $gender);  
$contactno = mysqli_real_escape_string($conn, $contactno); 
$email = mysqli_real_escape_string($conn, $email);  
$civilstat = mysqli_real_escape_string($conn, $civilstat);   

$spouse = mysqli_real_escape_string($conn, $spouse);   
$spousebday = mysqli_real_escape_string($conn, $spousebday);   


$mothersname = mysqli_real_escape_string($conn, $mothersname);  
$motheroccu = mysqli_real_escape_string($conn, $motheroccu);  
$fathersname = mysqli_real_escape_string($conn, $fathersname);   
$fatheroccu = mysqli_real_escape_string($conn, $fatheroccu);  
$ename = mysqli_real_escape_string($conn, $ename); 
$erelatioship = mysqli_real_escape_string($conn, $erelatioship);
$eaddress = mysqli_real_escape_string($conn, $eaddress);   
$econtactno = mysqli_real_escape_string($conn, $econtactno);   

$hireddate = mysqli_real_escape_string($conn, $hireddate);   
$thirdmonth = mysqli_real_escape_string($conn, $thirdmonth);  
$fifthmonth = mysqli_real_escape_string($conn, $fifthmonth);   

$tenure = mysqli_real_escape_string($conn, $tenure); 
$level = mysqli_real_escape_string($conn, $level);   
$department = mysqli_real_escape_string($conn, $department);  
$team = mysqli_real_escape_string($conn, $team);  
$genpos = mysqli_real_escape_string($conn, $genpos);  
$jobtitle = mysqli_real_escape_string($conn, $jobtitle);
$supervisor = mysqli_real_escape_string($conn, $supervisor);   
$salarycode = mysqli_real_escape_string($conn, $salarycode);   
$effectdate = mysqli_real_escape_string($conn, $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'";
    $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 = '
      ';
      $alerts ='<div class="alert alert-warning">
      Employee Name already exist.
   </div>
   ';
      $nameexisted ="yes";
    
    }
    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");

    $years = date('Y');

    $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`,`f_password`,`upassword`)
          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','$empID','1111')";
        //Employee details
        $sql2 = "INSERT INTO `empdetails`(`detailid`, `hireddate`, `thirdmonth`, `fourthmonth`, `tenure`, `level`, `department`, `team`, `generalpos`, `jobtitle`, `supervisor`,`status`,`date`,`inactivedate`,`empid`) 
        VALUES ('$empID','$hireddate','$formatt','$formatd','$tenure','$level','$department','$team','$genpos','$jobtitle','$supervisor','Active','$hireddate','0000-00-00','$empID')";

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


        $positionhistory = "INSERT INTO `positionhistory`( `position`, `date`, `empid`) VALUES ('$genpos','$hireddate','$empID')";

       
       
    

        $today = date('Y-m-d');

        $getday = strtotime($hireddate);
        $today = strtotime($today);

        $ygetday = date('Y', $hireddate);
        $ytoday = date('Y', $today);

        $mgetday = date('m', $hireddate);
        $mtoday = date('m', $today);

        $dgetday = date('d', $hireddate);
        $dtoday = date('d', $today); 

  




         $diff = (($ytoday - $ygetday) * 12) + ($mtoday - $mgetday);
        $curyear = date('Y');
        $hiredday = date('d', strtotime($hireddate));

        $yearupdate = $curyear.'-'.$mgetday.'-'.$hiredday;

        $yearupdate = $curyear.'-01-'.'01';

       
        //EMPLOYEE PTO 
        if($gender == 'Female'){

            $ptosql = "INSERT INTO `pto`(`name`,`maxpto`, `multiplier`, `updatestat`, `ptoearned`, `usedpto`, `availablepto`, `empid`, `yearupdate`) VALUES
            ('Paid Time Off','20','1.67','0','0','0','0','$empID','$yearupdate'),
            ('Bereavement','','','','5','','5','$empID','$yearupdate'),
            ('VAWC','','','','10','','10','$empID','$yearupdate'),
            ('Magna Carta','','','','60','','60','$empID','$yearupdate'),
            ('Maternity','','','','60','','60','$empID','$yearupdate'),
            ('Paternity','','','','7','','7','$empID','$yearupdate'),
            ('Solo Parent','','','','0','','0','$empID','$yearupdate'),
            ('Maternity Allocation','','','','0','','0','$empID','$yearupdate')
   
   
            ";


        }else{

            $ptosql = "INSERT INTO `pto`(`name`,`maxpto`, `multiplier`, `updatestat`, `ptoearned`, `usedpto`, `availablepto`, `empid`, `yearupdate`) VALUES
            ('Paid Time Off','20','1.67','0','0','0','0','$empID','$yearupdate'),
            ('Bereavement','','','','5','','5','$empID','$yearupdate'),
            ('Paternity','','','','7','','7','$empID','$yearupdate'),
            ('Solo Parent','','','','0','','0','$empID','$yearupdate'),
            ('Maternity Allocation','','','','0','','0','$empID','$yearupdate')
   
   
            ";


        }


        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) && mysqli_query($conn, $ptosql) && mysqli_query($conn, $positionhistory)) {
            
           
          $alert='<div class="alert alert-success" role="alert">Employee Successfully Added!</div>';

           

            $startdate = date('W', strtotime($hireddate));



            $weeksql = "SELECT week FROM schedule WHERE team='$team' AND week >= $startdate GROUP BY week ORDER BY week DESC LIMIT 1";

            //echo $weeksql.'<br>';

           
            $result = mysqli_query($conn, $weeksql);
            $rowcount = mysqli_num_rows($result);
            $wr = mysqli_fetch_assoc($result);
            $enddate = $wr['week'];

         
            //echo $hireddate;


            for($startdate; $startdate<=$enddate; $startdate++){

                $getsched = "SELECT * FROM schedule WHERE team='$team' AND indi='Original' AND week='$startdate' AND year='$years' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                $schedres = mysqli_query($conn, $getsched);

              // echo $getsched.'<br>';

             // echo $conn->error.'<br>';
            
            
    
    
                while($schedrow = mysqli_fetch_array($schedres)){
                
                   $insertsched = "INSERT INTO `schedule`(`schedcode`, `week`, `day`,`date`,`month`,`year`,`starttime`, `endtime`,`pststarttime`, `pstendtime`,`team`, `empid`, `indi`) 
                   VALUES 
            
                   ('$empID$schedrow[3]', '$startdate', '$schedrow[2]',  '$schedrow[3]', '$schedrow[4]','$schedrow[5]', '$schedrow[6]', '$schedrow[7]','$schedrow[8]','$schedrow[9]','$team','$empID', '0')
    
                   ";
                  //echo $insertsched.'<br>';

           
            
                       if (mysqli_query($conn, $insertsched)) {
                           //echo "New record created successfully";
                       } else {
                           echo $conn->error.'<BR>';
                          // echo "Error: " . $insertsched . "<br>" . mysqli_error($conn);
                       }
    
                }
            }
            
            

            header("location: addemp.php?alert=$alert");


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

    }
    else if($nameexisted == "yes"){

      $showmodal = "<script> $('#nameexist').modal('show');</script>";






    }  
    


}

if(isset($_POST['createexisted'])){
    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");

    $years = date('Y');

    $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`,`inactivedate`,`empid`) 
        VALUES ('$empID','$hireddate','$formatt','$formatd','$tenure','$level','$department','$team','$genpos','$jobtitle','$supervisor','Active','$hireddate','0000-00-00','$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, $docsql) && mysqli_query($conn, $sqlsal)) {
            
           
          $alert='<div class="alert alert-success" role="alert">Employee Successfully Added!</div>';

            header("location: addemp.php?alert=$alert");

            $startdate = ltrim( date('W', strtotime($hireddate)),0);



            $weeksql = "SELECT week FROM schedule WHERE team='$team' AND week >= '$startdate' GROUP BY week ORDER BY week DESC LIMIT 1";
            $result = mysqli_query($conn, $weeksql);
            $rowcount = mysqli_num_rows($result);
            $wr = mysqli_fetch_assoc($result);
            $enddate = $wr['week'];

           // echo $startdate;
           // echo $hireddate;


            for($startdate; $startdate<=$enddate; $startdate++){

                $getsched = "SELECT * FROM schedule WHERE team='$team' AND indi='Original' AND week='$startdate' AND year='$years' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                $schedres = mysqli_query($conn, $getsched);
            
            
    
    
                while($schedrow = mysqli_fetch_array($schedres)){
            
                   $insertsched = "INSERT INTO `schedule`(`schedcode`, `week`, `day`,`date`,`month`,`year`,`starttime`, `endtime`, `team`, `empid`, `indi`) 
                   VALUES 
            
                   ('$empID$schedrow[2]$startdate$years', '$startdate', '$schedrow[2]',  '$schedrow[3]', '$schedrow[4]','$schedrow[5]', '$schedrow[6]', '$schedrow[7]','$team','$empID', '0')
    
                   ";
            
                       if (mysqli_query($conn, $insertsched)) {
                          // echo "New record created successfully";
                       } else {
                          // echo "Error: " . $insertsched . "<br>" . mysqli_error($conn);
                       }
    
                    }
            
                    }


            
        } 
        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>Super 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 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;

        document.getElementById("effectdate").value = hdate;




    }

    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();

        if (m < 0 || (m === 0 && today.getDate() < getbday.getDate())) {
            age--;
        }

        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>





    <?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. $_GET['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' required>"; 
                                        echo "<option value='' disabled selected> Team </option>";
                                        while($r = mysqli_fetch_array($result)) {
                                            if($_POST['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 readOnly>
                                <?php switch ($status) {
                                                case "Active":
                                                $act= 'selected';
                                                    break;
                                                case "Inactive":
                                                $iact= 'selected';
                                                        break; }
                                                    ?>

                                <option value="Active" selected>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='' id='salarycode' class='form-control' onchange='showdesc()'>
                                        <option value='' selected disabled> Salary Code </option>
                                        "; 
                                        while($r = mysqli_fetch_array($result)) {
                                            if($salarycode==$r['salarycode']){
                                                echo "<option value=".$r['description']." selected>".$r['salarycode']."</option>
                                                
                                                ";
                                         
                                            }
                                           else{
                                   
                                            echo "<option value='".$r['description']."' >".$r['salarycode']."</option>";
                                           }
                                       
                                           echo"";
                                            
                                        }
                                        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">
                            <p id="lbl"> </p>
                            <input type="text" name="salarycode" id="salcode" value="<?php echo $salarycode?>" hidden>
                        </div>
                        <script>
                        function showdesc() {
                            var salarycode = document.getElementById('salarycode');
                            var textHolder = salarycode.options[salarycode.selectedIndex].text

                            document.getElementById('lbl').innerHTML = salarycode.value;

                            document.getElementById("salcode").value = textHolder;





                        }
                        </script>


                        <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>
                                    <?php  echo $error ?>
                                    <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>

                        <div class="modal fade" id="nameexist" tabindex="-1" role="dialog"
                            aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered" role="document">
                                <div class="modal-content">

                                    <?php  echo $alerts ?>
                                    <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="createexisted" 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>
        <?php  mysqli_close($conn)?>

        <!-- 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>
        <?php echo $showmodal ?>


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

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

        <!-- <script> $('#nameexist').modal('show');</script>
     -->

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

            $('#preloader').fadeOut();
        }); //document ready
        </script>
</body>

</html>