Esempio n. 1
0
 public function testFindSchedules()
 {
     heading('findSchedules');
     $data = SchedulesData::findSchedules(array());
     $this->assertNotEqual($data, false);
     heading('Find disabled schedules');
     $data = SchedulesData::findSchedules(array('s.enabled' => 0));
     $this->assertNotEqual($data, false);
 }
Esempio n. 2
0
 public function testExtractRoute()
 {
     $routes = array('VMA1234A', 'VMA324AB', 'VMS3030B');
     echo "<strong>Checking to see if flight numbers are parsed</strong><br />";
     # Check the first one
     $route = SchedulesData::getProperFlightNum($routes[0]);
     $this->assertEqual($route['code'], 'VMA');
     $this->assertEqual($route['flightnum'], '1234A');
     # Second
     $route = SchedulesData::getProperFlightNum($routes[1]);
     $this->assertEqual($route['code'], 'VMA');
     $this->assertEqual($route['flightnum'], '324AB');
     # Third
     $route = SchedulesData::getProperFlightNum($routes[2]);
     $this->assertEqual($route['code'], 'VMS');
     $this->assertEqual($route['flightnum'], '3030B');
     echo "<br />";
 }
Esempio n. 3
0
function post_module_load()
{
    /* Misc tasks which need to get done */
    /* If the setting to auto-retired pilots is on, then do that
       and only check every 24 hours
       */
    if (Config::Get('USE_CRON') == false) {
        if (Config::Get('PILOT_AUTO_RETIRE') == true) {
            $within_timelimit = CronData::check_hoursdiff('find_retired_pilots', '24');
            if ($within_timelimit === false) {
                PilotData::findRetiredPilots();
                CronData::set_lastupdate('find_retired_pilots');
            }
        }
        if (Config::Get('CLOSE_BIDS_AFTER_EXPIRE') === false) {
            $within_timelimit = CronData::check_hoursdiff('check_expired_bids', '24');
            if ($within_timelimit === false) {
                SchedulesData::deleteExpiredBids();
                CronData::set_lastupdate('check_expired_bids');
            }
        }
        /* Expenses, make sure they're all populated */
        $within_timelimit = CronData::check_hoursdiff('populate_expenses', 18);
        if ($within_timelimit === false) {
            FinanceData::updateAllExpenses();
            CronData::set_lastupdate('populate_expenses');
        }
        /* And finally, clear expired sessions */
        Auth::clearExpiredSessions();
    }
    if (Config::Get('TWITTER_AIRLINE_ACCOUNT') != '') {
        $within_timelimit = CronData::check_hoursdiff('twitter_update', '3');
        if ($within_timelimit === false) {
            ActivityData::readTwitter();
            CronData::set_lastupdate('twitter_update');
        }
    }
    // @TODO: Clean ACARS records older than one month
    if (Config::Get('MAINTENANCE_MODE') == true && !Auth::LoggedIn() && !PilotGroups::group_has_perm(Auth::$usergroups, FULL_ADMIN)) {
        Template::Show('maintenance.tpl');
        die;
    }
    return true;
}
Esempio n. 4
0
 public function index()
 {
     if ($this->get->maptype == 'hubmap') {
         // Show hubmap
         $params = array('s.depicao' => $this->get->hub, 's.enabled' => 1);
         // Show only 20 routes
         $allschedules = SchedulesData::findSchedules($params, Config::Get('ROUTE_MAP_SHOW_NUMBER'));
         if (count($allschedules) == 0) {
             echo 'There are no departures from this airport!';
             return;
         }
         $airportinfo = OperationsData::GetAirportInfo($this->get->hub);
         echo '<h3>Departures from ' . $airportinfo->name . '</h3>';
     } else {
         # Get all of the schedule
         $allschedules = SchedulesData::findSchedules(array('s.enabled' => 1), Config::Get('ROUTE_MAP_SHOW_NUMBER'));
     }
     $this->set('allschedules', $allschedules);
     $this->render('flown_routes_map.tpl');
 }
Esempio n. 5
0
function post_module_load()
{
    /* Misc tasks which need to get done */
    /* If the setting to auto-retired pilots is on, then do that
    		and only check every 24 hours
    	 */
    if (Config::Get('USE_CRON') === true) {
        if (Config::Get('PILOT_AUTO_RETIRE') == true) {
            $within_timelimit = CronData::check_hoursdiff('find_retired_pilots', '24');
            if ($within_timelimit == false) {
                PilotData::findRetiredPilots();
                CronData::set_lastupdate('find_retired_pilots');
            }
        }
        if (Config::Get('CLOSE_BIDS_AFTER_EXPIRE') === false) {
            $within_timelimit = CronData::check_hoursdiff('check_expired_bids', '24');
            if ($within_timelimit == false) {
                SchedulesData::deleteExpiredBids();
                CronData::set_lastupdate('check_expired_bids');
            }
        }
        /* Expenses, make sure they're all populated */
        $within_timelimit = CronData::check_hoursdiff('populate_expenses', '18');
        if ($within_timelimit == false) {
            FinanceData::updateAllExpenses();
            CronData::set_lastupdate('populate_expenses');
        }
        /* And finally, clear expired sessions */
        Auth::clearExpiredSessions();
    }
    // @TODO: Clean ACARS records older than one month
    if (Config::Get('MAINTENANCE_MODE') == true && !Auth::LoggedIn() && !PilotGroups::group_has_perm(Auth::$usergroups, FULL_ADMIN)) {
        echo '<html><head><title>Down for maintenance - ' . SITE_NAME . '</title></head><body>';
        Debug::showCritical(Config::Get('MAINTENANCE_MESSAGE'), 'Down for maintenance');
        echo '</body></html>';
        die;
    }
    return true;
}
Esempio n. 6
0
 protected function delete_schedule_post()
 {
     $schedule = SchedulesData::findSchedules(array('s.id' => $this->post->id));
     SchedulesData::DeleteSchedule($this->post->id);
     $params = array();
     if (DB::errno() != 0) {
         $params['status'] = 'There was an error deleting the schedule';
         $params['error'] = DB::error();
         echo json_encode($params);
         return;
     }
     $params['status'] = 'ok';
     echo json_encode($params);
     LogData::addLog(Auth::$userinfo->pilotid, 'Deleted schedule "' . $schedule->code . $schedule->flightnum . '"');
 }
