<style type="text/css">
  .cap{
    text-transform:uppercase
    };
</style>
<?php 
if($_REQUEST['action']=='delete' && $_GET['id']!='')
{
	$del_sql=DB_query("Delete from form_type_master where id='".$_GET['id']."'",$db);
	echo "<script>location.href='index.php?route=form_type_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'] != '')
{
	$sql="INSERT INTO form_type_master(id,form_name,CompanyId) VALUES('','".$_POST['name']."','".$_SESSION['ACGCompanyId']."')";
	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=form_type_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from form_type_master where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['name']=$get_row['form_name'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
$update_sql="Update form_type_master SET form_name='".$_POST['name']."' where id='".$_REQUEST['row_id']."' ";
$update_res=DB_query($update_sql,$db);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=form_type_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<h2 align="center"><strong>Form Types</strong></h2>
<form action="" method="post">
<table width="25%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>Name</strong></th>
    <td><input name="name" type="text" id="name" value="<?php echo $_REQUEST['name'];?>" style="width: 100%; height: 22px" class="cap"></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 
$q_sql=DB_query("Select * from form_type_master",$db);
?>
<table width="20%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<th><strong>Form Type</strong></th>
<th colspan="2"><strong>Action</strong></th>
</tr>
<?php
if(DB_num_rows($q_sql)>0){
while($q_row=DB_fetch_array($q_sql))
{ 
?>
<tr>
<td><?php echo $q_row['form_name'];?></td>
<td><a href="index.php?route=form_type_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $q_row['id'];?>&action=edit">Edit</a></td>
<td><a href="index.php?route=form_type_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $q_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');
?>