<link rel="stylesheet" href="css/new_mxerp.css">
<?php
if($_REQUEST['action']=='delete')
{
$del=DB_query("delete from break_down_type where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=Break_down_type&daction=Updated".$rurl);	
}
if(isset($_POST['Submit']))
{
$insert="insert into break_down_type set breakdown_reason='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."' ";
$query=Db_query($insert,$db);
}
if(isset($_POST['Update']))
{
$update=DB_query("update break_down_type set breakdown_reason='".$_REQUEST['shift_category']."'
,branch_code='".$_REQUEST['site']."' where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=Break_down_type&daction=Updated".$rurl);	
}

?>
<?php if($_REQUEST['action']==''){ ?>

<div class="">
<div class="">


<h1>Break Down Type</h1>
<form action="" method="post">
<table width="40%" border="0" cellpadding="2" cellspacing="1" style="border:#666666 solid 1px;">
<tr>
     <th><strong>Branch</strong></th>	
	  <td> <select name="site" style="width:100%">
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
                        while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</option></select></td></tr>
</tr>
<tr>
  <th><strong>Break Down Type</strong></th>	
<td><input name="shift_category" id="shift_category" style="width:100%" type="text">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Save" name="Submit"></p>
</form>
<?php } if($_REQUEST['action']=='edit' and $_REQUEST['Id']!=''){
	$sql=DB_query("select * from break_down_type where id='".$_REQUEST['Id']."'",$db);
	$edit_row=DB_fetch_array($sql);
	?>

<div class="">
<div class="">

	<h1>Edit Break Down Reason</h1>
<form action="" method="post">
<table width="40%" border="0" cellpadding="2" cellspacing="1" style="border:#666666 solid 1px;">
<tr>
     <th><strong>Branch</strong></th>	
	  <td> <select name="site" style="width:100%">
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
                        while($site_row=DB_fetch_array($site_sql)){
                        	$k='';
							if($site_row['loccode']==$edit_row['branch_code'])
							{
							$k="selected";	
							}
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>" <?php echo $k; ?> ><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</option></select></td></tr>
</tr>

<tr>
<th><strong>Break Down Type</strong></th>	
<td><input name="shift_category" id="shift_category" style="width:100%" type="text" value="<?php echo $edit_row['breakdown_reason']; ?>">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Update" name="Update"></p>
</form>
	<?php  } ?>

	<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Branch</td>
<td class="tabledata">Break Down Type  </td>
<td class="tabledata" colspan="2">Action</td>
</tr>
<?php
$sql="select * from break_down_type where CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=DB_query($sql,$db);
while($row=DB_fetch_array($query))
{
	
?>
<tr>
	
<td><?php $db1="select * from locations where loccode='".$row['branch_code']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['locationname']; ?></td>
<td><?php echo $row['breakdown_reason']; ?></td>

<td><a href="index.php?route=Break_down_type&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $row['id'];?>">Edit</a></td>
<td><a href="index.php?route=Break_down_type&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $row['id'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>
</tr>
<?php } ?>
</table>

</div></div>

<?php 
//include('includes/footer.inc');
?>