<?php
/*
    if($_REQUEST['act']=='del' && $_REQUEST[Id]!='')
    {
      DB_query("delete from hr_leave_opening where id='".$_REQUEST['Id']."'",$db);
    }
*/

    if($_REQUEST['Delete'])
{
   
  for($i=0;$i<count($_REQUEST['leadid']);$i++)
  {

    $condition="id='".$_REQUEST['leadid'][$i]."'";
    $s->DeleteRecord('hr_leave_opening', $condition);
    //$condition="id='".$_REQUEST['leadid'][$i]."'";
    //$s->DeleteRecord('spare_part_kits', $condition);
  }
  //$s->pageLocation("index.php?route=HRModule/holidays");
}
 ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<form method="post" action="" name="myform">
<h1><?php echo $s->GetFieldValue("modules_form","moduleid='".$_REQUEST['modid']."' and id='".$_REQUEST['frmid']."'","frm_name"); ?></h1>
<p align="left"><a href="index.php?route=HRModule/employee_opening&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" value="Employee Leave Opening" class="search" /></a>
<?php if($_SESSION['frmDelete']=='1'){?>&nbsp;<input type="submit" name="Delete" value="Delete" class="search" onClick="return confirm('Are you sure you want to delete this Item record?');" /><?php } ?>
</p>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
<tr>
 <th rowspan="2" width="2%"><input type="checkbox" id="selecctall"/></th>
 <th rowspan="2">Site</th>
 <th width="10%" rowspan="2">Employee Code</th>
 <th width="22%" rowspan="2">Employee Name</th>
 <th width="10%" rowspan="2">Leave Opening</th>
 <th width="10%" rowspan="2">Leave Opening Year</th>
 <th width="10%" rowspan="2">Leave Type</th>
 <th style="text-align:center;">Action</th>
</tr>
<tr>
  <th width="5%" style="text-align:center;">Edit</th>
  <!--<td width="5%" style="text-align:center;">Delete</td>-->
</tr>
<?php

    $openingYear='<select name="opening_year" >';
    for($t=date("Y");$t>=2000;$t--)
     {

$openingYear.='<option value='.$t.'>'.$t.'</option>';
     }
    $openingYear.='</select>';
$sql=DB_query("select * from hr_leave_opening order by empid ASC",$db);
while($row=DB_fetch_array($sql))
{
?>
<tr>
<td><input name="leadid[]" type="checkbox" class="checkbox1" id="leadid_<?php echo $i+1; ?>" value="<?php echo $row['id']?>" /></td>
<td><?php echo $s->getField('locations','loccode',$row['site'],'locationname'); ?></td>
<td><?php echo $s->getField('empmaster','id',$row['empid'],'emp_code');  ?></td>
<td><?php echo $s->getField('empmaster','id',$row['empid'],'emp_name');  ?></td>
<td><?php echo $row['opening']; ?></td>
<td><?php echo $row['opening_year']; ?></td>
<td><?php echo $s->getField('leavemaster','id',$row['leave_type'],'leavename'); ?></td>
<td style="text-align:center;"><img src="images/icon-edit.png" onclick="createForEdit('<?php echo $row['emp_id']; ?>',this);" style="cursor:pointer;" width="15" height="15" />
<span onclick="saveForEdit('<?php echo $row['id']; ?>',this);" style="color:green;display:none;cursor:pointer;">Save</span>
</td>
<!--<td style="text-align:center;"><?php if($_SESSION['frmDelete']=='1'){?><a href="index.php?route=HRModule/employee_opening_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $row['id'];?>&act=del" onclick="return confirm('This record will be deleted. Are you sure?')"><img src='images/Icon_Delete.png' width="15" height="15" title="Delete Document" /></a><?php }else{ ?><img src='images/Icon_Delete.png' width="15" height="15" title="No Permission to Delete Document" style="opacity:0.5;" /><?php } ?></td>
--></tr>
<?php } ?>
</table>
</form>
</div>
</div>



<style type="text/css" >
.button{ background-color:#666666;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #359CA2;
}
.link{ color:#9900CC; font-family:"Comic Sans MS"; letter-spacing:1px
}
</style>

<script type="text/javascript">
  function createForEdit(empid,obj)
  {//ajax_emp_loan_edit
  	 $(obj).hide();
  	 $(obj).next().show();
  	var opening=$(obj).closest('tr').find('td:eq(4)').html();
  	var openingYear=$(obj).closest('tr').find('td:eq(5)').html();
  
  	$(obj).closest('tr').find('td:eq(4)').html('<input type="text" value="'+opening+'" />');

  	$(obj).closest('tr').find('td:eq(5)').html('<?php echo $openingYear; ?>');
  	  $(obj).closest('tr').find('td:eq(5)').find('select').val(openingYear);
  	
  }

  function saveForEdit(empId,obj)
  {
  	$(obj).hide();
  	 $(obj).prev().show();
    var currOpening=$(obj).closest('tr').find('td:eq(4)').find('input[type="text"]').val();
    var CurrOpeningYear=$(obj).closest('tr').find('td:eq(5)').find('select').val();  
     $(obj).closest('tr').find('td:eq(4)').html(currOpening);
     $(obj).closest('tr').find('td:eq(5)').html(CurrOpeningYear);
   

     $.ajax({
            url : "ajax_emp_leave_open_edit.php",
            type : "POST",
            data : {             
            emp_id:empId,
            opening:currOpening,
            forYear:CurrOpeningYear
         
            },
            success : function(data) {
            	//alert(data);
              
            alert('You have update record successfully !'); 
 
                          }
          });


  }

  function LeadData()
{ 
  myCheckboxArray = document.myform.elements["leadid[]"];
  var t=myCheckboxArray.length;
  //alert(myCheckboxArray);
  if(document.getElementById('leadid').checked==true)
  { 
  if(t==undefined)
  document.getElementById('leadid_'+1).checked=true;    
  for (var i = 1; i <= t; i++)
  {
  document.getElementById('leadid_'+i).checked=true;  
  } 
  }
  else
  {
  if(t==undefined)    
  document.getElementById('leadid_'+1).checked=false;   
  for (var i = 1; i <= t; i++)
  {
  document.getElementById('leadid_'+i).checked=false; 
  }
  }
}
$(document).ready(function() {
    $('#selecctall').click(function(event) {  //on click
        if(this.checked) { // check select status
            $('.checkbox1').each(function() { //loop through each checkbox
                this.checked = true;  //select all checkboxes with class "checkbox1"              
            });
        }else{
            $('.checkbox1').each(function() { //loop through each checkbox
                this.checked = false; //deselect all checkboxes with class "checkbox1"                      
            });        
        }
    });
   
});
</script>
