<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: Options.php
| Description:
| Manages the script options
| Created Dec-5-2002
+------------------------------------------------------
*/
/* Class: Options
* Description:
* Driver for our options page
*/
class Options
{
var $skin = "";
var $menu = true;
var $error = '';
function run()
{
global $W2L, $userinfo, $output, $CONFIG;
// Do skin related stuff
require( "./Skin/Options.php" );
$this->skin = new Skin_Options();
$output->page_title = "Options";
$output->loc_add( "Options" );
$output->add( $this->skin->body_top() );
if( array_key_exists( 'M', $W2L->input ) )
{
if( $W2L->input['M'] == 'save' )
$this->save_options( explode( ",", $W2L->input['keys'] ) );
}
// Display any result message
if( $this->error != "" )
$output->add( "<div class=\"error\">\n" . $this->error . "\n</div><br />\n" );
$config_items['General'][] = 'debug';
$config_items['General'][] = 'enable_gzip';
$config_items['General'][] = 'session_timeout';
$config_descs['debug']['name'] = 'Debug Mode';
$config_descs['debug']['desc'] = 'Display debugging information. (1 = On, 0 = Off)';
$config_descs['enable_gzip']['name'] = 'Enable gzip';
$config_descs['enable_gzip']['desc'] = 'Compresses all backend and frontend pages for smaller size. (1 = On, 0 = Off)';
$config_descs['session_timeout']['name'] = 'Session Timeout';
$config_descs['session_timeout']['desc'] = 'The timeout time of a session on the admin interface (in seconds).';
$config_items['Database'][] = 'db_server';
$config_items['Database'][] = 'db_user';
$config_items['Database'][] = 'db_pass';
$config_items['Database'][] = 'db_name';
$config_descs['db_server']['name'] = 'Server';
$config_descs['db_server']['desc'] = 'The database server to connect to (most likely localhost).';
$config_descs['db_user']['name'] = 'Username';
$config_descs['db_user']['desc'] = 'The username to use to connect to the database server.';
$config_descs['db_pass']['name'] = 'Password';
$config_descs['db_pass']['desc'] = 'The server password for the username.';
$config_descs['db_name']['name'] = 'Database Name';
$config_descs['db_name']['desc'] = 'The name of the database to use on the server.';
$keys = array_keys( $config_items );
$items = array();
$output->add( $this->skin->group_top() );
foreach( $keys as $key )
{
$output->add( $this->skin->group_item( $key ) );
$output->add( $this->skin->options_top() );
foreach( $config_items[$key] as $item )
{
$items[] = $item;
$CONFIG[$item] = str_replace( "\\\\", "\\", $CONFIG[$item] );
$output->add( $this->skin->option_item( $config_descs[$item]['name'],
$config_descs[$item]['desc'],
$item,
$CONFIG[$item] ) );
}
$output->add( $this->skin->options_bottom() );
}
$output->add( $this->skin->group_bottom( implode( ",", $items ) ) );
$output->add( $this->skin->body_bottom() );
}
//================
// Saves the options to config.php
//================
function save_options( $keys )
{
global $CONFIG, $output, $W2L;
foreach( $keys as $key )
{
$W2L->input[$key] = str_replace( "\",
"\\\\",
$W2L->input[$key] );
$CONFIG[$key] = $W2L->input[$key];
}
if ( !copy( 'config.php', 'config.bak.php' ) )
{
$this->error = 'failed to backup config..<br />';
return;
}
$contents = "<?php\n\n";
foreach( $CONFIG as $key => $item )
{
$contents .= "\$CONFIG['$key'] = '$item';\n";
}
$contents .= "\n?>";
$config_fp = fopen( 'config.php', 'wt' );
if( $config_fp == FALSE )
{
$this->error = 'Unable to open config file!';
return;
}
fwrite( $config_fp, $contents );
fclose( $config_fp );
}
}
$driver = new Options();
?>