/**
  * Retrieve Airport Information
  */
 public static function RetrieveAirportInfo($icao)
 {
     $icao = strtoupper($icao);
     if (Config::Get('AIRPORT_LOOKUP_SERVER') == 'geonames') {
         $url = Config::Get('GEONAME_API_SERVER') . '/searchJSON?maxRows=1&style=medium&featureCode=AIRP&type=json&q=' . $icao;
     } elseif (Config::Get('AIRPORT_LOOKUP_SERVER') == 'phpvms') {
         $url = Config::Get('PHPVMS_API_SERVER') . '/index.php/airport/get/' . $icao;
     }
     # Updated to use CodonWebServer instead of simplexml_load_url() straight
     #	Could cause errors
     $file = new CodonWebService();
     $contents = @$file->get($url);
     $reader = json_decode($contents);
     if ($reader->totalResultsCount == 0 || !$reader) {
         return false;
     } else {
         if (isset($reader->geonames)) {
             $apt = $reader->geonames[0];
         } elseif (isset($reader->airports)) {
             $apt = $reader->airports[0];
         }
         if (!isset($apt->jeta)) {
             $apt->jeta = '';
         }
         // Add the AP
         $data = array('icao' => $icao, 'name' => $apt->name, 'country' => $apt->countryName, 'lat' => $apt->lat, 'lng' => $apt->lng, 'hub' => false, 'fuelprice' => $apt->jeta);
         OperationsData::addAirport($data);
     }
     return self::GetAirportInfo($icao);
 }
Example #2
0
    public function importairports()
    {
        if (!file_exists($_FILES['uploadedfile']['tmp_name'])) {
            $this->render('airport_import_form.php');
            return;
        }
        echo '<h3>Processing Import</h3>';
        # Get the column headers
        $allaircraft = OperationsData::getAllAirports(false);
        $headers = array();
        $dbcolumns = DB::get_cols();
        foreach ($dbcolumns as $col) {
            $headers[] = $col->name;
        }
        $temp_name = $_FILES['uploadedfile']['tmp_name'];
        $new_name = CACHE_PATH . '/' . $_FILES['uploadedfile']['name'];
        if (!move_uploaded_file($temp_name, $new_name)) {
            $this->render('core_error.php');
            $this->set('message', 'Shit the bed?');
            return false;
        }
        $fp = fopen($new_name, 'r');
        if (isset($_POST['header'])) {
            $skip = true;
        }
        $added = 0;
        $updated = 0;
        $total = 0;
        echo '<div style="overflow: auto; height: 400px; 
					border: 1px solid #666; margin-bottom: 20px; 
					padding: 5px; padding-top: 0px; padding-bottom: 20px;">';
        if (isset($_POST['erase_airports'])) {
            OperationsData::deleteAllAirports();
            echo "Deleting All Airports<br />";
        }
        while ($fields = fgetcsv($fp, 1000, ',')) {
            // Skip the first line
            if ($skip == true) {
                $skip = false;
                continue;
            }
            //Check for empty lines, continue
            if (empty($fields)) {
                continue;
            }
            //Create Varibles...
            $icao = $fields[0];
            $name = $fields[1];
            $country = $fields[2];
            $lat = $fields[3];
            $lng = $fields[4];
            $hub = $fields[5];
            $fuelprice = $fields[6];
            $chartlink = $fields[7];
            //Since we need the values filled in, if not, then continue
            if (empty($icao) || empty($lat) || empty($lng)) {
                continue;
            }
            # Enabled or not
            if ($hub == '1') {
                $hub = true;
            } else {
                $hub = false;
            }
            //Build Array, seem can't use the array merge for some reason...
            $data = array('icao' => $fields[0], 'name' => $fields[1], 'country' => $fields[2], 'lat' => $fields[3], 'lng' => $fields[4], 'hub' => $hub, 'fuelprice' => $fields[6], 'chartlink' => $fields[7]);
            # Does this airport exist?
            $aiport_info = OperationsData::getAirportInfo($icao);
            if ($aiport_info) {
                echo "Editing {$icao} - {$name}<br>";
                OperationsData::editAirport($data);
                $updated++;
            } else {
                echo "Adding {$icao} - {$name}<br>";
                OperationsData::addAirport($data);
                $added++;
            }
            $total++;
        }
        //You should always close a file before deleting otherwise it will spit the unlink error due to permissions
        fclose($fp);
        unlink($new_name);
        echo "The import process is complete, added {$added} airports, updated {$updated}, for a total of {$total}<br />";
    }