Esempio n. 7
0
 /**
  * CentralData::send_schedules()
  * 
  * @return
  */
 public static function send_schedules()
 {
     if (!self::central_enabled()) {
         return false;
     }
     if (self::$debug === false) {
         $within_timelimit = CronData::check_hoursdiff('update_schedules', self::$limits['update_schedules']);
         if ($within_timelimit == true) {
             return false;
         }
     }
     $schedules = SchedulesData::findSchedules(array('s.enabled' => '1'));
     if (!is_array($schedules)) {
         return false;
     }
     self::startBody('update_schedules');
     self::addElement(null, 'total', count($schedules));
     $schedules_parent = self::addElement(null, 'schedules');
     foreach ($schedules as $sched) {
         $sp = self::addElement($schedules_parent, 'schedule', null, array('flightnum' => $sched->code . $sched->flightnum, 'depicao' => $sched->depicao, 'arricao' => $sched->arricao, 'aircraft' => $sched->aircraft, 'registration' => $sched->registration, 'distance' => $sched->distance, 'daysofweek' => $sched->daysofweek, 'price' => $sched->price, 'flighttype' => $sched->flighttype, 'notes' => $sched->notes, 'deptime' => $sched->deptime, 'arrtime' => $sched->arrtime));
     }
     # Package and send
     CronData::set_lastupdate('update_schedules');
     $res = self::sendToCentral();
     return $res;
 }
</ul>
<br />
<form action="<?php 
echo url('/FBSV11/jumpseat');
?>
" method="get">
	<table>
		<tr>	
			<td>select airport to transfer : </td>
			<td >
					
					<select name="depicao" onchange="listSel(this,'cost')">
						<option value="">--Select--</option>
						<?php 
foreach ($airports as $airport) {
    $distance = round(SchedulesData::distanceBetweenPoints($last_name->lat, $last_name->lng, $airport->lat, $airport->lng), 0);
    $permile = Config::Get('JUMPSEAT_COST');
    $cost = $permile * $distance;
    $check = PIREPData::getLastReports(Auth::$userinfo->pilotid, 1, 1);
    if ($cost >= Auth::$userinfo->totalpay) {
        continue;
    } elseif ($check->accepted == PIREP_ACCEPTED || !$check) {
        echo "<option name='{$cost}' value='{$airport->icao}'>{$airport->icao} - {$airport->name}    /Cost - <font color='#66FF00'>\$ {$cost}</font></option>";
    }
    ?>
								   
								   <hr> 
					 <?php 
}
?>
 
