Example #1
0
 function show(ATC $controller)
 {
     if (!is_null($controller->airport_id) && $controller->facility_id >= 2 && $controller->facility_id <= 5) {
         $otherControllers = ATC::whereAirportId($controller->airport_id)->whereNull('end')->where('facility_id', '<', $controller->facility_id)->orderBy('facility_id', 'desc')->pluck('facility_id');
         $otherControllers = range(max(2, $otherControllers + 1), $controller->facility_id);
     } else {
         $otherControllers = array();
     }
     if ($controller->pilot->getOriginal('updated_at') == '0000-00-00 00:00:00') {
         Queue::push('LegacyUpdate', $controller->pilot->vatsim_id, 'legacy');
         $controller->pilot->processing = 2;
         $controller->pilot->save();
     }
     $this->autoRender(compact('controller', 'otherControllers'), $controller->callsign);
 }
 function show(Pilot $pilot)
 {
     $actives = ATC::with('airport', 'airport.country')->whereVatsimId($pilot->vatsim_id)->whereNull('end')->where('facility_id', '!=', 99)->get();
     $duties = ATC::with('airport', 'airport.country')->whereVatsimId($pilot->vatsim_id)->whereNotNull('end')->where('facility_id', '!=', 99)->orderBy('end', 'desc')->take(15)->get();
     if ($pilot->processing == 0) {
         Queue::push('LegacyUpdate', $pilot->vatsim_id, 'legacy');
         $pilot->processing = 2;
         $pilot->save();
     }
     if ($pilot->processing == 2) {
         Messages::success('The data for this controller is currently being processed. In a couple of minutes, all statistics will be available.')->one();
     }
     $stat = new ControllerStat(ATC::whereVatsimId($pilot->vatsim_id)->where('facility_id', '!=', 99));
     extract($stat->durations($pilot->duration_atc));
     $airports = $stat->topAirports();
     $facilities = $stat->topFacilities();
     $this->javascript('assets/javascript/jquery.flot.min.js');
     $this->javascript('assets/javascript/jquery.flot.pie.min.js');
     $this->autoRender(compact('pilot', 'duties', 'actives', 'airport', 'airports', 'longest', 'hours', 'minutes', 'facilities'), $pilot->name);
 }
Example #3
0
    $globalDebug = FALSE;
}
// Check if schema is at latest version
$schema = new Connection();
if ($schema->latest() === false) {
    echo "You MUST update to latest schema. Run install/index.php";
    exit;
}
if (isset($globalServer) && $globalServer) {
    $SI = new SpotterServer();
} else {
    $SI = new SpotterImport();
}
$APRS = new APRS();
$SBS = new SBS();
$ATC = new ATC();
$Common = new Common();
date_default_timezone_set('UTC');
// signal handler - playing nice with sockets and dump1090
if (function_exists('pcntl_fork')) {
    pcntl_signal(SIGINT, function ($signo) {
        global $sockets;
        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
        die("Bye!\n");
    });
    pcntl_signal_dispatch();
}
// let's try and connect
if ($globalDebug) {
    echo "Connecting...\n";
}
Example #4
0
 public function become_user_from_session($sessid)
 {
     $details = self::check_user_session($sessid);
     if ($details) {
         self::$currentuser = $details->personnel_id;
         self::$currentpermissions = $details->access_rights;
     }
 }
