<?php
   $PageSecurity = 3;
$title = _('View/Search Items') ;
include('includes/SQL_CommonFunctions.inc');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
		$condition="parant_id='".$_REQUEST['leadid'][$i]."'";
		$s->DeleteRecord('spare_part_kits_details', $condition);
		$condition="id='".$_REQUEST['leadid'][$i]."'";
		$s->DeleteRecord('spare_part_kits', $condition);
	}
	$s->pageLocation("index.php?route=Inventory/maintenance/spare_part_kit_index".$rurl);
}
?>
 <script language="javascript" >
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;	
	}
	}
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Spare Part Kits</h1>

<form action="" name="myform" method="post">
<p align="left">
    <?php if($_SESSION['frmcreate']=='1'){?>
    <a href="index.php?route=Inventory/maintenance/spare_part_kids_add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" value="Add New" class="search" /></a><?php } ?>
<?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="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
<tr>
	<th rowspan="2" width="15%">Asset Code</th>
	<th rowspan="2">Asset Name</th>
	<th colspan="3" style="text-align:center"><!--<input name="leadid" type="checkbox" id="leadid" onclick="LeadData()"/>-->Action</th>
</tr>
<tr>
	<th width="5%" style="text-align:center">Select</th>
	<th width="5%" style="text-align:center">View</th>
	<th width="5%" style="text-align:center">Edit</th>
</tr>
<?php 
$contractor_search="select * from spare_part_kits";
$result=DB_query($contractor_search,$db);
$i=0;
if(DB_num_rows($result)>0)
{
	while($myrow=DB_fetch_array($result))
	{
?> 
 <tr bgcolor="#fff">
    <td><?php echo $s->getField('machine_center','id',$myrow['kitid'],'code');?></td>
    <td><?php echo $s->getField('machine_center','id',$myrow['kitid'],'name');?></td>
    <td style="text-align:center"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>" value="<?php  echo $myrow['id']?>" /></td>
    <td style="text-align:center"><?php if($_SESSION['frmDelete']=='1'){?><a href="index.php?route=Inventory/maintenance/spare_part_kids_view&Viewid=<?php echo $myrow['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" width="15"  height="15" title="View" /></a><?php } ?></td>
	<!--<img src="images/print.jpeg" width="18px"  height="18" />--> 
	<td style="text-align:center"><a href="index.php?route=Inventory/maintenance/spare_part_kids_add_Edit&Viewid=<?php echo $myrow['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit" /></a></td>
  </tr>
  <?php $i++;} 
  }
  else
  {?>
  <tr>
  <td colspan="5" align="center"><font color="#FF0000">No Record Found!</font></td>
  </tr>
  <?php 	
  }?>
</table>
</form>
</div>
</div>
<?php 
include('includes/footer.inc');

 if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>