 <?php  $table="holidays";
 
$table1="emp_leave";
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
 $status=true;
$rurl="index.php?route=HRModule/holidays&modid=".$modid."&frmid=".$frmid."";
if($_REQUEST['Save']){
 if(empty($_REQUEST['holiday_title']))
	{
 	   $msgErr[]='Please Enter Title';
	   $status=false;
	}	 

	 if(empty($_REQUEST['start_date']))
	{
 	   $msgErr[]='Please Enter Start Date';
	   $status=false;
	} 
	 if(empty($_REQUEST['end_date']))
	{
 	   $msgErr[]='Please Enter End Date';
	   $status=false;
	} 
	if(empty($_REQUEST['published']))
	{
 	   $msgErr[]='Please select Action';
	   $status=false;
	} 
}	
if($_REQUEST['Save']&& $_REQUEST['action']=='')
{
 $data['site']=$_REQUEST['site'];
 $data['emptype']=$_REQUEST['emptype'];

 $data['holiday_title']=$_REQUEST['holiday_title'];
 $data['start_date']=FormatDateForSQL($_REQUEST['start_date']);
 $data['end_date']=FormatDateForSQL($_REQUEST['end_date']);
 $data['halfday']=$_REQUEST['halfday'];
 $data['published']=$_REQUEST['published'];
 if($data['start_date']<date('Y-m-d'))
 {
 	$msgErr[]="Date can not be greater then current Date";
	 $status=false;	 
 }
 if($status)
 {
	  $insert=$s->RecordInsert($table, $data);
	  if(!$insert){
	  	die("can't insert record");		
	  }
		$s->pageLocation($rurl."&daction=Inserted"); 
 }		 
}

if($_REQUEST['Save']&& $_REQUEST['Edit']=='')
{
 $data['site']=$_REQUEST['site'];
 $data['emptype']=$_REQUEST['emptype'];
  $data['holiday_title']=$_REQUEST['holiday_title'];
 $data['start_date']=FormatDateForSQL($_REQUEST['start_date']);
 $data['end_date']=FormatDateForSQL($_REQUEST['end_date']);
 $data['halfday']=$_REQUEST['halfday'];
 $data['published']=$_REQUEST['published'];
 if($data['start_date']<date('Y-m-d'))
 {
 	$msgErr[]="You Can not update Previous Record";
	 $status=false;	 
 }
 if($status)
 {
  $cond="id='".$_REQUEST['ID']."'";
  $update=$s->RecordEdit($table, $data, $cond);
   if(!$update){
  	die("can't Update record");
  }
	$s->pageLocation($rurl."&daction=Updated"); 
 }	 
}

if($_REQUEST['action']=='Edit')
{
	$condition="id='".$_REQUEST['ID']."'";
	$query=$s->GetRecord($table,  $condition);	 
	$rowdata=DB_query($query,$db);
	$RData=DB_fetch_array($rowdata);
	$site=$RData['site'];			
	$emptype=$RData['emptype'];		
	$holiday_title=$RData['holiday_title'];		
	$start_date=ConvertSQLDate($RData['start_date']);
	$end_date=ConvertSQLDate($RData['end_date']);
	$halfday=$RData['halfday'];
	$published=$RData['published'];
}

//************************Delete*********************************************** 
if($_REQUEST['action']=='Del')
{
	$condition="id='".$_REQUEST['ID']."'";
	$s->DeleteRecord($table,$condition);	 
	 $s->pageLocation($rurl.'&daction=Deleted');
} 
 ?>
<script src="js/function-ajax.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Holidays Master</h1>
<form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
	 <?php if(isset($_REQUEST['daction']))
  {?>
    <tr>  
    <td colspan="6" align="center"><div class="success"><?php echo "Record ".$_REQUEST['daction']." Successfully";	
	 //;
	 ?></div></td>
  </tr>
<?php 
  }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>  
    <td colspan="6" align="center"><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
    <?php }?>
 <tr class="row1">
 	<td width="13%" align="right">Site</td>
	<td width="20%"><select name="site" >
      <option value="0">---Select---</option>
      <?php 
 	 $query1=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db); 
	while($result1=DB_fetch_array($query1))
	{
	?>
      <option value="<?php echo $result1['loccode'];?>" <?php  echo $result1['loccode']==$site?'selected':''; ?>><?php echo $result1['locationname'];?></option>
      <?php } ?>
    </select>
    </td>	
 	<td width="13%" align="right">Emp Type</td>
	<td width="20%">
        <select name="emptype" >
		<option value="0">---</option>
		<option value="worker" <?php  echo ('worker'==$emptype)?'selected':''; ?>>Worker</option>
		<option value="staff" <?php  echo ('staff'==$emptype)?'selected':''; ?>>Staff</option>
		<option value="doctor" <?php  echo ('doctor'==$emptype)?'selected':''; ?>>Doctor</option>
		</select>
    </td>
 	<td width="13%" align="right">Title</td>
	<td><input type="text"  name="holiday_title" value="<?php echo $holiday_title; ?>"></td>	