Esempio n. 9
0
 /**
  * File a PIREP from an ACARS program
  *
  * @param mixed $pilotid The pilot ID of the pilot filing the PIREP
  * @param mixed $data This is the data structure with the PIREP info
  * @return bool true/false
  *
  */
 public static function FilePIREP($pilotid, $data)
 {
     if (!is_array($data)) {
         self::$lasterror = 'PIREP data must be array';
         return false;
     }
     # Call the pre-file event
     #
     if (CodonEvent::Dispatch('pirep_prefile', 'PIREPS', $_POST) == false) {
         return false;
     }
     # File the PIREP report
     #
     $ret = PIREPData::FileReport($data);
     # Set them as non-retired
     PilotData::setPilotRetired($pilotid, 0);
     if (!$ret) {
         return false;
     }
     self::$pirepid = DB::$insert_id;
     # Call the event
     #
     CodonEvent::Dispatch('pirep_filed', 'PIREPS', $_POST);
     # Close out a bid if it exists
     #
     $bidid = SchedulesData::GetBidWithRoute($pilotid, $data['code'], $data['flightnum']);
     if ($bidid) {
         SchedulesData::RemoveBid($bidid->bidid);
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Populate the PIREP with the fianancial info needed
  *  Pass the PIREPID or the PIREP row
  */
 public static function populatePIREPFinance($pirep, $reset_fuel = false)
 {
     if (!is_object($pirep) && is_numeric($pirep)) {
         $pirep = PIREPData::getReportDetails($pirep);
         if (!$pirep) {
             self::$lasterror = 'PIREP does not exist';
             return false;
         }
     }
     # Set the PIREP ID
     $pirepid = $pirep->pirepid;
     $sched = SchedulesData::getScheduleByFlight($pirep->code, $pirep->flightnum, '');
     if (!$sched) {
         self::$lasterror = 'Schedule does not exist. Please update this manually.';
         return false;
     }
     $pilot = PilotData::getPilotData($pirep->pilotid);
     # Get the load factor for this flight
     if ($pirep->load == '' || $pirep->load == 0) {
         $pirep->load = FinanceData::getLoadCount($pirep->aircraft, $sched->flighttype);
     }
     // Fix for bug #62, check the airport fuel price as 0 for live
     //$depapt = OperationsData::getAirportInfo($pirep->depicao);
     if ($pirep->fuelunitcost == '' || $pirep->fuelunitcost == 0 || $reset_fuel == true) {
         $pirep->fuelunitcost = FuelData::getFuelPrice($pirep->depicao);
     }
     # Check the fuel
     if ($pirep->fuelprice != '' || $reset_fuel == true) {
         $pirep->fuelprice = FinanceData::getFuelPrice($pirep->fuelused, $pirep->depicao);
     }
     # Get the expenses for a flight
     $total_ex = 0;
     $expense_list = '';
     /* Account for any fixed-cost percentages */
     $allexpenses = FinanceData::getFlightExpenses();
     if (is_array($allexpenses)) {
         foreach ($allexpenses as $ex) {
             $total_ex += $ex->cost;
         }
     }
     /* Account for any per-flight %age expenses */
     $all_percent_expenses = FinanceData::getFlightPercentExpenses();
     $gross = floatval($sched->price) * floatval($pirep->load);
     if (is_array($all_percent_expenses)) {
         foreach ($all_percent_expenses as $ex) {
             $cost = str_replace('%', '', $ex->cost);
             $percent = $cost / 100;
             $total = $gross * $percent;
             $total_ex += $total;
         }
     }
     $data = array('price' => $sched->price, 'load' => $pirep->load, 'fuelprice' => $pirep->fuelprice, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'flighttime' => $pirep->flighttime);
     $revenue = self::getPIREPRevenue($data);
     /* Now update the PIREP */
     $fields = array('price' => $sched->price, 'load' => $pirep->load, 'gross' => $gross, 'fuelprice' => $pirep->fuelprice, 'fuelunitcost' => $pirep->fuelunitcost, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'revenue' => $revenue);
     if (isset($data['load']) && $data['load'] != '') {
         $fields['load'] = $data['load'];
     }
     return self::editPIREPFields($pirepid, $fields);
 }
Esempio n. 11
0
 public static function send_schedules()
 {
     if (!self::central_enabled()) {
         return false;
     }
     if (self::$debug === false) {
         $within_timelimit = CronData::check_hoursdiff('update_schedules', self::$limits['update_schedules']);
         if ($within_timelimit == true) {
             return false;
         }
     }
     self::set_xml('update_schedules');
     $params = array('s.enabled' => '1');
     $schedules = SchedulesData::findSchedules($params);
     if (!is_array($schedules)) {
         return false;
     }
     self::$xml->addChild('total', count($schedules));
     $schedules_parent = self::$xml->addChild('schedules');
     foreach ($schedules as $sched) {
         $schedule_xml = $schedules_parent->addChild('schedule');
         $schedule_xml->addChild('flightnum', $sched->code . $sched->flightnum);
         $schedule_xml->addChild('depicao', $sched->depicao);
         $schedule_xml->addChild('arricao', $sched->arricao);
         $schedule_xml->addChild('aircraft', $sched->aircraft);
         $schedule_xml->addChild('registration', $sched->registration);
         $schedule_xml->addChild('distance', $sched->distance);
         $schedule_xml->addChild('daysofweek', $sched->daysofweek);
         $schedule_xml->addChild('price', $sched->price);
         $schedule_xml->addChild('flighttype', $sched->flighttype);
         $schedule_xml->addChild('notes', $sched->notes);
         $schedule_xml->addChild('deptime', $sched->deptime);
         $schedule_xml->addChild('arrtime', $sched->arrtime);
     }
     # Package and send
     CronData::set_lastupdate('update_schedules');
     $res = self::send_xml();
     return $res;
 }
Esempio n. 12
0
 public function processimport()
 {
     echo '<h3>Processing Import</h3>';
     if (!file_exists($_FILES['uploadedfile']['tmp_name'])) {
         $this->set('message', 'File upload failed!');
         $this->render('core_error.tpl');
         return;
     }
     echo '<p><strong>DO NOT REFRESH OR STOP THIS PAGE</strong></p>';
     set_time_limit(270);
     $errs = array();
     $skip = false;
     # Fix for bug VMS-325
     $temp_name = $_FILES['uploadedfile']['tmp_name'];
     $new_name = CACHE_PATH . $_FILES['uploadedfile']['name'];
     move_uploaded_file($temp_name, $new_name);
     $fp = fopen($new_name, 'r');
     if (isset($_POST['header'])) {
         $skip = true;
     }
     /* Delete all schedules before doing an import */
     if (isset($_POST['erase_routes'])) {
         SchedulesData::deleteAllSchedules();
     }
     $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;">';
     while ($fields = fgetcsv($fp, 1000, ',')) {
         // Skip the first line
         if ($skip == true) {
             $skip = false;
             continue;
         }
         // list fields:
         $code = $fields[0];
         $flightnum = $fields[1];
         $depicao = $fields[2];
         $arricao = $fields[3];
         $route = $fields[4];
         $aircraft = $fields[5];
         $flightlevel = $fields[6];
         $distance = $fields[7];
         $deptime = $fields[8];
         $arrtime = $fields[9];
         $flighttime = $fields[10];
         $notes = $fields[11];
         $price = $fields[12];
         $flighttype = $fields[13];
         $daysofweek = $fields[14];
         $enabled = $fields[15];
         $week1 = $fields[16];
         $week2 = $fields[17];
         $week3 = $fields[18];
         $week4 = $fields[19];
         if ($code == '') {
             continue;
         }
         // Check the code:
         if (!OperationsData::GetAirlineByCode($code)) {
             echo "Airline with code {$code} does not exist! Skipping...<br />";
             continue;
         }
         // Make sure airports exist:
         if (!($depapt = OperationsData::GetAirportInfo($depicao))) {
             $this->get_airport_info($depicao);
         }
         if (!($arrapt = OperationsData::GetAirportInfo($arricao))) {
             $this->get_airport_info($arricao);
         }
         # Check the aircraft
         $aircraft = trim($aircraft);
         $ac_info = OperationsData::GetAircraftByReg($aircraft);
         # If the aircraft doesn't exist, skip it
         if (!$ac_info) {
             echo 'Aircraft "' . $aircraft . '" does not exist! Skipping<br />';
             continue;
         }
         $ac = $ac_info->id;
         if ($flighttype == '') {
             $flighttype = 'P';
         }
         if ($daysofweek == '') {
             $daysofweek = '0123456';
         }
         // Replace a 7 (Sunday) with 0 (since PHP thinks 0 is Sunday)
         $daysofweek = str_replace('7', '0', $daysofweek);
         # Check the distance
         if ($distance == 0 || $distance == '') {
             $distance = OperationsData::getAirportDistance($depicao, $arricao);
         }
         $flighttype = strtoupper($flighttype);
         if ($enabled == '0') {
             $enabled = false;
         } else {
             $enabled = true;
         }
         # This is our 'struct' we're passing into the schedule function
         #	to add or edit it
         $data = array('code' => $code, 'flightnum' => $flightnum, 'depicao' => $depicao, 'arricao' => $arricao, 'route' => $route, 'aircraft' => $ac, 'flightlevel' => $flightlevel, 'distance' => $distance, 'deptime' => $deptime, 'arrtime' => $arrtime, 'flighttime' => $flighttime, 'daysofweek' => $daysofweek, 'notes' => $notes, 'enabled' => $enabled, 'price' => $price, 'flighttype' => $flighttype, 'week1' => $week1, 'week2' => $week2, 'week3' => $week3, 'week4' => $week4);
         # Check if the schedule exists:
         if ($schedinfo = SchedulesData::getScheduleByFlight($code, $flightnum)) {
             # Update the schedule instead
             $val = SchedulesData::updateScheduleFields($schedinfo->id, $data);
             $updated++;
         } else {
             # Add it
             $val = SchedulesData::addSchedule($data);
             $added++;
         }
         if ($val === false) {
             if (DB::errno() == 1216) {
                 echo "Error adding {$code}{$flightnum}: The airline code, airports, or aircraft does not exist";
             } else {
                 $error = DB::error() != '' ? DB::error() : 'Route already exists';
                 echo "{$code}{$flightnum} was not added, reason: {$error}<br />";
             }
             echo '<br />';
         } else {
             $total++;
             echo "Imported {$code}{$flightnum} ({$depicao} to {$arricao})<br />";
         }
     }
     CentralData::send_schedules();
     echo "The import process is complete, added {$added} schedules, updated {$updated}, for a total of {$total}<br />";
     foreach ($errs as $error) {
         echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $error . '<br />';
     }
     echo '</div>';
     unlink($new_name);
 }
Esempio n. 13
0
<?php

include '../core/codon.config.php';
echo '<pre>';
Config::Set('PIREP_CHECK_DUPLICATE', false);
$schedules = SchedulesData::findSchedules(array('s.flighttype' => 'P'));
$idx = rand(0, count($schedules) - 1);
$sched = $schedules[$idx];
unset($schedules);
echo '<strong>Filing report...</strong><br />';
$data = array('pilotid' => 1, 'code' => $sched->code, 'flightnum' => $sched->flightnum, 'route' => 'HYLND DCT PUT J42 RBV J230 BYRDD J48 MOL DCT FLCON', 'depicao' => $sched->depicao, 'arricao' => $sched->arricao, 'aircraft' => $sched->aircraft, 'flighttime' => $sched->flighttime, 'submitdate' => 'NOW()', 'fuelused' => 6000, 'source' => 'unittest', 'comment' => 'Test Flight');
//$data = array(
//	'pilotid'=>1,
//	'code'=>'vms',
//	'flightnum'=>1,
//	//'route' => 'HYLND DCT PUT J42 RBV J230 BYRDD J48 MOL DCT FLCON',
//	'depicao'=>'lfll',
//	'arricao'=>'egll',
//	'aircraft'=>'1',
//	'route' => 'BUSIL UT133 AMORO',
//	'flighttime'=>'3',
//	'submitdate'=>'NOW()',
//	'fuelused'=>6000,
//	'source'=>'unittest',
//	'comment'=>'Test Flight',
//	);
$pirepid = PIREPData::fileReport($data);
if ($ret == false) {
    echo PIREPData::$lasterror;
}
echo "PIREP ID is {$pirepid}";
Esempio n. 14
0
    public function resetscheduleroute()
    {
        echo '<h3>Reset cached schedule routes</h3> 
				Resetting... <br />';
        SchedulesData::deleteAllScheduleDetails();
        echo 'Completed!';
        LogData::addLog(Auth::$userinfo->pilotid, 'Reset cached schedule route details');
    }
Esempio n. 15
0
 /**
  * Change the status of a PIREP. For the status, use the constants:
  * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
  * 
  * Also handle paying the pilot, and handle PIREP rejection, etc
  * 
  * @param int $pirepid The PIREP ID of status to change
  * @param int $status Use consts: PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
  * @return bool
  */
 public static function changePIREPStatus($pirepid, $status)
 {
     # Look up the status of the PIREP of previous
     $pirep_details = PIREPData::getReportDetails($pirepid);
     if (!$pirep_details) {
         return false;
     }
     if ($pirep_details->accepted == $status) {
         return true;
     }
     $ret = self::editPIREPFields($pirepid, array('accepted' => $status));
     # Do something if the PIREP was previously marked as pending
     if ($pirep_details->accepted == PIREP_PENDING) {
         if ($status == PIREP_ACCEPTED) {
             self::calculatePIREPPayment($pirepid);
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '+1');
         } elseif ($status == PIREP_REJECTED) {
             // Do nothing, since nothing in the PIREP was actually counted
         }
     } elseif ($pirep_details->accepted == PIREP_ACCEPTED) {
         # If already accepted
         if ($status == PIREP_REJECTED) {
             LedgerData::deletePaymentByPIREP($pirep_details->pirepid);
             PilotData::resetPilotPay($pirep_details->pilotpay);
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '-1');
         }
     }
     PilotData::updatePilotStats($pirep_details->pilotid);
     RanksData::calculateUpdatePilotRank($pirep_details->pilotid);
     PilotData::generateSignature($pirep_details->pilotid);
     StatsData::updateTotalHours();
     return $ret;
 }
