<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Submit']))
{
	$sql="select * from job_work_process where out_side_process='".$_REQUEST['shift_category']."' and branch_code='".$_REQUEST['site']."'";
	$query1=DB_query($sql,$db);
	$numrows = DB_num_rows($query1);
	if($numrows<=0)
	{
 $insert="insert into job_work_process set out_side_process='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=Db_query($insert,$db);
}	
}
if(isset($_POST['Update']))
{
$update=DB_query("update job_work_process set out_side_process='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."' where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=job_work_process&daction=Updated".$rurl);	
}

if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++){
	$del=DB_query("delete from job_work_process where id='".$_REQUEST['leadid'][$i]."'",$db);
	}	
	$s->pageLocation("index.php?route=job_work_process&daction=Updated".$rurl);	
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']=='') { ?>
<h1>Job Work Process</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 } ?>		
		
		</select>
	</td>
	<td class="tabledata1">Our Side Process</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_edit=DB_query("select * from job_work_process where id='".$_REQUEST['Id']."'",$db);
	$edit_row=DB_fetch_array($sql_edit);
	?>
<h1>Edit Job Work Process</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;" >
	  	
	  <?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']==$edit_row['branch_code'])
							{
							$k="selected";	
							}
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo $k;?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>		
		</select></td>
		<td class="tabledata1">Our Side Process</td>	
<td><input name="shift_category" id="shift_category" style="width:150px;" type="text" value="<?php echo $edit_row['out_side_process'];?>">
</td>

</tr>
<tr class="row1">
	<td colspan="4">
		<p align="center"><input type="submit" value="Update" name="Update" class="search"></p>
	</td>
</tr>
</table>

</form>
<?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>
<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
<td class="tabledata">Branch</td>
<td class="tabledata">Our Side Process  </td>
</tr>
<?php $i=0;
$sql="select * from job_work_process 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=job_work_process&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=view_machinecente&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=view&Id=<?php echo $row1['id'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>-->
	</td>
<td><?php $db1="select * from locations where loccode='".$row['branch_code']."'";
$query1=Db_query($db1,$db);
$row11=Db_fetch_array($query1); 
echo $row11['locationname']; ?></td>
<td><?php echo $row['out_side_process']; ?></td>
</tr>
<?php $i++;} ?>
</table>
</form>
</div>
</div>
<script language="JavaScript">
function valid()
{
	if(document.getElementById("site").value=='000')
	{
	alert("Must Select Branch Name");
	document.getElementById("site").focus();
	return false;	
	}
	if(document.getElementById("shift_category").value=='')
	{
	alert("Please Enter Out Side Process");
	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>
