<?php
include('../headertop.php');
include('../db.php');
include('../datepicker.php');

$disp = '';
$pagetitle = 'Edit Employee Information';

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

$id = $_GET['id'];

$q = "select * from employee where id='$id'";
$res = mysqli_query($dbcon,$q) or die(mysqli_error($dbcon));


if(mysqli_num_rows($res)<1)
{
$sm = "No employee found with this id. Try again";
echo '<meta http-equiv="refresh" content="0;URL=viewemployees.php?sm='.$sm.'">';
exit;
}

$row = mysqli_fetch_array($res);


if($row['photopath'])
{
$photo = '<a href="'.$row['photopath'].'" target=_blank><img src="'.$row['photopath'].'" style="width:100px;height:100px;"></a>';
}
else
$photo = 'No Photo uploaded';

if(isset($_REQUEST['sm']))
$disp .= '<div class="smdiv">'.$_REQUEST['sm'].'</div>';
else
$disp .= '<div class="smdiv">Let us begin</div>';

$disp .= '
<form method="post" action="editemployee2.php" id="editemployeeform" enctype="multipart/form-data">
<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Editing employee details 
                        </div>
						</div>
										
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <tbody>
                                        <tr><th>'.$photo.'</th><td> Change Picture: <br><input type="file" name="empphoto"></td></tr>
                                            <tr><th>Employee Name</th><td><input type="text" name="name"  data-validation="required" class="form-control" value="'.$row['name'].'"></td></tr>
                                            <tr><th>Father/Husband Name</th><td><input type="text" name="fname" data-validation="required" class="form-control" value="'.$row['fname'].'"></td></tr>
											<tr><th>Qualification</th><td><input type="text" name="qualification" data-validation="required" class="form-control" value="'.$row['qualification'].'"></td></tr>
											<tr><th>Mobile</th><td><input type="text" name="mobile"  data-validation="required number" class="form-control" value="'.$row['mobile'].'"></td></tr>
											<tr><th>Address</th><td><textarea name="address" data-validation="required" class="form-control">'.$row['address'].'</textarea></td></tr>
											<tr><th>Date of Joining</th><td><input type="text" name="doj"  data-validation="required" class="form-control" id="datep1" readonly value="'.$row['doj'].'"></td></tr>
											<tr><th>Salary</th><td><input type="text" name="salary" data-validation="required" class="form-control" value="'.$row['salary'].'"></td></tr>
											
                                    </tbody>
                                    
									</table>
									<input type="hidden" name="id" value="'.$row['id'].'">
									<button type="submit" class="btn btn-primary" name="editemployeesubmit"  style="margin-top:25px">Submit Button</button>
									
									</form>
                            </div>
                            
                        </div>
                    </div>
					</div>
									';
									

									   
									   include('../template.php');
									   include('../header.php');
									   ?>
									   
                                            <script>
$.validate({
  form : '#editemployeeform'
});
</script>
