Jump to content

New: airport lookup server with extended data


Recommended Posts

Posted (edited)

Hello all,

I know lots of you have been annoyed with the absence of the airport lookup function in PHPvms.. well at least I was! 

So, in a bid to save time not just for myself but also for you, I've recreated a service that provides the same functionality with minimal changes but some extra data :) 

All you have to do is this:

1) Go to your local.config.php / app.config.php to change your phpvms_api_server to https://virtualairlines.eu .. if you haven't already :)

2) 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=?";

save it all on your server and the airport lookup should work again! Note that this seems not to work with firefox or internet explorer! Chrome is your safest bet. 

Now, I have some extra goodies up my sleeve: for every airport I also have the IATA code, city name, timezone offset, dbtimezone and altitude. Don't worry, airport lookup will work without it, but if you want these extra data you have them available now.

In the next couple of days I'm going to post on my blog how to implement these extra values and display them on a website.  If you have any questions or comments let me know in the comments below.

Oh, and I *guarantee* that I will provide this service for free as long as I run this website - although I may restrict it to members of virtualairlines.eu at some point in the future. 

 

Edited by mischka
Posted (edited)

have you changed the phpvms_api_server in the local.config.php or app.config.php? I just did the change on another website (a clean 5.5.2 install) and the lookup works flawlessly.  

on chrome you can hit F12 and look at the console. You should see some kind of error there. If you are 100% sure you are querying virtualairlines.eu and not the old api server, drop me a PM and attach the phpvmsadmin.js and specify your phpvms version

Edited by mischka
Posted
2 minutes ago, CPC900 said:

Ok, the airport lookup worked in Chrome, but NOT in Firefox.....I had been using Firefox ;)

Ooh, that's odd. It might be some security setting that was implemented after vacentral went down. The only thing you change is the address of the server name. 

Do you get any error messages in firefox?

Posted
1 hour ago, Nabeel said:

You still need the " "&callback=?";" portion. It might not be working because it needs the JSONP callback

what callback did you use in the jsonp though? as far as I researched, you had to add some kind of java bit to the json

  • Administrators
Posted
14 minutes ago, mischka said:

what callback did you use in the jsonp though? as far as I researched, you had to add some kind of java bit to the json

I'm trying to find my code for that... but I don't know where the code is. Hmm. What you basically do is:

#instead of this:
return jsonencode({"some" => "structure"});

# you do:
return $_GET["callback"] . '(' . jsonencode({"some" => "structure"}) . ')';

So you're essentially wrapping the JSON that's returned. So if the request is:

airports?icao=KJFK&callback=somefn

