<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
?>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<?php 
if($_REQUEST['submit_tech']!='')
{

	 $key = key($_REQUEST['submit_tech']);
	 $sql1="Insert into project_work_assignment set
			boq_id='".$_REQUEST['bed_id']."', 
			tech_id='".$_REQUEST['tech_id'][$key]."'";
		
	$result1=DB_query($sql1,$db);
	 
	$_SESSION['session_msg']="Assigned Sucessfully";
?>
<script>
window.opener.location.href = window.opener.location.href;self.close();self.close();
</script>
<?php 
}
if($_REQUEST['act']=='edit')
{
if($_REQUEST['submit_tech1']!='')
{ 
$sql2= "select * from project_assign_contractor where boq_id='".$_REQUEST['bed_id']."'";
$result2=DB_query($sql2,$db);
	if(DB_num_rows($result2)>0)
	{
		$delete = DB_query("delete from project_assign_contractor where
		        boq_id = '".$_REQUEST['bed_id']."'",$db);
				
				 $key = key($_REQUEST['submit_tech1']);
	 $sql11="Insert into project_work_assignment set
			boq_id='".$_REQUEST['bed_id']."', 
			tech_id='".$_REQUEST['tech_id'][$key]."'";
	
	 $result1=DB_query($sql11,$db);
	
?>
<script>
window.opener.location.href = window.opener.location.href;self.close();
</script>
<?php 
}
else
{
$key = key($_REQUEST['submit_tech']);
		$data6['tech_id'] = $_REQUEST['tech_id'][$key];	
		$condition6="boq_id='".$_REQUEST['bed_id']."'";
		$s->RecordEdit('project_work_assignment',$data6,$condition6);
		$_SESSION['session_msg']="Assigned Sucessfully";
		?>
<script>
window.opener.location.href = window.opener.location.href;self.close();
</script>
<?php
}
}
}
?>
<script language="javascript" type="text/javascript">
function open_technician_detail(str)
{
	var techid=str;
	window.open("project_asinment_details.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&techaid="+techid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function confirm_func(str)
{
var tect=str;
var con=confirm("Are you want to assigned this job to "+tect);
	if(con)
	{ return true;
	}else{
		return false;
	}
}


</script>


<h2 align="center">Contractor List</h2>
<form name="form1" action="" method="post">
  <table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
    <tr>
		<th width="23%"><strong>S.No.</strong></th>
      <th width="23%"><strong>Technician Name</strong></th>
      <th width="39%">&nbsp;</th>
      <th width="26%">&nbsp;</th>
    </tr>
  </table>
  <?php
	$sql=DB_query("SELECT * FROM technicians where location='".$_REQUEST['braid']."'",$db); 	?>
  <div style="overflow: scroll; height: 300px" id="sub_id">
    <table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
      <?php	
	
	$i=0;
	$j = 1;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 
		$j = $j +$i;	
		 
  ?>
<tr bgcolor="#CCCCCC">
<td width="24%"><?php echo  $j;?></td>
<td width="24%"><?php echo  $myrow['technician'];?>
<input type="hidden" name="tech_id[<?php echo $i;?>]" id="tech_id_<?php echo $i;?>" value="<?php echo  $myrow['id'];?>" /></td>
<td width="40%"><input type="button" name="profile_popup" value="View Detail" id="profile_popup"  onclick="open_technician_detail(<?php echo $myrow['id']; ?>)" class="search" /></td>
<td width="24%"><input type="submit" name="<?php if($_REQUEST['act']=='edit') { ?>submit_tech1[<?php echo $i; ?>]<?php } else { ?> submit_tech[<?php echo $i; ?>]<?php } ?>" value="<?php if($_REQUEST['act']=='edit') { echo 'Update'; } else { echo 'Assign'; } ?>" id="submit_tech_<?php echo $i;?>" class="search" onClick="return confirm_func('<?php echo $myrow['technician']; ?>')" /><input type="hidden" name="ttid" value="<?php echo $_REQUEST['bed_id'];?>" /><input type="hidden" name="orderID" value="<?php echo $_REQUEST['oid'];?>" /></td>
      </tr>
      <?php $i++;} }?>
    </table>
  </div>
</form>
<div style="text-align:center"><input type="button" name="back" value="Close" onClick="window.close()" class="search" /></div>
