<?php 
$PageSecurity = 11;
$title = _('Shift Master');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['id']!='' && $_REQUEST['action']=='delete')
{
	$del_sql="Delete from shift_master where id='".$_REQUEST['id']."'";
	$del_res=DB_query($del_sql,$db);
	echo "<script>location.href='index.php?route=shift_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'] != '' && $_REQUEST['action']=='AddNew')
{
	$sql="INSERT INTO shift_master set
					site='".$_REQUEST['site']."',   
					shift_for='".$_REQUEST['shift_for']."', 
					shift_category='".$_REQUEST['shift_category']."',   
					shift_start='".$_REQUEST['shift_start']."',     
					start_AMPM='".$_REQUEST['start_AMPM']."',
					shift_end='".$_REQUEST['shift_end']."',
					end_AMPM='".$_REQUEST['end_AMPM']."' ";
	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=HRModule/shift_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from shift_master where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['site']=$get_row['site'];
	$_REQUEST['shift_for']=$get_row['shift_for'];
	$_REQUEST['shift_category']=$get_row['shift_category'];
	$_REQUEST['shift_start']=$get_row['shift_start'];
	$_REQUEST['shift_end']=$get_row['shift_end'];
	$_REQUEST['start_AMPM']=$get_row['start_AMPM'];
	$_REQUEST['end_AMPM']=$get_row['end_AMPM'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
 $update_sql="Update shift_master SET 
					site='".$_REQUEST['site']."',   
					shift_for='".$_REQUEST['shift_for']."', 
					shift_category='".$_REQUEST['shift_category']."',   
					shift_start='".$_REQUEST['shift_start']."',     
					start_AMPM='".$_REQUEST['start_AMPM']."',
					shift_end='".$_REQUEST['shift_end']."',
					end_AMPM='".$_REQUEST['end_AMPM']."' where id='".$_REQUEST['row_id']."'"; 
$update_res=DB_query($update_sql,$db);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=HRModule/shift_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<h2 align="center"><strong>Shift Master</strong></h2>
<form action="" method="post">
<a href="index.php?route=HRModule/shift_master<?php echo $rurl;?>&action=AddNew">ADD NEW</a>
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
  <th><strong>BRANCH</strong></th>
	<?php
		 $result=DB_query('SELECT locationname, loccode FROM locations', $db);
		  ?>
	  <td> <select name="site" style="width:135px">
	  <option value="0">--Branch--</option>
	   <?php
		while($myrow = DB_fetch_array($result))
		 {
	 	$p='';
		if($_REQUEST['site']==$myrow['loccode'])
		$p="selected";
		 ?>
		<option VALUE= "<?php echo $myrow['loccode']; ?>" <?php echo $p;?>> <?php echo $myrow['locationname'];?></option>
		 <?php }?> 
		</option></select></td></tr>
<tr>
  <th><strong>SHIFT FOR </strong></th>
  <td><select name="shift_for" id="shift_for" style="width:135px">
   <option value="0">--Shift--</option>
    <option value="Staff"<?php echo ($_REQUEST['shift_for']=='Staff'?'selected':'')?>>Staff</option>
    <option value="Worker"<?php echo ($_REQUEST['shift_for']=='Worker'?'selected':'')?>>Worker</option>
  </select>
  </td>
</tr>
<tr>
  <th><strong>SHIFT CATEGORY </strong></th>
  <td><select name="shift_category" id="shift_category" style="width:135px">
  <option value="0">--Shift Category--</option>
        <option value="Day"<?php echo ($_REQUEST['shift_category']=='Day'?'selected':'')?>>Day</option>
        <option value="Night"<?php echo ($_REQUEST['shift_category']=='Night'?'selected':'')?>>Night</option>
        <option value="General"<?php echo ($_REQUEST['shift_category']=='General'?'selected':'')?>>General</option>
		
      </select>  </td>
</tr>
  <!--<tr>
    <th><strong>Shift Name </strong></th>
    <td>
      <input name="shift_name" type="text" id="shift_name" value="<?php// echo $_REQUEST['shift_name'];?>" size="30"></td>
  </tr>-->
  <tr>
    <th><strong>SHIFT START </strong></th>
	<?php if(isset($_REQUEST['shift_start'])){$shift_start=$_REQUEST['shift_start'];} else{$shift_start='00:00';}?>
     <td><input name="shift_start" type="text" id="shift_start" value="<?php echo $shift_start;?>" size="15" />
	 <select name="start_AMPM" id="start_AMPM" style="width:40px">
	 <option value="AM"<?php echo ($_REQUEST['start_AMPM']=='AM'?'selected':'')?>>AM</option>
	 <option value="PM"<?php echo ($_REQUEST['start_AMPM']=='PM'?'selected':'')?>>PM</option>
	 </select>	 </td>
  </tr>
    <tr>
    <th><strong>SHIFT END </strong></th>
	<?php if(isset($_REQUEST['shift_end'])){$shift_end=$_REQUEST['shift_end'];} else{$shift_end='00:00';}?>
    <td><input name="shift_end" type="text" id="shift_end" value="<?php echo $shift_end;?>" size="15">
	 <select name="end_AMPM" id="end_AMPM" style="width:40px">
	 <option value="AM"<?php echo ($_REQUEST['end_AMPM']=='AM'?'selected':'')?>>AM</option>
	 <option value="PM"<?php echo ($_REQUEST['end_AMPM']=='PM'?'selected':'')?>>PM</option>
	 </select>	</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 
$shift_sql=DB_query("Select * from shift_master",$db);
?>
<table width="60%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th><strong>BRANCH</strong></th>
<th><strong>SHIFT FOR </strong></th>
<th><strong>SHIFT CATEGORY </strong></th>
<th><strong>SHIFT START </strong></th>
<th><strong>SHIFT END </strong></th>

<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
if(DB_num_rows($shift_sql)>0){
while($shift_row=DB_fetch_array($shift_sql))
{ 
?>
<tr bgcolor="#FFFFFF">
<td><?php 
$loc=DB_query("SELECT locationname, loccode FROM locations where loccode= '".$shift_row['site']."'", $db);
$loc_row=DB_fetch_array($loc);
echo $loc_row['locationname'];
?>
<td><?php echo $shift_row['shift_for'];?></td>
<td><?php echo $shift_row['shift_category'];?></td>
<td><?php echo $shift_row['shift_start']." ".$shift_row['start_AMPM'];?></td>
<td><?php echo $shift_row['shift_end']." ".$shift_row['end_AMPM'];?></td>
<td><a href="index.php?route=shift_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $shift_row['id'];?>&action=edit">Edit</a></td>
<td><a href="index.php?route=shift_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $shift_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');
?>