Fixed issues with setup.php

This commit is contained in:
root
2019-06-11 14:53:44 -04:00
parent 99e7307c62
commit f06a66887d
6 changed files with 103 additions and 93 deletions

View File

@@ -45,9 +45,10 @@ CRM, Accounting and Invoicing System for small managed IT companies
### Installation Instructions ### Installation Instructions
* Create a mysql database dump db.sql into it * Download the files in this repository
* Set db user and password in config.php * Create a Mysql database
* Point your browser and away you go * Point your browser to setup.php fill in the info
* Your Done! that easy..
#### Requirements #### Requirements
* Webserver (Apache, NGINX) * Webserver (Apache, NGINX)

View File

@@ -34,7 +34,7 @@
$calendar_name = $row['calendar_name']; $calendar_name = $row['calendar_name'];
$calendar_color = $row['calendar_color']; $calendar_color = $row['calendar_color'];
?> ?>
<option data-content="<i class='fa fa-circle mr-2' style='color:<?php echo $calendar_color; ?>;'></i> value="<?php echo $calendar_id; ?> ><?php echo $calendar_name; ?></option> <option data-content="<i class='fa fa-circle mr-2' style='color:<?php echo $calendar_color; ?>;'></i> <?php echo $calendar_name; ?>" value="<?php echo $calendar_id; ?>"><?php echo $calendar_name; ?></option>
<?php <?php
} }

12
config.old.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
//DB Settings
$dbhost = "localhost";
$dbusername = "root";
$dbpassword = "password";
$database = "pittpc";
$mysqli = mysqli_connect($dbhost, $dbusername, $dbpassword, $database);
include("get_settings.php");
?>

View File

@@ -1,12 +1,12 @@
<?php <?php
//DB Settings
$dbhost = "localhost";
$dbhost = "localhost"; $dbusername = "root";
$dbusername = "root"; $dbpassword = "password";
$dbpassword = "password"; $database="test";
$database = "pittpc";
$mysqli = mysqli_connect($dbhost, $dbusername, $dbpassword, $database);
$mysqli = mysqli_connect($dbhost, $dbusername, $dbpassword, $database);
include("get_settings.php");
include("get_settings.php");
?> ?>

BIN
pittpc.tar.gz Normal file

Binary file not shown.

153
setup.php
View File

