Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv610
Modified Files:
index.php
Log Message:
It's now much easier to select countries, stations, and languages on
the page.
Index: index.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/index.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- index.php 2001/06/29 11:51:40 1.14
+++ index.php 2001/06/30 19:24:02 1.15
@@ -18,87 +18,173 @@
$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();
+
+ 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 . '">';
+}
+
+
if (empty($action)) {
/* No action - we display a form from which the user can select a
country. */
-
+
echo '
-<p>Select a country:</p>
+<p>
<form action="index.php" method="post">
<input type="hidden" name="action" value="show_stations">
-<select name="cc" size="10">
';
-
- $countries = $obj->db->get_countries();
- $num_countries = count($countries);
- while (list($cc, $country) = each($countries)) {
- echo "<option value=\"$cc\">$country</option>\n";
- }
- echo '</select>
-<p><input type="submit"></p>
+
+ make_countries_select();
+
+ echo '
+<input type="submit">
</form>
+</p>
';
-} elseif ($action == 'show_stations') {
+} elseif ($action == 'show_stations' && !empty($cc)) {
/* A country has just been selected - we make a form with all
stations in that country. */
- $country = '';
- $icaos = $obj->db->get_icaos($cc, $country);
-
- echo '<form action="index.php" method="post">
+
+ echo '
+<p>
+<form action="index.php" method="post">
<input type="hidden" name="action" value="show_weather">
-<p>Select a station from ' . $country . ':</p>
-<select name="icao" size="10">
';
- while (list($icao, $name) = each($icaos)) {
- echo "<option value=\"$icao\">$name</option>\n";
- }
- echo '</select>
-<p><input type="submit"></p>
+ make_countries_select();
+
+ make_stations_select();
+
+ make_languages_select();
+
+ echo '
+<input type="submit">
</form>
+</p>
';
-} elseif ($action == 'show_weather') {
- /* A station has just been selected - we print the weather. */
- if (empty($language)) {
- $language = 'en';
- }
- $obj->set_icao($icao);
- $obj->set_language($language);
+} elseif ($action == 'show_weather' && !empty($language)) {
- echo "<p>This is the current weather in " . $obj->get_location() . ":</p>\n";
+ /* A station has just been selected - we print the weather. */
- $obj->print_pretty();
+ echo '
+<p>
+<form action="index.php" method="post">
+<input type="hidden" name="action" value="show_weather">
+';
+
+ make_countries_select();
+
+ make_stations_select();
+
+ make_languages_select();
- echo "<p>The raw METAR is <code>" . $obj->get_metar() . "</code></p>\n";
- echo '<form action="index.php" method="post">
-<input type="hidden" name="action" value="show_weather">';
- echo "<p>Select a new language here: \n <select name=\"language\">\n";
- $languages = $obj->get_languages();
- while (list($lc, $language) = each($languages)) {
- if ($lc == $obj->get_language()) {
- echo "<option value=\"$lc\" selected>$language</option>\n";
- } else {
- echo "<option value=\"$lc\">$language</option>\n";
- }
- }
- echo '</select></p>
-<p><input type="submit"></p>
+ echo '
+<input type="submit">
</form>
+</p>
';
+
+ if ($cc == $old_cc) {
+ /* We should only display the current weather is the country
+ isn't changed */
+ $obj->set_icao($icao);
+ $obj->set_language($language);
+
+ echo "<p>This is the current weather in " . $obj->get_location() . ":</p>\n";
+
+ $obj->print_pretty();
+
+ echo "<p>The raw METAR is <code>" . $obj->get_metar() . "</code></p>\n";
+
+ }
}
+
$time[] = array(microtime(), 'end');
$max = count($time) - 1;
+/*
for ($i = 0; $i < $max; $i++) {
$start_time = explode(' ', $time[$i][0]);
$end_time = explode(' ', $time[$i+1][0]);
$diff = ($end_time[0] + $end_time[1]) - ($start_time[0] + $start_time[1]);
echo '<p>Time taken to go from "' . ($time[$i][1]) . '" to "' .
($time[$i+1][1]) . '": ' . number_format($diff * 1000, 2) . " miliseconds.</p>\n";
}
-
+*/
$start_time = explode(' ', $time[0][0]);
$end_time = explode(' ', $time[$max][0]);
_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins