Where pilots and airlines come together

The virtual airline blog

This is our blog with lots of useful tips about PHPvms and running VA's in general. We've just started but we got a lot in the pipeline, so keep an eye on this space!
Note that not all blog posts are public, so if you're not a member, sign up now to get the best out of this site. If you have any questions, don't hesitate to contact us.

Airport info API

In the olden days, when you wanted to add an airport to your VA, you could click on the lookup button and it would fill the fields for you. This has been inoperative for quite a while now, much to the annoyance of VA admins. Virtualairlines.eu now launched a service that will let you do exactly the same, and we have some extra fields as well. This is what you need to do

Go to /admin/lib/phpvmsadmin.js and scroll to line 250 where it says:

url = phpvms_api_server + "/airport/get/" + icao + "&callback=?";

replace it with:

url = phpvms_api_server + "/airports.php?icao="+ icao+ "&callback=?";

You also need to make sure that phpvms_api_server entry in your config is set to https://virtualairlines.eu but if you are a member here, you probably got that down already.

Along with the standard latitutde, longitude, airport and country name, we give you five extra fields: altitude, iata code, timezone offset, timezone name and city name

How to get these extra fields in your admin section

First of all, go back to your phpvmsadmin.js you added earlier, and add the following lines: (after the line$("#airportlong").val(item.lng);)

	$("#airportcity").val(item.city);
	$("#airportiata").val(item.iata);
	$("#airporttimezone").val(item.timezone);
	$("#airportdbtimezone").val(item.dbtimezone);
	$("#airportaltitude").val(item.altitude);

Then you go to /admin/templates/ops_airportform.php (or tpl) and paste the following lines within the form:

	
<dd><input id="airportaltitude" name="altitude" type="text" value="<?php echo $airport->altitude ?>" /></dd>

<dt>City</dt>
<dd><input id="airportcity" name="city" type="text" value="<?php echo $airport->city?>" /></dd>

<dt>Timezone offset (hours)</dt>
<dd><input id="airporttimezone" name="timezone" type="text" value="<?php echo $airport->timezone?>" /></dd>

<dt>Timezone name</dt>
<dd><input id="airportdbtimezone" name="dbtimezone" type="text" value="<?php echo $airport->dbtimezone?>" /></dd>

<dt>IATA code</dt>
<dd><input id="airportiata" name="iata" type="text" value="<?php echo $airport->iata?>" /></dd>

You can either add them alltogether at the end or add it in between, eg city after country and iata after icao code. Technically it doesn't matter. Next you open up /admin/modules/operations/operations.php and scroll to around line 827 in the add_airport_post function. There you see an array with airport data being built. Add the following lines to the array:

		city'=> $this->post->city,
		'timezone'=> $this->post->timezone,
		'dbtimezone'=> $this->post->dbtimezone,
		'iata'=> $this->post->iata
		

Then scroll down a bit to 878 (edit_airport_post) and you do the same. Next up is the /core/commom/operationsdata.php which will add our data to the database. Go to around line 559 and remove the entire line with the sql statement, replace it with this:

			if($data['timezone'] == '')
		
			$data['timezone'] = 0;
				
			if($data['altitude'] == '')
		
			$data['altitude'] = 0; 
		
			
		
			$sql = "INSERT INTO " . TABLE_PREFIX ."airports
		
			( `icao`, `name`, `country`, `lat`, `lng`, `hub`, `chartlink`, `fuelprice`, `iata`, `city`, `altitude`, `timezone`, `dbtimezone`)
		
			VALUES (
		
			'{$data['icao']}', '{$data['name']}', '{$data['country']}',
		
			{$data['lat']}, {$data['lng']}, {$data['hub']}, '{$data['chartlink']}', {$data['fuelprice']}
		
			, '{$data['iata']}', '{$data['city']}', {$data['altitude']}, {$data['timezone']}, '{$data['dbtimezone']}')";
	
	

Then go to around line 615 and remove the entire line with the sql statement. replace it with this:

			if($data['timezone'] == '')
		
			$data['timezone'] = 0;
		
			
		
			if($data['altitude'] == '')
		
			$data['altitude'] = 0; 
		
			
		
			$sql = "UPDATE " . TABLE_PREFIX . "airports
		
			SET `icao`='{$data['icao']}', `name`='{$data['name']}', `country`='{$data['country']}',
		
			`lat`={$data['lat']}, `lng`={$data['lng']}, `hub`={$data['hub']},
		
			`chartlink`='{$data['chartlink']}', `fuelprice`={$data['fuelprice']}
		
			,`iata`='{$data['iata']}',`city`='{$data['city']}',`altitude`={$data['altitude']},`timezone`={$data['timezone']},`dbtimezone`='{$data['dbtimezone']}'
		
			WHERE `icao`='{$data['icao']}'";
	
	

Last but not least, before you try any of this run the following SQL statement on your database to create the necessary fields:

		ALTER TABLE `phpvms_airports` ADD `IATA` VARCHAR(3) NULL AFTER `chartlink`, ADD `city` VARCHAR(255) NULL AFTER `IATA`, ADD `altitude` INT(11) NULL AFTER city, ADD `timezone` INT(11) NULL AFTER `altitude`, ADD `dbtimezone` VARCHAR(50) NULL AFTER `timezone`;