code

<?php

	// Prepare service string
	@$from    = "FRA";
	@$to      = "JFK";
	@$flight  = "LH400";
	@$date    = "2015-05-12";
	@$cabin   = "M";

	// Get an access token first
	$service_url = "https://api.lufthansa.com/v1/oauth/token";
    $curl = curl_init($service_url);
	curl_setopt($curl, CURLOPT_VERBOSE, 0);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "client_id=XXX&client_secret=XXX&grant_type=client_credentials");
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept:application/json"));
    curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);

    // Execute service call
    $curl_response = curl_exec($curl);
    curl_close($curl);

	// Remove header from service response
    $jsonStartPos = strpos($curl_response, '{"access');
    $curl_json_response = substr($curl_response, $jsonStartPos, strlen($curl_response));
	
	// Extract access token
	$output = json_decode($curl_json_response,true);
	$accessToken = $output["access_token"];

	// Get seatmap
	$service_url = "https://api.lufthansa.com/v1/offers/seatmaps/" . $flight . "/" . $from . "/" . $to . "/" . $date . "/" . $cabin;
    $curl = curl_init($service_url);
	curl_setopt($curl, CURLOPT_VERBOSE, 0);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($curl, CURLOPT_HEADER, true);
	$headers = array("Accept:application/json", "Authorization:Bearer " . $accessToken);
   	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);

    // Execute service call
    $curl_response = curl_exec($curl);
    curl_close($curl);
    
	// Remove header from service response
    $jsonStartPos = strpos($curl_response, 'SeatAvailabilityResource');
    $curl_json_response = substr($curl_response, $jsonStartPos, strlen($curl_response));

	// Prepare service response for processing
    $curl_json_response = str_replace("SeatAvailabilityResource", "{\"SeatAvailabilityResource", $curl_json_response);
    $output = json_decode($curl_json_response,true);
	print("<html><head></head><body>");
	print("<form action='http://www.vanwissen.ch/LHSeatmap.php'>");
	print("<table style='font-family:Arial; font-size:10pt;' border='0'><tr>");
	
	// Extract cabin rows
	// The following if checks, whether we get the SeatDisplay back as an array (e.g. in case of two business class cabins)
	// or as a single element (e.g. in case of one economy class cabin)
	if(is_array($output["SeatAvailabilityResource"]["SeatDisplay"]["Rows"]) == 1){
		$firstRow[0]  = $output["SeatAvailabilityResource"]["SeatDisplay"]["Rows"]["First"];
		$lastRow[0]   = $output["SeatAvailabilityResource"]["SeatDisplay"]["Rows"]["Last"];
		$cabinType[0] = $output["SeatAvailabilityResource"]["SeatDisplay"]["CabinType"]["Code"];
	}
	else{
		for($i=0; $i < 10; $i++){
			$firstRow[$i]  = $output["SeatAvailabilityResource"]["SeatDisplay"][$i]["Rows"]["First"];
			$lastRow[$i]   = $output["SeatAvailabilityResource"]["SeatDisplay"][$i]["Rows"]["Last"];
			$cabinType[$i] = $output["SeatAvailabilityResource"]["SeatDisplay"][$i]["CabinType"]["Code"];
		}
	}

	$actualCabin  = 0;
	$actualRow    = $firstRow[$actualCabin] - 1;
	$actualCol    = 1;
	$aisleSwitch  = false;
	
	// Loop through all seat detail elements
	for($i=0; $i < count($output["SeatAvailabilityResource"]["SeatDetails"]); $i++){
		
		// Check whether row is available or not
		if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Type"]["Code"] == "Z"){
			$actualRow++;
			$actualCol   = 1;
			$aisleSwitch = false;
			continue;
		}
		
		// Check whether a new row was started
		if($actualRow < $output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Number"]){
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Number"] >= $firstRow[$actualCabin] &&
			   $output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Number"] <= $lastRow[$actualCabin]){
				$actualRow++;
				$actualCol   = 1;
				$aisleSwitch = false;
				print("</tr><tr>");
			}
			else{
				$actualCabin++;
				$actualRow   = $firstRow[$actualCabin];
				$actualCol   = 1;
				$aisleSwitch = false;
				print("</tr></table><br><table style='font-family:Arial; font-size:10pt;' border='0'><tr>");
			}
		}

		$seatAvailability          = $output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Availability"]["Code"];
		$seatRow                   = $output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Number"];
		$seatColumn                = $output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Column"];
		$currentSeat_centerSeat    = false;
		$currentSeat_blockedSeat   = false;
		$currentSeat_noSeat        = false;
		$currentSeat_noSeatGalley  = false;
		$currentSeat_aisleSeat     = false;
		$nextSeat_noSeat           = false;
		$nextSeat_aisleSeat        = false;

		// Check seat characteristics for current seat
		$countCharacteristics = count($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"]);
		if($countCharacteristics > 1){
			for($j=0; $j <= $countCharacteristics; $j++){
				// Check whether seat is available
				if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "8"){
					$currentSeat_noSeat = true;
				}
			
				if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "9"){
					$currentSeat_centerSeat = true;
				}
			
				if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "GN"){
					$currentSeat_noSeatGalley = true;
				}
			
				// Check whether seat is an aisle seat
				if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "A"){
					$currentSeat_aisleSeat = true;
				}
			}
		}
		else{
			// Check whether seat is available
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "8"){
				$currentSeat_noSeat = true;
			}
			
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "9"){
				$currentSeat_centerSeat = true;
			}
			
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "GN"){
				$currentSeat_noSeatGalley = true;
			}
			
			// Check whether seat is an aisle seat
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "A"){
				$currentSeat_aisleSeat = true;
			}
		}

		// Check seat characteristics for next seat
		$countCharacteristics = count($output["SeatAvailabilityResource"]["SeatDetails"][$i+1]["Location"]["Row"]["Characteristics"]["Characteristic"]);
		if($countCharacteristics > 1){
			for($j=0; $j <= $countCharacteristics; $j++){
				// Check whether seat is an aisle seat
				if($output["SeatAvailabilityResource"]["SeatDetails"][$i+1]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "A" ||
				   $output["SeatAvailabilityResource"]["SeatDetails"][$i+1]["Location"]["Row"]["Characteristics"]["Characteristic"][$j]["Code"] == "1" ){
					$nextSeat_aisleSeat = true;
				}
			}
		}
		else{
			if($output["SeatAvailabilityResource"]["SeatDetails"][$i+1]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "A" ||
			   $output["SeatAvailabilityResource"]["SeatDetails"][$i+1]["Location"]["Row"]["Characteristics"]["Characteristic"]["Code"] == "1" ){
				$nextSeat_aisleSeat = true;
			}
		}

		// Check for aisle switch
		if($currentSeat_aisleSeat == true && $nextSeat_aisleSeat == true && $aisleSwitch == false){
			$aisleSwitch = true;
		}
		else{
			$aisleSwitch = false;
		}

		// Print seat
		if(($currentSeat_noSeat == true && $currentSeat_centerSeat == false) || ($currentSeat_noSeatGalley == true)){
			print("empty");
			print("<td>&nbsp;</td>");
		}
		else{
			print("<td>°</td>");
		}
			
		// Check whether to print an aisle
		if($aisleSwitch == true){
			print("<td width='14pt' height='23pt' valign='bottom' align='middle'>" . $seatRow . "</td>");
		}
		
		$actualCol++;
	}

	// Close HTML
	print("</tr></table></form></body></html>");
    return $result;
?>
Offers Operations Reference Data oAuth