<?php
$PageSecurity = 15;
$title = _('Shift Master') ;
if(!empty($_GET['id']) and $_REQUEST['act']=='del')
{
$SQL="delete from shift_category_master where id='".$_REQUEST['id']."'";
$ErrMsg = _('The record could not be deleted');
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' Record Has Been Deleted!'),'success');
echo "<script>location.href='index.php?route=HRModule/ShiftCategoryMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
}
function CheckDuplicacy($deptcode)
{
global $db;
$SQL ="select shift_category from shift_category_master where shift_category ='".$deptcode."' and CompanyId='".$_SESSION['ACGCompanyId']."'";	
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
if(isset($resrow['shift_category'])){return false;} else {return true;}
}
if(!$_POST['edit'] and $_REQUEST['act']=='edit')
{
$SQL="select * from shift_category_master where id='".$_REQUEST['id']."'";
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
$_POST['shift_category'] = $resrow['shift_category'];
}

if($_POST['edit'] && $_REQUEST['act'] == 'edit')
{
$SQL="update shift_category_master set shift_category = '".$_REQUEST['shift_category']."', modified_by='".$_SESSION['UserID']."', modified_date='".date('Y-m-d')."' where id='".$_GET['id']."'";
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _('Update Successfully'),'success');
echo "<script>location.href='index.php?route=HRModule/ShiftCategoryMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
unset($_POST);
}

if(isset($_REQUEST['add']) and isset($_REQUEST['shift_category']) and $_REQUEST['act']!='edit')
{
	if(CheckDuplicacy($_REQUEST['shift_category']))
	{
		$SQL = "INSERT into shift_category_master (id, shift_category, created_by, created_date,CompanyId) 
					 values('', '".$_REQUEST['shift_category']."', '".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."')";	
		
		$InsResult=DB_query($SQL,$db,$ErrMsg);
		prnMsg( _('A New Category Has been Inserted!'),'success');
		echo "<script>location.href='index.php?route=HRModule/ShiftCategoryMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
		unset($_POST);
	}
	else
	{	
	prnMsg( _('This Category All Ready Exists. Please Enter A New Category!'),'error');
	}	
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Shift Master</h1>
<form method="post" action="">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%" align="right">Shift Category</td>
	<td><input name="shift_category" type="text" id="shift_category" value="<?php echo $_POST['shift_category']; ?>" style="width:40%;" /></td>
</tr>
</table>
<p align="center"><?php
if($_REQUEST['act']=='edit'){?>
<input type="submit" name="edit" class="search"  value="Edit" />
<input type="hidden" name='uiqeid' class="search" value="<?php echo $_REQUEST['id']; ?>" />
<?php }else{ 
if($_SESSION['frmAdd']=='1'){?>
<input type="submit" name="add" class="search"  value="Submit" />
<input type="submit" name="cancel" class="search"  value="Cancel" /><?php }} ?>
</form>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" class="thborder">
<tr>
    <th>Shift Category</th>
    <th width="7%" class="text-center">Edit</th>
    <th width="7%" class="text-center">Delete</th>
</tr>
<?php
$SQL ="select * from shift_category_master where companyId='".$_SESSION['ACGCompanyId']."'";	
$result=DB_query($SQL,$db,$ErrMsg);
if(DB_num_rows($result)>0){
while($resrow=DB_fetch_array($result)){?>
<tr bgcolor="#fff">
<td><?php echo $resrow['shift_category']; ?></a></td>
<td align="center">
<?php if($_SESSION['frmEdit']=='1'){?>
<a href="index.php?route=HRModule/ShiftCategoryMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=edit&id=<?php echo $resrow['id']; ?>" class="link"><img src="images/icon-edit.png" width="15" title="Edit Document" /></a><?php } else { ?><img src="images/icon-edit.png"  width="13" height="13" style="opacity:0.6;" title="No Permission to Edit Document" /><?php } ?></td>
<td align="center">
<?php if($_SESSION['frmDelete']=='1') {?>
<a href="index.php?route=HRModule/ShiftCategoryMaster&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"><img src="images/Icon_Delete.png" width="13" height="13" title="Delete Document" /></a><?php }else { ?><img src="images/Icon_Delete.png" width="15" style="opacity:0.6;" title="No Permission to Delete Document" /><?php } ?></td>
</tr>
<?php }
}else{
    echo "<tr><td colspan='4' align='center'><font color='#FF0000'>NO RECORD FOUND!</font></td></tr>";
}
?>
</table>
