<?php 
$PageSecurity = 11;
include('includes/session.inc');
$title = _('Transport Master');
include('includes/header.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['id']!='' && $_REQUEST['action']=='delete')
{
	$delete_sql="delete from transport_master where id='".$_REQUEST['id']."'";
	$delete_res=DB_query($delete_sql,$db);
}
if($_REQUEST['Submit'] != '')
{
	$sql="INSERT INTO transport_master(id,name) VALUES('','".$_POST['name']."')";
	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='transport_master.php'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from transport_master where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['name']=$get_row['name'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
$update_sql="Update transport_master SET  name='".$_POST['name']."' where id='".$_REQUEST['row_id']."' ";
$update_res=DB_query($update_sql,$db);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='transport_master.php'</script>";
}
?>
<br>
<br>
<br>
<h1 align="center"><strong>Transport Master</strong></h1>
<br>
<br>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>TRANSPORT NAME </strong></th>
    <td><input name="name" type="text" id="name" value="<?php echo $_REQUEST['name'];?>" size="30"></td>
  </tr>
</table>
<p align="center">
<?php if($_GET['action']=='edit'){?>
<input type="submit" value="Update" name="Update">
<input type="hidden" name="row_id" value="<?php echo $_GET['id'];?>" id="row_id">
<?php } else {?>
<input type="submit" value="Submit" name="Submit">
<?php }?>
</p>
</form>
<br>	
<br>
<?php 
$trans_sql=DB_query("Select * from transport_master",$db);
?>
<table width="30%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<th><strong>TRANSPORT NAME</strong></th>
<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
if(DB_num_rows($trans_sql)>0){
while($trans_row=DB_fetch_array($trans_sql))
{ 
?>
<tr>
<td><?php echo $trans_row['name'];?></td>
<td><a href="transport_master.php?id=<?php echo $trans_row['id'];?>&action=edit">Edit</a></td>
<td><a href="transport_master.php?id=<?php echo $trans_row['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this record?')">Delete</a></td>
</tr>
<?php } }
else
{?>
<tr>
<td colspan="2"><h3 align="center"><strong><font color="#FF0000">NO RECORD FOUND!</font></strong></h3></td>
</tr>
<?php 
}?>
</table>
<?php 
include('includes/footer.inc');
?>