<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Submit']))
{
$insert="insert into break_down_master set brack_down_type='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."',brack_down_id='".$_REQUEST['break_down_type']."' ";
$query=Db_query($insert,$db);
}
if(isset($_POST['Update']))
{
$update=DB_query("update break_down_master set brack_down_type='".$_REQUEST['shift_category']."'
,branch_code='".$_REQUEST['site']."',brack_down_id='".$_REQUEST['break_down_type']."' where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=Break_down_reason&daction=Updated".$rurl);	
}
if($_REQUEST['action']=='delete')
{
$del=DB_query("delete from break_down_master where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=Break_down_reason&daction=Updated".$rurl);	
}
?>
<?php if($_REQUEST['action']==''){ ?>
<h2 align="center"><strong>Break Down Reason</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
  <th><strong>BRANCH</strong></th>	
	  <td> <select name="site" style="width:135px" id="site">
	  	<option value="000">--Select---</option>
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations ",$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> <select name="break_down_type" style="width:135px" id="site" >
	  	<option value="000">--Select---</option>
	  <?php 
            $site_sql1=DB_query("Select id,breakdown_reason from break_down_type",$db);
                        while($site_row1=DB_fetch_array($site_sql1)){
                    ?>
                      <option value="<?php echo $site_row1['id'];?>"><?php echo $site_row1['breakdown_reason'];?></option>
                      <?php } ?>		
		</option></select></td></tr>
</tr>
<tr>
<th><strong>Break Down Reason </strong></th>
<td><input name="shift_category" id="shift_category" style="width:135px" type="text">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Save" name="Submit" onclick="return valid();"></p>
</form>
<?php } if($_REQUEST['action']=='edit' and $_REQUEST['Id']!=''){
	$sql=DB_query("select * from break_down_master where id='".$_REQUEST['Id']."'",$db);
	$edit_row=DB_fetch_array($sql);
	?>
	<h2 align="center"><strong>Edit Break Down Reason</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
  <th><strong>BRANCH</strong></th>	
	  <td> <select name="site" style="width:135px">
	  <?php 
            $site_sql=DB_query("Select loccode,locationname from locations ",$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> <select name="break_down_type" style="width:135px" id="site" >
	  	<option value="000">--Select---</option>
	  <?php 
            $site_sql=DB_query("Select id,breakdown_reason from break_down_type ",$db);
                        while($site_row=DB_fetch_array($site_sql)){
                        	if($site_row['id']==$edit_row['brack_down_id'])
							{
							$j="selected";	
							}
                    ?>
                      <option value="<?php echo $site_row['id'];?>"<?php echo $j; ?>><?php echo $site_row['breakdown_reason'];?></option>
                      <?php } ?>		
		</option></select></td></tr>
</tr>
<tr>
<th><strong>Break Down Reason </strong></th>
<td><input name="shift_category" id="shift_category" style="width:135px" type="text" value="<?php echo $edit_row['brack_down_type']; ?>">
</td>
</tr>  
   
</table>
<p align="center">
<input type="submit" value="Update" name="Update"></p>
</form>
	<?php  } ?>
<br>	
<br>
<table width="60%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th><strong>BRANCH</strong></th>
<th><strong>Break Down Type  </strong></th>
<th><strong>Break Down Reason  </strong></th>
<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
$sql="select * from break_down_master";
$query=DB_query($sql,$db);
while($row=DB_fetch_array($query))
{
	
?>
<tr bgcolor="#FFFFFF">
	
<td><?php	echo $location=$s->getField('locations','loccode',$row['branch_code'],'locationname');	 ?></td>
<td><?php echo $btype=$s->getField('break_down_type','id',$row['brack_down_id'],'breakdown_reason');	 ?></td>
<td><?php echo $row['brack_down_type']; ?></td>
<td><a href="index.php?route=Break_down_reason&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_reason&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>
<?php 
include('includes/footer.inc');
?>
<script language="JavaScript">
function valid()
{
	if(document.getElementById("site").value=='000')
	{
	alert("Must Select Branch Name");
	document.getElementById("site").focus();
	return false;	
	}
	if(document.getElementById("shift_category").value=='')
	{
	alert("Please Enter Break Down Reason");
	document.getElementById("shift_category").focus();
	return false;	
	}
	if(document.getElementById("shift_category").value=='')
	{
	alert("Please Enter Break Down Reason");
	document.getElementById("shift_category").focus();
	return false;	
	}
	return true;
	
}	
	
	
	
	
	
</script>