</tr>
<tr class="row1">
 	<td align="right">Start Date</td>
   	<td><input type="text" name="start_date"  class="datepicker" value="<?php  echo $start_date;?>"></td>
 	<td align="right">End Date</td>
	<td><input type="text" name="end_date"  class="datepicker"value="<?php  echo $end_date;?>"></td>
	<td></td>
	<td></td>	
</tr>
<tr class="row1">
 	<td align="right">Half Day</td>
   	<td><input type="radio" name="halfday" id="halfday" value="Y" <?php echo ($halfday=='Y'?'checked':'')?> />Active
			<input type="radio" name="halfday" id="halfday" value="N" <?php echo ($halfday=='N'?'checked':'')?> />InActive		
	</td>
 	<td align="right">Published</td>
	<td><?php //echo $published; ?>
			<input type="radio" name="published" value="Y" <?php echo ($published=='Y'?'checked':'')?> />Active
			<input type="radio" name="published" value="N" <?php echo ($published=='N'?'checked':'')?> />InActive
	</td>
	<td></td>
	<td></td>
</tr>   
<tr class="row1">
		<td style="text-align:center;" colspan="6">
                    <?php if($_REQUEST['action'] == 'Edit') {?>
		 <input name="Save" class="search" type="submit" value="Save" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>/>
                     <?php } else {?>
                 <input name="Save" class="search" type="submit" value="Save" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>/><?php } ?>
	    </td>
</tr>

</table>
</form>
<p align="left">
 <?php if($_SESSION['frmcreate']=='1'){?><a href="<?php echo $rurl; ?>"><input type="button" value="Add New" class="search" /></a><?php } ?>
 </p>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
 <tr>
	<th width="3%">S. No.</th>
	<th width="10%">Site</th>
	<th width="10%">Emp Type</th>
	<th>Title</th>
	<th width="7%">Start Date</th>
	<th width="7%">End Date</th>
	<!-- <th class="tabledata">AccountsType</th>-->
	<th width="4%">Half Day</th>
	<th width="4%">Published</th>
	<th width="4%" class="text-center">Edit</th>
	<th width="4%" class="text-center">Delete</th>
</tr>
<?php 
 $GetRecord = "Select * from $table";	   
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='10'>--No Record--</td>";
   
   while($RowData = DB_fetch_array($ResultData))
   {?>
  <tr>
   <td><?php echo $i; ?></td>
   <td><?php  echo $RowData['site']; ?></td> 
   <td><?php  echo $RowData['emptype']; ?></td> 
    <td><?php
	echo $RowData['holiday_title'];
	  ?></td>
	 <td><?php  
	   echo ConvertSQLDate($RowData['start_date']);
	 //echo $RowData['emp_designation']; ?>	  </td> 
	 <td><?php  echo ConvertSQLDate($RowData['end_date']); ?></td> 
     <td><?php  echo $RowData['halfday']; ?></td> 
     <td><?php  echo $RowData['published']; ?></td>       
     <td align="center">
     	<?php if($_SESSION['frmEdit']=='1'){?><a href="<?php echo $rurl;?>&action=Edit&ID=<?php echo $RowData['id']; ?>">
     		<img src="images/icon-edit.png"  width="13" height="13" title="Edit Document" /></a><?php }else{ ?><img src="images/icon-edit.png" width="13" height="13" style="opacity:0.6;" title="No Permission to Edit Document" /><?php } ?></td>
	<td align="center"><?php if($_SESSION['frmDelete']=='1'){?>
		<a href="<?php echo $rurl;?>&action=Del&ID=<?php echo $RowData['id']; ?>" onclick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="13" height="13" title="Delete Document" /></a><?php }else{ ?><img src="images/Icon_Delete.png" width="13" height="13" style="opacity:0.6;" title="No Permission to Delete Document" /><?php } ?></td>
  </tr>
	<?php $i++;}   
   ?> 
</table>
</div>
</div>