Scripts

babbaScriptInstaller v2.0

Stel, je hebt een mooi PHP-script gebouwd dat een mysql database gebruikt. Dus je wilt ook een script hebben dat de benodigde MySQL-query's uitvoerd, je license (bijv. GPL) laat zien enz. voordat gebruikers dat script kunnen gebruiken. Met dit script kun je dus heel snel en makkelijk zo'n script maken. Even wat feitjes over dit script: - Alle Opmaak-code is xHTML 1.0 Strict en CSS2 gevalideerd. - Er word geen Javascript gebruikt waardoor dit script ook werkt op browsers waar scripting uitgeschakeld staat. - Dit script is getest op Internet Explorer 6.0, Firefox 1.5 en Opera 9 beta.

babbascriptinstaller-v20
[code]
<?php
/*

************************************************************************
* babbaScriptInstaller v2.0                                            *
* Auteur: Sjoert de Boer                                               *
* E-mail: [email protected]                                        *
************************************************************************
* 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. For full license see:            *
* http://www.gnu.org/licenses/gpl.txt                                  *
************************************************************************

*/

// Main Configuration //////////////////////////////////////////////////

$scriptname = "My Script";

$license = "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. For full license see: http://www.gnu.org/licenses/gpl.txt";

// Query's /////////////////////////////////////////////////////////////

