Location: PHPKode > projects > LySite > lysite/setup.php
<?php
/*----------------------------------------------------------

       LySite
       Brad Landis (hide@address.com)

   Copyright (C) 2005 Brad Landis

   This program is free software; you can redistribute it
   and/or modify it under the terms of the GNU General
   Public License as published by the Free Software
   Foundation; either version 2 of the License, or (at your
   option) any later version.

   This program is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the
   implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License
   for more details.
   
   You should have received a copy of the GNU General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth
   Floor, Boston, MA  02110-1301, USA.

----------------------------------------------------------*/
ob_start();
?>
<html>
<head>
<title>LySite Setup</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>LySite Setup</h1>
<hr>
<?php
if(isset($_POST['step5'])) {
	
	if(isset($_POST['admin_user'])) {
		if($_POST['admin_user'] == "")
			$_POST['admin_user'] = "admin";
		if($_POST['admin_pass'] == "")
			echo "<p>Notice: Administrator will be created with no password. It is recommended that you add one after installation is complete.\n";
		@mysql_connect($_POST['DB_HOST'], $_POST['DB_USER'], $_POST['DB_PASS']) or die("Database connection failed: " . mysql_error());
		@mysql_select_db($_POST['DB_NAME']) or die("Database failed to load: ".mysql_error());
		if(mysql_query("INSERT INTO users SET username='$_POST[admin_user]',password=PASSWORD('$_POST[admin_pass]'),permissions=15"))
			echo "<p>Successfully created user '$_POST[admin_user]'.";
	}
	
	//make option file
	foreach($_POST as $k=>$v) {
		if($k == strtoupper($k)) {
			if(substr($v,0,1) == "_")
				$v = substr($v,1);
			else
				$v = "'$v'";
			$opt .= "define('$k',$v);\n";
		}
	}
	$opt = "<?php\n$opt?>\n";
	if(is_writeable("./options.php")) {
		echo "<p>Attempting to write to file: ";
		if($handle = fopen("./options.php", 'w')) {
			if(fwrite($handle, $opt)) {
				$options_saved = true;
				echo "Success.\n";
				header("Refresh: 5; URL=index.php");
			} else {
				echo "Could not open file.\n";
			}
			fclose($handle);
		} else {
			echo "File is not writeable.\n";
		}
	}
	if(!$options_saved) {
		echo "<p>Copy this text to \"options.php\" into the directory of installation:\n<pre style='color: #000; padding: 8px 12px; background: #ddd; border: 2px solid #bbb;'>".htmlentities($opt)."</pre>\n";
	}
	
} else if(isset($_POST['step4'])) {
	echo "<form action='setup.php' method='post'>\n<fieldset><legend>Misc Options</legend>\n";
	foreach($_POST as $k=>$v) {
		if(strtoupper($k) == $k)
			echo "<input type='hidden' name='$k' value='$v'>\n";
	}
	$block_options = "<option value='songs'>Newest Songs</option>\n<option value='searches'>Top Searches</option>\n";
	if($_POST['OPT_FAVORITES'] == '_true')
		$block_options .= "<option value='favorites'>Top Favorites</option>\n";
	if($_POST['OPT_ATTACHMENTS'] == '_true')
		$block_options .= "<option value='attachments'>Newest Attachments</option>\n";
	if($_POST['OPT_ALBUMS'] == '_true')
		$block_options .= "<option value='albums'>Newest Albums</option>\n";
	
	echo "<p><label>Display on Left Block on Homepage</label><br>	<select name='SITE_LEFT_BLOCK'>\n$block_options</select>\n";
	echo "<p><label>Display on Right Block on Homepage</label><br>	<select name='SITE_RIGHT_BLOCK'>\n$block_options</select>\n";
	echo "</fieldset>";
	if(!isset($_POST['no_install'])) {
		echo "<fieldset><legend>Admin User</legend>\n";
		echo "<p><label>Username:</label><br>	<input type='text' name='admin_user' value='admin'>\n";
		echo "<p><label>Password:</label><br>	<input type='password' name='admin_pass'>\n";
		echo "</fieldset>\n";
	}
	
	echo "<input type='submit' name='step5' value='Next Step'>\n";
	echo "</form>\n";
} else {
	echo "<form action='setup.php' method='post'>\n";
	if(isset($_POST['step3'])) {
		foreach($_POST as $k=>$v) {
			if(strtoupper($k) == $k)
				echo "<input type='hidden' name='$k' value='$v'>\n";
		}
	} else {
		include("options.php");
		echo "<input type='hidden' name='no_install'>\n";
		echo "<input type='hidden' name='DB_HOST' value='".DB_HOST."'>\n";
		echo "<input type='hidden' name='DB_USER' value='".DB_USER."'>\n";
		echo "<input type='hidden' name='DB_PASS' value='".DB_PASS."'>\n";
		echo "<input type='hidden' name='DB_NAME' value='".DB_NAME."'>\n";
		echo "<input type='hidden' name='DB_PREFIX' value='".DB_PREFIX."'>\n";
	}
	
	echo "<fieldset><legend>Website Information</legend>\n";
	echo "<p><label>Website Title:</label><br>					<input type='text' name='SITE_TITLE' value='".(defined('SITE_TITLE')?SITE_TITLE:"")."'>\n";
	echo "<p><label>Website Subtitle:</label><br>					<input type='text' name='SITE_SUBTITLE' value='".(defined('SITE_SUBTITLE')?SITE_SUBTITLE:"")."'>\n";
	echo "<p><label>Website Email:</label><br>					<input type='text' name='SITE_EMAIL' value='".(defined('SITE_EMAIL')?SITE_EMAIL:"")."'>\n";
	echo "<p><label>Website Administrator's Name:</label><br>			<input type='text' name='SITE_ADMIN' value='".(defined('SITE_ADMIN')?SITE_ADMIN:"")."'>\n";
	echo "<p><label>Website URL:</label><br>					<input type='text' name='SITE_URL' value='".(defined('SITE_URL')?SITE_URL:"http://$_SERVER[HTTP_HOST]".substr($_SERVER['REQUEST_URI'],0,strrpos($_SERVER['REQUEST_URI'],"/")))."'>\n";
	echo "<p><label>Location of Site on Webserver:</label><br>			<input type='text' name='SITE_MAINDIR' value='".(defined('SITE_MAINDIR')?SITE_MAINDIR:realpath("./"))."'>\n";
	echo "<p><label>Default Content Posting Abilites of New Users:</label><br>	<select name='DEFAULT_USER_LEVEL'>\n<option value='0'".(DEFAULT_USER_LEVEL==0?" selected":"").">No Posting</option>\n<option value='5'".(DEFAULT_USER_LEVEL==5 || !DEFAULT_USER_LEVEL?" selected":"").">Posting, With Approval</option>\n<option value='10'".(DEFAULT_USER_LEVEL==10?" selected":"").">Posting, Without Approval</option>\n<option value='15'".(DEFAULT_USER_LEVEL==15?" selected":"").">Admin Abilities (Not Recommended)</option>\n</select>\n";
	echo "</fieldset>\n";
	//these should test to see if they are enabled (OPT_ALBUMS, albums...)
	
	echo "<fieldset><legend>Website Options</legend>\n";
	echo "<p><label>Albums:</label>					<select name='OPT_ALBUMS'><option value='_true'".(OPT_ALBUMS==true?" selected":"").">Use</option><option value='_false'".(OPT_ALBUMS==false?" selected":"").">Do Not Use</option></select>\n";
	echo "<p><label>Categories:</label>				<select name='OPT_CATEGORIES'><option value='_true'".(OPT_CATEGORIES==true?" selected":"").">Use</option><option value='_false'".(OPT_CATEGORIES==false?" selected":"").">Do Not Use</option></select>\n";
	echo "<p><label>Favorites:</label>				<select name='OPT_FAVORITES'><option value='_true'".(OPT_FAVORITES==true?" selected":"").">Use</option><option value='_false'".(OPT_FAVORITES==false?" selected":"").">Do Not Use</option></select>\n";
	echo "<p><label>Attachments:</label>				<select name='OPT_ATTACHMENTS'><option value='_true'".(OPT_ATTACHMENTS==true?" selected":"").">Use</option><option value='_false'".(OPT_ATTACHMENTS==false?" selected":"").">Do Not Use</option></select>\n";
	echo "<p><label>Comments:</label>				<select name='OPT_COMMENTS'><option value='_true'".(OPT_COMMENTS==true?" selected":"").">Use</option><option value='_false'".(OPT_COMMENTS==false?" selected":"").">Do Not Use</option></select>\n";
	echo "<p><label>Attempt to Censor Out Bad Language:</label>	<select name='CENSOR_LANGUAGE'><option value='_true'".(CENSOR_LANGUAGE==true?" selected":"").">Yes</option><option value='_false'".(CENSOR_LANGUAGE==false?" selected":"").">No</option></select>\n";
	echo "</fieldset>\n";
	
	echo "<input type='submit' name='step4' value='Next Step'>\n";
	echo "</form>\n";
}
?>
</body>
</html>
Return current item: LySite