public function acarsdata() { $output = ''; CodonEvent::Dispatch('refresh_acars', 'XML'); $flights = ACARSData::GetACARSData(); $xml = new SimpleXMLElement('<livemap/>'); if (!$flights) { $flights = array(); } foreach ($flights as $flight) { $pilot = $xml->addChild('aircraft'); $pilot->addAttribute('flightnum', $flight->flightnum); $pilot->addAttribute('lat', $flight->lat); $pilot->addAttribute('lng', $flight->lng); $pilot->addChild('pilotid', PilotData::GetPilotCode($flight->code, $flight->pilotid)); $pilot->addChild('pilotname', $flight->firstname . ' ' . $flight->lastname); $pilot->addChild('flightnum', $flight->flightnum); $pilot->addChild('lat', $flight->lat); $pilot->addChild('lng', $flight->lng); $pilot->addChild('depicao', $flight->depicao); $pilot->addChild('arricao', $flight->arricao); $pilot->addChild('phase', $flight->phasedetail); $pilot->addChild('alt', $flight->alt); $pilot->addChild('gs', $flight->gs); $pilot->addChild('distremain', $flight->distremain); $pilot->addChild('timeremain', $flight->timeremain); } header('Content-type: text/xml'); echo $xml->asXML(); }
public function testTimesAdded() { echo '<h3>Checking Times</h3>'; $sql = 'SELECT `flighttime` FROM ' . TABLE_PREFIX . 'pireps WHERE `accepted`=' . PIREP_ACCEPTED; $results = DB::get_results($sql); $this->added_time = 0; foreach ($results as $row) { $this->added_time = Util::AddTime($this->added_time, $row->flighttime); } heading('Time added, all PIREPS at once'); $this->assertNotEqual(0, $this->added_time); heading('Time added, pilot by pilot'); // Now calculate by PIREP $allpilots = PilotData::GetAllPilots(); $total = 0; foreach ($allpilots as $pilot) { $p_hours = PilotData::getPilotHours($pilot->pilotid); $total = Util::AddTime($total, $p_hours); } $this->assertNotEqual(0, $total); heading('Comparing pilot to pilot vs all PIREPS'); $this->assertEqual($total, $this->added_time); heading('Compare to STAT total hours'); StatsData::UpdateTotalHours(); $this->assertEqual($total, StatsData::TotalHours()); echo '<br />'; }
/** * ActivityData::pushToTwitter() * * @param mixed $params * @return void */ public static function pushToTwitter($params) { require_once CORE_LIB_PATH . '/twitteroauth/twitteroauth.php'; $params = array_merge(array('pilotid' => '', 'type' => '', 'refid' => '', 'message' => ''), $params); $message = ''; # These defaults will be ignored $lat = -120; $long = -120; if (!empty($params['pilotid'])) { $pilot = PilotData::getPilotData($params['pilotid']); $message .= PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' ' . $pilot->firstname . ' ' . $pilot->lastname . ' '; } $message .= $params['message'] . ' '; # Show a new PIREP, also get the airport information if ($params['type'] == ACTIVITY_NEW_PIREP) { $message .= url('/pireps/view/' . $params['refid']); $pirep = PIREPData::findPIREPS(array('pirepid' => $params['refid']), 1); $pirep = $pirep[0]; $airport = OperationsData::getAirportInfo($pirep->arricao); $lat = $airport->lat; $long = $airport->lng; } elseif ($params['type'] == ACTIVITY_NEW_PILOT) { $message .= url('/profile/view/' . $params['pilotid']); $airport = OperationsData::getAirportInfo($pilot->hub); $lat = $airport->lat; $long = $airport->lng; } $tweet = new TwitterOAuth(Config::get('TWITTER_CONSUMER_KEY'), Config::get('TWITTER_CONSUMER_SECRET'), Config::get('TWITTER_OAUTH_TOKEN'), Config::get('TWITTER_OAUTH_SECRET')); $status = $tweet->post('statuses/update', array('status' => $message, 'lat' => $lat, 'long' => $long, 'trim_user' => true)); return $status; }
public function testTimesAdded() { $sql = 'SELECT `flighttime` FROM ' . TABLE_PREFIX . 'pireps WHERE `accepted`=' . PIREP_ACCEPTED; $results = DB::get_results($sql); if (!$results) { $this->markTestSkipped('No PIREPs to test against'); } $this->added_time = 0; foreach ($results as $row) { $this->added_time = Util::AddTime($this->added_time, $row->flighttime); } $this->assertNotEqual(0, $this->added_time); // Now calculate by PIREP $allpilots = PilotData::GetAllPilots(); $total = 0; foreach ($allpilots as $pilot) { $p_hours = PilotData::getPilotHours($pilot->pilotid); $total = Util::AddTime($total, $p_hours); } $this->assertNotEqual(0, $total); $this->assertEqual($total, $this->added_time); StatsData::UpdateTotalHours(); $this->assertEqual($total, StatsData::TotalHours()); }
public function savepro() { if ($this->post->firstname == '' || $this->post->lastname == '') { $this->set('message', 'The first or lastname cannot be blank!'); $this->render('core_error.tpl'); return; } $params = array('firstname' => $this->post->firstname, 'lastname' => $this->post->lastname, 'email' => $this->post->email, 'hub' => $this->post->hub, 'retired' => $this->post->retired, 'totalflights' => $this->post->totalflights, 'totalpay' => floatval($this->post->totalpay), 'transferhours' => $this->post->transferhours); PilotData::updateProfile($this->post->pilotid, $params); PilotData::SaveFields($this->post->pilotid, $_POST); /* Don't calculate a pilot's rank if this is set */ if (Config::Get('RANKS_AUTOCALCULATE') == false) { PilotData::changePilotRank($this->post->pilotid, $this->post->rank); } else { RanksData::calculateUpdatePilotRank($this->post->pilotid); } StatsData::UpdateTotalHours(); $this->set('message', 'Profile updated successfully'); $this->render('core_success.tpl'); $this->set('pilots', PilotData::getAllPilots()); $this->render('/pm/pilot_manager.php'); if ($this->post->resend_email == 'true') { $this->post->id = $this->post->pilotid; $this->resendemail(false); } $pilot = PilotData::getPilotData($this->post->pilotid); LogData::addLog(Auth::$userinfo->pilotid, 'Updated profile for ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' ' . $pilot->firstname . ' ' . $pilot->lastname); return; break; }
function testDeleteUser() { $result = PilotData::DeletePilot($this->pilotid); $this->assertTrue($result, 'Deleting pilot'); # Verify deletion $data = PilotData::GetPilotData($this->pilotid); $this->assertFalse($data, "Pilot still exists"); # Last test, add a line break echo "<br />"; }
public function sendmail() { $this->checkPermission(EMAIL_PILOTS); echo '<h3>Sending email</h3>'; if ($this->post->subject == '' || trim($this->post->message) == '') { $this->set('message', 'You must enter a subject and message!'); $this->render('core_error.php'); return; } if (count($this->post->groups) == 0) { $this->set('message', 'You must select groups to send to!'); $this->render('core_error.php'); return; } echo 'Sending email...<br />'; $pilotarray = array(); //Begin the nice long assembly of e-mail addresses foreach ($this->post->groups as $groupid) { if ($groupid == 'all') { $all_pilots = PilotData::findPilots(array()); foreach ($all_pilots as $pilot) { $pilotarray[$pilot->pilotid] = $pilot; } break; } else { $tmp = PilotGroups::getUsersInGroup($groupid); if (count($tmp) == 0 || !is_array($tmp)) { continue; } foreach ($tmp as $pilot) { $pilotarray[$pilot->pilotid] = $pilot; } } } $subject = DB::escape($this->post->subject); $message = stripslashes($this->post->message) . PHP_EOL . PHP_EOL; # Do some quick fixing of obvious formatting errors $message = str_replace('<br>', '<br />', $message); foreach ($pilotarray as $pilot) { echo 'Sending for ' . $pilot->firstname . ' ' . $pilot->lastname . '<br />'; # Variable replacements $send_message = str_replace('{PILOT_FNAME}', $pilot->firstname, $message); $send_message = str_replace('{PILOT_LNAME}', $pilot->lastname, $send_message); $send_message = str_replace('{PILOT_ID}', PilotData::GetPilotCode($pilot->code, $pilot->pilotid), $send_message); $send_message = utf8_encode($send_message); Util::SendEmail($pilot->email, $subject, $send_message); } echo 'Complete!'; LogData::addLog(Auth::$userinfo->pilotid, 'Sent pass mail'); return; }
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; }
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; }
/** * 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; }
/** * UserTest::testDeleteUser() * * @return void */ public function testDeleteUser() { $pilot = PilotData::getPilotByEmail('*****@*****.**'); $this->assertObjectHasAttribute('pilotid', $pilot, 'PilotData::getPilotByEmail'); $result = PilotData::deletePilot($pilot->pilotid); $data = PilotData::GetPilotData($pilot->pilotid); $this->assertFalse($data, "Pilot still exists"); }
protected function write_template($name, $save_as) { $this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid)); $this->set('userinfo', Auth::$userinfo); $acars_config = Template::GetTemplate($name, true); $acars_config = str_replace("\n", "\r\n", $acars_config); Util::downloadFile($acars_config, $save_as); return; # Set the headers so the browser things a file is being sent header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="' . $save_as . '"'); header('Content-Length: ' . strlen($acars_config)); echo $acars_config; }
* * @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');
/** * Add a User * * $data = array( * 'firstname' => '', * 'lastname' => '', * 'email' => '', * 'password' => '', * 'code' => '', * 'location' => '', * 'hub' => '', * 'confirm' => false); */ public static function addUser($data) { /*$data = array( 'firstname' => '', 'lastname' => '', 'email' => '', 'password' => '', 'code' => '', 'location' => '', 'hub' => '', 'confirm' => false);*/ $exists = self::CheckUserEmail($data['email']); if (is_object($exists)) { self::$error = 'Email already exists'; return false; } //Set the password, add some salt $salt = md5(date('His')); $password = md5($data['password'] . $salt); //Stuff it into here, the confirmation email will use it. self::$salt = $salt; $code = DB::escape(strtoupper($data['code'])); $firstname = DB::escape(ucwords($data['firstname'])); $lastname = DB::escape(ucwords($data['lastname'])); $location = DB::escape(strtoupper($data['location'])); //Add this stuff in if ($data['confirm'] === true) { $confirm = 1; } else { $confirm = 0; } $sql = "INSERT INTO " . TABLE_PREFIX . "pilots (firstname, lastname, email,\n\t\t\t\t\tcode, location, hub, password, salt, confirmed, joindate, lastip)\n\t\t\t\t VALUES ('{$firstname}', '{$lastname}', '{$data['email']}', '{$code}',\n\t\t\t\t\t\t\t'{$location}', '{$data['hub']}', '{$password}', '{$salt}', {$confirm}, NOW(), '{$_SERVER['REMOTE_ADDR']}')"; $res = DB::query($sql); if (DB::errno() != 0) { if (DB::errno() == 1062) { self::$error = 'This email address is already registered'; return false; } self::$error = DB::error(); return false; } //Grab the new pilotid, we need it to insert those "custom fields" $pilotid = DB::$insert_id; RanksData::CalculateUpdatePilotRank($pilotid); PilotData::GenerateSignature($pilotid); /* Add them to the default group */ $defaultGroup = SettingsData::getSettingValue('DEFAULT_GROUP'); PilotGroups::addUsertoGroup($pilotid, $defaultGroup); // For later self::$pilotid = $pilotid; //Get customs fields $fields = self::GetCustomFields(); if (!$fields) { return true; } foreach ($fields as $field) { $value = Vars::POST($field->fieldname); $value = DB::escape($value); if ($value != '') { $sql = "INSERT INTO " . TABLE_PREFIX . "fieldvalues (fieldid, pilotid, value)\n\t\t\t\t\t\t\tVALUES ({$field->fieldid}, {$pilotid}, '{$value}')"; DB::query($sql); } } return true; }
protected function edit_pirep_post() { 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!'); $this->render('core_error.tpl'); return false; } $pirepInfo = PIREPData::getReportDetails($this->post_action->pirepid); if (!$pirepInfo) { $this->set('message', 'Invalid PIREP!'); $this->render('core_error.tpl'); return false; } $this->post->fuelused = str_replace(' ', '', $this->post->fuelused); $this->post->fuelused = str_replace(',', '', $this->post->fuelused); $fuelcost = $this->post->fuelused * $this->post->fuelunitcost; # form the fields to submit $data = array('pirepid' => $this->post->pirepid, 'code' => $this->post->code, 'flightnum' => $this->post->flightnum, 'leg' => $this->post->leg, 'depicao' => $this->post->depicao, 'arricao' => $this->post->arricao, 'aircraft' => $this->post->aircraft, 'flighttime' => $this->post->flighttime, 'load' => $this->post->load, 'price' => $this->post->price, 'pilotpay' => $this->post->pilotpay, 'fuelused' => $this->post->fuelused, 'fuelunitcost' => $this->post->fuelunitcost, 'fuelprice' => $fuelcost, 'expenses' => $this->post->expenses); if (!PIREPData::UpdateFlightReport($this->post->pirepid, $data)) { $this->set('message', 'There was an error editing your PIREP'); $this->render('core_error.tpl'); return false; } PIREPData::SaveFields($this->post->pirepid, $_POST); //Accept or reject? $this->post->id = $this->post->pirepid; $submit = strtolower($this->post->submit_pirep); // Add a comment if (trim($this->post->comment) != '' && $submit != 'reject pirep') { PIREPData::AddComment($this->post->pirepid, Auth::$userinfo->pilotid, $this->post->comment); } if ($submit == 'accept pirep') { $this->approve_pirep_post(); } elseif ($submit == 'reject pirep') { $this->reject_pirep_post(); } StatsData::UpdateTotalHours(); # Update a pilot's stats PilotData::updatePilotStats($pirepInfo->pilotid); LogData::addLog(Auth::$userinfo->pilotid, 'Edited PIREP #' . $this->post->id); return true; }
/** * SchedulePIREPTest::testPIREPRejected() * * @return void */ public function testPIREPRejected() { $this->resetPilot(); $sched = $this->findSchedule(); Config::Set('PIREP_CHECK_DUPLICATE', false); Config::Set('EMAIL_SEND_PIREP', false); # Update this schedule to only pay per-hour SchedulesData::editScheduleFields($sched->id, array('payforflight' => 0)); $sched = $this->findSchedule(); $this->assertEquals(0, $sched->payforflight, 'Pay per-flight set to 0'); $pirep_test = array('pilotid' => $this->samplePilotID, 'code' => $sched->code, 'flightnum' => $sched->flightnum, 'route' => $sched->route, 'depicao' => $sched->depicao, 'arricao' => $sched->arricao, 'aircraft' => $sched->aircraft, 'flighttime' => $sched->flighttime, 'submitdate' => 'NOW()', 'fuelused' => 6000, 'source' => 'unittest', 'comment' => 'Test Flight'); # Update Pilot Pay to be set to zero PilotData::updateProfile($this->samplePilotID, array('totalpay' => 0)); $pilot_data = PilotData::getPilotData($this->samplePilotID); $this->assertEquals($pilot_data->totalpay, 0, 'Reset Pilot Pay to 0'); # File the flight report $pirepid = PIREPData::fileReport($pirep_test); $this->assertGreaterThan(0, $pirepid, PIREPData::$lasterror); $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid)); $this->assertGreaterThan(0, count($pirepdata), 'No PIREPs returned'); # Work on one... $pirepdata = $pirepdata[0]; # Verify the little bits of this PIREP.... $this->assertEquals(PILOT_PAY_HOURLY, $pirepdata->paytype, 'PIREP Pay Type'); $this->assertEquals($pilot_data->payrate, $pirepdata->pilotpay, 'PIREP Pay Amount'); # Check the pilot pay $pilot_data = PilotData::getPilotData($this->samplePilotID); $this->assertEquals(0, $pilot_data->totalpay, 'Check pilot pay after PIREP FILE'); # Reject the PIREP and then check the pilot pay $status = PIREPData::changePIREPStatus($pirepdata->pirepid, PIREP_REJECTED); $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid)); $this->assertEquals(PIREP_REJECTED, $pirepdata[0]->accepted, 'changePIREPStatus to ACCEPTED'); $pirepdata = $pirepdata[0]; # Check the schedule flown count: $post_accept = $this->findSchedule(); $this->assertEquals($sched->timesflown, $post_accept->timesflown, "Schedule increment count"); $post_pilot_data = PilotData::getPilotData($this->samplePilotID); $this->assertEquals(0, $post_pilot_data->totalpay, 'Check pilot pay after PIREP REJECT'); $this->assertEquals($pilot_data->totalflights, $post_pilot_data->totalflights, 'Total Flights'); # Delete the PIREP PIREPData::deletePIREP($pirepid); # Verify delete $data = PIREPData::findPIREPS(array('p.pirepid' => $pirepid)); $this->assertEmpty($data, 'PIREPDdata::deletePIREP()'); }
/** * Write out a config file to the user, give the template name and * the filename to save the template as to the user * * @param mixed $template_name Template to use for config (fspax_config.php) * @param mixed $save_as File to save as (xacars.ini) * @return mixed Nothing, sends the file to the user * */ public function write_config($template_name, $save_as) { if (!Auth::LoggedIn()) { echo 'You are not logged in!'; exit; } $this->set('pilotcode', PilotData::GetPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid)); $this->set('userinfo', Auth::$pilot); $this->set('pilot', Auth::$pilot); $acars_config = Template::GetTemplate($template_name, true); $acars_config = str_replace("\n", "\r\n", $acars_config); Util::downloadFile($acars_config, $save_as); }
public function RecentFrontPage($count = 5) { $this->set('pilots', PilotData::GetLatestPilots($count)); $this->render('frontpage_recentpilots.tpl'); }
public static function calculateUpdatePilotRank($pilotid) { /* Don't calculate a pilot's rank if this is set */ if (Config::Get('RANKS_AUTOCALCULATE') == false) { return; } $pilotid = intval($pilotid); $allranks = self::GetAllRanks(); $pilot = PilotData::GetPilotData($pilotid); $pilothours = $pilot->totalhours; if (Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $pilothours += $pilot->transferhours; } $i = 0; foreach ($allranks as $rank) { $i++; if ($pilothours >= intval($rank->minhours)) { $rank_level = $i; $last_rank = $rank->rank; $last_rankid = $rank->rankid; } } $update = array('rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level); PilotData::updateProfile($pilot->pilotid, $update); }
protected static function create_acars_flight($flight) { if (is_object($flight)) { $flight = (array) $flight; } // If a unique was specified if (isset($flight['unique_id'])) { $flight['id'] = $flight['unique_id']; } $acars_xml = self::$xml->addChild('flight'); $acars_xml->addChild('unique_id', $flight['id']); $acars_xml->addChild('pilotid', PilotData::GetPilotCode($flight['code'], $flight['pilotid'])); $acars_xml->addChild('pilotname', $flight['pilotname']); $acars_xml->addChild('flightnum', $flight['flightnum']); $acars_xml->addChild('aircraft', $flight['aircraft']); $acars_xml->addChild('lat', $flight['lat']); $acars_xml->addChild('lng', $flight['lng']); $acars_xml->addChild('depicao', $flight['depicao']); $acars_xml->addChild('arricao', $flight['arricao']); $acars_xml->addChild('deptime', $flight['deptime']); $acars_xml->addChild('arrtime', $flight['arrtime']); $acars_xml->addChild('heading', $flight['heading']); $acars_xml->addChild('phase', $flight['phasedetail']); $acars_xml->addChild('alt', $flight['alt']); $acars_xml->addChild('gs', $flight['gs']); $acars_xml->addChild('distremain', $flight['distremain']); $acars_xml->addChild('timeremain', $flight['timeremaining']); $acars_xml->addChild('client', $flight['client']); $acars_xml->addChild('lastupdate', $flight['lastupdate']); }
case 'pirep': Debug::log('PIREP FILE', 'fsacars'); Debug::log(serialize($_GET), 'fsacars'); $pilotid = PilotData::parsePilotID($_GET['pilot']); /*if(is_numeric($_GET['pilot'])) { $pilotid = $_GET['pilot']; } else { # see if they are a valid pilot: preg_match('/^([A-Za-z]*)(\d*)/', $_GET['pilot'], $matches); $code = $matches[1]; $pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET'); }*/ if (!($pilot = PilotData::GetPilotData($pilotid))) { echo 'Invalid Pilot!'; return; } # # Check if anything was in the log # If not, then it probably wasn't a multi-chunk, so # just pull it straight from the query string # Otherwise, pull the full-text from the session # if ($_GET['more'] == '1') { # # We have more coming to the log # $report = PIREPData::GetLastReports($pilotid, 1); /* Check for any other data which might be in the other
protected function save_profile_post() { if (!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.tpl'); return; } $userinfo = Auth::$userinfo; //TODO: check email validity if ($this->post->email == '') { return; } $params = array('code' => Auth::$userinfo->code, 'email' => $this->post->email, 'location' => $this->post->location, 'hub' => Auth::$userinfo->hub, 'bgimage' => $this->post->bgimage, 'retired' => false); PilotData::updateProfile($userinfo->pilotid, $params); PilotData::SaveFields($userinfo->pilotid, $_POST); # Generate a fresh signature PilotData::GenerateSignature($userinfo->pilotid); PilotData::SaveAvatar($userinfo->code, $userinfo->pilotid); $this->set('message', 'Profile saved!'); $this->render('core_success.tpl'); }
/** * Log the user in */ public static function ProcessLogin($useridoremail, $password) { # Allow them to login in any manner: # Email: blah@blah.com # Pilot ID: VMA0001, VMA 001, etc # Just ID: 001 if (is_numeric($useridoremail)) { $useridoremail = $useridoremail - intval(Config::Get('PILOTID_OFFSET')); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE pilotid=' . $useridoremail; } else { # They're logging in with an email if (preg_match('/^.*\\@.*$/i', $useridoremail) > 0) { $emailaddress = DB::escape($useridoremail); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE email=\'' . $useridoremail . '\''; } elseif (preg_match('/^([A-Za-z]*)(.*)(\\d*)/', $useridoremail, $matches) > 0) { $id = trim($matches[2]); $id = $id - intval(Config::Get('PILOTID_OFFSET')); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE pilotid=' . $id; } else { self::$error_message = 'Invalid user ID'; return false; } } $password = DB::escape($password); $userinfo = DB::get_row($sql); if (!$userinfo) { self::$error_message = 'This user does not exist'; return false; } /* Implement the pilot statuses, see if they are allowed in according to their status */ $pilotStatuses = Config::get('PILOT_STATUS_TYPES'); foreach ($pilotStatuses as $id => $info) { if ($userinfo->retired == $id && $info['canlogin'] == false) { self::$error_message = $info['message']; return false; } } /*if($userinfo->retired == 1) { self::$error_message = 'Your account was deactivated, please contact an admin'; return false; }*/ //ok now check it $hash = md5($password . $userinfo->salt); if ($hash == $userinfo->password) { self::$userinfo = $userinfo; #deprecated self::$pilot = self::$userinfo; self::update_session(self::$session_id, self::$userinfo->pilotid); SessionManager::Set('loggedin', 'true'); SessionManager::Set('userinfo', $userinfo); SessionManager::Set('usergroups', PilotGroups::GetUserGroups($userinfo->pilotid)); PilotData::updateProfile($pilotid, array('lastlogin' => 'NOW()', 'lastip' => $_SERVER['REMOTE_ADDR'])); return true; } else { self::$error_message = 'Invalid login, please check your username and password'; self::LogOut(); return false; } }
public function ProcessLogin() { $email = $this->post->email; $password = $this->post->password; if ($email == '' || $password == '') { $this->set('message', 'You must fill out both your username and password'); $this->render('login_form.tpl'); return false; } if (!Auth::ProcessLogin($email, $password)) { $this->set('message', Auth::$error_message); $this->render('login_form.tpl'); return false; } else { if (Auth::$pilot->confirmed == PILOT_PENDING) { $this->render('login_unconfirmed.tpl'); Auth::LogOut(); // show error } elseif (Auth::$pilot->confirmed == PILOT_REJECTED) { $this->render('login_rejected.tpl'); Auth::LogOut(); } else { $pilotid = Auth::$pilot->pilotid; $session_id = Auth::$session_id; # If they choose to be "remembered", then assign a cookie if ($this->post->remember == 'on') { $cookie = "{$session_id}|{$pilotid}|{$_SERVER['REMOTE_ADDR']}"; $res = setrawcookie(VMS_AUTH_COOKIE, $cookie, time() + Config::Get('SESSION_LOGIN_TIME'), '/'); } PilotData::updateLogin($pilotid); CodonEvent::Dispatch('login_success', 'Login'); $this->post->redir = str_replace('index.php/', '', $this->post->redir); header('Location: ' . url('/' . $this->post->redir)); } return; } }
/** * Pilots::RecentFrontPage() * * @param integer $count * @return */ public function RecentFrontPage($count = 5) { $pilot_list = PilotData::getLatestPilots($count); $this->set('pilots', $pilot_list); $this->set('pilot_list', $pilot_list); $this->render('frontpage_recentpilots.tpl'); }
/** * CentralData::create_acars_flight() * * @param mixed $flight * @return */ protected static function create_acars_flight($flight) { if (is_object($flight)) { $flight = (array) $flight; } // If a unique was specified if (isset($flight['unique_id'])) { $flight['id'] = $flight['unique_id']; } $acars_xml = self::addElement(null, 'flight', null, array('unique_id' => $flight['id'], 'pilotid' => PilotData::GetPilotCode($flight['code'], $flight['pilotid']), 'pilotname' => $flight['pilotname'], 'flightnum' => $flight['flightnum'], 'aircraft' => $flight['aircraft'], 'lat' => $flight['lat'], 'lng' => $flight['lng'], 'depicao' => $flight['depicao'], 'arricao' => $flight['arricao'], 'deptime' => $flight['deptime'], 'arrtime' => $flight['arrtime'], 'heading' => $flight['heading'], 'phase' => $flight['phasedetail'], 'alt' => $flight['alt'], 'gs' => $flight['gs'], 'distremain' => $flight['distremain'], 'timeremain' => $flight['timeremaining'], 'client' => $flight['client'], 'lastupdate' => $flight['lastupdate'])); }
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; } } }
/** * Update a pilot's flight data, ie after a pirep * * @param int $pilotid Pilot ID * @param int $flighttime Number of hours.minutes to increment by * @param int $numflights Number of flights (default 1) * @return bool Success * */ public static function updateFlightData($pilotid, $flighttime, $numflights = 1) { # Update the flighttime $pilotdata = PilotData::getPilotData($pilotid); $flighttime = Util::AddTime($pilotdata->totalhours, $flighttime); if ($numflights == '') { $numflights = 1; } $params = array('totalhours' => $flighttime, 'totalflights' => $pilotdata->totalflights + $numflights); return self::updateProfile($pilotid, $params); }
/** * Installer::SiteSetup() * * @return */ public static function SiteSetup() { /*$_POST['SITE_NAME'] == '' || $_POST['firstname'] == '' || $_POST['lastname'] == '' || $_POST['email'] == '' || $_POST['password'] == '' || $_POST['vaname'] == '' || $_POST['vacode'] == ''*/ // first add the airline $_POST['vacode'] = strtoupper($_POST['vacode']); if (!OperationsData::addAirline($_POST['vacode'], $_POST['vaname'])) { self::$error = __FILE__ . ' ' . __LINE__ . ' ' . DB::$error; return false; } // Add the user $data = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'email' => $_POST['email'], l, 'password' => $_POST['password'], 'code' => $_POST['vacode'], 'location' => 'US', 'hub' => 'KJFK', 'confirm' => true); if (!RegistrationData::addUser($data)) { self::$error = __FILE__ . ' ' . __LINE__ . ' ' . DB::$error; return false; } RanksData::calculatePilotRanks(); # Add to admin group $pilotdata = PilotData::getPilotByEmail($_POST['email']); if (!PilotGroups::addUsertoGroup($pilotdata->pilotid, 'Administrators')) { self::$error = __FILE__ . ' ' . __LINE__ . ' ' . DB::$error; return false; } # Add the final settings in SettingsData::SaveSetting('SITE_NAME', $_POST['SITE_NAME']); SettingsData::SaveSetting('ADMIN_EMAIL', $_POST['email']); SettingsData::SaveSetting('GOOGLE_KEY', $_POST['googlekey']); return true; }
if (!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die; } ?> <div id="mainbox"> <h3>Pilot Center</h3> <div class="indent"> <p><strong>Welcome back <?php echo $pilot->firstname . ' ' . $pilot->lastname; ?> !</strong></p> <table> <tr> <td valign="top" align="center"> <img src="<?php echo PilotData::getPilotAvatar($pilotcode); ?> " /> <br /><br /> <img src="<?php echo $pilot->rankimage; ?> " /> </td> <td valign="top"> <ul style="margin-top: 0px;"> <li><strong>Your Pilot ID: </strong> <?php echo $pilotcode; ?> </li> <li><strong>Your Rank: </strong><?php