<? include("si_confi.php"); ?>
<? include("ad_head.php"); ?>
  <div class="container">
  <? include("mn_option.php");
  date_default_timezone_set("Asia/Kolkata");
  ?>
<?
if(isset($_REQUEST['submit_emp']))
{
	 $username=$_REQUEST['username'];
	 $expl=explode(",",$username);
	
	 $emid=$expl[0];
	 $emname=$expl[1];
	
     $leavefor=$_REQUEST['leavefor'];
	 $fdate=$_REQUEST['fdate'];
	 $todate=$_REQUEST['todate'];
 
$datt=date("Y-m-d");
	 
$time1 = strtotime($fdate);
$time2 = strtotime($todate);
$diff=floor( ($time2-$time1) /(60*60*24))+1;

/*for($ii=0;$ii<$diff;$ii++)
{
	
	
	if($ii>=1)
	{
		  $datecc = strtotime("+1 day", strtotime($fdate123));
		  $fdate123 =  date("Y-m-d", $datecc);
	}
	else
	{
	  $fdate123= $fdate;
	}
	  
      $expldat=explode('-',$fdate123);
	  
	  $yr=$expldat[0];
	  $mn=$expldat[1];
	  $dt=$expldat[2];
	  
	  $cdt=$dt[0];
	  if($cdt==0)
	  {
		  $cdatt=$dt[1];
	  }
	  else
	  {
		 $cdatt=$expldat[2]; 
	  }
	  
      $mnth=date("F",mktime(0, 0, 0, $mn, 10));
	  $year=$yr;
	  
	  
	 
    $weekday = date('l', strtotime($fdate123));

    if($weekday!='Sunday')
	{
	  
	  $ckkqu=mysql_query("select * from emp_attendance where empid='$emid' and  month='$mnth' and year='$year'  ");
	  $chknum=mysql_num_rows($ckkqu);
	  
	  if($chknum==0)
	  {
	   $insf=mysql_query("insert into emp_attendance(`empid`,`emp_name`,`year`,`month`,`$cdatt`) values('$emid','$emname','$year','$mnth','1')");
	  }
	  else
	  {
		$insfup=mysql_query("update emp_attendance set `$cdatt`='1' where empid='$emid' and  month='$mnth' and year='$year' ");
	  }
	  
	}
	else
	{
		$mns=$mnus-1;
	}
}
*/

$diff=$diff-$mns;

$insert_employeee_details=mysql_query("insert into `leave` (`empid`,`name`,`leavefor`,`fdate`,`tdate`,`count`,`type`,`status`,`date`,`req`) values ('$emid','$emname','$leavefor','$fdate','$todate','$diff','1','1','$datt','1')");
	
?>
<script>window.location="ad_leave.php?ad=suc";</script>
<?
}
include("update.php");
?>

<? if($_REQUEST['ad']=='suc'){ ?>
  <div class="success" style="width:92%;margin:0 auto;margin-top:9px;">Work Allocation Details Added Successfully.</div><? } ?>
  <link type="text/css" href="calender/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="calender/jquery.min.js"></script>
<script type="text/javascript" src="calender/jquery.datepick.js"></script>
<script type="text/javascript">
$nocal=$.noConflict();
$nocal(function() {
	$nocal('#popupDatepicker').datepick();
	$nocal('#inlineDatepicker').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>
<script type="text/javascript">
$nocal(function() {
	$nocal('#popupDatepicker2').datepick();
	$nocal('#inlineDatepicker2').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>

   <div style="border:groove;margin-top:10px;border-width:thin;padding:20px;border-radius:4px;border-color:#cccccc;box-shadow: 10px 9px 90px #000;">
   <h2>Add Leave Details </h2>
   
 
  <form method="post" enctype="multipart/form-data" name="form" id="add_certi" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="validation.js"></script>
        <table cellpadding="9" id="add_certi">
        <tr>
        <td valign="top">Employee ID</td>
        <td>
        <select name="username" class="validate-selection" autofocus>
        
        <option value="" hidden="">Select</option>
        <? $seleect_employee=mysql_query("select * from `employee_mng`");
		while($fetch_employee=mysql_fetch_array($seleect_employee)){ ?>
        <option value="<? echo $fetch_employee['emp_id']; ?>,<? echo ucwords($fetch_employee['name']); ?>"><? echo ucwords($fetch_employee['name']); ?> - <? echo ucwords($fetch_employee['emp_id']); ?></option>
		<? } ?>
        </select>
        
        </td>  
        </tr>
         <tr>
        <td valign="top">Leave For</td>
        <td><textarea name="leavefor" class="required" style="width:350px;height:100px;"></textarea></td>
        </tr>
        <tr>
        <td valign="top">From Date</td>
        <td><input type="text" name="fdate" class="required" id="popupDatepicker" value="<? echo date("Y-m-d"); ?>"></td>
        </tr>
         <tr>
        <td valign="top">To Date</td>
        <td><input type="text" name="todate" class="required" id="popupDatepicker2" value="<? echo date("Y-m-d"); ?>"></td>
        </tr>
        
       <!-- <tr>
        <td valign="top">Time</td>
        <td><input type="text" name="time_allocation" value="<? echo date("g:i a"); ?>" readonly style="background:#CCC;" class="required"></td>
        </tr>-->
        <td valign="top">&nbsp;</td>
        <td><input type="submit" name="submit_emp" onClick="return confirm('Are you sure you want to confirm add Details ?');"></td>
        </tr>
        </table>
			
		</form>
         <script type="text/javascript">
						function formCallback(result, form) 
						{window.status = "valiation callback for form '" + form.id + "': result = " + result;}
						var valid = new Validation('add_certi', {immediate : true, onFormValidate : formCallback});
					</script>
  </div>
</div><!-- container -->
  </body>
</html>