Location: PHPKode > projects > eqEpic > eqEpic0.7.8/setup.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" href="sources/eqplan.css" type="text/css" />
</head>
<body>
<?php
/******************************************************************************
* setup.php                                                                   *
* Auto Setup File                                                             *
* See readme.txt for additional information                                   *
*******************************************************************************
* eqEpic - The Epic Raid Manager                                              *
* Open-Source Project By Ryan Christenson                                     *
* =========================================================================== *
* Software Version:           eqEpic 0.7.8                                    *
* Software by:                The RSWR Network (http://www.rswr.net)          *
* Copyright 2006-2007 by:     Ryan Christenson (http://www.rswr.net)          *
* Support, News, Updates at:  http://forum.rswr.net/                          *
*******************************************************************************
* 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 DownloadCounter; if not, write to the Free Software              *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *
******************************************************************************/
	include(dirname(__FILE__)."/language.php");
	
	$divFormat="<div style=\"text-align: center; font-weight: bold; font-family: verdana,arial; font-size: 15px;\">";
	$backHome="$divFormat<center><p>Install/Update has completed.</p></center><br /><br /><a href=\"./\">".$Translation["goto start page"]."</a></div>";
	
	// check this file's MD5 to make sure it wasn't called before
	$prevMD5=@implode('', @file("./setup.md5"));
	$thisMD5=md5(@implode('', @file("./setup.php")));
	if($thisMD5==$prevMD5){
		echo "$divFormat ".$Translation["setup performed"]." ".date("r", filemtime("./setup.md5")).".<br /><br /></div>";
		echo "$divFormat<div style=\"font-size: 10px;\">".$Translation["delete md5"]."</div></div><br /><br />";
		echo $backHome;
		exit;
	}
	
	// connect to the database
	$dbServer=$HTTP_POST_VARS['dbServer'];
	$dbUsername=$HTTP_POST_VARS['dbUsername'];
	$dbPassword=$HTTP_POST_VARS['dbPassword'];
	$dbDatabase=$HTTP_POST_VARS['dbDatabase'];
	$email=$HTTP_POST_VARS['email'];
	$noDB=0;
	if(!@mysql_connect($dbServer, $dbUsername, $dbPassword)){
		$noDB=1;
	}elseif(!@mysql_select_db($dbDatabase)){
		if(!@mysql_query("create database `$dbDatabase`")){
			$noDB=2;
		}else{
			if(!@mysql_select_db($dbDatabase)){
				$noDB=2;
			}
		}
	}
	
	// if no connection established, ask for connection data
	if($noDB){
		if($dbServer!=''){
			echo $divFormat."<div style=\"color: red;\">".($noDB==1 ? $Translation["no db connection"] : str_replace("<DBName>", $dbDatabase, $Translation["no db name"]))."</div>"."</div>";
		}
		
		?>
		<form method="post" action="setup.php">
			<?php echo $divFormat; ?>
				<?php echo $Translation["provide connection data"]; ?>
				<br /><br /><center>
				<table class="table_other">
					<tr>
						<td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql server"]; ?></div></td>
						<td><input type="text" name="dbServer" size="20" class="text" /></td>
						</tr>
					<tr>
						<td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql username"]; ?></div></td>
						<td><input type="text" name="dbUsername" size="10" class="text" /></td>
						</tr>
					<tr>
						<td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql password"]; ?></div></td>
						<td><input type="password" name="dbPassword" size="10" class="text" /></td>
						</tr>
					<tr>
						<td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql db"]; ?></div></td>
						<td><input type="text" name="dbDatabase" size="15" class="text" /></td>
						</tr>
					<tr>
						<td align="right"><?php echo $divFormat; ?><?php echo $Translation["email"]; ?></div><br/><span class="ewmsg"><?php echo $Translation["email2"]; ?></span></td>
						<td><input type="text" name="email" size="15" class="text" /></td>
						</tr>
					<tr>
						<td align="right"></td>
						<td>
						<input type="image" src="images/but_install-trans.png" width="108" height="65" value="<?php echo $Translation["connect"]; ?>" /></td>
						</tr>
					</table>
				</div>
			</form>
<?php include ("footer.php") ?>
		<?php
		exit;
	}else{
		// if connection is successful, save parameters into config.php
		if(!$fp=@fopen("./db.php", "r+")){
			echo $divFormat."<div style=\"color: red;\">".$Translation["couldnt save config"]."</div></div><br />";
			echo $backHome;
			exit;
		}else{

			fwrite($fp, "<?php\n");
			fwrite($fp, "\tdefine(\"HOST\", \"$dbServer\");\n");
			fwrite($fp, "\tdefine(\"PORT\", 3306);\n");
			fwrite($fp, "\tdefine(\"USER\", \"$dbUsername\");\n");
			fwrite($fp, "\tdefine(\"PASS\", \"$dbPassword\");\n");
			fwrite($fp, "\tdefine(\"DB\", \"$dbDatabase\");\n");
			fwrite($fp, "\t\$Email_Name = \"$email\";\n");
			fclose($fp);
			
		}
	}
	
// Set Up Tables and Data

	// Filename
        $contents = file('./eqepic.sql');

        // Display file contents if activated.
        if (1 == $_POST['contents']) {
            printf("<pre>\n%s</pre>\n", implode('', $contents));
        }

        // Remove blank lines and comments.
        $sql = '';
        foreach ($contents as $line) {
            $line = trim($line);
            // Sort out empty or comment lines.
            if (($line == '') or ($line{0} == '#') or (substr($line, 0, 2) == '--')) {
                continue;
            }
            $sql .= $line . ' ';
        }

        // Execute SQL statements.
        foreach (explode(';', $sql) as $cmd) {
            $cmd = trim($cmd);
            if ($cmd != '') {
                mysql_query($cmd);
            }
        }
	
	// save MD5
	if($fp=@fopen("./setup.md5", "w")){
		fwrite($fp, $thisMD5);
		fclose($fp);
	}
		
	// go to index
	echo $backHome;
?>
Return current item: eqEpic