/** * 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 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; }
/** * UserTest::testEditUserData() * * @return void */ public function testEditUserData() { $pilot = PilotData::getPilotByEmail('*****@*****.**'); $this->assertObjectHasAttribute('pilotid', $pilot, 'PilotData::getPilotByEmail'); # Check a save profile $save = PilotData::updateProfile($pilot->pilotid, array('email' => '*****@*****.**', 'location' => 'PK')); $this->assertTrue($save, DB::error()); # Verify if data was written, and if it differs $changeset1 = PilotData::getPilotData($pilot->pilotid); $this->assertEquals('PK', $changeset1->location); unset($data); }
/** * Profile::view() * * @param string $pilotid * @return */ public function view($pilotid = '') { $pilotid = PilotData::parsePilotID($pilotid); $pilot = PilotData::getPilotData($pilotid); $this->title = 'Profile of ' . $pilot->firstname . ' ' . $pilot->lastname; $this->set('userinfo', $pilot); $this->set('pilot', $pilot); $this->set('allfields', PilotData::getFieldData($pilotid, false)); $pirep_list = PIREPData::getAllReportsForPilot($pilotid); $this->set('pireps', $pirep_list); $this->set('pirep_list', $pirep_list); $this->set('pilotcode', PilotData::getPilotCode($pilot->code, $pilot->pilotid)); $this->set('allawards', AwardsData::getPilotAwards($pilot->pilotid)); $this->render('pilot_public_profile.tpl'); $this->render('pireps_viewall.tpl'); }
/** * This is the public profile for the pilot */ public function view($pilotid = '') { if (!is_numeric($pilotid)) { preg_match('/^([A-Za-z]*)(\\d*)/', $pilotid, $matches); $code = $matches[1]; $pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET'); } $userinfo = PilotData::getPilotData($pilotid); $this->title = 'Profile of ' . $userinfo->firstname . ' ' . $userinfo->lastname; $this->set('userinfo', $userinfo); $this->set('allfields', PilotData::GetFieldData($pilotid, false)); $this->set('pireps', PIREPData::GetAllReportsForPilot($pilotid)); $this->set('pilotcode', PilotData::GetPilotCode($userinfo->code, $userinfo->pilotid)); $this->set('allawards', AwardsData::GetPilotAwards($userinfo->pilotid)); $this->render('pilot_public_profile.tpl'); $this->render('pireps_viewall.tpl'); }
/** * Profile::view() * * @param string $pilotid * @return */ public function view($pilotid = '') { #replacement for OFC charts - Google Charts API - simpilot $this->set('chart_url', ChartsData::build_pireptable($pilotid, 30)); #end $pilotid = PilotData::parsePilotID($pilotid); $pilot = PilotData::getPilotData($pilotid); $this->title = 'Profile of ' . $pilot->firstname . ' ' . $pilot->lastname; $this->set('userinfo', $pilot); $this->set('pilot', $pilot); $this->set('allfields', PilotData::getFieldData($pilotid, false)); $pirep_list = PIREPData::getAllReportsForPilot($pilotid); $this->set('pireps', $pirep_list); $this->set('pirep_list', $pirep_list); $this->set('pilotcode', PilotData::getPilotCode($pilot->code, $pilot->pilotid)); $this->set('allawards', AwardsData::getPilotAwards($pilot->pilotid)); $this->render('pilot_public_profile.tpl'); $this->render('pireps_viewall.tpl'); }
$slot_time = $slot_time + $event->slot_interval * 60; } echo '</td>'; } else { echo '<td>Available Signups</td>'; echo '<td align="left">'; $slot_time = strtotime($event->time); $slots = 1; while ($slots <= $event->slot_limit) { $test = date('G:i', $slot_time); $check2 = EventsData::signup_time($event->id, $test); if (!$check2) { echo date('G:i', $slot_time) . ' - <a href="' . SITE_URL . '/index.php/events/signup?eid=' . $event->id . '&pid=' . Auth::$userinfo->pilotid . '&time=' . date('G:i', $slot_time) . '">Open</a><br />'; $slots++; } else { $pilot = PilotData::getPilotData($check2->pilot_id); echo date('G:i', $slot_time) . ' - '; echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid) . ' - '; echo $pilot->firstname . ' ' . $pilot->lastname . '<br />'; } $slot_time = $slot_time + $event->slot_interval * 60; } echo '</td>'; ?> </tr> <?php } } ?> </table> <br />
<?php /*Cologne International Pilot Profile Page * VERSION: 1.0 * DATE: 2015.12.25 * AUTHOR: BASTIAN WAGNER */ require './smarty/libs/Smarty.class.php'; //Smarty einbinden require '../phpvms/core/codon.config.php'; // phpVMS config file einbinden //Neue Smarty Instanz erstellen $tpl = new Smarty(); //Pilot-Basisinformationen aus URL und phpVMS auslesen $pilotid = $_GET["id"]; $userinfo = PilotData::getPilotData($pilotid); //Alle Daten des Piloten in Variablen speichern //PilotID $pilotcode = PilotData::GetPilotCode($userinfo->code, $userinfo->pilotid); //Pilot Name $name = $userinfo->firstname . ' ' . $userinfo->lastname; //Rang Bild $rankimg = $userinfo->rankimage; //Rang $rank = $userinfo->rank; //Flüge insg. $totalflights = $userinfo->totalflights; //Stunden insg. $totalhours = Util::AddTime($userinfo->totalhours, $userinfo->transferhours); //Landesflagge $countryflag = Countries::getCountryImage($userinfo->location);
/** * Maintenance::changepilotid() * * @return */ public function changepilotid() { CodonModule::checkPermission(MAINTENANCE); CodonModule::checkPermission(EDIT_PILOTS); echo '<h3>Change Pilot ID</h3>'; if (isset($this->post->submit)) { $error = false; if (!is_numeric($this->post->new_pilotid)) { $error = true; $this->set('message', 'The pilot ID isn\'t numeric!'); $this->render('core_error.php'); return; } if ($this->post->new_pilotid < 1) { $error = true; $this->set('message', 'You cannot have an ID less than 1'); $this->render('core_error.php'); return; } if (empty($this->post->new_pilotid)) { $error = true; $this->set('message', 'The pilot ID is blank!'); $this->render('core_error.php'); return; } if (empty($this->post->old_pilotid) || $this->post->old_pilotid == 0) { $error = true; $this->set('message', 'No pilot selected'); $this->render('core_error.php'); return; } $pilot = PilotData::getPilotData($this->post->new_pilotid); if (is_object($pilot)) { $error = true; $this->set('message', 'This ID is already used!'); $this->render('core_error.php'); return; } if ($error === false) { PilotData::changePilotID($this->post->old_pilotid, $this->post->new_pilotid); $this->set('message', "Pilot ID changed from {$this->post->old_pilotid} to {$this->post->new_pilotid}"); $this->render('core_success.php'); } } $this->set('allpilots', PilotData::findPilots(array())); $this->render('maintenance_changepilotid.php'); }
/** * 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); }
/** * Populate the PIREP with the fianancial info needed * * @param mixed $pirep Either a PIREP ID or the row * @param bool $reset_fuel Reset the fuel costs or not? * @return */ 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; } } /* Set the pilotpay here - if it was a per-schedule payment, then set the pilot pay to that, otherwise, set it to the total amount paid... */ # Handle pilot pay if (!empty($sched->payforflight)) { $pilot->payrate = $sched->payforflight; $payment_type = PILOT_PAY_SCHEDULE; } else { $payment_type = PILOT_PAY_HOURLY; } $data = array('price' => $sched->price, 'load' => $pirep->load, 'fuelprice' => $pirep->fuelprice, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'flighttime' => $pirep->flighttime); $revenue = self::getPIREPRevenue($data, $payment_type); /* 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, 'paytype' => $payment_type, 'revenue' => $revenue); if (isset($data['load']) && $data['load'] != '') { $fields['load'] = $data['load']; } return self::editPIREPFields($pirepid, $fields); }
public function changepilotid() { echo '<h3>Change Pilot ID</h3>'; if (isset($this->post->submit)) { $error = false; if (!is_numeric($this->post->new_pilotid)) { $error = true; $this->set('message', 'The pilot ID isn\'t numeric!'); $this->render('core_error.tpl'); return; } if ($this->post->new_pilotid < 1) { $error = true; $this->set('message', 'You cannot have an ID less than 1'); $this->render('core_error.tpl'); return; } if (empty($this->post->new_pilotid)) { $error = true; $this->set('message', 'The pilot ID is blank!'); $this->render('core_error.tpl'); return; } if (empty($this->post->old_pilotid) || $this->post->old_pilotid == 0) { $error = true; $this->set('message', 'No pilot selected'); $this->render('core_error.tpl'); return; } $pilot = PilotData::getPilotData($this->post->new_pilotid); if (is_object($pilot)) { $error = true; $this->set('message', 'This ID is already used!'); $this->render('core_error.tpl'); return; } if ($error === false) { PilotData::changePilotID($this->post->old_pilotid, $this->post->new_pilotid); CodonEvent::Dispatch('pilotid_changed', 'Maintenance', array('old_pilotid' => $this->post->old_pilotid, 'new_pilotid' => $this->post->new_pilotid)); $this->set('message', "Pilot ID changed from {$this->post->old_pilotid} to {$this->post->new_pilotid}"); $this->render('core_success.tpl'); } } $this->set('allpilots', PilotData::findPilots(array())); $this->render('maintenance_changepilotid.tpl'); }
//Creative Commons Attribution Non-commercial Share Alike (by-nc-sa) //To view full license text visit http://creativecommons.org/licenses/by-nc-sa/3.0/ // //@author David Clark (simpilot) //@copyright Copyright (c) 2009-2010, David Clark //@license http://creativecommons.org/licenses/by-nc-sa/3.0/ ?> <h3>Event Attendance Pilot Statistics</h3> <center> <table width="100%" border="1px"> <tr> <td>Pilot</td> <td># Of Events Attended</td> </tr> <?php if (!$rankings) { echo '<tr><td colspan="2">No Rankings Available</td></tr>'; } else { foreach ($rankings as $rank) { $pilot = PilotData::getPilotData($rank->pilot_id); echo '<tr><td>' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' - ' . $pilot->firstname . ' ' . $pilot->lastname . '</td><td>' . $rank->ranking . '</td></tr>'; } } ?> </table> </center> <hr /> <a href="<?php echo SITE_URL; ?> /index.php/events"><b>Return To Events Listing</b></a>
public static function calculateUpdatePilotRank($pilotid, $ranks_list = null) { /* Don't calculate a pilot's rank if this is set */ if (Config::Get('RANKS_AUTOCALCULATE') == false) { return; } if ($ranks_list === null) { $ranks_list = self::getAllRanks(); } $pilotid = intval($pilotid); $pilot = PilotData::getPilotData($pilotid); $pilothours = $pilot->totalhours; if (Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $pilothours += $pilot->transferhours; } $i = 0; foreach ($ranks_list 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); if ($pilot->rank != $last_rank) { $message = Lang::get('activity.pilot.promotion'); $message = str_replace('$rank', $last_rank, $message); # Add it to the activity feed ActivityData::addActivity(array('pilotid' => $pilotid, 'type' => ACTIVITY_PROMOTION, 'refid' => $pilotid, 'message' => htmlentities($message))); } }
/** * 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()'); }
$this->show('events/events_header.tpl'); echo '<h4>' . $event->title . '</h4><hr />'; echo 'Event Image: '; if ($event->image == 'none') { echo 'No Image Posted<hr />'; } else { echo '<img src="' . $event->image . '" alt="Event Image" /><hr />'; } echo 'Scheduled Date: <b>' . date(DATE_FORMAT, strtotime($event->date)) . '</b><hr />'; echo 'Description: <b>' . $event->description . '</b><hr />'; echo 'Departure Field: <b>' . $event->dep . '</b><hr />'; echo 'Arrival Field: <b>' . $event->arr . '</b><hr />'; echo 'Company Schedule: <b>' . $event->schedule . '</b><hr />'; echo 'Start Time (GMT): <b>' . date('G:i', strtotime($event->time)) . '</b><hr />'; echo 'Slot Limit: <b>' . $event->slot_limit . '</b><hr />'; echo 'Slot Interval (minutes): <b>' . $event->slot_interval . '</b><hr />'; echo 'Current Signups: <br /><b>'; if (!$signups) { echo 'No Signups'; } else { foreach ($signups as $signup) { $pilot = PilotData::getPilotData($signup->pilot_id); echo date('G:i', strtotime($signup->time)) . ' - '; echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid) . ' - '; echo $pilot->firstname . ' ' . $pilot->lastname; echo ' - <a href="' . SITE_URL . '/admin/index.php/events_admin/remove_signup?id=' . $signup->pilot_id . '&event=' . $event->id . '">Remove Pilot Signup</a><br />'; } } echo '</b><hr />'; echo '<a href="' . SITE_URL . '/admin/index.php/events_admin/edit_event?id=' . $event->id . '"><b>Edit Event</b></a><br /><hr />'; echo '<a href="' . SITE_URL . '/admin/index.php/events_admin/delete_event?id=' . $event->id . '"><b>Delete Event</b></a> - This will delete the event and any associated signups from the datbase permanently!<br /><hr />';
protected function AddAward() { if ($this->post->awardid == '' || $this->post->pilotid == '') { return; } # Check if they already have this award $award = AwardsData::GetPilotAward($this->post->pilotid, $this->post->awardid); if ($award) { $this->set('message', Lang::gs('award.exists')); $this->render('core_error.tpl'); return; } AwardsData::AddAwardToPilot($this->post->pilotid, $this->post->awardid); $pilot = PilotData::getPilotData($this->post->pilotid); LogData::addLog(Auth::$userinfo->pilotid, 'Added and award to ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' - ' . $pilot->firstname . ' ' . $pilot->lastname); }
/** * This updates the ACARS live data for a pilot * * @param mixed $data This is the data structure with flight properties * @return mixed Nothing * */ public static function updateFlightData($pilotid, $data) { if (!is_array($data)) { self::$lasterror = 'Data not array'; return false; } if (isset($data['code']) && isset($data['flightnum'])) { $data['flightnum'] = $data['code'] . $data['flightnum']; } // Add pilot info $pilotinfo = PilotData::getPilotData($pilotid); $data['pilotid'] = $pilotid; $data['pilotname'] = $pilotinfo->firstname . ' ' . $pilotinfo->lastname; // Store for later if (isset($data['registration'])) { $ac_registration = $data['registration']; unset($data['registration']); } if (isset($data['depicao'])) { $dep_apt = OperationsData::GetAirportInfo($data['depicao']); $data['depapt'] = DB::escape($dep_apt->name); } if (isset($data['arricao'])) { $arr_apt = OperationsData::GetAirportInfo($data['arricao']); $data['arrapt'] = DB::escape($arr_apt->name); } if (isset($data['route']) && empty($data['route'])) { $flight_info = SchedulesData::getProperFlightNum($data['flightnum']); $params = array('s.code' => $flight_info['code'], 's.flightnum' => $flight_info['flightnum']); $schedule = SchedulesData::findSchedules($params); $schedule = $schedule[0]; $data['route'] = $schedule->route; //$data['route_details'] = serialize(SchedulesData::getRouteDetails($schedule->id)); } elseif (isset($data['route']) && !empty($data['route'])) { /*$tmp = new stdClass(); $tmp->deplat = $dep_apt->lat; $tmp->deplng = $dep_apt->lng; $tmp->route = $data['route']; $data['route_details'] = NavData::parseRoute($tmp); $data['route_details'] = serialize($data['route_details']); unset($tmp);*/ } if (!empty($data['route_details'])) { $data['route_details'] = DB::escape($data['route_details']); } if (isset($dep_apt)) { unset($dep_apt); } if (isset($arr_apt)) { unset($arr_apt); } // Clean up times if (isset($data['deptime']) && !is_numeric($data['deptime'])) { $data['deptime'] = strtotime($data['deptime']); } if (isset($data['arrtime']) && !is_numeric($data['arrtime'])) { $data['arrtime'] = strtotime($data['arrtime']); } /* Check the heading for the flight If none is specified, then point it straight to the arrival airport */ if ($data['heading'] == '' || !isset($data['heading']) && isset($data['lat']) && isset($data['lng'])) { /* Calculate an angle based on current coords and the destination coordinates */ $data['heading'] = intval(atan2($data['lat'] - $arr_apt->lat, $data['lng'] - $arr_apt->lng) * 180 / 3.14); if ($data['lat'] - $data['lng'] < 0) { $data['heading'] += 180; } if ($data['heading'] < 0) { $data['heading'] += 360; } } // Manually add the last set $data['lastupdate'] = 'NOW()'; // first see if we exist: $sql = 'SELECT `id` FROM ' . TABLE_PREFIX . "acarsdata \n\t\t\t\tWHERE `pilotid`={$pilotid}"; $exist = DB::get_row($sql); $flight_id = ''; if ($exist) { // update $upd = array(); $flight_id = $exist->id; foreach ($data as $field => $value) { $value = DB::escape(trim($value)); // Append the message log if ($field === 'messagelog') { $upd[] = "`messagelog`=CONCAT(`messagelog`, '{$value}')"; } elseif ($field === 'lastupdate') { $upd[] = "`lastupdate`=NOW()"; } elseif ($field === 'deptime' || $field === 'arrtime') { /* If undefined, set a default time to now (penalty for malformed data?) Won't be quite accurate.... */ if ($value == '') { $value = time(); } $upd[] = "`{$field}`=FROM_UNIXTIME({$value})"; } else { $upd[] = "`{$field}`='{$value}'"; } } $upd = implode(',', $upd); $query = 'UPDATE ' . TABLE_PREFIX . "acarsdata \n\t\t\t\t\tSET {$upd} \n\t\t\t\t\tWHERE `id`='{$flight_id}'"; DB::query($query); } else { // form array with $ins[column]=value and then // give it to quick_insert to finish $ins = array(); $vals = array(); foreach ($data as $field => $value) { $ins[] = "`{$field}`"; if ($field === 'deptime' || $field === 'arrtime') { if (empty($value)) { $value = time(); } $vals[] = "FROM_UNIXTIME({$value})"; } elseif ($field === 'lastupdate') { $vals[] = 'NOW()'; } else { $value = DB::escape($value); $vals[] = "'{$value}'"; } } $ins = implode(',', $ins); $vals = implode(',', $vals); $query = 'INSERT INTO ' . TABLE_PREFIX . "acarsdata ({$ins}) \n\t\t\t\t\t\tVALUES ({$vals})"; DB::query($query); $data['deptime'] = time(); $flight_id = DB::$insert_id; } $flight_info = self::get_flight_by_id($flight_id); // Add this cuz we need it $data['code'] = $pilotinfo->code; $data['pilotid'] = $pilotid; $data['unique_id'] = $flight_id; $data['aircraft'] = $flight_info->aircraftname; $data['registration'] = $flight_info->registration; $res = CentralData::send_acars_data($data); return true; }
/** * Registration::ProcessRegistration() * * @return */ protected function ProcessRegistration() { // Yes, there was an error if (!$this->VerifyData()) { $this->ShowForm(); return; } $data = array('firstname' => $this->post->firstname, 'lastname' => $this->post->lastname, 'email' => $this->post->email, 'password' => $this->post->password1, 'code' => $this->post->code, 'location' => $this->post->location, 'hub' => $this->post->hub, 'confirm' => false); if (CodonEvent::Dispatch('registration_precomplete', 'Registration', $_POST) == false) { return false; } $ret = RegistrationData::CheckUserEmail($data['email']); if ($ret) { $this->set('error', Lang::gs('email.inuse')); $this->render('registration_error.tpl'); return false; } $val = RegistrationData::AddUser($data); if ($val == false) { $this->set('error', RegistrationData::$error); $this->render('registration_error.tpl'); return; } else { $pilotid = RegistrationData::$pilotid; /* Automatically confirm them if that option is set */ if (Config::Get('PILOT_AUTO_CONFIRM') == true) { PilotData::AcceptPilot($pilotid); RanksData::CalculatePilotRanks(); $pilot = PilotData::getPilotData($pilotid); $this->set('pilot', $pilot); $this->render('registration_autoconfirm.tpl'); } else { /* Otherwise, wait until an admin confirms the registration */ RegistrationData::SendEmailConfirm($email, $firstname, $lastname); $this->render('registration_sentconfirmation.tpl'); } } CodonEvent::Dispatch('registration_complete', 'Registration', $_POST); // Registration email/show user is waiting for confirmation $sub = 'A user has registered'; $message = "The user {$data['firstname']} {$data['lastname']} ({$data['email']}) has registered, and is awaiting confirmation."; $email = Config::Get('EMAIL_NEW_REGISTRATION'); if (empty($email)) { $email = ADMIN_EMAIL; } Util::SendEmail($email, $sub, $message); // Send email to user $this->set('firstname', $data['firstname']); $this->set('lastname', $data['lastname']); $this->set('userinfo', $data); $message = Template::Get('email_registered.tpl', true); Util::SendEmail($data['email'], 'Registration at ' . SITE_NAME, $message); $rss = new RSSFeed('Latest Pilot Registrations', SITE_URL, 'The latest pilot registrations'); $pilot_list = PilotData::GetLatestPilots(); foreach ($pilot_list as $pilot) { $rss->AddItem('Pilot ' . PilotData::GetPilotCode($pilot->code, $pilot->pilotid) . ' (' . $pilot->firstname . ' ' . $pilot->lastname . ')', SITE_URL . '/admin/index.php?admin=pendingpilots', '', ''); } $rss->BuildFeed(LIB_PATH . '/rss/latestpilots.rss'); }
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; } } }
/** * 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 (\n '{$firstname}', '{$lastname}', '{$data['email']}', '{$code}',\n\t\t\t\t\t'{$location}', '{$data['hub']}', '{$password}', \n '{$salt}', {$confirm}, NOW(), \n '{$_SERVER['REMOTE_ADDR']}'\n )"; $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 (count($fields) > 0) { 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); } } } $pilotdata = PilotData::getPilotData($pilotid); /* Add this into the activity feed */ $message = Lang::get('activity.new.pilot'); foreach ($pilotdata as $key => $value) { $message = str_replace('$' . $key, $value, $message); } # Add it to the activity feed ActivityData::addActivity(array('pilotid' => $pilotid, 'type' => ACTIVITY_NEW_PILOT, 'refid' => $pilotid, 'message' => htmlentities($message))); return true; }