Example #5
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
if (!isset($_GET['action'])) {
    $id = isset($_GET['id']) ? (int) $_GET['id'] : null;
    $user = $ATC->get_personnel($id);
    if (isset($_POST['personnel_id']) && isset($_GET['id'])) {
        foreach ($_POST as $var => $val) {
            $user->{$var} = $val;
        }
        if (!isset($_POST['enabled']) || !$_POST['enabled']) {
            $user->enabled = 0;
        }
        if (!isset($_POST['social_media_approved']) || !$_POST['social_media_approved']) {
            $user->social_media_approved = 0;
        }
        try {
            $ATC->set_personnel($user);
        } catch (ATCExceptionInsufficientPermissions $e) {
            header("HTTP/1.0 401 Unauthorised");
            echo 'Caught exception: ', $e->getMessage(), "\n";
            exit;
        } catch (ATCExceptionDBError $e) {
            header("HTTP/1.0 500 Internal Server Error");
            echo 'Caught exception: ', $e->getMessage(), "\n";
            exit;
        } catch (ATCExceptionDBConn $e) {
            header("HTTP/1.0 500 Internal Server Error");
            echo 'Caught exception: ', $e->getMessage(), "\n";
            exit;
Example #6
0
             }
             if (isset($line['arricao'])) {
                 $data['arrival_airport_icao'] = $line['arricao'];
             }
             //$data['arrival_airport_time'] = $line['arrtime'];
             if (isset($line['aircraft'])) {
                 $data['aircraft_icao'] = $line['aircraft'];
             }
             if (isset($line['transponder'])) {
                 $data['squawk'] = $line['transponder'];
             }
             $data['datetime'] = date('Y-m-d h:i:s');
             if ($line['icon'] == 'plane') {
                 $SBS::add($data);
             } elseif ($line['icon'] == 'ct') {
                 echo ATC::add($data['ident'], '', $data['latitude'], $data['longitude'], '0', '', $data['datetime'], '', $data['pilot_id'], $data['pilot_name']);
             }
             unset($data);
         }
     }
 } elseif ($value == 'phpvmacars') {
     $buffer = Common::getData($hosts[$id]);
     $all_data = json_decode($buffer, true);
     foreach ($all_data as $line) {
         $data = array();
         $data['id'] = $line['id'];
         // id
         $data['hex'] = str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT);
         // hex
         if (isset($line['pilotname'])) {
             $data['pilot_name'] = $line['pilotname'];
<?php

require_once "atc.class.php";
$ATC = new ATC();
$id = isset($_GET['id']) ? $_GET['id'] : null;
$what = isset($_GET['what']) && trim(strtolower($_GET['what'])) == 'personal' ? 'personal' : 'nok';
$how = isset($_GET['how']) && trim(strtolower($_GET['how'])) == 'email' ? 'email' : 'sms';
$returnvalue = array();
if (is_array($id)) {
    foreach ($id as $personnel) {
        if ($ATC->user_has_permission(ATC_PERMISSION_PERSONNEL_VIEW, $personnel)) {
            switch (strtolower(trim($what))) {
                case 'personal':
                    $details = $ATC->get_personnel($personnel, 'ASC', null);
                    if ($details && isset($details->display_name)) {
                        switch (strtolower(trim($how))) {
                            case 'sms':
                                if ($details->mobile_phone) {
                                    $returnvalue[] = $details->mobile_phone;
                                }
                                break;
                            case 'email':
                                $returnvalue[] = '"' . $details->rank . ' ' . $details->display_name . '" <' . $details->email . '>';
                                break;
                            default:
                                throw new ATCExceptionBadData('Unknown "how" URL variable.');
                        }
                    }
                    break;
                case 'nok':
                    $details = $ATC->get_nok($personnel);
Example #8
0
<?php

require 'require/class.Connection.php';
require 'require/class.ATC.php';
if (isset($_GET['download'])) {
    header('Content-disposition: attachment; filename="atc.geojson"');
}
header('Content-Type: text/javascript');
$ATC = new ATC();
if (isset($_GET['coord'])) {
    //$coords = explode(',',$_GET['coord']);
    $spotter_array = $ATC->getAll();
} else {
    $spotter_array = $ATC->getAll();
}
$output = '{"type": "FeatureCollection","features": [';
if (!empty($spotter_array)) {
    foreach ($spotter_array as $spotter_item) {
        date_default_timezone_set('UTC');
        //waypoint plotting
        $output .= '{"type": "Feature",';
        $output .= '"properties": {';
        $output .= '"ident": "' . $spotter_item['ident'] . '",';
        $output .= '"frequency": "' . $spotter_item['frequency'] . '",';
        $radius = $spotter_item['atc_range'] * 100;
        $output .= '"atc_range": "' . $radius . '",';
        $output .= '"ivao_id": "' . $spotter_item['ivao_id'] . '",';
        $output .= '"ivao_name": "' . $spotter_item['ivao_name'] . '",';
        $output .= '"info": "' . $spotter_item['info'] . '",';
        $output .= '"type": "' . $spotter_item['type'] . '"';
        $output .= '},';
 /**
  * Checks whether the ATC controller has relocated
  * to another location.
  *
  * @param  \ATC   $atc
  * @param  array  $datafeed
  * @return boolean
  */
 protected function hasRelocated($atc, $datafeed)
 {
     return $datafeed['longitude'] != $atc->getOriginal('lon') || $datafeed['latitude'] != $atc->getOriginal('lat');
 }
Example #10
0
|
*/
Route::bind('flight', function ($value) {
    $flight = Flight::with(['aircraft', 'departure', 'arrival', 'pilot', 'departureCountry', 'arrivalCountry', 'airline', 'positions' => function ($positions) {
        $positions->join('updates', 'positions.update_id', '=', 'updates.id');
        $positions->select('positions.*', DB::raw('updates.timestamp AS time'));
        $positions->orderBy('time', 'asc');
    }])->find($value);
    if (is_null($flight) || $value == 0) {
        return App::abort(404);
    } else {
        return $flight;
    }
});
Route::bind('atc', function ($value) {
    $atc = ATC::with('pilot')->find($value);
    if (is_null($atc) || $value == 0) {
        return App::abort(404);
    } else {
        return $atc;
    }
});
Route::bind('pilot', function ($value) {
    $pilot = Pilot::whereVatsimId($value)->first();
    if (is_null($pilot) || $value == 0) {
        return App::abort(404);
    } else {
        return $pilot;
    }
});
Route::bind('airport', function ($value, $route) {
Example #11
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
if (isset($_POST['firstname_0']) && isset($_GET['id'])) {
    try {
        foreach ($_POST['nok_id'] as $i) {
            if (strlen(trim($_POST['firstname_' . $i])) && strlen(trim($_POST['lastname_' . $i]))) {
                $ATC->set_next_of_kin($i, $_GET['id'], $_POST['firstname_' . $i], $_POST['lastname_' . $i], $_POST['relationship_' . $i], $_POST['email_' . $i], $_POST['mobile_' . $i], $_POST['home_' . $i], $_POST['address1_' . $i], $_POST['address2_' . $i], $_POST['city_' . $i], $_POST['postcode_' . $i]);
            }
        }
    } catch (ATCExceptionInsufficientPermissions $e) {
        header("HTTP/1.0 401 Unauthorised");
        echo 'Caught exception: ', $e->getMessage(), "\n";
        exit;
    } catch (ATCExceptionDBError $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
        exit;
    } catch (ATCExceptionDBConn $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
        exit;
    } catch (ATCException $e) {
        header("HTTP/1.0 400 Bad Request");
        echo 'Caught exception: ', $e->getMessage(), "\n";
        exit;
    } catch (Exception $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
Example #12
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
if (isset($_POST['startdate']) && strtotime($_POST['startdate']) && isset($_POST['enddate']) && strtotime($_POST['enddate'])) {
    try {
        $ATC->add_term(strtotime($_POST['startdate']), strtotime($_POST['enddate']));
    } catch (ATCExceptionInsufficientPermissions $e) {
        header("HTTP/1.0 401 Unauthorised");
        echo 'Caught exception: ', $e->getMessage(), "\n";
    } catch (ATCExceptionDBError $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
    } catch (ATCExceptionDBConn $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
    } catch (ATCException $e) {
        header("HTTP/1.0 400 Bad Request");
        echo 'Caught exception: ', $e->getMessage(), "\n";
    } catch (Exception $e) {
        header("HTTP/1.0 500 Internal Server Error");
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }
    exit;
    // Save the attendance register
} elseif (isset($_POST['attendance_register']) && $_POST['attendance_register']) {
    try {
        foreach ($_POST as $entry => $status) {
            $foo = explode("|", $entry);
            if (count($foo) == 2) {
                $ATC->set_attendance_register($foo[0], $foo[1], $status);
Example #13
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['username']) && isset($_POST['password'])) {
        try {
            if ($ATC->login($_POST['username'], $_POST['password'])) {
                header('Location: ./', true, 302);
            }
        } catch (ATCExceptionInsufficientPermissions $e) {
            header("HTTP/1.0 401 Unauthorised");
            echo 'Caught exception: ', $e->getMessage(), "\n";
        } catch (ATCExceptionDBError $e) {
            header("HTTP/1.0 500 Internal Server Error");
            echo 'Caught exception: ', $e->getMessage(), "\n";
        } catch (ATCExceptionDBConn $e) {
            header("HTTP/1.0 500 Internal Server Error");
            echo 'Caught exception: ', $e->getMessage(), "\n";
        } catch (ATCException $e) {
            header("HTTP/1.0 400 Bad Request");
            echo 'Caught exception: ', $e->getMessage(), "\n";
        } catch (Exception $e) {
            header("HTTP/1.0 500 Internal Server Error");
            echo 'Caught exception: ', $e->getMessage(), "\n";
        }
    }
}
if ($ATC->current_user_id()) {
    header('Location: ./', true, 302);
}
Example #14
0
 function fire($job, $vatsim_id)
 {
     $pilot = Pilot::whereVatsimId($vatsim_id)->first();
     if ($pilot->processing == 1) {
         $job->delete();
         return;
     }
     try {
         $it = new XmlIterator\XmlIterator('https://cert.vatsim.net/vatsimnet/idstatusint.php?cid=' . $vatsim_id, 'user');
         $official = iterator_to_array($it)[0];
         $pilot->name = $official['name_first'] . ' ' . $official['name_last'];
         $pilot->rating_id = $official['rating'];
     } catch (ErrorException $e) {
     }
     $newFlights = array();
     $flights = Flight::whereVatsimId($pilot->vatsim_id)->whereState(2)->get();
     $totalDistance = 0;
     $totalDuration = 0;
     $totalFlights = $flights->count();
     foreach ($flights as $flight) {
         if ($flight->processed == 1) {
             $totalDistance += $flight->distance;
             $totalDuration += $flight->duration;
         } else {
             $callsign = str_replace('-', '', strtoupper($flight->callsign));
             if (!is_null($airline = $this->getAirlines($callsign))) {
                 // Airline
                 $flight->isAirline($airline->icao);
                 unset($airline);
             } elseif (!is_null($registration = $this->getRegistrations($callsign))) {
                 $flight->isPrivate($registration->country_id);
                 unset($registration);
             }
             if (!is_null($flight->departure_time) && !is_null($flight->arrival_time)) {
                 $duration = $this->duration($flight->departure_time, $flight->arrival_time);
                 $flight->duration = $duration;
                 $totalDuration += $duration;
                 unset($duration);
             }
             $distance = 0;
             foreach ($flight->positions as $key => $position) {
                 if ($key > 0) {
                     $distance += $this->distance($position->lat, $position->lon, $previous->lat, $previous->lon);
                 }
                 $previous = $position;
             }
             $flight->distance = $distance;
             // $flight->processed = true;
             // $flight->save();
             if (!is_nan($distance)) {
                 $totalDistance += $distance;
             }
             unset($distance, $previous);
         }
         $newFlights[] = array('id' => $flight->id, 'duration' => $flight->duration, 'distance' => $flight->distance, 'airline_id' => $flight->airline_id, 'callsign_type' => $flight->callsign_type);
         unset($flight);
     }
     unset($flights);
     Log::info('queue:legacy[' . $job->getJobId() . '] - processed flights');
     DB::statement("create temporary table if not exists flights_temp (\n\t\t\t`id` int(10) unsigned NOT NULL,\n\t\t\t`callsign_type` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t`airline_id` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n\t\t\t`duration` smallint(6) NOT NULL DEFAULT '0',\n\t\t\t`distance` smallint(6) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY (`id`)\n\t\t)");
     Log::info('queue:legacy[' . $job->getJobId() . '] - created temp table flights');
     $remaining = count($newFlights);
     $step = 0;
     do {
         Log::info('queue:legacy[' . $job->getJobId() . '] - inserted flights - ' . $remaining);
         DB::table('flights_temp')->insert(array_slice($newFlights, 100 * $step, 100));
         $remaining -= 100;
         $step++;
     } while ($remaining > 0);
     Log::info('queue:legacy[' . $job->getJobId() . '] - inserted flights - done');
     DB::statement("update flights dest, flights_temp src set\n\t\t\tdest.callsign_type = src.callsign_type,\n\t\t\tdest.airline_id = src.airline_id,\n\t\t\tdest.duration = src.duration,\n\t\t\tdest.distance = src.distance,\n\t\t\tdest.processed = 1\n\t\twhere dest.id = src.id\n\t\t");
     Log::info('queue:legacy[' . $job->getJobId() . '] - updated flights');
     $atcs = ATC::whereVatsimId($vatsim_id)->whereNotNull('end')->get();
     $totalDurationAtc = 0;
     $totalAtc = $atcs->count();
     $newAtc = array();
     foreach ($atcs as $atc) {
         if ($atc->processed) {
             if ($atc->facility_id != 99) {
                 $totalDurationAtc += $atc->duration;
             } else {
                 $totalAtc--;
             }
         } else {
             $atc->facility_id = ends_with($atc->callsign, '_ATIS') ? 99 : $atc->facility_id;
             $duration = $this->duration($atc->start, $atc->end);
             $atc->duration = $duration;
             if ($atc->facility_id != 99) {
                 $totalDurationAtc += $duration;
             }
             if ($atc->facility_id < 6) {
                 $airport = Airport::select('icao')->whereIcao(explode('_', $atc->callsign)[0])->orWhere('iata', '=', explode('_', $atc->callsign)[0])->pluck('icao');
                 $atc->airport_id = is_null($airport) ? null : $airport;
                 unset($airport);
             } elseif ($atc->facility_id == 6) {
                 $sector = SectorAlias::select('sectors.code')->where('sector_aliases.code', '=', explode('_', $atc->callsign)[0])->join('sectors', 'sector_aliases.sector_id', '=', 'sectors.id')->pluck('code');
                 $atc->sector_id = is_null($sector) ? null : $sector;
                 unset($sector);
             } else {
                 $totalAtc--;
             }
             // $atc->processed = true;
             // $atc->save();
         }
         $newAtc[] = array('id' => $atc->id, 'airport_id' => $atc->airport_id, 'sector_id' => $atc->sector_id, 'duration' => $atc->duration, 'facility_id' => $atc->facility_id);
         unset($atc);
     }
     unset($atcs);
     Log::info('queue:legacy[' . $job->getJobId() . '] - processed atc');
     DB::statement("create temporary table if not exists atc_temp (\n\t\t\t`id` int(10) unsigned NOT NULL,\n\t\t\t`facility_id` smallint(6) unsigned NOT NULL,\n\t\t\t`airport_id` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL,\n\t\t\t`sector_id` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n\t\t\t`duration` smallint(6) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY (`id`)\n\t\t)");
     Log::info('queue:legacy[' . $job->getJobId() . '] - created temp table atc');
     $remaining = count($newAtc);
     $step = 0;
     do {
         Log::info('queue:legacy[' . $job->getJobId() . '] - inserted atc - ' . $remaining);
         DB::table('atc_temp')->insert(array_slice($newAtc, 100 * $step, 100));
         $remaining -= 100;
         $step++;
     } while ($remaining > 0);
     Log::info('queue:legacy[' . $job->getJobId() . '] - inserted atc - done');
     DB::statement("update atc dest, atc_temp src set\n\t\t\tdest.duration = src.duration,\n\t\t\tdest.facility_id = src.facility_id,\n\t\t\tdest.airport_id = src.airport_id,\n\t\t\tdest.sector_id = src.sector_id,\n\t\t\tdest.processed = 1\n\t\twhere dest.id = src.id\n\t\t");
     Log::info('queue:legacy[' . $job->getJobId() . '] - updated atc');
     $pilot->processing = 1;
     $pilot->distance = $totalDistance;
     $pilot->duration = $totalDuration;
     $pilot->counter = $totalFlights;
     $pilot->counter_atc = $totalAtc;
     $pilot->duration_atc = $totalDurationAtc;
     $pilot->save();
     $job->delete();
 }
Example #15
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
if ($ATC->logout()) {
    header('Location: ./', true, 302);
}
$ATC->gui_output_page_header('Logout');
?>
<h1> Goodbye </h1>
<p> You have been logged out </h1>
	
<?php 
$ATC->gui_output_page_footer('Logout');
Example #16
0
<?php

require_once "atc.class.php";
$ATC = new ATC();
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
if (!isset($_GET['showall'])) {
    $_GET['showall'] = 0;
}
$user = $ATC->get_personnel($id, 'ASC', null, (int) $_GET['showall']);
$ATC->gui_output_page_header('Personnel');
if (is_object($user)) {
    ?>
		<div id="personnelform">
			<h2 href="personal.php?id=<?php 
    echo $user->personnel_id;
    ?>
"> Personal details &mdash; <?php 
    echo $user->rank . ' ' . $user->display_name;
    ?>
 </h2>
			<div id="personal">
			</div>
	
			<h2 href="nok.php?id=<?php 
    echo $user->personnel_id;
    ?>
"> Next of Kin </h2>
			<div id="nok">
			</div>
	
			<h2 href="attendance.php?id=<?php 
Example #17
0
<?php

require 'require/class.Connection.php';
require 'require/class.ATC.php';
if (isset($_GET['download'])) {
    header('Content-disposition: attachment; filename="atc.geojson"');
}
header('Content-Type: text/javascript');
if (isset($_GET['coord'])) {
    $coords = explode(',', $_GET['coord']);
    //	$spotter_array = Spotter::getAllNOTAMbyCoord($coords);
    $spotter_array = ATC::getAll();
} else {
    $spotter_array = ATC::getAll();
}
$output = '{"type": "FeatureCollection","features": [';
if (!empty($spotter_array)) {
    foreach ($spotter_array as $spotter_item) {
        date_default_timezone_set('UTC');
        //waypoint plotting
        $output .= '{"type": "Feature",';
        $output .= '"properties": {';
        $output .= '"ident": "' . $spotter_item['ident'] . '",';
        $output .= '"frequency": "' . $spotter_item['frequency'] . '",';
        $radius = $spotter_item['atc_range'] * 100;
        $output .= '"atc_range": "' . $radius . '",';
        $output .= '"ivao_id": "' . $spotter_item['ivao_id'] . '",';
        $output .= '"ivao_name": "' . $spotter_item['ivao_name'] . '",';
        $output .= '"info": "' . $spotter_item['info'] . '"';
        $output .= '},';
        $output .= '"geometry": {';