File size: 2.08Kb
<?php
include "../lib/config.php";
include "../lib/functions_class.php";
//Database Import Config
$filename = '../setup/database.sql';
$templine = '';
$lines = file($filename); // Read entire file
//End
$action = $_POST['action'];
if($action == 'setupdatabase'){
$DB_USER = $_POST['dbusername'];
$DB_PASS = $_POST['dbpassword'];
$DB_NAME = $_POST['dbname'];
$DIRECTORY = $_POST['directory'];
if($DB_USER == ''){
echo "Enter Database Username";
}
else if($DB_NAME == ''){
echo "Enter Database Name";
}
else{
//read the entire string
$str=file_get_contents('../lib/conn.php~');
//replace something in the file string - this is a VERY simple example
$old = array("~username~", "~password~", "~database~", "~directory~");
$new = array($DB_USER, $DB_PASS, $DB_NAME, $DIRECTORY);
$str = str_replace($old, $new, $str);
//write the entire string
file_put_contents('../lib/conn.php', $str);
echo 1;
}
}
if($action == 'setupadmin'){
$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$role = "admin";
if($fname == ''){
echo "Enter your first name";
}
else if($lname == ''){
echo "Enter your first last";
}
else if($email == ''){
echo "Enter your email";
}
else if($password == ''){
echo "Enter password";
}
else if($password2 == ''){
echo "Re-Enter password";
}
else if($password != $password2){
echo "Both password not match";
}else{
//Check Tables IN DATABASE
$sql = "SELECT * FROM ".MEMBER_TABLE;
$result = $conn->query($sql);
if (!$result) {
// Import Database
foreach ($lines as $line){
if ( (substr($line, 0, 2) != '--') && ($line != '') ) // Skip all comments
$templine .= $line;
if (substr(trim($line), -1, 1) == ';'){
$conn->query($templine);
$templine = '';
}
}
}
//
$re = $DB->add_user($username,$fname,$lname,$email,$password,$role);
echo $re;
}
}
?>