<link href="../assets/css/fileuploadstyle.css" rel="stylesheet" />
<?php
include('../headertop.php');
include('../db.php');
//include('../datepicker.php');

$disp = '';
$pagetitle = 'Add New Employee';

if(!isset($_POST['addemployeesubmit']))
{
echo '<meta http-equiv="refresh" content="0;URL=addemployee.php">';
exit;
}

$name = $_POST['name'];
$fname = $_POST['fname'];
$qualification = $_POST['qualification'];
$doj = $_POST['doj'];
$salary = $_POST['salary'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];
$gender = $_POST['gender'];

if(empty($name) or empty($fname) or empty($qualification) or empty($doj) or empty($salary) or empty($mobile) or empty($address) or empty($gender))
{
$disp .= '<span class="errordiv">Please go back and fill all required fields</span>';
include('../template.php');
exit;
}

if(!is_numeric($salary))
{
$disp .= '<span class="errordiv">Salary should be numeric value only</span>';
include('../template.php');
exit;
}


$q = "insert into employee (name,fname,qualification,doj,salary,mobile,address,gender) values('$name','$fname','$qualification','$doj','$salary','$mobile','$address','$gender')";
mysqli_query($dbcon,$q) or die(mysqli_error($dbcon));
$eid = mysqli_insert_id($dbcon);

$sm = "Employee information saved ";



/*
$docsname = explode(".",$_FILES['docs']['name']);
foreach($docsname as $v)
$docsext = $v;
$docslocation = "empuploads/".$eid.".".$v;
*/

/*
if(!empty($_FILES['docs']['type']))
{
if($_FILES['docs']['type'] != 'application/zip')
{
$disp .= '<span class="error">Please upload zip files</span>';
include('template.php');
exit;
}


$docsname = $_FILES['docs']['name'];
if(mkdir("../empuploads/".$eid))
{
$docslocation = "../empuploads/".$eid."/".$docsname;
$temp = $_FILES['docs']['tmp_name'];

if(!move_uploaded_file($temp,$docslocation))
$sm .= 'but documents could not be uploaded';
else
$sm .= 'and documents uploaded';
}
else
$sm .= 'but documents have not been uploaded';
}//end of if for checking if documents were attached
*/

if(!empty($_FILES['empphoto']['type']))
{
if($_FILES['empphoto']['type'] != 'image/jpeg' and $_FILES['empphoto']['type'] != 'image/png')
{
$disp .= '<span class="error">Please upload only image files</span>';
include('../template.php');
exit;
}


$photoname = explode(".",$_FILES['empphoto']['name']);
foreach($photoname as $v)
$photoext = $v;

$photolocation = "../files/empphotos/".$eid.".".$photoext;
$temp = $_FILES['empphoto']['tmp_name'];


if(!move_uploaded_file($temp,$photolocation))
$sm .= ' but picture could not be uploaded';
else
{
$sm .= ' and picture uploaded';
$qupload = "update employee set photopath = '$photolocation' where id='$eid'";
//$qupload = "insert into photouploads (uid,name,fname,phone,path,user) values('$eid','$name','$fname','$mobile','$photolocation','employee')";
mysqli_query($dbcon,$qupload);
}

}//end of if to check if employee photo exists or not

 
echo '<meta http-equiv="refresh" content="0;URL=addemployee.php?sm='.$sm.'">';

