CVS: phpweather/config make_config.php,NONE,1.1 make_db.php,NONE,1.1 ...
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-05-15 22:26:53
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv7237 Modified Files: index.php Added Files: make_config.php make_db.php Log Message: I've moved the Configuration Builder from index.php to make_config.php and added make_db.php which can be used to (re)create the database. --- NEW FILE --- <?php error_reporting(E_ALL); /* Require a couple of validators: */ require_once('pw_validator.php'); require_once('pw_validator_ereg.php'); require_once('pw_validator_range.php'); /* Require_once some options: */ require_once('pw_option.php'); require_once('pw_option_text.php'); require_once('pw_option_select.php'); require_once('pw_option_multi_select.php'); require_once('pw_option_boolean.php'); require_once('pw_option_integer.php'); /* We want to group the options: */ require_once('pw_optiongroup.php'); /* A couple of dependencies: */ require_once('pw_dependency.php'); require_once('pw_dependency_or.php'); /* We have to strip slashes from the GPC variables. */ if (get_magic_quotes_gpc() == 1) { function recursive_stripslashes(&$array) { $keys = array_keys($array); foreach($keys as $key) { if (is_array($array[$key])) { recursive_stripslashes($array[$key]); } else { $array[$key] = stripslashes($array[$key]); } } } recursive_stripslashes($HTTP_POST_VARS); } /* Start the session. */ session_start(); /* If $options isn't registered, then we should make the variable and * register it: */ if (!session_is_registered('options')) { /* Common dependencies: */ $db_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql', 'dba')); $sql_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql')); $dba_dep = new pw_dependency('db_type', 'dba'); $proxy_dep = new pw_dependency('use_proxy', 'true'); $port_validator = new pw_validator_range("Sorry, '%s' is not a valid port-number " . "because is't outside the range 1-65536", 1, 65536); $port_validator_empty = new pw_validator_range("Sorry, '%s' is not a valid port-number " . "because is't outside the range 1-65536", 1, 65536, true); /* This just catches the most obvious errors. */ $table_validator = new pw_validator_ereg("Sorry, '%s' is not a valid name.", '^[^./]+$'); $icao_validator = new pw_validator_ereg("Sorry, '%s' is not a valid ICAO.", '^[a-zA-Z0-9]{4}$'); /* This just catches the most obvious errors. */ $host_validator = new pw_validator_ereg("Sorry, '%s' is not a valid hostname.", '^[^/#?~]+$'); /* Next comes all the options: */ $options['verbosity'] = new pw_option_select('verbosity', "The setting of this variable controls the amount of " . "errors, warnings, and debug-information PHP Weather " . "will print. It is suggested that you always include " . "errors in the output and perhaps also warnings.", array(), array('1' => 'Errors only', '2' => 'Warnings only', '4' => 'Debug information only', '3' => 'Errors + warnings', '5' => 'Errors + debug information', '6' => 'Warnings + debug information', '7' => 'Everything')); $options['icao'] = new pw_option_text('icao', 'This will be the default station used by PHP Weather. ' . 'You should enter a valid four-letter ICAO.', array(), $icao_validator, 'EKYT'); $options['pref_units'] = new pw_option_select('pref_units', 'You may choose to display the data in several ' . 'formats. Please choose one that fits your need.', array(), array('both_metric' => 'Metric first, then imperial', 'both_imperial' => 'Imperial first, then metric', 'only_metric' => 'Only metric', 'only_imperial' => 'Only imperial')); $options['language'] = new pw_option_select('language', 'PHP Weather can produce output in several languages ' . '- please select your default from the list.', array(), array('en' => 'English', 'da' => 'Danish', 'hu' => 'Hungarian', 'no' => 'Norwegian')); $options['offset'] = new pw_option_integer('offset', "Due to a bug in PHP, on some systems the time reported may " . "be incorrect. If you experience this, you specify the " . "offset here. For example, if your times generated are 1 " . "hour too early (so METARs appear an hour older than they " . "are), set this option to be +1.", array(), false, 0); $options['use_proxy'] = new pw_option_boolean('use_proxy', "Set this option to 'Yes' to enable support for a " . "proxy server.", array(), array('false' => 'No', 'true' => 'Yes')); $options['proxy_host'] = new pw_option_text('proxy_host', "This is the hostname of the proxy server.", array($proxy_dep), $host_validator); $options['proxy_port'] = new pw_option_integer('proxy_port', "This is the port number of the proxy server. The " . "default is what is used by the Squid proxy server. " . "Another common port number is '8080'", array($proxy_dep), $port_validator, 3128); $options['db_type'] = new pw_option_select('db_type', 'PHP Weather can use several kinds of databases.', array(), array('null' => 'No database at all', 'mysql' => 'A MySQL database', 'pgsql' => 'A PostgreSQL database', 'dba' => 'A DBA database')); $options['db_handler'] = new pw_option_select('db_handler', "If you've chosen to use a Berkeley DB style database " . "through the PHP database abstraction layer (DBA), then " . "please select the handler you would like to use.", array($dba_dep), 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 Softwares DB2', 'db3' => 'db3 - Sleepycat Softwares DB3')); $options['always_use_db'] = new pw_option_boolean('always_use_db', "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.", array($db_dep), array('false' => 'No', 'true' => 'Yes')); $options['cache_timeout'] = new pw_option_integer('cache_timeout', "This specifies when a METAR in the cache is " . "considered to be old. If a METAR is older than this " . "number of seconds, then an attempt is made to fetch " . "a new METAR from the web. The default value is 3600 " . "seconds (1 hour), but some stations make two " . "reports each hour, so you might want to lower this " . "number to perhaps 2400 or even 1800.", array(new pw_dependency('always_use_db', 'false'), $db_dep), false, '3600'); $options['db_pconnect'] = new pw_option_boolean('db_pconnect', "If you want to make a persistent connection to the " . "database, then set this option to 'Yes'.", array($sql_dep), array('false' => 'No', 'true' => 'Yes')); $options['db_port'] = new pw_option_integer('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.', array($sql_dep), $port_validator_empty); $options['db_hostname'] = new pw_option_text('db_hostname', 'This is the hostname that PHP Weather will use, ' . 'if you choose to use a database-backend, that ' . 'supports network connections.', array($sql_dep), $host_validator); $options['db_database'] = new pw_option_text('db_database', 'This is the name of the database that PHP Weather ' . 'should use.', array($sql_dep), $table_validator); $options['db_username'] = new pw_option_text('db_username', 'This is the username that PHP Weather will use ' . 'for accessing the database.', array($sql_dep)); $options['db_password'] = new pw_option_text('db_password', 'This is the password that PHP Weather will use when ' . 'trying to make a connection to the database. Please ' . "remember to protect the file after you've stored the " . "password in it.", array($sql_dep)); $options['db_metars'] = new pw_option_text('db_metars', 'This is the name of the table that is used ' . 'to cache the METARs.', array($db_dep), $table_validator, 'pw_metars'); $options['db_stations'] = new pw_option_text('db_stations', 'This is the name of the database/table that is used ' . 'to store the names of the stations.', array($db_dep), $table_validator, 'pw_stations'); $options['db_countries'] = new pw_option_text('db_countries', 'This is the name of the database that is used to ' . 'store the names of the countries together with ' . 'country-codes.', array($dba_dep), $table_validator, 'pw_countries'); $options['mark_begin'] = new pw_option_text('mark_begin', 'This string will be placed in front 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 <code><i></code>, <code><font " . 'color="red"></code>, etc.', array(), false, '<b>'); $options['mark_end'] = new pw_option_text('mark_end', 'This string is placed after all the changable parts. ' . 'You should make sure that it closes any tags ' . "you've opened in <code>mark_begin</code>.", array(), false, '</b>'); $options['exclude'] = new pw_option_multi_select('exclude', '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 several options at once in Netscape ' . 'by holding down Ctrl while clicking on the option.', array(), array('time' => 'Leave out the time part', 'wind' => 'Leave out the wind part', 'runway' => 'Leave out information about runways')); /* Finally - we register all the options with the session. */ session_register('options'); } /* The options should now be ready - they might come from a restored * session, or they might just have been created. */ /* We update the options with the latest information. We have to be carefull when we do this, because we have to operate directly on the options in $options and not on a copy. */ $keys = array_keys($options); foreach ($keys as $option) { $options[$option]->update_value($HTTP_POST_VARS); } /* Grouping */ $general_group = new pw_optiongroup('general_group', 'General Options', 'This is some general options for PHP Weather.', array('verbosity', 'icao', 'pref_units', 'language', 'offset', 'use_proxy', 'proxy_host', 'proxy_port'), !empty($HTTP_POST_VARS['general_group_visible'])); $db_group = new pw_optiongroup('db_group', 'Database Options', 'These options deal with the database. PHP Weather ' . 'can use a database for caching the METARs it ' . 'retrieves. This is very nice, since it takes at ' . 'least a second or two to fetch a METAR from the ' . 'National Weather Service.', array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', 'cache_timeout', 'db_hostname', 'db_port', 'db_username', 'db_password', 'db_database', 'db_metars', 'db_stations', 'db_countries'), !empty($HTTP_POST_VARS['db_group_visible'])); $rendering_group = new pw_optiongroup('rendering_group', 'Rendering Options', 'You can customize the looks of PHP Weather using these options.', array('mark_begin', 'mark_end', 'exclude'), !empty($HTTP_POST_VARS['rendering_group_visible'])); /* We can now generate a configuration file with the options selected so far: */ $timestamp = date ('dS of F, Y H:i:s'); $config = "<?php /* This is a local configuration file for PHP Weather. It was generated on the $timestamp. */\n" . $general_group->get_config() . $db_group->get_config() . $rendering_group->get_config() . "\n?>\n"; if (!empty($HTTP_POST_VARS['download'])) { header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="defaults.php"'); echo $config; exit(); } ?> <html> <head> <title>Configuration Builder for PHP Weather</title> <style type="text/css"> <!-- BODY { font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif; font-size: small; } DT { font-weight: bold } P { margin-top: 0.5em; margin-bottom: 0.5em; } --> </style> </head> <body> <script language="JavaScript1.2"> function update(accepted, error, value, output) { if (accepted) { document.getElementById(output).innerHTML = "<font color=\"green\">Input accepted.</font>"; } else { while ((index = error.indexOf("%s")) > -1) { error = error.substring(0, index) + value + error.substring(index+2); } document.getElementById(output).innerHTML = "<font color=\"red\">" + error + "</font>"; } } function validate(error, value, output, field) { update(field.value == value, error, field.value, output); } function validate_ereg(error, ereg, output, field) { regex = new RegExp(ereg); update(regex.test(field.value), error, field.value, output); } function validate_range(error, low, high, empty_ok, output, field) { update((empty_ok == 1 && field.value == "") || (field.value >= low && field.value <= high), error, field.value, output); } function toggle_group(id) { group = document.getElementById(id); text = document.getElementById(id + "_text"); input = document.getElementById(id + "_input"); if (group.style.display == "none") { text.innerHTML = "Hide options."; group.style.display = "block"; input.value = 1; } else { text.innerHTML = "Show options."; group.style.display = "none"; input.value = 0; } } </script> <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> <h1>Configuration Builder for PHP Weather</h1> <p>This is the Configuretor shipped with PHP Weather.</p> <p>Change the options below - when you're done, then press one of the 'Update Configuration' buttons. Depending on your choices, more options might appear. Continue to change the options until they all say <span style="color: green">Input accepted.</span></p> <form action="<? echo $PHP_SELF . '?' . SID ?>" method="POST"> <p>You can <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> <dl> <?php $general_group->show(); $db_group->show(); $rendering_group->show(); ?> </dl> <p><input type="submit" value="Update options"></p> <p>This is a configuration file bases on your answers above:</p> <?php highlight_string($config); ?> <p>You should copy the above configuration to a file called <code>defaults.php</code> in the root directory of your PHP Weather installation. It's very important that the lines with <code><font color="#0000CC"><?php</font></code> and <code><font color="#0000CC">?></font></code> are the very first and very last, respectively. There should be no blank lines outside these two tags.</p> <p>You can also <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> </form> </body> </html> --- NEW FILE --- <html> <head> <title>Database Builder for PHP Weather</title> <style type="text/css"> <!-- BODY { font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif; font-size: small; } DT { font-weight: bold } P { margin-top: 0.5em; margin-bottom: 0.5em; } --> </style> </head> <body> <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> <h1>Database Builder for PHP Weather</h1> <p>This is the tool you use to create the tables used by PHP Weather. PHP Weather uses the tables for several things: the lists of countries and the stations in each country is stored in two tables, and then the METARs are cached in a third table.</p> <p>If you want to use a different database than the default <code>null</code> database, then you should start by making a <code>defaults.php</code> file using the <a href="make_config.php">Configuration Builder</a>. After you've made the file and uploaded it to your webserver, then you can proceed on this page.</p> <h2>Create Tables</h2> <p>If you're installing PHP Weather for the first time, then you'll need to make the tables. <b>This will delete any tables with the same name in the database!</b></p> <p>You can also use this button to update the list of stations from <code>stations.cvs</code>. The list changes from time to time as we discover new stations and when old stations disappear. This will remove any cached METARs from the database, but they would have been removed sooner or later anyway, so this isn't a problem.</p> <form action="make_db.php" method="POST"> <input type="submit" name="do_sql" value="Create or Recreate Tables"> </form> <?php if (!empty($HTTP_POST_VARS['do_sql'])) { echo "<blockquote>\n"; define('PHPWEATHER_BASE_DIR', dirname(__FILE__) . '/..'); require_once(PHPWEATHER_BASE_DIR . '/db_layer.php'); $db = new db_layer(); if ($db->db->create_tables()) { $num_rows = 0; $num_countries = 0; echo "<p>The tables have been created. They will now be " . "filled with data, please wait...</p>\n"; flush(); $fp = fopen(PHPWEATHER_BASE_DIR . '/stations.csv', 'r'); while ($row = fgets($fp, 1024)) { $row = trim($row); if (substr($row, 0, 2) == '##' && substr($row, -2) == '##') { /* We've found a country */ $cc = substr($row, 3, 2); // The country-code. $country = substr($row, 6, -3); // The name of the country. $countries[$cc] = $country; $num_countries++; //echo "<p>Now processing stations in $country.</p>\n"; } elseif ($row[0] != '#' && $row != '') { list($icao, $name) = explode(';', $row, 2); $num_rows++; $data[$cc][$icao] = $name; } } $db->db->insert_stations($data, $countries); echo "<p>Data about <b>$num_rows</b> stations from " . "<b>$num_countries</b> countries were inserted.</p>\n"; } else { echo "<p>The was a problem with the creation of the tables!</p>\n"; } echo "</blockquote>\n"; } ?> </body> </html> Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- index.php 14 Apr 2002 18:27:38 -0000 1.5 +++ index.php 15 May 2002 22:26:50 -0000 1.6 @@ -1,343 +1,6 @@ -<?php - -error_reporting(E_ALL); - -/* Require a couple of validators: */ -require_once('pw_validator.php'); -require_once('pw_validator_ereg.php'); -require_once('pw_validator_range.php'); - -/* Require_once some options: */ -require_once('pw_option.php'); -require_once('pw_option_text.php'); -require_once('pw_option_select.php'); -require_once('pw_option_multi_select.php'); -require_once('pw_option_boolean.php'); -require_once('pw_option_integer.php'); - -/* We want to group the options: */ -require_once('pw_optiongroup.php'); - -/* A couple of dependencies: */ -require_once('pw_dependency.php'); -require_once('pw_dependency_or.php'); - -/* We have to strip slashes from the GPC variables. */ -if (get_magic_quotes_gpc() == 1) { - - function recursive_stripslashes(&$array) { - $keys = array_keys($array); - foreach($keys as $key) { - if (is_array($array[$key])) { - recursive_stripslashes($array[$key]); - } else { - $array[$key] = stripslashes($array[$key]); - } - } - } - - recursive_stripslashes($HTTP_POST_VARS); -} - -/* Start the session. */ -session_start(); - -/* If $options isn't registered, then we should make the variable and - * register it: */ -if (!session_is_registered('options')) { - /* Common dependencies: */ - $db_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql', 'dba')); - $sql_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql')); - $dba_dep = new pw_dependency('db_type', 'dba'); - $proxy_dep = new pw_dependency('use_proxy', 'true'); - - $port_validator = new pw_validator_range("Sorry, '%s' is not a valid port-number " . - "because is't outside the range 1-65536", - 1, 65536); - $port_validator_empty = new pw_validator_range("Sorry, '%s' is not a valid port-number " . - "because is't outside the range 1-65536", - 1, 65536, true); - - /* This just catches the most obvious errors. */ - $table_validator = new pw_validator_ereg("Sorry, '%s' is not a valid name.", - '^[^./]+$'); - $icao_validator = new pw_validator_ereg("Sorry, '%s' is not a valid ICAO.", - '^[a-zA-Z0-9]{4}$'); - - /* This just catches the most obvious errors. */ - $host_validator = new pw_validator_ereg("Sorry, '%s' is not a valid hostname.", - '^[^/#?~]+$'); - - /* Next comes all the options: */ - - $options['verbosity'] = - new pw_option_select('verbosity', - "The setting of this variable controls the amount of " . - "errors, warnings, and debug-information PHP Weather " . - "will print. It is suggested that you always include " . - "errors in the output and perhaps also warnings.", - array(), - array('1' => 'Errors only', - '2' => 'Warnings only', - '4' => 'Debug information only', - '3' => 'Errors + warnings', - '5' => 'Errors + debug information', - '6' => 'Warnings + debug information', - '7' => 'Everything')); - - $options['icao'] = - new pw_option_text('icao', - 'This will be the default station used by PHP Weather. ' . - 'You should enter a valid four-letter ICAO.', - array(), $icao_validator, 'EKYT'); - - $options['pref_units'] = - new pw_option_select('pref_units', - 'You may choose to display the data in several ' . - 'formats. Please choose one that fits your need.', - array(), - array('both_metric' => 'Metric first, then imperial', - 'both_imperial' => 'Imperial first, then metric', - 'only_metric' => 'Only metric', - 'only_imperial' => 'Only imperial')); - - $options['language'] = - new pw_option_select('language', - 'PHP Weather can produce output in several languages ' . - '- please select your default from the list.', - array(), - array('en' => 'English', - 'da' => 'Danish', - 'hu' => 'Hungarian', - 'no' => 'Norwegian')); - - $options['offset'] = - new pw_option_integer('offset', - "Due to a bug in PHP, on some systems the time reported may " . - "be incorrect. If you experience this, you specify the " . - "offset here. For example, if your times generated are 1 " . - "hour too early (so METARs appear an hour older than they " . - "are), set this option to be +1.", - array(), false, 0); - - $options['use_proxy'] = - new pw_option_boolean('use_proxy', - "Set this option to 'Yes' to enable support for a " . - "proxy server.", - array(), - array('false' => 'No', - 'true' => 'Yes')); - - $options['proxy_host'] = - new pw_option_text('proxy_host', - "This is the hostname of the proxy server.", - array($proxy_dep), $host_validator); - - $options['proxy_port'] = - new pw_option_integer('proxy_port', - "This is the port number of the proxy server. The " . - "default is what is used by the Squid proxy server. " . - "Another common port number is '8080'", - array($proxy_dep), $port_validator, 3128); - - $options['db_type'] = - new pw_option_select('db_type', - 'PHP Weather can use several kinds of databases.', - array(), - array('null' => 'No database at all', - 'mysql' => 'A MySQL database', - 'pgsql' => 'A PostgreSQL database', - 'dba' => 'A DBA database')); - - $options['db_handler'] = - new pw_option_select('db_handler', - "If you've chosen to use a Berkeley DB style database " . - "through the PHP database abstraction layer (DBA), then " . - "please select the handler you would like to use.", - array($dba_dep), - 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 Softwares DB2', - 'db3' => 'db3 - Sleepycat Softwares DB3')); - - $options['always_use_db'] = - new pw_option_boolean('always_use_db', - "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.", - array($db_dep), - array('false' => 'No', 'true' => 'Yes')); - - $options['cache_timeout'] = - new pw_option_integer('cache_timeout', - "This specifies when a METAR in the cache is " . - "considered to be old. If a METAR is older than this " . - "number of seconds, then an attempt is made to fetch " . - "a new METAR from the web. The default value is 3600 " . - "seconds (1 hour), but some stations make two " . - "reports each hour, so you might want to lower this " . - "number to perhaps 2400 or even 1800.", - array(new pw_dependency('always_use_db', 'false'), $db_dep), - false, '3600'); - - $options['db_pconnect'] = - new pw_option_boolean('db_pconnect', - "If you want to make a persistent connection to the " . - "database, then set this option to 'Yes'.", - array($sql_dep), - array('false' => 'No', 'true' => 'Yes')); - - $options['db_port'] = - new pw_option_integer('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.', - array($sql_dep), $port_validator_empty); - - $options['db_hostname'] = - new pw_option_text('db_hostname', - 'This is the hostname that PHP Weather will use, ' . - 'if you choose to use a database-backend, that ' . - 'supports network connections.', - array($sql_dep), $host_validator); - - $options['db_database'] = - new pw_option_text('db_database', - 'This is the name of the database that PHP Weather ' . - 'should use.', - array($sql_dep), $table_validator); - - $options['db_username'] = - new pw_option_text('db_username', - 'This is the username that PHP Weather will use ' . - 'for accessing the database.', - array($sql_dep)); - - $options['db_password'] = - new pw_option_text('db_password', - 'This is the password that PHP Weather will use when ' . - 'trying to make a connection to the database. Please ' . - "remember to protect the file after you've stored the " . - "password in it.", - array($sql_dep)); - - $options['db_metars'] = - new pw_option_text('db_metars', - 'This is the name of the table that is used ' . - 'to cache the METARs.', - array($db_dep), $table_validator, 'pw_metars'); - - $options['db_stations'] = - new pw_option_text('db_stations', - 'This is the name of the database/table that is used ' . - 'to store the names of the stations.', - array($db_dep), $table_validator, 'pw_stations'); - - $options['db_countries'] = - new pw_option_text('db_countries', - 'This is the name of the database that is used to ' . - 'store the names of the countries together with ' . - 'country-codes.', - array($dba_dep), $table_validator, 'pw_countries'); - - - $options['mark_begin'] = - new pw_option_text('mark_begin', - 'This string will be placed in front 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 <code><i></code>, <code><font " . - 'color="red"></code>, etc.', - array(), false, '<b>'); - - $options['mark_end'] = - new pw_option_text('mark_end', - 'This string is placed after all the changable parts. ' . - 'You should make sure that it closes any tags ' . - "you've opened in <code>mark_begin</code>.", - array(), false, '</b>'); - - $options['exclude'] = - new pw_option_multi_select('exclude', - '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 several options at once in Netscape ' . - 'by holding down Ctrl while clicking on the option.', - array(), - array('time' => 'Leave out the time part', - 'wind' => 'Leave out the wind part', - 'runway' => 'Leave out information about runways')); - - - /* Finally - we register all the options with the session. */ - session_register('options'); -} - -/* The options should now be ready - they might come from a restored - * session, or they might just have been created. */ - -/* We update the options with the latest information. We have to be - carefull when we do this, because we have to operate directly on the - options in $options and not on a copy. */ -$keys = array_keys($options); -foreach ($keys as $option) { - $options[$option]->update_value($HTTP_POST_VARS); -} - -/* Grouping */ -$general_group = - new pw_optiongroup('general_group', 'General Options', - 'This is some general options for PHP Weather.', - array('verbosity', 'icao', 'pref_units', 'language', 'offset', - 'use_proxy', 'proxy_host', 'proxy_port'), - !empty($HTTP_POST_VARS['general_group_visible'])); - -$db_group = - new pw_optiongroup('db_group', 'Database Options', - 'These options deal with the database. PHP Weather ' . - 'can use a database for caching the METARs it ' . - 'retrieves. This is very nice, since it takes at ' . - 'least a second or two to fetch a METAR from the ' . - 'National Weather Service.', - array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', - 'cache_timeout', 'db_hostname', 'db_port', - 'db_username', 'db_password', 'db_database', - 'db_metars', 'db_stations', 'db_countries'), - !empty($HTTP_POST_VARS['db_group_visible'])); - -$rendering_group = - new pw_optiongroup('rendering_group', 'Rendering Options', - 'You can customize the looks of PHP Weather using these options.', - array('mark_begin', 'mark_end', 'exclude'), - !empty($HTTP_POST_VARS['rendering_group_visible'])); - -/* We can now generate a configuration file with the options selected so far: */ - -$timestamp = date ('dS of F, Y H:i:s'); -$config = "<?php -/* This is a local configuration file for PHP Weather. - It was generated on the $timestamp. */\n" . -$general_group->get_config() . -$db_group->get_config() . -$rendering_group->get_config() . -"\n?>\n"; - -if (!empty($HTTP_POST_VARS['download'])) { - header('Content-type: application/octet-stream'); - header('Content-Disposition: attachment; filename="defaults.php"'); - echo $config; - exit(); -} - -?> - <html> <head> - <title>Configuration Builder for PHP Weather</title> + <title>Configuration of PHP Weather</title> <style type="text/css"> <!-- BODY { @@ -359,88 +22,34 @@ </head> <body> -<script language="JavaScript1.2"> -function update(accepted, error, value, output) { - if (accepted) { - document.getElementById(output).innerHTML = "<font color=\"green\">Input accepted.</font>"; - } else { - while ((index = error.indexOf("%s")) > -1) { - error = error.substring(0, index) + value + error.substring(index+2); - } - document.getElementById(output).innerHTML = "<font color=\"red\">" + error + "</font>"; - } -} - -function validate(error, value, output, field) { - update(field.value == value, error, field.value, output); -} - -function validate_ereg(error, ereg, output, field) { - regex = new RegExp(ereg); - update(regex.test(field.value), error, field.value, output); -} - -function validate_range(error, low, high, empty_ok, output, field) { - update((empty_ok == 1 && field.value == "") || - (field.value >= low && field.value <= high), - error, field.value, output); -} - -function toggle_group(id) { - group = document.getElementById(id); - text = document.getElementById(id + "_text"); - input = document.getElementById(id + "_input"); - if (group.style.display == "none") { - text.innerHTML = "Hide options."; - group.style.display = "block"; - input.value = 1; - } else { - text.innerHTML = "Show options."; - group.style.display = "none"; - input.value = 0; - } -} -</script> - -<img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> -<h1>Configuration Builder for PHP Weather</h1> - -<p>This is the Configuretor shipped with PHP Weather.</p> - -<p>Change the options below - when you're done, then press one of the -'Update Configuration' buttons. Depending on your choices, more options -might appear. Continue to change the options until they all say <span style="color: green">Input accepted.</span></p> - - <form action="<? echo $PHP_SELF . '?' . SID ?>" method="POST"> - -<p>You can <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> - - <dl> - <?php - - $general_group->show(); - $db_group->show(); - $rendering_group->show(); - - ?> - </dl> - - <p><input type="submit" value="Update options"></p> - - <p>This is a configuration file bases on your answers above:</p> - - <?php highlight_string($config); ?> + <h1>Configuration of PHP Weather</h1> - <p>You should copy the above configuration to a file called - <code>defaults.php</code> in the root directory of your PHP Weather - installation. It's very important that the lines with <code><font - color="#0000CC"><?php</font></code> and <code><font - color="#0000CC">?></font></code> are the very first and very last, - respectively. There should be no blank lines outside these two tags.</p> - -<p>You can also <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> + <p>This is the place where you configurate PHP Weather. You'll need + to complete two steps to fully utilise PHP Weather: make a local + configuration file with information about which database to use, + and then create the database.</p> + + <p>It's save to leave these pages unprotected as they wont do + anything destructive. You cannot actually change the configuration + of PHP Weather using these pages, instead you download a new + configuration-file which you'll have to upload to the webserver + before it becomes effective. The <a href="make_db.php">Database + Builder</a> will also just recreate the existing tables - nothing + permanent will be deleted.</p> + + <dl> + <dt><a href="make_config.php">Configuration Builder</a></dt> + + <dd><p>Use this page to build a custom configuration-file for PHP + Weather.</p></dd> + + <dt><a href="make_db.php">Database Builder</a></dt> + + <dd><p>After you've made a custom configuration using the link + above, you'll need to use this page to create the database and fill + it with data.</p></dd> - </form> + </dl> </body> </html> |