
<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;

if(isset($_POST['Submit']))
{
$check=DB_query("select * from production_shift where shift_name='".$_REQUEST['shift_category']."' and loccode='".$_REQUEST['site']."'",$db);
$num=DB_num_rows($check);
if($num<=0)
{	
$insert="insert into production_shift set shift_name='".$_REQUEST['shift_category']."',loccode='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."' ";
$query=Db_query($insert,$db);
}	
}
if(isset($_POST['Update']))
{
$check=DB_query("select * from production_shift where shift_name='".$_REQUEST['shift_category']."' and loccode='".$_REQUEST['site']."'",$db);
$num=DB_num_rows($check);
if($num<=0)
{		
$update="update production_shift set shift_name='".$_REQUEST['shift_category']."',loccode='".$_REQUEST['site']."' where id='".$_REQUEST['Id']."'";
$query=DB_query($update,$db);	
}
$s->pageLocation("index.php?route=Production_Shift&daction=Updated".$rurl);	
}

if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++){
	$del="delete from production_shift where id='".$_REQUEST['leadid'][$i]."'";
	$query=DB_query($del,$db);
	}	
$s->pageLocation("index.php?route=Production_Shift&daction=Updated".$rurl);	
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']==''){?>
<h1>Production Shift Master</h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td class="tabledata1">BRANCH</td>		
	<td><select name="site" style="width:150px;" id="site" >
	  	
	  <?php  $site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
             while($site_row=DB_fetch_array($site_sql)){?>
         <option value="<?php echo $site_row['loccode'];?>"><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</option></select></td>
		<td class="tabledata1">Shift Name</td>	
		<td><input  name="shift_category" id="shift_category" style="width:150px;" type="text"></td>
</tr>
<tr class="row1">
	<td colspan="4">
		<p align="center">
			<input type="submit" value="Save" name="Submit" onclick="return valid();" class="search">
		</p>
	</td>
</tr>  
   
</table>
</form> <?php } if($_REQUEST['action']=='edit' and $_REQUEST['Id']!='' ){
$sql="select * from production_shift where id='".$_REQUEST['Id']."'";
$query=DB_query($sql,$db);
$row1=DB_fetch_array($query);	
?>
<h1>Edit Production Shift Master</h1>
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td class="tabledata1">BRANCH</td>	
	  <td> <select name="site" style="width:150px;" id="site" >
	  	
	  <?php 
            $site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
                        while($site_row=DB_fetch_array($site_sql)){
                        $k='';
						if($site_row['loccode']==$row1['loccode'])
						{
						$k="selected";	
						}		
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo $k; ?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</option></select></td>
	<td class="tabledata1">Shift Name</td>	
<td>
<input  name="shift_category" id="shift_category" style="width:150px;" type="text" value="<?php echo $row1['shift_name']; ?>">
</td>
</tr>
<tr class="row1">
	<td colspan="4">
		<p align="center">
			<input type="submit" value="Update" name="Update" onclick="return valid();" class="search"></p>
	</td>
</tr>
</table>
<?php }?>
<form name="myform" method="post">
<p align="left">
	<input type="submit" name="Delete" value="Delete" class="search" onclick="return confirm('Are you sure you want to delete?')" />
</p>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="11%" class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
<td width="37%" class="tabledata">Branch</td>
<td width="52%" class="tabledata">Shift Name </td>
</tr>
<?php $i=0; $sql="select * from production_shift where CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=DB_query($sql,$db);
while($row=DB_fetch_array($query)){?>
<tr class="row1">
<td style="white-space:nowrap;"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $row['id']?>" />
	
	<a href="index.php?route=Production_Shift&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $row['id'];?>"><img src="images/icon_edit.gif" width="12px"  height="12" /></a>
	
	<!--<a href="index.php?route=CRM/dot_request_form&action=View&id=<?php echo $fetchArray['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>-->
	</td>
<td><?php $db1="select * from locations where loccode='".$row['loccode']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['locationname']; ?></td>
<td><?php echo $row['shift_name']; ?></td>
</tr>
<?php $i++;} ?>
</table>
</form>
</div></div>


<?php 
//include('includes/footer.inc');
?>
<script language="JavaScript">
function valid()
{
if(document.getElementById("site").value==0)
{
alert("Must Select Site Name");
document.getElementById("site").focus();
return false;	
}
if(document.getElementById("shift_category").value=='')
{
alert("Must Enter Shift Name");
document.getElementById("shift_category").focus();
return false;	
}
return true;	
}	



function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}	
	
	
</script>