(the browser populates "somefn" with some name, it gets returned as:

somefn({JSON});

  • Like 1
  • 3 weeks later...
Posted (edited)

mischka, I followed the instructions to add the extended values. For some reason the table on my admin side isn't showing the extra information, yet it populates when searching and in the db.

admin2_zps6gke3dit.png

admin3_zpsta6izvub.png

Here is what I changed in ops.airportlist.php:

colNames: ['ICAO', 'IATA', 'Airport Name', 'Hub', 'Country', 'City', 'Fuel Cost', 'Altitude', 'Lat', 'Lng', 'TZ Offset', 'Timezone', 'Edit'],
   colModel : [
        {index: 'icao', name : 'icao', width: 30, sortable : true, align: 'center', search: 'true', searchoptions:{sopt:['eq','ne']}},
        {index: 'iata', name : 'iata', width: 30, sortable : true, align: 'center', searchoptions:{sopt:['in']}},
        {index: 'name', name : 'name', width: 65, sortable : true, align: 'center', searchoptions:{sopt:['in']}},
        {index: 'hub', name : 'hub', width: 15, sortable : true, align: 'center', search: 'false'},
        {index: 'country', name : 'country', width: 65, sortable : true, align: 'center', searchoptions:{sopt:['in']}},
        {index: 'city', name : 'city', width: 65, sortable : true, align: 'center', search:false},
        {index: 'fuelprice', name : 'fuelprice', width: 30, sortable : true, align: 'center', search:false},
        {index: 'altitude', name : 'altitude', width: 25, sortable : true, align: 'center', search:false},
        {index: 'lat', name : 'lat', width: 40, sortable : true, align: 'center', search:false},
        {index: 'lng', name : 'lng', width: 40, sortable : true, align: 'center', search:false},
        {index: 'timezone', name : 'timezone', width: 40, sortable : true, align: 'center', search:false},
        {index: 'dbtimezone', name : 'dbtimezone', width: 65, sortable : true, align: 'center', search:false},
        {index: '', name : '', width: 100, sortable : true, align: 'center', search: false}

 

This is what was changed in the phpvmsadmin.js:

$.each(data.airports, function(i, item) {
				$("#airporticao").val(icao);
				$("#airportiata").val(item.iata);
                                $("#airportname").val(item.name);
				$("#airportcity").val(item.city);
				$("#airportcountry").val(item.countryName);
				$("#airportlat").val(item.lat);
				$("#airportlong").val(item.lng);
				$("#airportaltitude").val(item.altitude);
				$("#fuelprice").val(item.jeta);
				$("#airporttimezone").val(item.timezone);
				$("#airportdbtimezone").val(item.dbtimezone);

				$("#statusbox").html("");
				$("#lookupicao").show();

 

The ops_airportform.php is changed at instructed:

admin4_zpsgsyzp8zf.png

 

Changed in operations.php:

$data = array('icao' => $this->post->icao, 'iata'=> $this->post->iata, 'name' => $this->post->name, 'hub' => $this->post->hub,
              'country' => $this->post->country, 'city'=> $this->post->city, 'fuelprice' => $this->post->fuelprice,
              'altitude'=> $this->post->altitude, 'lat' => $this->post->lat, 'lng' => $this->post->lng, 
              'timezone'=> $this->post->timezone, 'dbtimezone'=> $this->post->dbtimezone, 'chartlink' => $this->post->chartlink);

 

operationsdata.php:

Line 550:

if ($data['icao'] == '') return false;

        $data['icao'] = strtoupper(DB::escape($data['icao']));
        $data['name'] = DB::escape($data['name']);

        if ($data['hub'] === true) $data['hub'] = 1;
        else  $data['hub'] = 0;

        if ($data['fuelprice'] == '') $data['fuelprice'] = 0;

        if (!isset($data['chartlink'])) {
            $data['chartlink'] = '';
        }

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

        $res = DB::query($sql);

        if (DB::errno() != 0) return false;

        CodonCache::delete('all_airports');
        CodonCache::delete('all_airports_json');
        CodonCache::delete('get_airport_' . $data['icao']);
        return true;

    }

Line 596:

 

public static function editAirport($data) {
        $data['icao'] = strtoupper(DB::escape($data['icao']));
        $data['name'] = DB::escape($data['name']);

        if ($data['hub'] === true) $data['hub'] = 1;
        else  $data['hub'] = 0;

        if ($data['fuelprice'] == '') $data['fuelprice'] = 0;

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

        $res = DB::query($sql);

        if (DB::errno() != 0) return false;

        CodonCache::delete('get_airport_' . $data['icao']);
        CodonCache::delete('all_airports_json');
        CodonCache::delete('all_airports');
        return true;
    }

I'm scratching my head over this and can't figure out how to get the columns to give the correct information. Any suggestions?

Edited by Longhaul444
Posted

Hi there,

So far I have done this from the first post:

Quote

All you have to do is this:

1) Go to your local.config.php / app.config.php to change your phpvms_api_server to https://virtualairlines.eu .. if you haven't already :)

2) 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=?";

save it all on your server and the airport lookup should work again! 

I am using Chrome and when using "Add new Airport" still only get:

Quote

Fetching airport data...

Have not as yet tried "Import Schedules & Routes.

Posted (edited)

I'd really love to get this working correctly, as it makes the airport listings more professional looking. Just can't get the columns in the admin section to populate correctly. Haven't tried the import/export yet either.

Screenshot_1_zpspaqukwc4.png

Screenshot_2_zpslxxbprac.png

 

 

Edited by Longhaul444
Posted
5 hours ago, david said:

Hi there,

So far I have done this from the first post:

I am using Chrome and when using "Add new Airport" still only get:

Have not as yet tried "Import Schedules & Routes.

When you press F12 in chrome, do you get any error messages?

4 hours ago, Longhaul444 said:

I'd really love to get this working correctly, as it makes the airport listings more professional looking. Just can't get the columns in the admin section to populate correctly. Haven't tried the import/export yet either.

Screenshot_1_zpspaqukwc4.png

Screenshot_2_zpslxxbprac.png

 

I just tried to add NTSU and it says added but it's not in db

Ok, I'm confused.. the airport lookup itself works, but the extra fields don't show up in the columns in the grid? I never thought of extending the grid to be honest, I'd have to look into it.

Posted
1 hour ago, mischka said:

When you press F12 in chrome, do you get any error messages?

Yes

Capture.JPG

Hope this helps.

I did add the google maps API key to "core/templates/core_htmlhead.tpl the other night which fixed routes not being displayed on the public side of the website

but has not fixed routes not being displayed in the admin panel ie:routes in PIREP's. I have posted about this in another post and on Discord #support.

I have Discord if you want to catch up and talk (UTC+11)

Posted
3 hours ago, mischka said:

Ok, I'm confused.. the airport lookup itself works, but the extra fields don't show up in the columns in the grid? I never thought of extending the grid to be honest, I'd have to look into it.

Could you? That would be awesome if you could figure out where I went wrong. I've been racking my brain for days now trying to figure out what is wrong. Anything you need from me to help figure this out please let me know.

Posted

In my operations.php, around line 338, I have this:

            $tmp = array(
                'id' => $row->id,
                'cell' => array(
                        # Each column, in order
                        $row->icao,
                        $row->name,
                        $row->country,
                        $row->fuelprice,
                        $row->lat,
                        $row->lng,
                        $edit,
                        ),
                    );

Have you added the new fields there?

Posted
13 minutes ago, mischka said:

In my operations.php, around line 338, I have this:

            $tmp = array(
                'id' => $row->id,
                'cell' => array(
                        # Each column, in order
                        $row->icao,
                        $row->name,
                        $row->country,
                        $row->fuelprice,
                        $row->lat,
                        $row->lng,
                        $edit,
                        ),
                    );

Have you added the new fields there?

AH, that might be the piece that's missing. let me try and see what happens

Posted (edited)

Screenshot_3_zpslx8rar3u.png

 

That worked! Now I just have to figure out why the IATA code isn't going in. Thanks for the missing piece to the puzzle. And I haven't tried the import function yet either, I'll get back to ya in a bit.

Edited by Longhaul444
Posted

might be a case senstive problem (iata vs IATA)

by import you mean the automatic add of airports when importing schedules? That *should* work, cause afaik it uses the same mechanism. I haven't tried it myself actually :)

Posted
3 minutes ago, mischka said:

might be a case senstive problem (iata vs IATA)

by import you mean the automatic add of airports when importing schedules? That *should* work, cause afaik it uses the same mechanism. I haven't tried it myself actually :)

Yup that was exactly the case. My db had IATA and it was looking for iata. Working beautifully now, thanks for the help. Hopefully the schedules still work. And I changed the template form for the airports admin/lib/airport_template.csv as well to show the extra colums:

icao,iata,name,hub,country,city,fuelprice,altitude,lat,lng,timezoneoffset,timezone,chartlink 

Posted (edited)
4 hours ago, mischka said:

It's strange... the 2nd line below doesn't show the full url you are calling. 

What is the actual url of your website? Can you send me your phpvms.js by PM? 

Is this for me or Longhaul444?

If for me URL is: http://msfairways.net

Quote

VACENTRAL_API_SERVER to https://virtualairlines.eu

I have check this and it has not been changed.

Should I copy this line over to the local.config.php file and edit it?

David.

Oz Flyer.

Edited by david
Posted
18 hours ago, david said:

I have check this and it has not been changed.

Should I copy this line over to the local.config.php file and edit it?

David.

Oz Flyer.

Yes, you need to make the change or add it to your local.config.php otherwise you are just querying the old vacentral server

Posted (edited)

Sorry for my lateness, we got hammered by a snow storm nobody was expecting. Almost a foot of snow. Power just came back on. Ah I see mischka beat me to it. :)

Edited by Longhaul444
Posted

Still not working.

Now today the add airport is no longer a popup window but a fresh page of is own and when you click look up you get a blank page with "Some fields were blank" 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...