Esempio n. 16
0
 public function approveall()
 {
     echo '<h3>Approve All</h3>';
     $allpireps = PIREPData::findPIREPS(array('p.accepted' => PIREP_PENDING));
     $total = count($allpireps);
     $count = 0;
     foreach ($allpireps as $pirep_details) {
         if ($pirep_details->aircraft == '') {
             continue;
         }
         # Update pilot stats
         SchedulesData::IncrementFlownCount($pirep_details->code, $pirep_details->flightnum);
         PIREPData::ChangePIREPStatus($pirep_details->pirepid, PIREP_ACCEPTED);
         // 1 is accepted
         #PilotData::UpdatePilotStats($pirep_details->pilotid);
         #RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
         RanksData::CalculatePilotRanks();
         #PilotData::GenerateSignature($pirep_details->pilotid);
         #StatsData::UpdateTotalHours();
         $count++;
     }
     $skipped = $total - $count;
     echo "{$count} of {$total} were approved ({$skipped} has errors)";
 }
 /**
  * Get the distance between two airports
  *
  * @param mixed $depicao ICAO or object of the departure airport
  * @param mixed $arricao ICAO or object of the destination airport
  * @return int The distance
  *
  */
 public static function getAirportDistance($depicao, $arricao)
 {
     if (!is_object($depicao)) {
         $depicao = self::getAirportInfo($depicao);
     }
     if (!is_object($arricao)) {
         $arricao = self::getAirportInfo($arricao);
     }
     return SchedulesData::distanceBetweenPoints($depicao->lat, $depicao->lng, $arricao->lat, $arricao->lng);
 }
Esempio n. 18
0
     # Estimate the time remaining
     if ($gs > 0) {
         $time_remain = $dist_remain / $gs;
     } else {
         $time_remain = '00:00';
     }
     ob_start();
     $fields['distremain'] = $dist_remain;
     $fields['timeremaining'] = $time_remain;
     Debug::log(print_r($fields, true), 'xacars');
     ACARSData::UpdateFlightData($pilotid, $fields);
     echo '1|' . $outstring;
     break;
 case 'pirep':
     $data = explode('~', $_REQUEST['DATA2']);
     $flightinfo = SchedulesData::getProperFlightNum($data[2]);
     $code = $flightinfo['code'];
     $flightnum = $flightinfo['flightnum'];
     /*if(!is_numeric($data[0]))
     		{
     			# see if they are a valid pilot:
     			preg_match('/^([A-Za-z]*)(\d*)/', $data[0], $matches);
     			$pilot_code = $matches[1];
     			$pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');
     		}
     		else
     		{
     			$pilotid = $data[0];
     		}*/
     $pilotid = PilotData::parsePilotID($data[0]);
     # Make sure airports exist:
