Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv15670 Modified Files: configurator.php Log Message: The objects are working! Index: configurator.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/configurator.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- configurator.php 2001/05/19 09:11:13 1.2 +++ configurator.php 2001/05/19 10:16:56 1.3 @@ -13,7 +13,7 @@ var $data; var $config_header; - function property($name, $description, $data) { + function property($name, $data, $description) { $this->name = $name; $this->description = $description; $this->data = $data; @@ -25,13 +25,16 @@ } function get_description() { - return $this->description + return $this->description; } - } class text extends property { + + function text($name, $data, $description) { + $this->property($name, $data, $description); + } function get_html() { return '<input type="text" name="' . $this->name . '" value="' . @@ -41,8 +44,7 @@ function get_config($new_data) { if ($new_data != $this->data) { - return '/* ' . $this->name . " */\n\$this->properties['" . - $this->name . "'] = '$new_data'\n\n"; + return $this->config_header . "'$new_data';\n\n"; } else { return ''; } @@ -51,6 +53,10 @@ class select extends property { + function select($name, $data, $description) { + $this->property($name, $data, $description); + } + function get_html() { $output = '<select name="' . $this->name . "\">\n"; list($option, $label) = each($this->data); @@ -65,7 +71,7 @@ function get_config($new_data) { list($default) = each($this->data); if ($new_data != $default) { - return $this->config_header "'$new_data'\n\n"; + return $this->config_header . "'$new_data';\n\n"; } else { return ''; } @@ -75,6 +81,10 @@ class multi_select extends property { + function multi_select($name, $data, $description) { + $this->property($name, $data, $description); + } + function get_html() { $output = '<select name="' . $this->name . "\" multiple>\n"; while(list($option, $label) = each($this->data)) { @@ -85,7 +95,7 @@ } function get_config($new_data) { - $output = $this->config_header "array(\n" . + $output = $this->config_header . "array(\n" . " '$new_data[0]'"; for ($i = 1; $i < count($new_data); $i++) { $output .= ",\n '$new_data[$i]'"; @@ -98,6 +108,10 @@ class boolean extends property { + function boolean($name, $data, $description) { + $this->property($name, $data, $description); + } + function get_html() { $output = '<select name="' . $this->name . "\">\n"; /* The first option is the default */ @@ -113,7 +127,7 @@ function get_config($new_data) { list($default) = each($this->data); if ($new_data != $default) { - return $this->config_header . "'$new_data'\n\n"; + return $this->config_header . "'$new_data';\n\n"; } else { return ''; } @@ -121,132 +135,144 @@ } -$properties['always_use_db'] = array( - 'type' => 'boolean', - 'values' => array('false' => 'No', +$properties['always_use_db'] = + new boolean('always_use_db', + array('false' => 'No', 'true' => 'Yes'), - 'desc' => "If you set this option to 'Yes', then PHP Weather " . + "If you set this option to 'Yes', then PHP Weather " . "will always use the data it finds in the database, " . "even if it's too old. But if the data isn't there, " . "it will still fetch new data from the Internet."); -$properties['station'] = array( - 'type' => 'text', - 'value' => 'EKYT', - 'desc' => 'This will be the default station used by PHP ' . - 'Weather. You should enter a four-letter ICAO.'); - -$properties['db_hostname'] = array( - 'type' => 'text', - 'value' => '', - 'desc' => 'This is the hostname that PHP Weather will use, ' . - 'if you choose to use a database-backend, that ' . - 'supports network connections.'); - -$properties['db_database'] = array( - 'type' => 'text', - 'value' => '', - 'desc' => 'This is the name of the database that PHP Weather ' . - 'should use.'); - -$properties['db_username'] = array( - 'type' => 'text', - 'value' => '', - 'desc' => 'This is the username that PHP Weather will use.'); - -$properties['db_password'] = array( - 'type' => 'text', - 'value' => '', - 'desc' => 'This is the password that PHP Weather will use when ' . - 'trying to make a connection to the database. If you ' . - ' don\'t use a database that requires a password, ' . - 'then just leave this field blank.'); - -$properties['db_pconnect'] = array( - 'type' => 'boolean', - 'values' => array('false' => 'No', +$properties['station'] = + new text('station', + 'EKYT', + 'This will be the default station used by PHP Weather. ' . + 'You should enter a four-letter ICAO.'); + +$properties['db_hostname'] = + new text('db_hostname', + '', + 'This is the hostname that PHP Weather will use, ' . + 'if you choose to use a database-backend, that ' . + 'supports network connections.'); + +$properties['db_database'] = + new text('db_database', + '', + 'This is the name of the database that PHP Weather ' . + 'should use.'); + +$properties['db_username'] = + new text('db_username', + '', + 'This is the username that PHP Weather will use.'); + +$properties['db_password'] = + new text('db_password', + '', + 'This is the password that PHP Weather will use when ' . + 'trying to make a connection to the database. If you ' . + ' don\'t use a database that requires a password, ' . + 'then just leave this field blank.'); + +$properties['db_pconnect'] = + new boolean('db_pconnect', + array('false' => 'No', 'true' => 'Yes'), - 'desc' => 'If you want to make a persistent connection to the ' . + 'If you want to make a persistent connection to the ' . 'database, then set this option to \'Yes\'.'); -$properties['db_port'] = array( - 'type' => 'text', - 'value' => '', - 'desc' => 'If you have to use a non-standard port when ' . - 'connecting to the database, then please specify it ' . - 'here. If not, then just leave this field blank.'); - -$properties['db_path'] = array( - 'type' => 'text', - 'value' => 'PHPWEATHER_BASE_DIR', - 'desc' => 'If you\'re using a text-style database, then use ' . - 'this option to select the directory you would like ' . - 'to use, for the database-files. If you wan\'t '. - 'PHP Weather to use it\'s base-directory, then leave ' . - 'this option at \'PHPWEATHER_BASE_DIR\'.'); - -$properties['db_metars'] = array( - 'type' => 'text', - 'value' => 'metars.db', - 'desc' => 'This is the name of the database that is used to cache ' . - 'METARs.'); - -$properties['db_stations'] = array( - 'type' => 'text', - 'value' => 'stations.db', - 'desc' => 'This is the name of the database that is used to store ' . - 'the names of the stations.'); - -$properties['db_type'] = array( - 'type' => 'select', - 'values' => array('null' => 'No database at all', - 'mysql' => 'A MySQL database', - 'dba' => 'A Berkeley DB style database', - 'pqsql' => 'A PostgreSQL database'), - 'desc' => 'PHP Weather can use several different ' . - 'database-engines. Please choose one from the list.'); - -$properties['pref_units'] = array( - 'type' => 'select', - 'values' => array('both_metric' => 'Metric first, then imperical', - 'both_imperial' => 'Imperial first, then metric', - 'only_metric' => 'Only metric', - 'only_imperial' => 'Only imperial'), - 'desc' => 'You can choose to display the data in several ' . - 'formats. Pleace choose one that fits your need.'); - -$properties['mark_begin'] = array( - 'type' => 'text', - 'value' => '<b>', - 'desc' => 'This string will be placed infront of all the ' . - 'changable parts of the output. If you don\'t want ' . - ' this to happen, then just use an empty string. ' . - 'Other good choices include \'<i>\', \'<font ' . - 'color="red">, etc.'); - -$properties['mark_end'] = array( - 'type' => 'text', - 'value' => '</b>', - 'desc' => 'This string is places after all the changable parts. ' . - 'You should make sure, that it closes any tags ' . - ' you\'ve opened in <code>mark_begin</code>'); - -$properties['exclude'] = array( - 'type' => 'multi_select', - 'values' => array('time' => 'The time part', - 'wind' => 'The wind part', - 'runway' => 'Information about runways'), - 'desc' => 'You can disable some of the output produced. If ' . - 'you\'re not interested in information about ' . - ' runways-visibility, then select it in this list. ' . - 'You can select severel options at once by holding ' . - 'down Ctrl while clicking on the option in Netscape.'); - -$properties['language'] = array( - 'type' => 'select', - 'values' => array('en' => 'English'), - 'desc' => 'PHP Weather can produce output in several langauges ' . - '- pleace select the default from the list.'); +$properties['db_port'] = + new text('db_port', + '', + 'If you have to use a non-standard port when ' . + 'connecting to the database, then please specify it ' . + 'here. If not, then just leave this field blank.'); + +$properties['db_path'] = + new text('db_path', + 'PHPWEATHER_BASE_DIR', + 'If you\'re using a text-style database, then use ' . + 'this option to select the directory you would like ' . + 'to use, for the database-files. If you wan\'t '. + 'PHP Weather to use it\'s base-directory, then leave ' . + 'this option at \'PHPWEATHER_BASE_DIR\'.'); + +$properties['db_metars'] = + new text('db_metars', + 'metars.db', + 'This is the name of the database that is used to cache ' . + 'METARs.'); + +$properties['db_stations'] = + new text('db_stations', + 'stations.db', + 'This is the name of the database that is used to store ' . + 'the names of the stations.'); + +$properties['db_type'] = + new select('db_type', + array('null' => 'No database at all', + 'mysql' => 'A MySQL database', + 'dba' => 'A Berkeley DB style database', + 'pqsql' => 'A PostgreSQL database'), + 'PHP Weather can use several different ' . + 'database-engines. Please choose one from the list.'); + +$properties['db_handler'] = + new select('db_handler', + array('dbm' => 'dbm - The oldest (original) type of ' . + 'Berkeley DB style databases', + 'ndbm' => 'ndbm - a newer and more flexible type.', + 'gdbm' => 'gdbm - The GNU database manager', + 'db2' => 'db2 - Sleepycat Software\'s DB2', + 'db3' => 'db3 - Sleepycat Software\'s DB3'), + 'If you\'ve chosen to use a Berkeley DB style database ' . + 'through PHP database abstraction layer (dba), then ' . + 'please select the handler you would like to use.'); + +$properties['pref_units'] = + new select('pref_units', + array('both_metric' => 'Metric first, then imperical', + 'both_imperial' => 'Imperial first, then metric', + 'only_metric' => 'Only metric', + 'only_imperial' => 'Only imperial'), + 'You can choose to display the data in several ' . + 'formats. Pleace choose one that fits your need.'); + +$properties['mark_begin'] = + new text('mark_begin', + '<b>', + 'This string will be placed infront of all the ' . + 'changable parts of the output. If you don\'t want ' . + ' this to happen, then just use an empty string. ' . + 'Other good choices include \'<i>\', \'<font ' . + 'color="red">, etc.'); + +$properties['mark_end'] = + new text('mark_end', + '</b>', + 'This string is places after all the changable parts. ' . + 'You should make sure, that it closes any tags ' . + ' you\'ve opened in <code>mark_begin</code>'); + +$properties['exclude'] = + new multi_select('exclude', + array('time' => 'The time part', + 'wind' => 'The wind part', + 'runway' => 'Information about runways'), + 'You can disable some of the output produced. If ' . + 'you\'re not interested in information about ' . + ' runways-visibility, then select it in this list. ' . + 'You can select severel options at once by holding ' . + 'down Ctrl while clicking on the option in Netscape.'); + +$properties['language'] = + new select('language', + array('en' => 'English'), + 'PHP Weather can produce output in several langauges ' . + '- pleace select the default from the list.'); if ($action == 'make_config') { @@ -257,38 +283,19 @@ print_r($GLOBALS['HTTP_POST_VARS']); echo "</pre>\n"; + $config = "<?php +echo '<p>defaults.php was included!</p>'; - $config = " /* This is a local configurations file for PHP Weather. It was generated on the $timestamp. */\n\n"; while(list($option, $value) = each($GLOBALS['HTTP_POST_VARS'])) { - if (!empty($value)) { - if ($properties[$option]['type'] == 'boolean' && - $properties[$option]['value'] != $value) { - $config .= "/* $option: */\n\$this->properties['$option'] = $value;\n"; - } elseif ($properties[$option]['type'] == 'text' && - $properties[$option]['value'] != $value) { - $config .= "/* $option: */\n\$this->properties['$option'] = '$value';\n"; - } elseif ($properties[$option]['type'] == 'select') { - list($default) = each($properties[$option]['values']); - if ($default != $value) { - $config .= "/* $option: */\n\$this->properties['$option'] = '$value';\n"; - } - } elseif ($properties[$option]['type'] == 'multi_select') { - /* $value is then an array */ - $config .= "/* $option: */\n\$this->properties['$option'] = array(\n"; - $config .= " '$value[0]'"; - for ($i = 1; $i < count($value); $i++) { - $config .= ",\n '$value[$i]'"; - } - $config .= "\n);\n"; - - } + if (!empty($properties[$option])) { + $config .= $properties[$option]->get_config($value); } } + $config .= "\n?>\n"; - /* We first check to see, if there's already a config-file. */ if (file_exists('defaults.php')) { /* We make a backup-copy of the file */ @@ -300,7 +307,6 @@ $fp = @fopen('defaults.php', 'w'); } - echo "<p>Here's the configuration file based on your answers:</p> <pre> @@ -493,37 +499,10 @@ <input type="hidden" name="action" value="make_config"> '; -while(list($property, $data) = each($properties)) { - echo "<tr>\n <td>\n <p><b><code>$property</code></b></p>\n <p>$data[desc]</p>\n </td>\n"; - switch($data['type']) { - case 'boolean': - echo " <td>\n <select name=\"$property\">\n"; - while(list($option, $label) = each($data['values'])) { - echo " <option value=\"$option\">$label</option>\n"; - } - echo " </select>\n </td>\n"; - break; - case 'text': - echo " <td>\n <input type=\"text\" name=\"$property\" value=\"$data[value]\">\n </td>\n"; - break; - case 'select': - echo " <td>\n <select name=\"$property\">\n"; - /* The first option is the default */ - list($option, $label) = each($data['values']); - echo " <option value=\"$option\" selected>$label</option>\n"; - while(list($option, $label) = each($data['values'])) { - echo " <option value=\"$option\">$label</option>\n"; - } - echo " </select>\n </td>\n"; - break; - case 'multi_select': - echo " <td>\n <select multiple name=\"${property}[]\">\n"; - while(list($option, $label) = each($data['values'])) { - echo " <option value=\"$option\">$label</option>\n"; - } - echo " </select>\n </td>\n"; - break; - } +while(list($property, $obj) = each($properties)) { + echo "<tr>\n <td>\n <p><b><code>" . $obj->get_name() . "</code></b></p>\n +<p>" . $obj->get_description() . "</p>\n </td>\n"; + + echo "<td>" . $obj->get_html() . "</td>\n"; } echo ' _______________________________________________ PHPWeather-checkins mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/phpweather-checkins