Location: PHPKode > projects > PHP easy ticket and help system > php-easy-ticket-and-help-system/install.php
<?php
/*
Name: install.php
Description: installer for pets ( php easy ticket system )
Purpose: to install the data base and inital settings
Maker: lee johnstone
Site: www.freakcms.com
Support: hide@address.com

--------------------------------------------------------------------------------------------------------------------------

YOU MAY NOT
1. Use this for commercial usage
2. Claim the code as your own
3. Remove any copyrights from its original authors

YOU MAY

1. Upgrade, Update, Adjust, Modify this script, providing you keep all original comments.
2. Redistribute this code under the same license and none other.
3. Modify and use this script on your own site as you wish, providing you keep the copyright markings from original authors.


More information here.
http://www.freakcms.com/licensing.php

--------------------------------------------------------------------------------------------------------------------------


*/

  echo '<html><head>
  <meta http-equiv="Content-Language" content="en-au">
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  <link rel="stylesheet" type="text/css" href="css.css" />
<title>php Easy ticket system installation</title></head><body>';

if(!$_GET['install']){
  echo '<table border="0" width="100%" style="border-collapse: collapse">
  <tr>
  <td>
  Welcome to the TDLC installer<br />
  The installion script should make installing TDLC easy as can b and should take u no longer the five minutes to setup 
  <br>
  your download centre and have your files ready for download.<br>
  <br>
  Just follow the five easy steps<p>Requirements<br>
  <br>
  php5+<br>
  file uploads allowed in php (default enabled)<br>
  Tested on apache but im sure it will work with IIS and other php enabled servers<br>
  Tested on windows and linux servers<br>
  decent amount of space for your file storage</p>
  <p>Directory Permission Testing<br>';
//check for directory permissions before we go ahead
  $check1 = fopen("data/dbcon.php", "w+");
if($check1==false){
  die("<font color=red>Please Make data/dbcon.php read/writeable </font><br />");
  }else{
  echo '<font color=green>data/dbcon.php is writeable</font><br />';
}
if($check1){
  echo '<p><a href="?install=true&step=1">Continue</a></p>';
  }else{
  echo '<font color=red>please fix the writeable problems before u procced</font><br />';
 }
}
if($_GET['step']=="1"){
if(isset($_GET['install'])){
if($_GET['agree']=="true"){
  echo 'Please Enter your Database and admin information ';
  echo '<form method="POST" action="install.php?install=true&step=2&agree=true">
  <input type="text" name="hostname" size="20" value="localhost">Host Name<br />
  <input type="text" name="dbname" size="20" value="TDLC">Database Name<br />
  <input type="text" name="username" size="20">User Name<br />
  <input type="password" name="password" size="20">Password<br />
  <input type="submit" value="Next" name="Adddb"></form>';
  }else{
  echo '<textarea>Coming soon...</textarea><br/ >do u agree to our terms and conditions? <a href="?install=true&step=1&agree=true"> yes</a> <a href="install.php">no</a>';
  }
 }
}
if($_GET['step']=="2"){
if(isset($_POST['Adddb'])){
if($_GET['agree']=="true"){
  $dbname =$_POST['dbname'];
  $hostname = $_POST['hostname'];
  $password = $_POST['password'];
  $user = $_POST['username'];
  $con  = mysql_connect($hostname, $user, $password) or die(mysql_error()); 
  mysql_query("CREATE DATABASE $dbname",$con) or die(mysql_error()); 
  mysql_select_db($dbname, $con) or die(mysql_error());
  $makeconf = fopen("data/dbcon.php", "w+");
if($makeconf==false){
  die("unable to create file");
  }else{
  $cfg = '<?php
/*
Name: dbcon.php
Description: database addon for pets ( php easy ticket system )
Purpose: to connect and disconnect the sql db
Maker: lee johnstone
Site: www.freakcms.com
Support: hide@address.com

--------------------------------------------------------------------------------------------------------------------------

YOU MAY NOT
1. Use this for commercial usage
2. Claim the code as your own
3. Remove any copyrights from its original authors

YOU MAY

1. Upgrade, Update, Adjust, Modify this script, providing you keep all original comments.
2. Redistribute this code under the same license and none other.
3. Modify and use this script on your own site as you wish, providing you keep the copyright markings from original authors.


More information here.
http://www.freakcms.com/licensing.php

--------------------------------------------------------------------------------------------------------------------------
*/
	function checkdb(){
		if(!isset($g_link)){
			$g_link = false;
		}
	}
	function OpenDb(){
		if($g_link)
		return $g_link;
        $db_host = "'.$hostname.'"; //MySQL hostname (default is localhost)
        $db_user = "'.$user.'";  // MySQL Data Base user name  (default is root)
        $db_password = "'.$password.'";// MySQL Data Base Password
        $db_name = "'.$dbname.'";  // MySQL Data Base Name (default is tickets)
		$g_link = mysql_connect($db_host, $db_user, $db_password) or die(\'Could not connect to mysql server.\' );
		mysql_select_db($db_name) or die(\'Could not select database.\');
        return $g_link;
	}

	function CloseDb(){
		if($g_link!=false)
		mysql_close($g_link);
		$g_link = false;
	} 
?>';
  fwrite($makeconf, $cfg);
  }
  echo 'Connection to the data base successful <br />';
  echo 'Table Created: '.$dbname.'<br />';
  echo 'SQL Config Created: data/dbcon.php<br />';
  echo '<a href="install.php?install=true&step=3&agree=true">Set up your Download center nowt<a/>';
  }
 }
}
if($_GET['step']=="3"){
if($_GET['agree']=="true"){
?>
</p>
  <div align="center" class="set">
  <h1>Installation Core Settings</h1>
  <form method="POST" action="install.php?install=true&step=4&agree=true">
	<table class=set>
		<tr>
			<td class="set_name"><h3>Core</h3></td>
			<td class="set_input"></td>
			<td class="set_desc">&nbsp;</td>
		</tr>
		<tr class=set>
			<td class="set_name">Site name</td>
			<td class="set_input"><input class="set" type="text" name="site_name" size="20" ></td>
			<td class="set_desc"><label>Your Web Site Name Example ( Example: Freakcms )</label></td>
		</tr>
		<tr class=set>
			<td class="set_name" >Site title</td>
			<td class="set_input"><input class="set" type="text" name="page_title" size="20" ></td>
			<td class="set_desc"><label>Ticket System Page Title ( Example: Freakcms Ticket System )</label></td>
		</tr>
        <tr class=set>
			<td class="set_name">Admin name</td>
			<td class="set_input"><input class="set" type="text" name="adm" size="20" ></td>
			<td class="set_desc"><label>Your adminstration name</label></td>
		</tr>
		<tr class=set>
			<td class="set_name" >Password</td>
			<td class="set_input"><input class="set" type="text" name="pwd" size="20" ></td>
			<td class="set_desc"><label>Your adminstration password</label></td>
		</tr>
        <tr class=set>
			<td class="set_name" >Password again</td>
			<td class="set_input"><input class="set" type="text" name="pwd2" size="20" ></td>
			<td class="set_desc"><label>Your adminstration password again</label></td>
		</tr>
		<tr>
			<td class="set_name"><h3>Security</h3></td>
			<td class="set_desc"></td>
			<td>&nbsp;</td>
		</tr>
		<tr class=set>
			<td class="set_name">secret question</td>
			<td class="set_input"><input class="set" type="text" name="secert_q" size="20" > </td>
			<td class="set_desc"><label>Used for the submit and deletion forms</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">secret answer</td>
			<td class="set_input"><input class="set" type="text" name="secert_a" size="20" ></td>
			<td class="set_desc"><label>Used for the submit and deletion forms</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">check ips</td>
			<td class="set_input"><select class="set" size="1" name="check_ip">
			<option value="1">true</option>
			<option value="0">false</option>
			</select> </td>
			<td class="set_desc"><label>Checks tickets for duplicate ips entrys.</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">check emails</td>
			<td class="set_input"><select class="set" size="1" name="check_em">
			<option value="1">true</option>
			<option value="0">false</option>
			</select> </td>
			<td class="set_desc"><label>Check tickets for duplicate email entrys and email validation</label></td>
		</tr>
		<tr>
			<td class="set_name"><h3>Mail</h3></td>
			<td class="set_input"></td>
			<td class="set_desc">&nbsp;</td>
		</tr>
		<tr class=set>
			<td class="set_name">Admin email</td>
			<td class="set_input"><input class="set" type="text" name="adm_mail" size="20"></td>
			<td class="set_desc"><label>Ticket system administer email</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">Script Email</td>
			<td class="set_input"><input class="set" type="text" name="script_mail" size="20"></td>
			<td class="set_desc"> <label>Email used to send ticket information to users</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">Site mail</td>
			<td class="set_input"><input class="set" type="text" name="site_mail" size="20"></td>
			<td class="set_desc"><label>Main site email</label></td>
		</tr>
		<tr>
			<td class="set_name"><h3>Links</h3></td>
			<td class="set_input"></td>
			<td class="set_desc"><label>Make sure to define either http:// or https://</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">site link</td>
			<td class="set_input"><input class="set" type="text" name="site_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/index.php"></td>
			<td class="set_desc"><label>direct link to the ticket page</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">Admin link</td>
			<td class="set_input"><input class="set" type="text" name="adm_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/adm.php"></td>
			<td class="set_desc"><label>direct link to the admin page</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">remove link</td>
			<td class="set_input"><input class="set" type="text" name="rem_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/index.php?remove&ticket="></td>
			<td class="set_desc"><label>direct link to the remove form</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">status link</td>
			<td class="set_input"><input class="set" type="text" name="status_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/index.php?status&ticket="></td>
			<td class="set_desc"><label>direct link to the status form</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">valid link</td>
			<td class="set_input"><input class="set" type="text" name="valid_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/index.php?validate&ticket="></td>
			<td class="set_desc"><label>direct link to the validation form</label></td>
		</tr>
		<tr class=set>
			<td class="set_name">remove valid link</td>
			<td class="set_input"><input class="set" type="text" name="remval_link" size="20" value="http://<?=$_SERVER['HTTP_HOST'];?>/index.php?delete&ticket="></td>
			<td class="set_desc"><label>direct link to the remove validation page</label></td>
		</tr>
		</table>
	<input type="submit" value="Submit" name="setupdb"></p></form></div>
	<?php
 }
}
if($_GET['step']=="4"){
if($_GET['agree']=="true"){
if($_POST['setupdb']){
if(!$_POST['pwd']==$_POST['pwd2']){
  echo ' Your Passwords did not match ';
  die();
}
include 'data/dbcon.php';
OpenDb();
//sort out some vars
  $adm = $_POST['adm'];
  $pwd = md5($_POST['pwd']);
  $site_name = $_POST['site_name'];
  $site_link = $_POST['site_link'];
  $adm_link = $_POST['adm_link'];
  $page_title = $_POST['page_title'];
  $site_mail = $_POST['site_mail'];
  $adm_mail = $_POST['adm_mail'];
  $script_mail = $_POST['script_mail'];
  $secert_q = $_POST['secert_q'];
  $secert_a = $_POST['secert_a'];
  $check_ip = $_POST['check_ip'];
  $check_em = $_POST['check_em'];
  $valid_link = $_POST['valid_link'];
  $status_link = $_POST['status_link'];
  $rem_link = $_POST['rem_link'];
  $remval_link = $_POST['remval_link'];
  $max_ticket = $_POST['max_ticket'];
//check and create config table if it doesnt exists
$sql = '
CREATE TABLE IF NOT EXISTS `core` (
  `emp` varchar(1) NOT NULL,
  `adm` varchar(100) NOT NULL,
  `pwd` varchar(32) NOT NULL,
  `site_name` varchar(200) NOT NULL,
  `site_link` varchar(150) NOT NULL,
  `adm_link` varchar(150) NOT NULL,
  `page_title` varchar(150) NOT NULL,
  `site_mail` varchar(90) NOT NULL,
  `adm_mail` varchar(90) NOT NULL,
  `script_mail` varchar(90) NOT NULL,
  `secert_q` varchar(100) NOT NULL,
  `secert_a` varchar(100) NOT NULL,
  `check_ip` tinyint(1) NOT NULL,
  `check_em` tinyint(1) NOT NULL,
  `valid_link` varchar(200) NOT NULL,
  `status_link` varchar(200) NOT NULL,
  `rem_link` varchar(200) NOT NULL,
  `remval_link` varchar(200) NOT NULL,
  `total` int(5) NOT NULL,
  `max_ticket` int(5) NOT NULL,
  PRIMARY KEY  (`emp`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
  echo 'Creating table: `core`....<br />';
  mysql_query($sql) or die(mysql_error());
//check and create files table if it doesnt exists
  $sql = '
CREATE TABLE IF NOT EXISTS `tickets` (
  `id` int(5) NOT NULL auto_increment,
  `name` varchar(150) NOT NULL,
  `email` varchar(320) NOT NULL,
  `site` varchar(150) NOT NULL,
  `ticket` varchar(64) NOT NULL,
  `subject` varchar(200) NOT NULL,
  `msg` longtext NOT NULL,
  `ip` varchar(150) NOT NULL,
  `date` date NOT NULL,
  `time` time NOT NULL,
  `valid` tinyint(1) NOT NULL,
  `state` tinyint(1) NOT NULL,
  `cdate` date NOT NULL,
  `ctime` time NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ; ';
  echo 'Creating table: `tickets`....<br />';
  mysql_query($sql) or die(mysql_error());
  $sql = "
  INSERT INTO core (`adm`, `pwd`, `site_name`, `site_link`, `adm_link`, `page_title`, `site_mail`, `adm_mail`, `script_mail`, `secert_q`, `secert_a`, `check_ip`, `check_em`, `valid_link`, `status_link`, `rem_link`, `remval_link`, `total`, `max_ticket`) VALUES 
  ('$adm', 'md5($pwd)', '$site_name', '$site_link', '$adm_link', '$page_title', '$site_mail', '$adm_mail', '$script_mail', '$secert_q', '$secert_a', '$check_ip', '$check_em', '$valid_link', '$status_link', '$rem_link', '$remval_link', '0', '$max_ticket')";
  echo 'Adding core Settings....<br />';
  mysql_query($sql) or die(mysql_error());
  echo 'Data base installed and updated please login to your admin account now<br /> <a href="adm.php"> click here to login to your account now</a>';
  }
 }
}
  echo '</tr></table></body></html>';
?>
Return current item: PHP easy ticket and help system