<?php
$PageSecurity = 15;
$title = _('Allowance Master');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];echo "<br>";

function selectcode()
{
global $db;
$SQL ="select allowcode from allowmaster";
$result=DB_query($SQL,$db,$ErrMsg);
while($resrow=DB_fetch_array($result)){
echo '<option value='.$resrow['allowcode'].'>'.$resrow['allowcode'].'</option>';
}
}

if(isset($_GET['id']) and $_GET['act']=='del')
{
$SQL="delete from allowmaster where id='".$_GET['id']."'";
$ErrMsg = _('The Allowance Master  record could not be deleted because');
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' Allowance Code Has Deleted!'),'success');
echo "<script>location.href='index.php?route=AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
}
function CheckallowCode($allowcode){
global $db;
$SQL ="select allowcode,allowname from allowmaster where id ='".$_GET['id']."'";	
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
if(isset($resrow['allowcode'])){return false;} else {return true;}
}
if($_POST['edit'] =='' && $_REQUEST['act']=='edit' and $_GET['id']!='')
{
$SQL="select allowcode,allowname from allowmaster where id='".$_GET['id']."'";
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
$_POST['allowcode']=$resrow[allowcode];
$_POST['allowname']=$resrow[allowname];
}

if($_POST['edit']!='' && $_REQUEST['act'] == 'edit' and $_GET['id']!='')
{
$SQL="update allowmaster set allowcode='".$_POST['allowcode']."' , allowname ='".$_POST['allowname']."' where id='".$_GET['id']."'";
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' allow  Code Has Updated!'),'success');
echo "<script>location.href='index.php?route=AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
unset($_POST);
}

if(isset($_POST['add']) and !empty($_POST['allowcode']) and !empty($_POST['allowname']) and $_GET['act']!='edit')
{
	if(CheckallowCode($_POST['allowcode'])){
$SQL = "insert into allowmaster(id, allowcode, allowname)values ('','".$_POST['allowcode']."','".$_POST['allowname']."')";	
		$InsResult=DB_query($SQL,$db,$ErrMsg);
		prnMsg( _('A New Allowance Code Has Inserted!'),'success');
		echo "<script>location.href='index.php?route=AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
		unset($_POST);
	}
	else{	
	prnMsg( _('This Allowance Code All Ready Exit please Enter New Group Code!'),'error');
		
	}	
}
?>
<h2 align="center"><strong>Allowance Master</strong></h2>
<form method="post" action="">
<table width="40%" border="0" align="center">
<tr>
<th><strong>ALLOWANCE CODE </strong></th>
<td><input name="allowcode" type="text" id="allowcode" value="<?php echo $_POST['allowcode'];?>" size="30"/></td>
</tr>
<tr>
<th><strong>ALLOWANCE NAME </strong></th>
<td><input name="allowname" type="text" id="allowname"  value="<?php echo $_POST['allowname'];?>" size="30"/></td>
</tr>
</table>
<p align="center">
<?php if($_GET['act']=='edit'){?>
<input type="submit" name="edit"  value="Edit" />
<input type="hidden" name='uiqeid' value="<?php echo $_GET['id'];?>" />
<?php }else{ if($_SESSION['frmAdd']=='1'){ ?>
<input type="submit" name="add"  value="Accept" />
 <input type="submit" name="cancel"  value="Cancel" /><?php } }?></p>
</form>
<br />
<table width="50%" border="0" align="center">
<tr>
<th><strong>ALLOWANCE CODE</strong></th>
<th><strong>ALLOWANCE NAME </strong></th>
<th><strong>EDIT</strong></th>
<th><strong>DELETE</strong></th>
</tr>
<?php
$SQL ="select * from allowmaster";	
$result=DB_query($SQL,$db,$ErrMsg); 
while($resrow=DB_fetch_array($result)){?>
<tr class="tdclass">
<td><?php echo $resrow['allowcode']?></a></td>
<td><?php echo $resrow['allowname']?></td>
<td><?php if($_SESSION['frmEdit']=='1') {?><a href="index.php?route=AllowanceMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=edit&id=<?php echo $resrow['id']?>" class="link">Edit</a><?php }else echo "No Permission";?></td>
<td><?php if($_SESSION['frmDelete']=='1') {?><a href="index.php?route=AllowanceMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=del&id=<?php echo $resrow['id']?>" onclick="return confirm('Are you sure you want to delete this record?')" class="link">Delete</a><?php }else echo "No Permission";?></td>
</tr>
<?php }?>
</table>
<?php
include('includes/footer.inc');
?>
<style type="text/css" >
.button{ background-color:#666666;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #359CA2;
}
.link{ color:#9900CC; font-family:"Comic Sans MS";
}
</style>