<?php
echo "manish";
$PageSecurity = 15;
$title = _('Leave 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 leavecode from leavemaster";
$result=DB_query($SQL,$db,$ErrMsg);
while($resrow=DB_fetch_array($result))
{
echo '<option value='.$resrow[leavecode].'>'.$resrow[leavecode].'</option>';
}
}

if(isset($_GET['id']) and $_GET['act']=='del')
{
$SQL="delete from leavemaster where id='".$_GET['id']."'";
$ErrMsg = _('The Leave Master  record could not be deleted because');
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' Leave Code Has Deleted!'),'success');
echo "<script>location.href='index.php?route=HRModule/LeaveMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
}

function CheckleaveCode($leavecode)
{
global $db;
$SQL ="select leavecode,leavename from leavemaster where id ='".$_GET['id']."'";	
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
if(isset($resrow['leavecode'])){return false;} else {return true;}
}

if(!$_POST['edit'] and $_REQUEST['act']=='edit' and $_GET['id']!='')
{
$SQL="select leavecode,leavename from leavemaster where id='".$_GET['id']."'";
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
$_POST['leavecode']=$resrow[leavecode];
$_POST['leavename']=$resrow[leavename];
}

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

if(isset($_POST['add']) and !empty($_POST['leavecode']) and !empty($_POST['leavename']) and $_GET['act']!='edit')
{
	if(CheckleaveCode($_POST['leavecode'])){
 $SQL = "INSERT into leavemaster(id, leavecode, leavename ) values ('','".$_POST['leavecode']."','".$_POST['leavename']."')";	
		$InsResult=DB_query($SQL,$db,$ErrMsg);
		prnMsg( _('A New Leave Code Has Inserted!'),'success');
		echo "<script>location.href='index.php?route=HRModule/LeaveMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
		unset($_POST);
	}
	else{	
	prnMsg( _('This Leave Code All Ready Exit please Enter New Group Code!'),'error');
		
	}	
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><strong>Leave Master</strong></h1>
<form method="post" action="">
<table width="35%" border="0" align="center">
<tr>
<th><strong>LEAVE CODE </strong></th>
<td><input name="leavecode" type="text" id="leavecode" value="<?php echo $_POST['leavecode']?>" size="30"/></td>
</tr>
<tr>
<th><strong>LEAVE NAME </strong></th>
<td><input name="leavename" type="text" id="leavename" value="<?php echo $_POST['leavename']?>" size="30"/></td>
</tr>
</table>
<p align="center">
<?php if($_GET['act']=='edit'){?>
<input type="submit" name="edit"  value="Edit" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>/>
<input type="hidden" name='uiqeid' value="<?php echo $_GET['id']?>" />
<?php }else{ ?>
<input type="submit" name="add"  value="Accept" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?> />
<input type="submit" name="cancel"  value="Cancel" /><?php } ?></p>
</form>
<table width="50%" border="0" align="center">
<tr>
<th><strong>LEAVE CODE </strong></th>
<th><strong>LEAVE NAME </strong></th>
<th><strong>EDIT</strong></th>
<th><strong>DELETE</strong></th>
</tr>
<?php
$SQL ="select * from leavemaster";	
$result=DB_query($SQL,$db,$ErrMsg); 
while($resrow=DB_fetch_array($result)){?>
<tr>
<td><?php echo $resrow['leavecode']; ?></td>
<td><?php echo $resrow['leavename']; ?>sdfdss</td>
<td><?php if($_SESSION['frmEdit']=='1'){?><a href="index.php?route=HRModule/LeaveMaster&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=HRModule/LeaveMaster&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>