<?php
////// function call from 2 palces from listing and from edit form when call from edit form $isDropDown send as 1
function getName($approver,$nameId,$isDropDown = 0){
	$id = $_SESSION['id'];
	if($approver == "Associate"){
		if($isDropDown == 1){
			$result = mysql_query("SELECT AScode, AScontact, ASserial FROM associates where companySerial = '$id' AND ASstatus = '1' ORDER BY AScode, AScontact");
			while($row = mysql_fetch_array($result , MYSQL_ASSOC)){
				$aidd = $row["ASserial"];
			 	$return .= "<option value='$aidd' ".(($aidd == $nameId) ? 'selected' : '' ).">".$row["AScode"]." - ".$row["AScontact"]."</option>";
			}
		}else{
			$result = mysql_query("SELECT AScode, AScontact, ASserial FROM associates where companySerial = '$id' AND ASstatus = '1' AND `ASserial` = '".$nameId."'");
			if(mysql_num_rows($result)){
				$row = mysql_fetch_array($result);
				$return = $row["AScode"]." - ".$row["AScontact"];
			}			
		}	
	}elseif($approver == "Consultant"){
		if($isDropDown == 1){
			$result = mysql_query("SELECT conContactName, conCode, conSerial FROM consultants where companySerial = '$id' AND conStatus='1' ORDER BY conCode, conContactName");
			while($row = mysql_fetch_array($result , MYSQL_ASSOC)){
				$cidd = $row["conSerial"];
				$return .= "<option value='$cidd' ".(($cidd == $nameId) ? 'selected' : '' ).">".$row["conCode"]." - ".$row["conContactName"]."</option>";
			}
		}else{
			$result = mysql_query("SELECT conContactName, conCode, conSerial FROM consultants where companySerial = '$id' AND conStatus='1' AND `conSerial` = '".$nameId."'");
			if(mysql_num_rows($result)){
				$row = mysql_fetch_array($result);
				$return = $row["conCode"]." - ".$row["conContactName"];
			}
		}
		
	}elseif($approver == "Client"){
		if($isDropDown == 1){
			$result = mysql_query("SELECT clientContactName, clientCode, clientSerial FROM client where companySerial = '$id' AND clientStatus='1' ORDER BY clientCode, clientContactName");
			while($row = mysql_fetch_array($result , MYSQL_ASSOC))
			{
				$cidd = $row["clientSerial"];
				$return .= "<option value='$cidd' ".(($cidd == $nameId) ? 'selected' : '' ).">".$row["clientCode"]." - ".$row["clientContactName"]."</option>";
			}
		}else{
			
			$result = mysql_query("SELECT clientContactName, clientCode, clientSerial FROM client where companySerial = '$id' AND clientStatus='1' AND clientSerial = '".$nameId."'");
			if(mysql_num_rows($result)){
				$row = mysql_fetch_array($result);
				$return = $row["clientCode"]." - ".$row["clientContactName"];
			}
		}
		
	}elseif($approver == "Vendor"){
		if($isDropDown == 1){
			$result = mysql_query("SELECT resSerial, resCatCode, resSubCatCode, resName, vendFname, vendLname FROM resources, resourcecategory, resourcesubcategory where resources.companyID='$id' AND resources.resStatus='1' AND resourcecategory.resCatSerial=resources.rescatID AND  resourcesubcategory.resSubCatSerial=resources.ressubcatID AND resourcecategory.resCatCode = 'VEN' ORDER BY resCatCode, resSubCatCode, resName, vendFname, vendLname");
			while($row = mysql_fetch_array($result , MYSQL_ASSOC)){
				$s = $row['resSerial'];
			 	$return .= "<option value='$s' ".(($s == $nameId) ? 'selected' : '' ).">".$row["resCatCode"]." - ".$row["resSubCatCode"]." - ".$row["resName"]. " - " . $row['vendFname']. " - " . $row['vendLname']."</option>";
			}
		}else{
			$result = mysql_query("SELECT resSerial, resCatCode, resSubCatCode, resName, vendFname, vendLname FROM resources, resourcecategory, resourcesubcategory where resources.companyID='$id' AND resources.resStatus='1' AND resourcecategory.resCatSerial=resources.rescatID AND  resourcesubcategory.resSubCatSerial=resources.ressubcatID AND resourcecategory.resCatCode = 'VEN' AND resSerial = '".$nameId."'");
			if(mysql_num_rows($result)){
				$row = mysql_fetch_array($result);
				$return = $row["resCatCode"]." - ".$row["resSubCatCode"]." - ".$row["resName"]. " - " . $row['vendFname']. " - " . $row['vendLname'];
			}
		}
	}elseif($approver == "Team"){
		if($isDropDown == 1){
			$result2 = mysql_query("SELECT internal_personnel_id,internal_personnel_firstName,internal_personnel_lastName,abbreviation FROM internal_personnel,company where internal_personnel.internal_personnel_company_id = '$id' AND internal_personnel.internal_personnel_status=1 AND internal_personnel.internal_personnel_company_id=company.serial order by abbreviation, internal_personnel_firstName, internal_personnel_lastName");
			while($row2 = mysql_fetch_array($result2 , MYSQL_ASSOC)){				
				$return .= "<option ".(($row2['internal_personnel_id'] == $nameId) ? 'selected' : '' )." value='".$row2['internal_personnel_id']."'> ".$row2["abbreviation"] . " - " . $row2["internal_personnel_firstName"] . " " . $row2["internal_personnel_lastName"] ."</option>";				
			}
		}else{
			$result2 = mysql_query("SELECT internal_personnel_id,internal_personnel_firstName,internal_personnel_lastName,abbreviation FROM internal_personnel,company where internal_personnel.internal_personnel_company_id = '$id' AND internal_personnel.internal_personnel_status=1 AND internal_personnel.internal_personnel_company_id=company.serial AND internal_personnel_id = '".$nameId."' ");
			if(mysql_num_rows($result2)){
				$row2 = mysql_fetch_array($result2);
				$return = $row2["abbreviation"] . " - " . $row2["internal_personnel_firstName"] . " " . $row2["internal_personnel_lastName"];
			}
		}
	}
	return $return;
}
?>