CVS: phpweather index.php,1.18,1.19
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-03-18 18:10:19
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv2062 Modified Files: index.php Log Message: Cleanups. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/index.php,v retrieving revision 1.18 retrieving revision 1.19 diff -u -3 -r1.18 -r1.19 --- index.php 17 Mar 2002 14:52:56 -0000 1.18 +++ index.php 18 Mar 2002 18:10:15 -0000 1.19 @@ -13,88 +13,9 @@ $time[] = array(microtime(), 'start'); require('phpweather.php'); +require('pw_utilities.php'); -//define('DEBUG', true); - -$obj = new phpweather(array()); - -function make_countries_select() { - echo' -<select name="cc"> -'; - - if (!empty($GLOBALS['cc'])) { - $selected = $GLOBALS['cc']; - } else { - $selected = ''; - } - - $countries = $GLOBALS['obj']->db->get_countries(); - while (list($cc, $country) = each($countries)) { - if ($cc == $selected) { - echo "<option value=\"$cc\" selected>$country</option>\n"; - } else { - echo "<option value=\"$cc\">$country</option>\n"; - } - } - echo "</select>\n"; - echo '<input type="hidden" name="old_cc" value="' . $selected . '">'; - -} - - -function make_stations_select() { - - $country = ''; - $icaos = $GLOBALS['obj']->db->get_icaos($GLOBALS['cc'], $country); - - echo ' -<select name="icao"> -'; - - if (!empty($GLOBALS['icao'])) { - $selected = $GLOBALS['icao']; - } else { - $selected = ''; - } - - while (list($icao, $name) = each($icaos)) { - if ($icao == $selected) { - echo "<option value=\"$icao\" selected>$name</option>\n"; - } else { - echo "<option value=\"$icao\">$name</option>\n"; - } - } - echo "</select>\n"; - echo '<input type="hidden" name="old_icao" value="' . $selected . '">'; - -} - - -function make_languages_select() { - - echo ' -<select name="language"> -'; - $languages = $GLOBALS['obj']->get_languages('text'); - - if (!empty($GLOBALS['language'])) { - $selected = $GLOBALS['language']; - } else { - $selected = ''; - } - - while (list($lc, $language) = each($languages)) { - if ($lc == $selected) { - echo "<option value=\"$lc\" selected>$language</option>\n"; - } else { - echo "<option value=\"$lc\">$language</option>\n"; - } - } - echo "</select>\n"; - echo '<input type="hidden" name="old_language" value="' . $selected . '">'; -} - +$weather = new phpweather(array()); if (empty($action)) { /* No action - we display a form from which the user can select a @@ -106,7 +27,7 @@ <input type="hidden" name="action" value="show_stations"> '; - make_countries_select(); + make_countries_select($weather, ''); echo ' <input type="submit"> @@ -124,11 +45,13 @@ <input type="hidden" name="action" value="show_weather"> '; - make_countries_select(); - - make_stations_select(); + if (empty($icao)) $icao = ''; + if (empty($language)) $language = ''; + - make_languages_select(); + make_countries_select($weather, $cc); + make_stations_select($weather, $cc, $icao); + make_languages_select($weather, $language); echo ' <input type="submit"> @@ -137,20 +60,16 @@ '; } elseif ($action == 'show_weather' && !empty($language)) { - /* A station has just been selected - we print the weather. */ - echo ' <p> <form action="index.php" method="get"> <input type="hidden" name="action" value="show_weather"> '; - make_countries_select(); - - make_stations_select(); - - make_languages_select(); + make_countries_select($weather, $cc); + make_stations_select($weather, $cc, $icao); + make_languages_select($weather, $language); echo ' <input type="submit"> @@ -159,26 +78,23 @@ '; if ($cc == $old_cc) { - /* We should only display the current weather is the country - isn't changed */ - $obj->set_icao($icao); + /* We should only display the current weather is the country isn't + changed */ + $weather->set_icao($icao); include(PHPWEATHER_BASE_DIR . "/output/pw_text_$language.php"); $type = 'pw_text_' . $language; - $text = new $type($obj, array()); + $text = new $type($weather, array()); - echo "<p>This is the current weather in " . $obj->get_location() . ":</p>\n"; + echo "<p>This is the current weather in " . + $weather->get_location() . ":</p>\n"; $text->print_pretty(); - echo "<p>The same information in a table:</p>\n"; - - $text->print_table(); - echo "<p>The matching icons are:</p>\n"; include(PHPWEATHER_BASE_DIR . "/output/pw_images.php"); - $icons = new pw_images($obj, array()); + $icons = new pw_images($weather, array()); echo "<blockquote>\n"; echo '<img src="' . $icons->get_sky_image() . @@ -190,7 +106,7 @@ echo "</blockquote>\n"; - echo "<p>The raw METAR is <code>" . $obj->get_metar() . "</code></p>\n"; + echo "<p>The raw METAR is <code>" . $weather->get_metar() . "</code></p>\n"; } } |