<link rel="stylesheet" href="css/new_mxerp.css">
<?php include('includes/Class_Branch.php');
include('includes/AccountGroupMaster_Class.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=service/technician_master".$rurl;
$msgErr=array();?>

<div class="body_contain">
<div class="tab_div">
  <h1>Technician</h1>

<?php 
if($_REQUEST['Save']){
	$Insert = DB_query("INSERT INTO technicians SET 
						location = '".$_REQUEST['location']."',
						technician = '".$_REQUEST['technician']."',
						mobile_number = '".$_REQUEST['mobile_number']."'",$db);
		$s->pageLocation("index.php?route=service/technician_master".$rurl);		
}
if($_REQUEST['action']=='Edit'){
$con ="id='".$_REQUEST['id']."'";
$Get_id = $s->GetRecordById('technicians',$con);
$var = DB_fetch_array($Get_id);

	if($_REQUEST['Update']){
	$UPDATE = DB_query("UPDATE technicians SET 
						location = '".$_REQUEST['location']."',
						technician = '".$_REQUEST['technician']."',
						mobile_number = '".$_REQUEST['mobile_number']."'
						where id = '".$_REQUEST['id']."'",$db);
						$s->pageLocation("index.php?route=service/technician_master".$rurl);
	
	}
	
}
if($_REQUEST['action']=='Delete'){
	$delete = DB_query("DELETE FROM technicians
						WHERE id = '".$_REQUEST['id']."'",$db);
}
?>
<form method="post" name="tech_master">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
      <td class="tabledata">Branch Name<label><font color="#FF0000"> *</font></label></td>
      <td><?php $location_qry = "Select * from locations";
		$get_loc=DB_query($location_qry,$db);?>
        <select name="location" style="width:150px">
          <?php while($fetch = DB_fetch_array($get_loc)){
		  		$p='';
				if($fetch['loccode']==$var['location'])
				$p="selected";
			?>
          <option value="<?php echo $fetch['loccode']?>"<?php echo $p;?>><?php echo $fetch['locationname']?></option>
          <?php } ?>
        </select>
      </td>

      <td class="tabledata">Technician<label><font color="#FF0000"> *</font></label></td>
      <td><input name="technician" type="text"  value="<?php echo $var['technician']?>" style="width:150px" /></td>
	  
	   <td class="tabledata">Mobile No<label><font color="#FF0000"> *</font></label></td>
      <td><input name="mobile_number" type="text"  value="<?php echo $var['mobile_number']?>" maxlength="10" style="width:150px" /></td>
    </tr>
  </table>
  <input name="<?php if($_REQUEST['action']=='Edit') { echo 'Update';}else { echo 'Save'; }?>" type="submit" onclick="return validate_teshMaster()" value="<?php if($_REQUEST['action']=='Edit') { echo 'Update';}else { echo 'Save'; }?>" />
</form>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata">S. No.</td>
    <td class="tabledata">Branch Name</td>
    <td class="tabledata">Technician </td>
	<td class="tabledata">Mobile Number </td>
    
    <td class="tabledata">Edit</strong>
    <td class="tabledata">Delete</td>
  </tr>
  <?php $j=0; 
    $ResultData=DB_query("select *  from technicians where 1=1 ",$db);
    while($RowData = DB_fetch_array($ResultData))
   {  if($j++%2==0)
     $bgcolor="#CCCCCC";
	 else{
	 $bgcolor="#FFFFFF";
	 }
	 ?>
<tr bgcolor="#c1c1c1">
    <td><?php echo $j."." ?></td>
    <td><?php echo $s->getField('locations','loccode',$RowData['location'],'locationname');;?> </td>
    <td><?php echo $RowData['technician'];?></td>
	<td><?php echo $RowData['mobile_number'];?></td>
  
    <td><a href="<?php  echo $targetpage;?>&action=Edit&id=<?php echo $RowData['id']?>">Edit</a></td>
    <td><a href="<?php echo $targetpage;?>&action=Delete&id=<?php echo $RowData['id']?>" >Delete</a></td>
  </tr>
  <?php } ?>
</table>
</div></div>
<script type="text/javascript">
function validate_teshMaster() {
	if(document.tech_master.location.value=='')
	{
		alert("Please Select Branch First");
		return false;
	}
	else if(document.tech_master.technician.value=='')
	{
		alert("Please Enter Technician Name");
		return false;
	}
	else if(document.tech_master.mobile_number.value=='')
	{
		alert("Please Enter Technician Mobile Number");
		return false;
	}
	
}
</script>