@@ -2,88 +2,84 @@
if(isset($_POST['add_database'])){ if(isset($_POST['add_database'])){
$host = $_POST['host']; $host = $_POST['host'];
$database = $_POST['database']; $database = $_POST['database'];
$username = $_POST['username']; $username = $_POST['username'];
$password = $_POST['password']; $password = $_POST['password'];
$myfile = fopen("dbconnect.php", "w"); $myfile = fopen("config.php", "w");
$txt = "<?php\n\n"; $txt = "<?php\n\n";
fwrite($myfile, $txt); fwrite($myfile, $txt);
$txt = "\$dbhost = \"$host\";\n\$dbusername = \"$username\";\n\$dbpassword = \"$password\";\n\$database=\"$database\";\n\n"; $txt = "\$dbhost = \"$host\";\n\$dbusername = \"$username\";\n\$dbpassword = \"$password\";\n\$database = \"$database\";\n\n";
fwrite($myfile, $txt); fwrite($myfile, $txt);
$txt = "\$mysqli = mysqli_connect(\$dbhost, \$dbusername, \$dbpassword, \$database);\n\n"; $txt = "\$mysqli = mysqli_connect(\$dbhost, \$dbusername, \$dbpassword, \$database);\n\n";
fwrite($myfile, $txt); fwrite($myfile, $txt);
$txt = "include(\"get_settings.php\");\n\n"; $txt = "include(\"get_settings.php\");\n\n";
fwrite($myfile, $txt); fwrite($myfile, $txt);
$txt = "?>"; $txt = "?>";
fwrite($myfile, $txt); fwrite($myfile, $txt);
fclose($myfile); fclose($myfile);
$_SESSION['alert_message'] = "Database successful"; include("config.php");
header("setup.php?import_database"); // Name of the file
$filename = 'db.sql';
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line){
// Skip it if it's a comment
if(substr($line, 0, 2) == '--' || $line == '')
continue;
} // Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if(substr(trim($line), -1, 1) == ';'){
// Perform the query
mysqli_query($mysqli,$templine);
// Reset temp variable to empty
$templine = '';
}
}
if(isset($_POST['import_database'])){ //Create Some Data
include("config.php"); mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_created_at = NOW()");
// Name of the file mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue', category_created_at = NOW()");
$filename = 'db.sql'; mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red', category_created_at = NOW()");
// Temporary variable, used to store current query mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green', category_created_at = NOW()");
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line){
// Skip it if it's a comment
if(substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Service', category_type = 'Income', category_color = 'orange', category_created_at = NOW()");
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if(substr(trim($line), -1, 1) == ';'){
// Perform the query
mysqli_query($mysqli,$templine);
// Reset temp variable to empty
$templine = '';
}
}
//Create Some Data mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Cash', category_type = 'Payment Method', category_color = 'purple', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'brown', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_created_at = NOW()"); mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue', calendar_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue', category_created_at = NOW()"); $_SESSION['alert_message'] = "Database successfully added";
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Service', category_type = 'Income', category_color = 'orange', category_created_at = NOW()"); header("Location: setup.php?user");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Cash', category_type = 'Payment Method', category_color = 'purple', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'brown', category_created_at = NOW()");
mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue', calendar_created_at = NOW()");
} }
if(isset($_POST['add_user'])){ if(isset($_POST['add_user'])){
include("config.php"); include("config.php");
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
$email = strip_tags(mysqli_real_escape_string($mysqli,$_POST['email'])); $email = strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']));
@@ -100,23 +96,25 @@ if(isset($_POST['add_user'])){
$_SESSION['alert_message'] = "User added"; $_SESSION['alert_message'] = "User added";
header("Location: setup.php?company");
} }
if(isset($_POST['add_company_settings'])){ if(isset($_POST['add_company_settings'])){
include("config.php"); include("config.php");
$config_company_name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_name'])); $config_company_name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_name']));
$config_company_address = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_address'])); $config_company_address = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_address']));
$config_company_city = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_city'])); $config_company_city = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_city']));
$config_company_state = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_state'])); $config_company_state = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_state']));
$config_company_zip = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_zip'])); $config_company_zip = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_zip']));
$config_company_phone = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_phone'])); $config_company_phone = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_phone']));
$config_company_site = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_site'])); $config_company_site = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_site']));
mysqli_query($mysqli,"INSERT INTO settings SET config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = '$config_company_phone', config_company_site = '$config_company_site', config_start_page = 'dashboard.php'"); mysqli_query($mysqli,"INSERT INTO settings SET config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = '$config_company_phone', config_company_site = '$config_company_site', config_start_page = 'dashboard.php'");
header("login.php"); header("Location: login.php");
} }
@@ -192,7 +190,7 @@ if(isset($_POST['add_company_settings'])){
<div id="content-wrapper"> <div id="content-wrapper">
<div class="container"> <div class="container">
<?php include("config.php"); ?>
<?php if(isset($_GET['database'])){ ?> <?php if(isset($_GET['database'])){ ?>
<div class="card mb-3"> <div class="card mb-3">
@@ -203,17 +201,17 @@ if(isset($_POST['add_company_settings'])){
<form class="p-3" method="post" autocomplete="off"> <form class="p-3" method="post" autocomplete="off">
<div class="form-group"> <div class="form-group">
<label>MySQL Host</label> <label>Database Name</label>
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-server"></i></span> <span class="input-group-text"><i class="fa fa-database"></i></span>
</div> </div>
<input type="text" class="form-control" name="host" placeholder="Usually localhost" required> <input type="text" class="form-control" name="database" placeholder="Name of the database" required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>MySQL Username</label> <label>Username</label>
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user"></i></span> <span class="input-group-text"><i class="fa fa-user"></i></span>
@@ -223,7 +221,7 @@ if(isset($_POST['add_company_settings'])){
</div> </div>
<div class="form-group"> <div class="form-group">
<label>MySQL Password</label> <label>Password</label>
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock"></i></span> <span class="input-group-text"><i class="fa fa-lock"></i></span>
@@ -231,16 +229,17 @@ if(isset($_POST['add_company_settings'])){
<input type="password" class="form-control" name="password" placeholder="Enter the password" required> <input type="password" class="form-control" name="password" placeholder="Enter the password" required>
</div> </div>
</div> </div>
<div class="form-group mb-5"> <div class="form-group mb-5">
<label>MySQL Database Name</label> <label>Database Host</label>
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-database"></i></span> <span class="input-group-text"><i class="fa fa-server"></i></span>
</div> </div>
<input type="text" class="form-control" name="database" placeholder="Name of the database" required> <input type="text" class="form-control" name="host" placeholder="Usually localhost" required>
</div> </div>
</div> </div>
<hr> <hr>
<button type="submit" name="add_database" class="btn btn-primary">Save</button> <button type="submit" name="add_database" class="btn btn-primary">Save</button>
</form> </form>
@@ -298,8 +297,6 @@ if(isset($_POST['add_company_settings'])){
<?php }elseif(isset($_GET['company'])){ ?> <?php }elseif(isset($_GET['company'])){ ?>
<?php include("config.php"); ?>
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<h6 class="mt-1"><i class="fa fa-building"></i> Company Settings</h6> <h6 class="mt-1"><i class="fa fa-building"></i> Company Settings</h6>
@@ -378,7 +375,7 @@ if(isset($_POST['add_company_settings'])){
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<h6 class="mt-1"><i class="fa fa-database"></i> Start Install</h6> <h6 class="mt-1"><i class="fa fa-database"></i> Start Install <?php echo $database; ?></h6>
</div> </div>
<div class="card-body"> <div class="card-body">
<p>Click on the install button to start the install process, you must create a database before starting</p> <p>Click on the install button to start the install process, you must create a database before starting</p>