/** * Uses getWeatherXML to retrieve TAF info, then parses it and returns array * * @param int $altn * @return array */ function getTafs($altn = 0) { $tafs = array(); $wx = new phpweather(); $xml = getWeatherXml('tafs', $altn); $ap_array = getAirportArray($altn); $severe_wx = getSevereWxSettings(); foreach ($xml->data->TAF as $taf) { $metCondition = 1; $decoded_taf = $wx->decode_taf($taf->raw_text); $station_id = (string) $taf->station_id; foreach ($decoded_taf['periods1'] as $period) { if (isset($period['desc']['clouds'])) { foreach ($period['desc']['clouds'] as $clouds) { if ($clouds['condition'] == 'BKN' || $clouds['condition'] == 'OVC' || $clouds['condition'] == 'VV') { if ($clouds['ft'] < $ap_array[$station_id]['2_ceil']) { if ($clouds['ft'] < $ap_array[$station_id]['3_ceil']) { $metCondition = 3; $decoded_taf['taf'] = colorize($clouds['coded'], $decoded_taf['taf'], 'red'); } else { if ($metCondition == 1) { $metCondition = 2; } $decoded_taf['taf'] = colorize($clouds['coded'], $decoded_taf['taf']); } } } } } if (isset($period['desc']['visibility'])) { foreach ($period['desc']['visibility'] as $vis) { if ($vis['meter'] < $ap_array[$station_id]['2_vis']) { if ($vis['meter'] < $ap_array[$station_id]['3_vis']) { $metCondition = 3; $decoded_taf['taf'] = colorize($vis['coded'], $decoded_taf['taf'], 'red'); } else { if ($metCondition == 1) { $metCondition = 2; } $decoded_taf['taf'] = colorize($vis['coded'], $decoded_taf['taf']); } } } } if (isset($period['desc']['weather'])) { foreach ($period['desc']['weather'] as $sigwx) { if (in_array($sigwx['coded'], $severe_wx['yellow'])) { if ($metCondition == 1) { $metCondition = 2; } $decoded_taf['taf'] = colorize($sigwx['coded'], $decoded_taf['taf']); } if (in_array($sigwx['coded'], $severe_wx['red'])) { $metCondition = 3; $decoded_taf['taf'] = colorize($sigwx['coded'], $decoded_taf['taf'], 'red'); } } } } $tafs[$station_id] = array('station_id' => $station_id, 'raw' => (string) $decoded_taf['taf'], 'metCondition' => $metCondition); } return $tafs; }
function run($dbi, $argstr, &$request, $basepage) { // When 'phpweather/phpweather.php' is not installed then // PHPWEATHER_BASE_DIR will be undefined. if (!defined('PHPWEATHER_BASE_DIR')) { return $this->error(_("You have to define PHPWEATHER_BASE_DIR before use. (config/config.ini)")); } //early return require_once PHPWEATHER_BASE_DIR . '/output/pw_images.php'; require_once PHPWEATHER_BASE_DIR . '/pw_utilities.php'; extract($this->getArgs($argstr, $request)); $html = HTML(); $w = new phpweather(); // Our weather object if (!empty($icao)) { /* We assign the ICAO to the weather object: */ $w->set_icao($icao); if (!$w->get_country_code()) { /* The country code couldn't be resolved, so we * shouldn't use the ICAO: */ trigger_error(sprintf(_("The ICAO '%s' wasn't recognized."), $icao), E_USER_NOTICE); $icao = ''; } } if (!empty($icao)) { /* We check and correct the language if necessary: */ //if (!in_array($language, array_keys($w->get_languages('text')))) { if (!in_array($language, array_keys(get_languages('text')))) { trigger_error(sprintf(_("%s does not know about the language '%s', using 'en' instead."), $this->getName(), $language), E_USER_NOTICE); $language = 'en'; } $class = "pw_text_{$language}"; require_once PHPWEATHER_BASE_DIR . "/output/{$class}.php"; $t = new $class($w); $t->set_pref_units($units); $i = new pw_images($w); $i_temp = HTML::img(array('src' => $i->get_temp_image())); $i_wind = HTML::img(array('src' => $i->get_winddir_image())); $i_sky = HTML::img(array('src' => $i->get_sky_image())); $m = $t->print_pretty(); $m_td = HTML::td(HTML::p(new RawXml($m))); $i_tr = HTML::tr(); $i_tr->pushContent(HTML::td($i_temp)); $i_tr->pushContent(HTML::td($i_wind)); $i_table = HTML::table($i_tr); $i_table->pushContent(HTML::tr(HTML::td(array('colspan' => '2'), $i_sky))); $tr = HTML::tr(); $tr->pushContent($m_td); $tr->pushContent(HTML::td($i_table)); $html->pushContent(HTML::table($tr)); } /* We make a menu if asked to, or if $icao is empty: */ if ($menu || empty($icao)) { $form_arg = array('action' => $request->getURLtoSelf(), 'method' => 'get'); /* The country box is always part of the menu: */ $p1 = HTML::p(new RawXml(get_countries_select($w, $cc))); /* We want to save the language: */ $p1->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'language', 'value' => $language))); /* And also the ICAO: */ $p1->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'icao', 'value' => $icao))); $caption = empty($cc) ? _("Submit country") : _("Change country"); $p1->pushContent(HTML::input(array('type' => 'submit', 'value' => $caption))); $html->pushContent(HTML::form($form_arg, $p1)); if (!empty($cc)) { /* We have selected a country, now display a list with * the available stations in that country: */ $p2 = HTML::p(); /* We need the country code after the form is submitted: */ $p2->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'cc', 'value' => $cc))); $p2->pushContent(new RawXml(get_stations_select($w, $cc, $icao))); $p2->pushContent(new RawXml(get_languages_select($language))); $p2->pushContent(HTML::input(array('type' => 'submit', 'value' => _("Submit location")))); $html->pushContent(HTML::form($form_arg, $p2)); } } return $html; }
echo "usage: send_metar.php?serweb_config=path/to/serweb/config/file/config.php\n"; exit(1); } $serweb_dir = dirname($serweb_config); require $serweb_config; require "phpweather/phpweather.php"; require "phpweather/output/pw_text_en.php"; require $serweb_dir . "/functions.php"; $db = connect_to_db(); if (!$db) { echo "can´t connect to sql server"; exit(1); } $reg = new Creg(); //create phpweather objects $weather = new phpweather(); $language = "en"; $text_type = 'pw_text_' . $language; //get users which have subscribed this service $q = "select username from " . $config->table_event . " where uri='" . $config->metar_event_uri . "'"; $res = mySQL_query($q); if (!$res) { echo "error in SQL query, line: " . __LINE__ . "\n"; exit(1); } while ($row = MySQL_Fetch_Object($res)) { //for each user get contacts $q = "select contact from " . $config->table_location . " where username='******'"; $res2 = mySQL_query($q); if (!$res2) { echo "error in SQL query, line: " . __LINE__ . "\n";