public function resetdistances() { echo '<h3>Updating and Calculating Distances</h3>'; # Update all of the schedules echo '<p><strong>Updating schedules...</strong></p>'; //$allschedules = SchedulesData::GetSchedulesNoDistance(); $allschedules = SchedulesData::findSchedules(array()); if (!$allschedules) { echo 'No schedules to update'; $allschedules = array(); } # Check 'em foreach ($allschedules as $sched) { $distance = SchedulesData::distanceBetweenPoints($sched->deplat, $sched->deplng, $sched->arrlat, $sched->arrlng); $distance = sprintf("%.6f", $distance); echo "{$sched->code}{$sched->flightnum} - {$sched->depname} to {$sched->arrname} " . "is {$distance} " . Config::Get('UNIT') . '<br />'; SchedulesData::updateScheduleFields($sched->id, array('distance' => $distance)); } # Update all of the PIREPS echo '<p><strong>Updating PIREPs...</strong></p>'; $allpireps = PIREPData::findPIREPS(array()); if (!$allpireps) { echo 'No PIREPs need updating!'; $allpireps = array(); } foreach ($allpireps as $pirep) { # Find the schedule, and the distance supplied by the schedule: $distance = SchedulesData::distanceBetweenPoints($pirep->deplat, $pirep->deplng, $pirep->arrlat, $pirep->arrlng); $distance = sprintf("%.2f", $distance); echo "PIREP Number {$pirep->pirepid} ({$pirep->code}{$pirep->flightnum}) " . "{$pirep->depname} to {$pirep->arrname} is {$distance} " . Config::Get('UNIT') . '<br />'; PIREPData::editPIREPFields($pirep->pirepid, array('distance' => $distance)); } echo '<p>Completed!</p><br />'; LogData::addLog(Auth::$userinfo->pilotid, 'Reset distances'); }
/** * Always find and return the test schedule, run the asserts * on what's found/returned too * * @return void */ protected function findSchedule() { $sched = SchedulesData::findSchedules(array('s.code' => $this->CODE, 's.flightnum' => $this->FLIGHTNUM)); $this->assertGreaterThan(0, count($sched)); # Make sure this schedule has an ID param? $sched = $sched[0]; $this->assertObjectHasAttribute('id', $sched, 'Has ID'); return $sched; }
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); }
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'); }
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; } } }
/** * 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; }
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(); }
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; }
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 . '"'); }
/** * 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; }
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); }
<?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}";