Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv13133
Modified Files:
pw_utilities.php
Log Message:
This should clear things up a bit.
Index: pw_utilities.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/pw_utilities.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- pw_utilities.php 2 Sep 2002 18:17:51 -0000 1.6
+++ pw_utilities.php 4 Sep 2002 21:04:41 -0000 1.7
@@ -3,57 +3,69 @@
/* Miscellaneous functions that can help you build an interactive site
* with PHP Weather. */
-function get_countries_select($weather, $old_cc) {
- $output = '<select name="cc">';
-
- $countries = $weather->db->get_countries();
- while (list($cc, $country) = each($countries)) {
- if ($cc == $old_cc) {
- $output .= "\n<option value=\"$cc\" selected=\"selected\">$country</option>";
- } else {
- $output .= "\n<option value=\"$cc\">$country</option>";
- }
- }
- $output .= "\n</select>\n";
- return $output;
-}
-
-
-function get_stations_select($weather, $cc, $old_icao) {
+/**
+ * Builds a select box.
+ *
+ * @param string The name assigned to the select tag.
+ * @param array An associative array with data.
+ * @param string The key that will be marked as the selected key,
+ * if any.
+ */
+function build_select($name, $data, $selected_key = '') {
+ $output = '<select name="' . $name . '">';
- $country = '';
- $icaos = $weather->db->get_icaos($cc, $country);
-
- $output = '<select name="icao">';
-
- while (list($icao, $name) = each($icaos)) {
- if ($icao == $old_icao) {
- $output .= "\n<option value=\"$icao\" selected=\"selected\">$name</option>";
+ while (list($k, $v) = each($data)) {
+ if ($k == $selected_key) {
+ $output .= "\n<option value=\"$k\" selected=\"selected\">$v</option>";
} else {
- $output .= "\n<option value=\"$icao\">$name</option>";
+ $output .= "\n<option value=\"$k\">$v</option>";
}
}
$output .= "\n</select>\n";
-
+
return $output;
}
+/**
+ * Returns HTML code which makes a select box with names of countries.
+ *
+ * @param object The phpweather object to query for available
+ * countries.
+ * @param string The country code that should be selected, if any.
+ * @return string The HTML code.
+ */
+function get_countries_select($weather, $old_cc = '') {
+ $countries = $weather->db->get_countries();
+ return build_select('cc', $countries, $old_cc);
+}
-function get_languages_select($old_language) {
- $output = '<select name="language">';
- $languages = get_languages('text');
+/**
+ * Returns HTML code which makes a select box with the names of
+ * stations in a given country.
+ *
+ * @param object The phpweather object to query for available
+ * stations.
+ * @param string The country code of the country.
+ * @param string The ICAO that should be selected, if any.
+ * @return string The HTML code.
+ */
+function get_stations_select($weather, $cc, $old_icao = '') {
+ $country = ''; // Dummy variable.
+ $icaos = $weather->db->get_icaos($cc, $country);
+ return build_select('icao', $icaos, $old_icao);
+}
- while (list($lc, $language) = each($languages)) {
- if ($lc == $old_language) {
- $output .= "\n<option value=\"$lc\" selected=\"selected\">$language</option>";
- } else {
- $output .= "\n<option value=\"$lc\">$language</option>";
- }
- }
- $output .= "\n</select>\n";
- return $output;
+/**
+ * Returns HTML code which makes a select box with available
+ * languages for the 'text' output module.
+ *
+ * @param string The language that should be selected, if any.
+ * @return string The HTML code.
+ */
+function get_languages_select($old_language = '') {
+ return build_select('language', get_languages('text'), $old_language);
}
|