$query[0] = "
	CREATE TABLE `test` (
	`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
	`test` TEXT NOT NULL
	) TYPE = MYISAM ;
";

$query[1] = "
	INSERT INTO `test` ( `id` , `test` )
	VALUES (
	NULL , 'Test'
	);
";

// Design //////////////////////////////////////////////////////////////

$css = "

.maintable {
	font-family : Tahoma, Helvetica, Sans-Serif;
	font-size : 11px;
	cursor : default;
	width : 500px;
}
.tab1 {
	width : 33%;
	padding : 3px;
	border-bottom : 1px solid #808080;
	border-top : 1px solid #C0C0C0;
	border-left : 1px solid #C0C0C0;
}
.tab2 {
	width : 34%;
	padding : 3px;
	color : #000000;
	background-color : #EFEFEF;
	border-top : 1px solid #808080;
	border-left : 1px solid #808080;
	border-right : 1px solid #808080;
}
.tab3 {
	width : 33%;
	padding : 3px;
	border-bottom : 1px solid #808080;
	border-top : 1px solid #C0C0C0;
	border-right : 1px solid #C0C0C0;
}
.main {
	padding : 10px;
	color : #000000;
	background-color : #EFEFEF;
	border-bottom : 1px solid #808080;
	border-left : 1px solid #808080;
	border-right : 1px solid #808080;
}
.title {
	font-weight : bold;
}
.formleft {
	width : 25%;
}
.formright {
	width : 75%;
}
.inputfield {
	font-family : Tahoma, Helvetica, Sans-Serif;
	font-size : 11px;
	border : 1px solid #808080;
	padding : 2px;
}
.textarea {
	font-family : Tahoma, Helvetica, Sans-Serif;
	font-size : 11px;
	border : 1px solid #808080;
	padding : 2px;
	width : 98%;
	height : 100px;
}
.button {
	font-family : Tahoma, Helvetica, Sans-Serif;
	font-size : 11px;
	font-weight : bold;
	border : 1px solid #808080;
	padding : 2px;
}
.agree {
	width : 100%;
}

";

// No need to configure below this line ////////////////////////////////

if (!isset($_GET["task"])) {
	$_GET["task"] = "license";
}

if ($_GET["task"]=="license") {
// Start Step 1 xHTML-code /////////////////////////////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $scriptname; ?> Installation</title>
<?php echo "<style type=\"text/css\">\n".$css."\n</style>"; ?>
</head>
<body>
<form id="mainform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?task=configure" method="post">
<table cellspacing="0" border="0" class="maintable">
	<tr>
		<td class="tab2">License</td>
		<td class="tab3">Configuration</td>
		<td class="tab3">Installation</td>
	</tr>
	<tr>
		<td class="main" colspan="3">

		<table width="100%">
			<tr>
				<td colspan="2" class="title"><?php echo $scriptname; ?> License</td>
			</tr>
			<tr>
				<td colspan="2"><textarea name="license" class="textarea" cols="50" rows="8"><?php echo $license; ?></textarea></td>
			</tr>
			<tr>
				<td><input type="checkbox" name="agree" /></td>
				<td class="agree">I agree</td>
			</tr>
			<tr>
				<td colspan="2" align="right"><input type="submit" name="nextbutton" class="button" value="Next »" /></td>
			</tr>
		</table>

		</td>
	</tr>
</table>
</form>
</body>
</html>
<?php
// End Step 1 xHTML-code ///////////////////////////////////////////////
}
elseif ($_GET["task"]=="configure") {

// Start Step 2 xHTML-code /////////////////////////////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $scriptname; ?> Installation</title>
<?php echo "<style type=\"text/css\">\n".$css."\n</style>"; ?>
</head>
<body>
<form id="mainform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?task=installation" method="post">
<table cellspacing="0" border="0" class="maintable">
	<tr>
		<td class="tab1">License</td>
		<td class="tab2">Configuration</td>
		<td class="tab3">Installation</td>
	</tr>
	<tr>
		<td class="main" colspan="3">

		<?php
		if(!isset($_POST["agree"])) {
			echo "You must agree with the license to use this software.";
		}
		elseif ($_POST["agree"]=="on") {
		?>
		<table width="100%">
			<tr>
				<td colspan="2" class="title"><?php echo $scriptname; ?> Configuration</td>
			</tr>
			<tr>
				<td class="formleft">Hostname:</td>
				<td class="formright"><input type="text" name="hostname" class="inputfield" value="localhost" /></td>
			</tr>
			<tr>
				<td class="formleft">MySQL username:</td>
				<td class="formright"><input type="text" name="username" class="inputfield" /></td>
			</tr>
			<tr>
				<td class="formleft">MySQL password:</td>
				<td class="formright"><input type="password" name="password" class="inputfield" /></td>
			</tr>
			<tr>
				<td class="formleft">MySQL database:</td>
				<td class="formright"><input type="text" name="database" class="inputfield" /></td>
			</tr>
			<tr>
				<td colspan="2" align="right"><input type="submit" name="nextbutton" class="button" value="Next »" /></td>
			</tr>
		</table>
		<?php
		}
		?>

		</td>
	</tr>
</table>
</form>
</body>
</html>
<?php
// End Step 2 xHTML-code ///////////////////////////////////////////////
}
elseif ($_GET["task"]=="installation") {

// Start Step 3 xHTML-code /////////////////////////////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $scriptname; ?> Installation</title>
<?php echo "<style type=\"text/css\">\n".$css."\n</style>"; ?>
</head>
<body>
<table cellspacing="0" border="0" class="maintable">
	<tr>
		<td class="tab1">License</td>
		<td class="tab1">Configuration</td>
		<td class="tab2">Installation</td>
	</tr>
	<tr>
		<td class="main" colspan="3">
		<?php
		error_reporting(E_ALL ^ E_WARNING);
		if ($_POST["hostname"]=="" OR $_POST["username"]=="" OR $_POST["password"]=="" OR $_POST["database"]=="") {
			if ($_POST["hostname"]=="") {
			echo "<b>Error:</b> Hostname is not set.<br />\n";
			}
			if ($_POST["username"]=="") {
			echo "<b>Error:</b> MySQL username is not set.<br />\n";
			}
			if ($_POST["password"]=="") {
			echo "<b>Error:</b> MySQL password is not set.<br />\n";
			}
			if ($_POST["database"]=="") {
			echo "<b>Error:</b> MySQL database is not set.<br />\n";
			}
		}
		else {
			if(!$mysql = mysql_connect($_POST["hostname"],$_POST["username"],$_POST["password"])) {
			echo "<b>Error:</b> ".mysql_error();
			}
			elseif(!mysql_select_db($_POST["database"],$mysql)) {
			echo "<b>Error:</b> ".mysql_error();
			}
			else {
					$numberofquerys = count($query)-1;
					for ($i = 0; $i <= $numberofquerys; $i++) {
						if (mysql_query($query[$i])) {
						echo "<b>MySQL query ".$i."</b>: Succes!<br />\n";
						}
						else {
						echo "<b>MySQL query ".$i."</b>: Error: ".mysql_error()."<br />\n";
						}
					}
			}
		}
		?>
		</td>
	</tr>
</table>
</body>
</html>
<?php
// End Step 3 xHTML-code ///////////////////////////////////////////////
}
?>
[/code]

Reacties

0
Nog geen reacties.