Esempio n. 19
0
 /**
  * Pass in a string with the route, and return back an array
  * with the data about each segment of the route. Pass a schedule
  * result into it.
  * 
  * You can pass in a PIREP, schedule, or ACARS result, as long as it
  * has the following fields:
  *	lat
  *	lng
  *	route
  * 
  * To cache the route, use ScheduleData::getRouteDetails() instead.
  * This function bypasses any cached info
  *
  * @param mixed $route_string This is a description
  * @return mixed This is the return value description
  *
  */
 public static function parseRoute($schedule)
 {
     $fromlat = $schedule->deplat;
     $fromlng = $schedule->deplng;
     $route_string = $schedule->route;
     if ($route_string == '') {
         return array();
     }
     // Remove any SID/STAR text
     $route_string = str_replace('SID', '', $route_string);
     $route_string = str_replace('STAR', '', $route_string);
     $navpoints = array();
     $all_points = explode(' ', $route_string);
     foreach ($all_points as $key => $value) {
         if (empty($value) === true) {
             continue;
         }
         $navpoints[] = strtoupper(trim($value));
     }
     $allpoints = array();
     $total = count($navpoints);
     $airways = self::getAirways($navpoints);
     for ($i = 0; $i < $total; $i++) {
         $name = self::cleanName($navpoints[$i]);
         /*	the current point is an airway, so go through 
         			the airway list and add each corresponding point
         			between the entry and exit to the list. */
         if (isset($airways[$name])) {
             $entry_name = self::cleanName($navpoints[$i - 1]);
             $exit_name = self::cleanName($navpoints[$i + 1]);
             $entry = self::getPointIndex($entry_name, $airways[$name]);
             $exit = self::getPointIndex($exit_name, $airways[$name]);
             if ($entry == -1) {
                 $entry = $exit;
             } else {
                 /*	Add information abotu the entry point in first,
                 			if it's valid and exists */
                 $allpoints[$entry_name] = $airways[$name][$entry];
             }
             if ($exit == -1) {
                 continue;
             }
             if ($entry < $exit) {
                 # Go forwards through the list adding each one
                 for ($l = $entry; $l <= $exit; $l++) {
                     $allpoints[$airways[$name][$l]->name] = $airways[$name][$l];
                 }
             } elseif ($entry > $exit) {
                 # Go backwards through the list
                 for ($l = $exit; $l >= $entry; $l--) {
                     $point_name = self::cleanName($airways[$name][$l]->name);
                     $allpoints[$point_name] = $airways[$name][$l];
                 }
             } elseif ($entry == $exit) {
                 $point_name = self::cleanName($airways[$name][$l]->name);
                 $allpoints[$point_name] = $airways[$name][$entry];
             }
             # Now add the exit point, and increment the main counter by one
             if ($exit > -1) {
                 $allpoints[$exit_name] = $airways[$name][$exit];
             }
             continue;
         } else {
             /* This nav point already exists in the list, don't add it
             			again */
             if (isset($allpoints[$navpoints[$i]])) {
                 continue;
             }
             /*	Means it is a track, so go into processing it 
             			See if it's something like XXXX/YYYY
             		 */
             if (substr_count($navpoints[$i], '/') > 0) {
                 $name = $navpoints[$i];
                 $point_name = explode('/', $name);
                 preg_match(self::$nat_pattern, $point_name[0], $matches);
                 $coord = $matches[1];
                 $lat = $matches[2] . $coord[0] . $coord[1] . '.' . $coord[2] . $coord[3];
                 /*	Match the second set of coordinates */
                 # Read the second set
                 preg_match(self::$nat_pattern, $point_name[1], $matches);
                 if ($matches == 0) {
                     continue;
                 }
                 $coord = $matches[1];
                 $lng = $matches[2] . $coord[0] . $coord[1] . $coord[2] . '.' . $coord[3];
                 /*	Now convert into decimal coordinates */
                 $coords = $lat . ' ' . $lng;
                 $coords = Util::get_coordinates($coords);
                 if (empty($coords['lat']) || empty($coords['lng'])) {
                     unset($allpoints[$navpoints[$i]]);
                     continue;
                 }
                 $tmp = new stdClass();
                 $tmp->id = 0;
                 $tmp->type = NAV_TRACK;
                 $tmp->name = $name;
                 $tmp->title = $name;
                 $tmp->lat = $coords['lat'];
                 $tmp->lng = $coords['lng'];
                 $tmp->airway = '';
                 $tmp->sequence = 0;
                 $tmp->freq = '';
                 $allpoints[$navpoints[$i]] = $tmp;
                 unset($point_name);
                 unset($matches);
                 unset($tmp);
             } else {
                 $allpoints[$navpoints[$i]] = $navpoints[$i];
                 $navpoint_list[] = $navpoints[$i];
             }
         }
     }
     $navpoint_list_details = self::getNavDetails($navpoint_list);
     foreach ($navpoint_list_details as $point => $list) {
         $allpoints[$point] = $list;
     }
     unset($navpoint_list_details);
     /*	How will this work - loop through each point, and
     			decide which one we'll use, determined by the
     			one which is the shortest distance from the previous 
     			
     			Go in the order of the ones passed in.
     		*/
     foreach ($allpoints as $point_name => $point_details) {
         if (is_string($point_details)) {
             unset($allpoints[$point_name]);
             continue;
         }
         if (!is_array($point_details)) {
             continue;
         }
         $results_count = count($point_details);
         if ($results_count == 1) {
             $allpoints[$point_name] = $point_details[0];
         } elseif ($results_count > 1) {
             /* There is more than one, so find the one with the shortest
             			distance from the previous point out of all the ones */
             $index = 0;
             $dist = 0;
             /* Set the inital settings */
             $lowest_index = 0;
             $lowest = $point_details[$lowest_index];
             $lowest_dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $lowest->lat, $lowest->lng);
             foreach ($point_details as $p) {
                 $dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $p->lat, $p->lng);
                 if ($dist < $lowest_dist) {
                     $lowest_index = $index;
                     $lowest_dist = $dist;
                 }
                 $index++;
             }
             $allpoints[$point_name] = $point_details[$lowest_index];
         }
         $fromlat = $allpoints[$point_name]->lat;
         $fromlng = $allpoints[$point_name]->lng;
     }
     return $allpoints;
 }
Esempio n. 20
0
 public function flightinfo($route = '')
 {
     if ($route == '') {
         $route = $_GET['route'];
     }
     preg_match('/^([A-Za-z]{2,3})(\\d*)/', $route, $matches);
     $code = $matches[1];
     $flightnum = $matches[2];
     $params = array('s.code' => $code, 's.flightnum' => $flightnum);
     $flightinfo = SchedulesData::findSchedules($params, 1);
     if (!$flightinfo) {
         return;
     }
     $flightinfo = $flightinfo[0];
     // Grab the first one
     $xml = new SimpleXMLElement('<flightinfo/>');
     $dep = $xml->addChild('departure');
     $dep->addAttribute('icao', $flightinfo->depicao);
     $dep->addAttribute('name', $flightinfo->depname);
     $dep->addAttribute('lat', $flightinfo->deplat);
     $dep->addAttribute('lng', $flightinfo->deplng);
     $arr = $xml->addChild('arrival');
     $arr->addAttribute('icao', $flightinfo->arricao);
     $arr->addAttribute('name', $flightinfo->arrname);
     $arr->addAttribute('lat', $flightinfo->arrlat);
     $arr->addAttribute('lng', $flightinfo->arrlng);
     header('Content-type: text/xml');
     echo $xml->asXML();
 }
Esempio n. 21
0
 if ($count > 0) {
     $landingrate = $matches[2];
 } else {
     $landingrate = 0;
 }
 # Get our aircraft
 $reg = trim($_GET['reg']);
 $ac = OperationsData::GetAircraftByReg($reg);
 # Do some cleanup
 $_GET['origin'] = DB::escape($_GET['origin']);
 $_GET['dest'] = DB::escape($_GET['dest']);
 # Get schedule info, using minimal information
 #	Check if they forgot the flight code
 if ($code == '') {
     # Find a flight using just the flight code
     $sched = SchedulesData::FindFlight($flightnum);
     # Can't do it. They completely f****d this up
     if (!$sched) {
         return;
     }
     $code = $sched->code;
     $flightnum = $sched->flightnum;
     if ($_GET['origin'] != $sched->depicao || $_GET['dest'] != $sched->arricao) {
         $comment = 'phpVMS Message: Arrival or Departure does not match schedule';
     }
 }
 # Make sure airports exist:
 #  If not, add them.
 if (!OperationsData::GetAirportInfo($_GET['origin'])) {
     OperationsData::RetrieveAirportInfo($_GET['origin']);
 }
