<?php 
$PageSecurity = 2;
$title = _('Employee Grade Master');
include('includes/SQL_CommonFunctions.inc');

if($_REQUEST['Submit'] != '')
{
	$sql="INSERT INTO emp_grade(id,grade_code,grade_name) VALUES('','".$_POST['code']."','".$_POST['name']."')";
	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=employee_gradeMaster&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from emp_grade where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['code']=$get_row['grade_code'];
	$_REQUEST['name']=$get_row['grade_name'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
$update_sql="Update emp_grade SET grade_code='".$_POST['code']."' , grade_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=employee_gradeMaster&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<h2 align="center"><strong>Employee Grade Master</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>GRADE CODE </strong></th>
    <td>
      <input name="code" type="text" id="code" value="<?php echo $_REQUEST['code'];?>" size="30">    </td>
  </tr>
  <tr>
    <th><strong>GRADE 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 
$grade_sql=DB_query("Select * from emp_grade",$db);
?>
<table width="50%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<th><strong>GRADE CODE</strong></th>
<th><strong>GRADE NAME</strong></th>
<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
if(DB_num_rows($grade_sql)>0){
while($grade_row=DB_fetch_array($grade_sql))
{ 
?>
<tr>
<td><?php echo $grade_row['grade_code'];?></td>
<td><?php echo $grade_row['grade_name'];?></td>
<td><a href="index.php?route=employee_gradeMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $grade_row['id'];?>&action=edit">Edit</a></td>
<td><a href="index.php?route=employee_gradeMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $grade_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');
?>