 
<?php  $table="holidays";
 
$table1="emp_leave";
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
 $status=true;
$rurl="index.php?route=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['holiday_title']=$_REQUEST['holiday_title'];
 $data['start_date']=FormatDateForSQL($_REQUEST['start_date']);
 $data['end_date']=FormatDateForSQL($_REQUEST['end_date']);
 $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['holiday_title']=$_REQUEST['holiday_title'];
 $data['start_date']=FormatDateForSQL($_REQUEST['start_date']);
 $data['end_date']=FormatDateForSQL($_REQUEST['end_date']);
 $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);
	$holiday_title=$RData['holiday_title'];		
	$start_date=ConvertSQLDate($RData['start_date']);
	$end_date=ConvertSQLDate($RData['end_date']);
	$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>
<p>&nbsp;</p>
<form action="" method="post">
<table border="0" cellpadding="3" cellspacing="3">
	<tr><td colspan="2"><h2>Holidays</h2></td></tr>
	
	
	 <?php if(isset($_REQUEST['daction']))
  {?>
    <tr>
  
    <td colspan="3" ><div class="success"><?php echo "Record ".$_REQUEST['daction']." Successfully";
	
	 //;

	 ?></div></td>
  </tr>
  <?php 
 
  }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="3" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
  
   <?php }?>
   
	
	 
    <tr><td>Title </td>
		<td>
         
       
        <input type="text"  name="holiday_title"  value="<?php echo $holiday_title; ?>"> 
        
</td>	
	</tr>
  
   <tr><td>Startdate </td>
   		<td><input type="text" name="start_date" class="datepicker" value="<?php  echo $start_date;?>"></td>
		
	</tr>   
 <tr><td>EndDate  </td>
		<td><input type="text" name="end_date"  class="datepicker"value="<?php  echo $end_date;?>"></td>	
	</tr>
     <tr><td>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
			 
	</tr>
    
		
	</tr>
   
    
  <tr>
		<td colspan="2">
		 <input name="Save" type="submit" value="save" />
	    </td></tr>
	
</table>
</form>


<table width="80%" border="0" cellspacing="1" cellpadding="2">
	<tr><td colspan="7"><div  align="right" ><a href="<?php echo $rurl; ?>">Add New</a></div></td></tr>
  <tr>
    <th scope="col"><span style="font-weight: bold">Sno.  </span></th>
      <th scope="col"><span style="font-weight: bold">Title </span></th>
	  <th scope="col"><span style="font-weight: bold">Start Date	  </span></th>
	  <th scope="col"><span style="font-weight: bold">End Date	  </span></th>
	 <!-- <th scope="col">AccountsType</th>-->
	    <th scope="col"><span style="font-weight: bold">Published</span></th>
     
      
  <th scope="col"><span style="font-weight: bold">Edit</span></th>
   <th scope="col"><span style="font-weight: bold">Delete</span></th>
  </tr>
 
  <tr>
    <?php 
    
 $GetRecord = "Select * from $table";	   
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='3'>--No Record--</td>";
   
   while($RowData = DB_fetch_array($ResultData))
   {?>
   <td><div align="center"><?php echo $i; ?></div></td>
    <td><?php
	echo $RowData['holiday_title'];
	  ?>	  </td>
	 <td><?php  
	   echo $RowData['start_date']
	 //echo $RowData['emp_designation']; ?>	  </td> 
	 <td><?php  echo $RowData['end_date']; ?>	  </td> 
    
     <td><?php  echo $RowData['published']; ?>	  </td> 
      
     <td> <div align="center">
     	<a href="<?php echo $rurl;?>&action=Edit&ID=<?php echo $RowData['id']; ?>">
     		<img src="images/icon-edit.png"  width="10" height="10"/></a></td>
	<td> <div align="center">
		<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="10" height="10" /></a></div> </td>
  </tr>
	<?php $i++;}   
   ?> 
</table>