Esempio n. 22
0
 /**
  * Process ACARS messages here
  * 
  */
 public function acars()
 {
     if (!isset($_REQUEST['DATA1'])) {
         die("0|Invalid Data");
     }
     if (!isset($_REQUEST['DATA1'])) {
         die("0|Invalid Data");
     }
     // TEST, BEGINFLIGHT, PAUSEFLIGHT, ENDFLIGHT and MESSAGE
     $method = strtoupper($_REQUEST['DATA2']);
     if (!isset($_REQUEST['DATA3'])) {
         $value = '';
     } else {
         $value = $_REQUEST['DATA3'];
     }
     if (!isset($_REQUEST['DATA4'])) {
         $message = '';
     } else {
         $message = $_REQUEST['DATA4'];
     }
     $this->log("Method: {$method}", 'fsfk');
     $fields = array();
     # Go through each method now
     if ($method == 'TEST') {
         $pilotid = $value;
         echo '1|30';
         return;
     } elseif ($method == 'BEGINFLIGHT') {
         $flight_data = explode('|', $value);
         if (count($flight_data) < 10) {
             echo '0|Invalid login data';
             return;
         }
         /*preg_match('/^([A-Za-z]*)(\d*)/', $flight_data[0], $matches);
         		$code = $matches[1];
         		$pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');*/
         $pilotid = PilotData::parsePilotID($flight_data[0]);
         $coords = $this->get_coordinates($flight_data[6]);
         $route = explode('~', $flight_data[5]);
         $depicao = $route[0];
         $arricao = $route[count($route) - 1];
         unset($route[0]);
         unset($route[count($route) - 1]);
         $route = implode(' ', $route);
         $flightinfo = SchedulesData::getProperFlightNum($flight_data[2]);
         $code = $flightinfo['code'];
         $flightnum = $flightinfo['flightnum'];
         $aircraft = $flight_data[3];
         $heading = $flight_data[12];
         $alt = $flight_data[7];
         $gs = 0;
         $dist_remain = $flight_data[16];
         $time_remain = 0;
         $deptime = time();
         $online = 0;
         $fields = array('pilotid' => $pilotid, 'flightnum' => $code . $flightnum, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'route' => $route, 'alt' => $alt, 'gs' => $gs, 'depicao' => $depicao, 'arricao' => $arricao, 'distremain' => $dist_remain, 'timeremaining' => $time_remain, 'phasedetail' => 'On the ground', 'online' => $online, 'client' => 'fsfk');
     } elseif ($method == 'MESSAGE') {
         $pilotid = $value;
         $flight_data = ACARSData::get_flight_by_pilot($pilotid);
         // Get the flight
         preg_match("/Flight ID: (.*)\n/", $message, $matches);
         $flightinfo = SchedulesData::getProperFlightNum($matches[1]);
         $code = $flightinfo['code'];
         $flightnum = $flightinfo['flightnum'];
         // Get the aircraft
         preg_match("/.*Aircraft Reg: \\.\\.(.*)\n/", $message, $matches);
         $aircraft_data = OperationsData::GetAircraftByReg(trim($matches[1]));
         $aircraft = $aircraft_data->id;
         $depicao = $flight_data->depicao;
         $arricao = $flight_data->arricao;
         // Get coordinates from ACARS message
         $count = preg_match("/POS(.*)\n/", $message, $matches);
         if ($count > 0) {
             $coords = $this->get_coordinates(trim($matches[1]));
         } else {
             $coords = array('lat' => $flight_data->lat, 'lng' => $flight_data->lng);
         }
         // Get our heading
         preg_match("/\\/HDG.(.*)\n/", $message, $matches);
         $heading = $matches[1];
         // Get our altitude
         preg_match("/\\/ALT.(.*)\n/", $message, $matches);
         $alt = $matches[1];
         // Get our speed
         preg_match("/\\/IAS.(.*)\\//", $message, $matches);
         $gs = $matches[1];
         $fields = array('pilotid' => $pilotid, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'alt' => $alt, 'gs' => $gs, 'phasedetail' => 'Enroute');
     } elseif ($method == 'UPDATEFLIGHTPLAN') {
         $flight_id = $value;
         $flight_data = explode("|", $message);
         echo '1|';
         return;
     }
     $depapt = OperationsData::GetAirportInfo($depicao);
     $dist_remain = SchedulesData::distanceBetweenPoints($coords->lat, $coords->lng, $depapt->lat, $depapt->lng);
     # Estimate the time remaining
     if ($gs != 0) {
         $time_remain = $dist_remain / $gs;
     } else {
         $time_remain = '0';
     }
     $fields['distremain'] = $dist_remain;
     $fields['timeremaining'] = $time_remain;
     if ($deptime != '') {
         $fields['deptime'] = $deptime;
     }
     if ($arrtime != '') {
         $fields['arrtime'] = $arrtime;
     }
     Debug::log(print_r($fields, true), 'fsfk');
     ACARSData::updateFlightData($pilotid, $fields);
     $id = DB::$insert_id;
     if ($method == 'BEGINFLIGHT') {
         echo '1|' . $pilotid;
         return;
     }
     echo '1|';
 }
Esempio n. 23
0
 /**
  * ScheduleTest::deleteTestSchedule()
  * 
  * @return void
  */
 public function deleteTestSchedule()
 {
     $sched = $this->findSchedule();
     $ret = SchedulesData::deleteSchedule($sched->id);
 }
Esempio n. 24
0
 protected function SubmitPIREP()
 {
     $pilotid = Auth::$userinfo->pilotid;
     if ($pilotid == '' || Auth::LoggedIn() == false) {
         $this->set('message', 'You must be logged in to access this feature!!');
         //$this->render('core_error.tpl');
         return false;
     }
     if ($this->post->code == '' || $this->post->flightnum == '' || $this->post->depicao == '' || $this->post->arricao == '' || $this->post->aircraft == '' || $this->post->flighttime == '') {
         $this->set('message', 'You must fill out all of the required fields!');
         return false;
     }
     # Only allow for valid routes to be filed
     $sched_data = SchedulesData::GetScheduleByFlight($this->post->code, $this->post->flightnum);
     if (!$sched_data) {
         $this->set('message', 'The flight code and number you entered is not a valid route!');
         return false;
     }
     # See if they entered more than 59 in the minutes part of the flight time
     $this->post->flighttime = str_replace(':', '.', $this->post->flighttime);
     $parts = explode('.', $this->post->flighttime);
     if ($parts[1] > 59) {
         $this->set('message', 'You entered more than 60 minutes in the minutes');
         return false;
     }
     /* Check the schedule and see if it's been bidded on */
     if (Config::Get('DISABLE_SCHED_ON_BID') == true) {
         $biddata = SchedulesData::GetBid($sched_data->bidid);
         if ($biddata) {
             if ($biddata->pilotid != $pilotid) {
                 $this->set('message', 'You are not the bidding pilot');
                 //$this->render('core_error.tpl');
                 return false;
             }
         }
     }
     /* Removed this check since maybe it's a training flight or something, who knows
        if($this->post->depicao == $this->post->arricao)
        {
        $this->set('message', 'The departure airport is the same as the arrival airport!');
        $this->render('core_error.tpl');
        return false;
        }*/
     $this->post->flighttime = str_replace(':', '.', $this->post->flighttime);
     if (!is_numeric($this->post->flighttime)) {
         $this->set('message', 'The flight time has to be a number!');
         return false;
     }
     # form the fields to submit
     $this->pirepdata = array('pilotid' => $pilotid, 'code' => $this->post->code, 'flightnum' => $this->post->flightnum, 'depicao' => $this->post->depicao, 'arricao' => $this->post->arricao, 'aircraft' => $this->post->aircraft, 'flighttime' => $this->post->flighttime, 'route' => $this->post->route, 'submitdate' => 'NOW()', 'fuelused' => $this->post->fuelused, 'source' => 'manual', 'comment' => $this->post->comment);
     CodonEvent::Dispatch('pirep_prefile', 'PIREPS');
     if (CodonEvent::hasStop('pirepfile')) {
         return false;
     }
     if (!PIREPData::FileReport($this->pirepdata)) {
         $this->set('message', 'There was an error adding your PIREP : ' . PIREPData::$lasterror);
         return false;
     }
     $pirepid = DB::$insert_id;
     PIREPData::SaveFields($pirepid, $_POST);
     # Remove the bid
     $bidid = SchedulesData::GetBidWithRoute($pilotid, $this->post->code, $this->post->flightnum);
     if ($bidid) {
         SchedulesData::RemoveBid($bidid->bidid);
     }
     # Call the event
     CodonEvent::Dispatch('pirep_filed', 'PIREPS');
     # Set them as non-retired
     PilotData::setPilotRetired($pilotid, 0);
     # Delete the bid, if the value for it is set
     if ($this->post->bid != '') {
         SchedulesData::RemoveBid($this->post->bid);
     }
     return true;
 }
