/** * Return all of the custom fields data */ public static function getAllFields() { $all_fields = CodonCache::read('allfields'); if ($all_fields === false) { $all_fields = DB::get_results('SELECT * FROM ' . TABLE_PREFIX . 'customfields'); CodonCache::write('allfields', $all_fields, 'long'); } return $all_fields; }
/** * Returns all the ranks, and the total number of pilots * on each rank */ public static function getAllRanks() { $allranks = CodonCache::read('all_ranks'); if ($allranks === false) { $sql = 'SELECT r.*, (SELECT COUNT(*) FROM ' . TABLE_PREFIX . 'pilots WHERE rank=r.rank) as totalpilots FROM ' . TABLE_PREFIX . 'ranks r ORDER BY r.minhours ASC'; $allranks = DB::get_results($sql); CodonCache::write('all_ranks', $allranks, 'long'); } return $allranks; }
/** * Get all of the groups */ public static function getAllGroups() { $all_groups = CodonCache::read('all_groups'); if ($all_groups === false) { $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'groups ORDER BY name ASC'; $all_groups = DB::get_results($sql); CodonCache::write('all_groups', $all_groups, 'medium'); } return $all_groups; }
public static function getAllAirportsJSON() { $key = 'all_airports_json'; $all_airports_json = CodonCache::read($key); $all_airports_json = false; if ($all_airports_json === false) { $json_string = array(); $allairports = self::getAllAirports(); foreach ($allairports as $airport) { $tmp = array('label' => "{$airport->icao} ({$airport->name})", 'value' => $airport->icao, 'id' => $airport->id); $json_string[] = $tmp; } $all_airports_json = json_encode($json_string); CodonCache::write($key, $all_airports_json, 'long'); } return $all_airports_json; }
/** * Return the total number of schedules in the system * * @return int $airline_code Total number * */ public static function TotalSchedules($airline_code = '') { $key = 'total_schedules'; if ($airline_code != '') { $key .= '_' . $airline_code; } $total = CodonCache::read($key); if ($total === false) { $params = array('table' => TABLE_PREFIX . 'schedules', 'fields' => 'COUNT(`id`) as `total`'); if (!empty($airline_code)) { $params['where'] = array('code' => $airline_code); $params['group'] = 'code'; } $sql = DB::build_select($params); $results = DB::get_results($sql); if (!$results) { $total = 0; } else { $total = $results[0]->total; } CodonCache::write($key, $total, '15minute'); } return $total; }
/** * Get information about an airport */ public static function getAirportInfo($icao) { $icao = strtoupper(DB::escape($icao)); $key = 'get_airport_' . $icao; $airport_info = CodonCache::read($key); if ($airport_info === false) { $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'airports WHERE `icao`=\'' . $icao . '\''; $airport_info = DB::get_row($sql); CodonCache::write($key, $airport_info, 'long'); } return $airport_info; }
/** * Show the notification that an update is available */ public function CheckForUpdates() { if (Config::Get('CHECK_RELEASE_VERSION') == true) { $key = 'PHPVMS_LATEST_VERSION'; $feed = CodonCache::read($key); if ($feed === false) { $url = Config::Get('PHPVMS_API_SERVER') . '/version/get/json/'; # Default to fopen(), if that fails it'll use CURL $file = new CodonWebService(); $contents = @$file->get($url); # Something should have been returned if ($contents == '') { $msg = '<br /><b>Error:</b> The phpVMS update server could not be contacted. Check to make sure allow_url_fopen is set to ON in your php.ini, or that the cURL module is installed (contact your host).'; $this->set('latestnews', $msg); return; } #$xml = @simplexml_load_string($contents); $message = json_decode($contents); if (!$message) { $msg = '<br /><b>Error:</b> There was an error retrieving news. It may be temporary. Check to make sure allow_url_fopen is set to ON in your php.ini, or that the cURL module is installed (contact your host).'; $this->set('latestnews', $msg); return; } CodonCache::write($key, $message, 'medium_well'); } if (Config::Get('CHECK_BETA_VERSION') == true) { $latest_version = $message->betaversion; } else { $latest_version = $message->version; } # GET THE VERSION THAT'S THE LATEST AVAILABLE preg_match('/^[v]?(.*)-([0-9]*)-(.*)/', $latest_version, $matches); list($FULL_VERSION_STRING, $full_version, $revision_count, $hash) = $matches; preg_match('/([0-9]*)\\.([0-9]*)\\.([0-9]*)/', $full_version, $matches); list($full, $major, $minor, $revision) = $matches; $latest_version = $major . $minor . ($revision + $revision_count); # GET THE CURRENT VERSION INFO INSTALLED $installed_version = PHPVMS_VERSION; preg_match('/^[v]?(.*)-([0-9]*)-(.*)/', $installed_version, $matches); list($FULL_VERSION_STRING, $full_version, $revision_count, $hash) = $matches; preg_match('/([0-9]*)\\.([0-9]*)\\.([0-9]*)/', $full_version, $matches); list($full, $major, $minor, $revision) = $matches; $installed_version = $major . $minor . ($revision + $revision_count); #echo "CURRVERSION : $installed_version<br>AVAILVERSION: $latest_version<br>"; if ($installed_version < $latest_version) { if (Config::Get('CHECK_BETA_VERSION') == true) { $this->set('message', 'Beta version ' . $message->betaversion . ' is available for download!'); } else { $this->set('message', 'Version ' . $message->version . ' is available for download! Please update ASAP'); } $this->set('updateinfo', Template::GetTemplate('core_error.php', true)); } /* Retrieve latest news from Feedburner RSS, in case the phpVMS site is down */ $key = 'PHPVMS_NEWS_FEED'; $feed_contents = CodonCache::read($key); if ($feed_contents === false) { $feed_contents = $file->get(Config::Get('PHPVMS_NEWS_FEED')); CodonCache::write($key, $feed_contents, 'medium_well'); } $i = 1; $count = 5; $contents = ''; $feed = simplexml_load_string($feed_contents); foreach ($feed->channel->item as $news) { $news_content = (string) $news->description; $guid = (string) $news->guid; $title = (string) $news->title; $date_posted = str_replace('-0400', '', (string) $news->pubDate); $contents .= "<div class=\"newsitem\">"; $contents .= '<a href="' . $guid . '"><b>' . $title . '</b></a><br />'; $contents .= $news_content; $contents .= '<br /><br />Posted: ' . $date_posted; $contents .= '</div>'; if ($i++ == $count) { break; } } $this->set('phpvms_news', $contents); if (Config::Get('VACENTRAL_ENABLED') == true) { /* Get the latest vaCentral News */ $contents = $file->get(Config::Get('VACENTRAL_NEWS_FEED')); $feed = simplexml_load_string($contents); $contents = ''; $i = 1; $count = 5; // Show the last 5 foreach ($feed->channel->item as $news) { $news_content = (string) $news->description; $date_posted = str_replace('-0400', '', (string) $news->pubDate); $contents .= "<div class=\"newsitem\">\n\t\t\t\t\t\t\t\t\t<b>{$news->title}</b> {$news_content}\n\t\t\t\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t\t\t\tPosted: {$date_posted}\n\t\t\t\t\t\t\t\t</div>"; if ($i++ == $count) { break; } } $this->set('vacentral_news', $contents); } } }
/** * StatsData::PilotAircraftFlownCounts() * * @param mixed $pilotid * @return */ public static function PilotAircraftFlownCounts($pilotid) { $key = 'ac_flown_counts_' . $pilotid; $counts = CodonCache::read($key); if ($counts === false) { //Select aircraft types $sql = 'SELECT a.name AS aircraft, COUNT(p.aircraft) AS count, SUM(p.flighttime) AS hours FROM ' . TABLE_PREFIX . 'pireps p, ' . TABLE_PREFIX . 'aircraft a WHERE p.aircraft = a.id AND p.pilotid=' . intval($pilotid) . ' GROUP BY a.name'; $counts = DB::get_results($sql); CodonCache::write($key, $counts, 'medium'); } return $counts; }