Esempio n. 25
0
 /**
  * Approve the PIREP, and then update
  * the pilot's data
  */
 protected function approve_pirep_post()
 {
     $pirepid = $this->post->id;
     if ($pirepid == '') {
         return;
     }
     $pirep_details = PIREPData::GetReportDetails($pirepid);
     # See if it's already been accepted
     if (intval($pirep_details->accepted) == PIREP_ACCEPTED) {
         return;
     }
     # Update pilot stats
     SchedulesData::IncrementFlownCount($pirep_details->code, $pirep_details->flightnum);
     PIREPData::ChangePIREPStatus($pirepid, PIREP_ACCEPTED);
     // 1 is accepted
     PilotData::UpdateFlightData($pirep_details->pilotid, $pirep_details->flighttime, 1);
     PilotData::UpdatePilotPay($pirep_details->pilotid, $pirep_details->flighttime);
     RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
     PilotData::GenerateSignature($pirep_details->pilotid);
     StatsData::UpdateTotalHours();
     LogData::addLog(Auth::$userinfo->pilotid, 'Approved PIREP #' . $pirepid);
     # Call the event
     CodonEvent::Dispatch('pirep_accepted', 'PIREPAdmin', $pirep_details);
 }
Esempio n. 26
0
 public function statsdaysdata($routeid)
 {
     $routeinfo = SchedulesData::findSchedules(array('s.id' => $routeid));
     $routeinfo = $routeinfo[0];
     // Last 30 days stats
     $data = PIREPData::getIntervalDataByDays(array('p.code' => $routeinfo->code, 'p.flightnum' => $routeinfo->flightnum), 30);
     $this->create_line_graph('Schedule Flown Counts', $data);
 }
Esempio n. 27
0
 *
 * @author Nabeel Shahzad
 * @copyright Copyright (c) 2008, Nabeel Shahzad
 * @link http://www.phpvms.net
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
 */
/*	This is the maintenance cron file, which can run nightly. 
	You should either point to this file directly in your web-host's control panel
	Or add an entry into the crontab file. I recommend running this maybe 2-3am, 
 */
define('ADMIN_PANEL', true);
include dirname(dirname(__FILE__)) . '/core/codon.config.php';
Auth::$userinfo->pilotid = 0;
error_reporting(E_ALL);
ini_set('display_errors', 'on');
/* Clear expired sessions */
Auth::clearExpiredSessions();
/* Update any expenses */
FinanceData::updateAllExpenses();
if (Config::Get('PILOT_AUTO_RETIRE') == true) {
    /* Find any retired pilots and set them to retired */
    PilotData::findRetiredPilots();
    CronData::set_lastupdate('find_retired_pilots');
}
if (Config::Get('CLOSE_BIDS_AFTER_EXPIRE') === false) {
    SchedulesData::deleteExpiredBids();
    CronData::set_lastupdate('check_expired_bids');
}
MaintenanceData::optimizeTables();
MainController::Run('Maintenance', 'resetpirepcount');
MainController::Run('Maintenance', 'resethours');
Esempio n. 28
0
    /**
     * Maintenance::resetscheduleroute()
     * 
     * @return
     */
    public function resetscheduleroute()
    {
        CodonModule::checkPermission(MAINTENANCE);
        echo '<h3>Reset cached schedule routes</h3> 
				Resetting... <br />';
        SchedulesData::deleteAllScheduleDetails();
        echo 'Completed!';
        LogData::addLog(Auth::$userinfo->pilotid, 'Reset cached schedule route details');
    }
Esempio n. 29
0
 public function index()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $postText = file_get_contents('php://input');
         $rec_xml = trim(utf8_encode(file_get_contents('php://input')));
         $xml = simplexml_load_string($rec_xml);
         if (!$xml) {
             #$this->log("Invalid XML Sent: \n".$rec_xml, 'kacars');
             return;
         }
         #$this->log(print_r($xml->asXML(), true), 'kacars');
         $case = strtolower($xml->switch->data);
         switch ($case) {
             case 'verify':
                 $results = Auth::ProcessLogin($xml->verify->pilotID, $xml->verify->password);
                 if ($results) {
                     $params = array('loginStatus' => '1');
                     //echo 1;
                 } else {
                     $params = array('loginStatus' => '0');
                     //echo 0;
                 }
                 $send = self::sendXML($params);
                 break;
             case 'getbid':
                 $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
                 $pilotinfo = PilotData::getPilotData($pilotid);
                 $biddata = SchedulesData::getLatestBid($pilotid);
                 $aircraftinfo = OperationsData::getAircraftByReg($biddata->registration);
                 if (count($biddata) == 1) {
                     if ($aircraftinfo->enabled == 1) {
                         $params = array('flightStatus' => '1', 'flightNumber' => $biddata->code . $biddata->flightnum, 'aircraftReg' => $biddata->registration, 'aircraftICAO' => $aircraftinfo->icao, 'aircraftFullName' => $aircraftinfo->fullname, 'flightLevel' => $biddata->flightlevel, 'aircraftMaxPax' => $aircraftinfo->maxpax, 'aircraftCargo' => $aircraftinfo->maxcargo, 'depICAO' => $biddata->depicao, 'arrICAO' => $biddata->arricao, 'route' => $biddata->route, 'depTime' => $biddata->deptime, 'arrTime' => $biddata->arrtime, 'flightTime' => $biddata->flighttime, 'flightType' => $biddata->flighttype, 'aircraftName' => $aircraftinfo->name, 'aircraftRange' => $aircraftinfo->range, 'aircraftWeight' => $aircraftinfo->weight, 'aircraftCruise' => $aircraftinfo->cruise);
                     } else {
                         $params = array('flightStatus' => '3');
                         // Aircraft Out of Service.
                     }
                 } else {
                     $params = array('flightStatus' => '2');
                     // You have no bids!
                 }
                 $send = $this->sendXML($params);
                 break;
             case 'getflight':
                 $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber);
                 $params = array('s.code' => $flightinfo['code'], 's.flightnum' => $flightinfo['flightnum'], 's.enabled' => 1);
                 $biddata = SchedulesData::findSchedules($params, 1);
                 $aircraftinfo = OperationsData::getAircraftByReg($biddata[0]->registration);
                 if (count($biddata) == 1) {
                     $params = array('flightStatus' => '1', 'flightNumber' => $biddata[0]->code . $biddata[0]->flightnum, 'aircraftReg' => $biddata[0]->registration, 'aircraftICAO' => $aircraftinfo->icao, 'aircraftFullName' => $aircraftinfo->fullname, 'flightLevel' => $biddata[0]->flightlevel, 'aircraftMaxPax' => $aircraftinfo->maxpax, 'aircraftCargo' => $aircraftinfo->maxcargo, 'depICAO' => $biddata[0]->depicao, 'arrICAO' => $biddata[0]->arricao, 'route' => $biddata[0]->route, 'depTime' => $biddata[0]->deptime, 'arrTime' => $biddata[0]->arrtime, 'flightTime' => $biddata[0]->flighttime, 'flightType' => $biddata[0]->flighttype, 'aircraftName' => $aircraftinfo->name, 'aircraftRange' => $aircraftinfo->range, 'aircraftWeight' => $aircraftinfo->weight, 'aircraftCruise' => $aircraftinfo->cruise);
                 } else {
                     $params = array('flightStatus' => '2');
                 }
                 $send = $this->sendXML($params);
                 break;
             case 'liveupdate':
                 $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
                 # Get the distance remaining
                 $depapt = OperationsData::GetAirportInfo($xml->liveupdate->depICAO);
                 $arrapt = OperationsData::GetAirportInfo($xml->liveupdate->arrICAO);
                 $dist_remain = round(SchedulesData::distanceBetweenPoints($xml->liveupdate->latitude, $xml->liveupdate->longitude, $arrapt->lat, $arrapt->lng));
                 # Estimate the time remaining
                 if ($xml->liveupdate->groundSpeed > 0) {
                     $Minutes = round($dist_remain / $xml->liveupdate->groundSpeed * 60);
                     $time_remain = self::ConvertMinutes2Hours($Minutes);
                 } else {
                     $time_remain = '00:00';
                 }
                 $lat = str_replace(",", ".", $xml->liveupdate->latitude);
                 $lon = str_replace(",", ".", $xml->liveupdate->longitude);
                 $fields = array('pilotid' => $pilotid, 'flightnum' => $xml->liveupdate->flightNumber, 'pilotname' => '', 'aircraft' => $xml->liveupdate->registration, 'lat' => $lat, 'lng' => $lon, 'heading' => $xml->liveupdate->heading, 'alt' => $xml->liveupdate->altitude, 'gs' => $xml->liveupdate->groundSpeed, 'depicao' => $xml->liveupdate->depICAO, 'arricao' => $xml->liveupdate->arrICAO, 'deptime' => $xml->liveupdate->depTime, 'arrtime' => '', 'route' => $xml->liveupdate->route, 'distremain' => $dist_remain, 'timeremaining' => $time_remain, 'phasedetail' => $xml->liveupdate->status, 'online' => '', 'client' => 'kACARS');
                 #$this->log("UpdateFlightData: \n".print_r($fields, true), 'kacars');
                 ACARSData::UpdateFlightData($pilotid, $fields);
                 break;
             case 'pirep':
                 $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber);
                 $code = $flightinfo['code'];
                 $flightnum = $flightinfo['flightnum'];
                 $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
                 # Make sure airports exist:
                 #  If not, add them.
                 if (!OperationsData::GetAirportInfo($xml->pirep->depICAO)) {
                     OperationsData::RetrieveAirportInfo($xml->pirep->depICAO);
                 }
                 if (!OperationsData::GetAirportInfo($xml->pirep->arrICAO)) {
                     OperationsData::RetrieveAirportInfo($xml->pirep->arrICAO);
                 }
                 # Get aircraft information
                 $reg = trim($xml->pirep->registration);
                 $ac = OperationsData::GetAircraftByReg($reg);
                 # Load info
                 /* If no passengers set, then set it to the cargo */
                 $load = $xml->pirep->pax;
                 if (empty($load)) {
                     $load = $xml->pirep->cargo;
                 }
                 /* Fuel conversion - kAcars only reports in lbs */
                 $fuelused = $xml->pirep->fuelUsed;
                 if (Config::Get('LiquidUnit') == '0') {
                     # Convert to KGs, divide by density since d = mass * volume
                     $fuelused = $fuelused * 0.45359237 / 0.8075;
                 } elseif (Config::Get('LiquidUnit') == '1') {
                     $fuelused = $fuelused * 6.84;
                 } elseif (Config::Get('LiquidUnit') == '2') {
                     $fuelused = $fuelused * 0.45359237;
                 }
                 $data = array('pilotid' => $pilotid, 'code' => $code, 'flightnum' => $flightnum, 'depicao' => $xml->pirep->depICAO, 'arricao' => $xml->pirep->arrICAO, 'aircraft' => $ac->id, 'flighttime' => $xml->pirep->flightTime, 'submitdate' => 'NOW()', 'comment' => $xml->pirep->comments, 'fuelused' => $fuelused, 'source' => 'kACARS', 'load' => $load, 'landingrate' => $xml->pirep->landing, 'log' => $xml->pirep->log);
                 #$this->log("File PIREP: \n".print_r($data, true), 'kacars');
                 $ret = ACARSData::FilePIREP($pilotid, $data);
                 if ($ret) {
                     $params = array('pirepStatus' => '1');
                     // Pirep Filed!
                 } else {
                     $params = array('pirepStatus' => '2');
                     // Please Try Again!
                 }
                 $send = $this->sendXML($params);
                 break;
             case 'aircraft':
                 $this->getAllAircraft();
                 break;
         }
     }
 }
Esempio n. 30
0
 public function viewbids()
 {
     if ($this->post->action == 'deletebid') {
         $ret = SchedulesData::RemoveBid($this->post->id);
         $params = array();
         if ($ret == true) {
             $params['status'] = 'ok';
         } else {
             $params['status'] = 'There was an error';
             $params['message'] = DB::error();
         }
         echo json_encode($params);
         return;
     }
     $this->set('allbids', SchedulesData::getAllBids());
     $this->render('pilots_viewallbids.tpl');
 }