DB Prefix Added In GUI Installer
This commit is contained in:
parent
e0248e5641
commit
4d00a7321a
|
|
@ -1,152 +1,143 @@
|
|||
<?php
|
||||
|
||||
// array to hold validation errors
|
||||
$errors = array();
|
||||
$errors = [];
|
||||
|
||||
// array to pass back data
|
||||
$data = array();
|
||||
$data = [];
|
||||
|
||||
// validate the variables
|
||||
// if any of these variables don't exist, add an error to our $errors array
|
||||
if (empty($_POST['app_name']))
|
||||
$errors['app_name'] = 'App Name is required.';
|
||||
|
||||
if (empty($_POST['app_name']))
|
||||
$errors['app_name'] = 'App Name is required.';
|
||||
|
||||
if (empty($_POST['app_url']))
|
||||
$errors['app_url'] = 'App Url is required.';
|
||||
if (empty($_POST['app_url']))
|
||||
$errors['app_url'] = 'App Url is required.';
|
||||
|
||||
if (empty($_POST['app_currency']))
|
||||
$errors['app_currency'] = 'The application currency is required.';
|
||||
|
||||
if (empty($_POST['app_locale']))
|
||||
$errors['app_locale'] = 'Please select a locale for the application.';
|
||||
if (empty($_POST['app_currency']))
|
||||
$errors['app_currency'] = 'The application currency is required.';
|
||||
|
||||
if (empty($_POST['app_timezone']))
|
||||
$errors['app_timezone'] = 'The application timezone is required.';
|
||||
if (empty($_POST['app_locale']))
|
||||
$errors['app_locale'] = 'Please select a locale for the application.';
|
||||
|
||||
if (empty($_POST['host_name']))
|
||||
$errors['host_name'] = 'Host Name is required.';
|
||||
if (empty($_POST['app_timezone']))
|
||||
$errors['app_timezone'] = 'The application timezone is required.';
|
||||
|
||||
// if (empty($_POST['database_name']))
|
||||
// $errors['database_name'] = 'Database Name is required.';
|
||||
if (empty($_POST['host_name']))
|
||||
$errors['host_name'] = 'Host Name is required.';
|
||||
|
||||
// if (empty($_POST['user_name']))
|
||||
// $errors['user_name'] = 'User Name is required.';
|
||||
if (empty($_POST['port_name']))
|
||||
$errors['port_name'] = 'Port Name is required.';
|
||||
|
||||
if (empty($_POST['port_name']))
|
||||
$errors['port_name'] = 'Port Name is required.';
|
||||
if (preg_match('/\s/', $_POST['app_url']))
|
||||
$errors['app_url_space'] = 'There should be no space in App URL ';
|
||||
|
||||
if (preg_match('/\s/', $_POST['app_url']))
|
||||
$errors['app_url_space'] = 'There should be no space in App URL ';
|
||||
if (preg_match('/\s/', $_POST['app_name']))
|
||||
$errors['app_name_space'] = 'There should be no space in App Name.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['app_name']))
|
||||
$errors['app_name_space'] = 'There should be no space in App Name.';
|
||||
if (preg_match('/\s/', $_POST['host_name']))
|
||||
$errors['host_name_space'] = 'There should be no space in Host Name.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['host_name']))
|
||||
$errors['host_name_space'] = 'There should be no space in Host Name.';
|
||||
if (preg_match('/\s/', $_POST['database_name']))
|
||||
$errors['database_name_space'] = 'There should be no space in Database Name.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['database_name']))
|
||||
$errors['database_name_space'] = 'There should be no space in Database Name.';
|
||||
if (preg_match('/\s/', $_POST['database_prefix']))
|
||||
$errors['database_prefix_space'] = 'There should be no space in Database Prefix.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['user_name']))
|
||||
$errors['user_name_space'] = 'There should be no space in User Name.';
|
||||
if (preg_match('/\s/', $_POST['user_name']))
|
||||
$errors['user_name_space'] = 'There should be no space in User Name.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['user_password']))
|
||||
$errors['user_password_space'] = 'There should be no space in User Password.';
|
||||
if (preg_match('/\s/', $_POST['user_password']))
|
||||
$errors['user_password_space'] = 'There should be no space in User Password.';
|
||||
|
||||
if (preg_match('/\s/', $_POST['port_name']))
|
||||
$errors['port_name_space'] = 'There should be no space in Port Name.';
|
||||
if (preg_match('/\s/', $_POST['port_name']))
|
||||
$errors['port_name_space'] = 'There should be no space in Port Name.';
|
||||
|
||||
//return a response
|
||||
// return a response
|
||||
// if there are any errors in our errors array, return a success boolean of false
|
||||
|
||||
if (! empty($errors)) {
|
||||
if (! empty($errors)) {
|
||||
// if there are items in our errors array, return those errors
|
||||
$data['success'] = false;
|
||||
$data['errors'] = $errors;
|
||||
} else {
|
||||
// if there are no errors process our form, then return a message
|
||||
// getting env file location
|
||||
$location = str_replace('\\', '/', getcwd());
|
||||
$currentLocation = explode("/", $location);
|
||||
array_pop($currentLocation);
|
||||
array_pop($currentLocation);
|
||||
$desiredLocation = implode("/", $currentLocation);
|
||||
$envFile = $desiredLocation . '/' . '.env';
|
||||
|
||||
// if there are items in our errors array, return those errors
|
||||
$data['success'] = false;
|
||||
$data['errors'] = $errors;
|
||||
$envExampleFile = $desiredLocation . '/' . '.env.example';
|
||||
|
||||
} else {
|
||||
if (! file_exists($envFile)) {
|
||||
if (file_exists($envExampleFile)) {
|
||||
copy($envExampleFile, $envFile);
|
||||
} else {
|
||||
touch($envFile);
|
||||
}
|
||||
}
|
||||
|
||||
// if there are no errors process our form, then return a message
|
||||
// reading env content
|
||||
$data = file($envFile);
|
||||
$keyValueData = [];
|
||||
|
||||
// getting env file location
|
||||
$location = str_replace('\\', '/', getcwd());
|
||||
$currentLocation = explode("/", $location);
|
||||
array_pop($currentLocation);
|
||||
array_pop($currentLocation);
|
||||
$desiredLocation = implode("/", $currentLocation);
|
||||
$envFile = $desiredLocation . '/' . '.env';
|
||||
if ($data) {
|
||||
foreach ($data as $line) {
|
||||
$line = preg_replace('/\s+/', '', $line);
|
||||
$rowValues = explode('=', $line);
|
||||
|
||||
$envExampleFile = $desiredLocation . '/' . '.env.example';
|
||||
|
||||
if (!file_exists($envFile)) {
|
||||
if (file_exists($envExampleFile)) {
|
||||
copy($envExampleFile, $envFile);
|
||||
} else {
|
||||
touch($envFile);
|
||||
if (strlen($line) !== 0) {
|
||||
$keyValueData[$rowValues[0]] = $rowValues[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reading env content
|
||||
$data = file($envFile);
|
||||
$keyValueData = [];
|
||||
// inserting form data to empty array
|
||||
$keyValueData['DB_HOST'] = $_POST["host_name"];
|
||||
$keyValueData['DB_DATABASE'] = $_POST["database_name"];
|
||||
$keyValueData['DB_PREFIX'] = $_POST["database_prefix"];
|
||||
$keyValueData['DB_USERNAME'] = $_POST["user_name"];
|
||||
$keyValueData['DB_PASSWORD'] = $_POST["user_password"];
|
||||
$keyValueData['APP_NAME'] = $_POST["app_name"];
|
||||
$keyValueData['APP_URL'] = $_POST["app_url"];
|
||||
$keyValueData['APP_CURRENCY'] = $_POST["app_currency"];
|
||||
$keyValueData['APP_LOCALE'] = $_POST["app_locale"];
|
||||
$keyValueData['APP_TIMEZONE'] = $_POST["app_timezone"];
|
||||
$keyValueData['DB_CONNECTION'] = $_POST["database_connection"];
|
||||
$keyValueData['DB_PORT'] = $_POST["port_name"];
|
||||
|
||||
if ($data) {
|
||||
foreach ($data as $line) {
|
||||
$line = preg_replace('/\s+/', '', $line);
|
||||
$rowValues = explode('=', $line);
|
||||
// making key/value pair with form-data for env
|
||||
$changedData = [];
|
||||
foreach ($keyValueData as $key => $value) {
|
||||
$changedData[] = $key . '=' . $value;
|
||||
}
|
||||
|
||||
if (strlen($line) !== 0) {
|
||||
$keyValueData[$rowValues[0]] = $rowValues[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
// inserting new form-data to env
|
||||
$changedData = implode(PHP_EOL, $changedData);
|
||||
file_put_contents($envFile, $changedData);
|
||||
|
||||
// inserting form data to empty array
|
||||
$keyValueData['DB_HOST'] = $_POST["host_name"];
|
||||
$keyValueData['DB_DATABASE'] = $_POST["database_name"];
|
||||
$keyValueData['DB_USERNAME'] = $_POST["user_name"];
|
||||
$keyValueData['DB_PASSWORD'] = $_POST["user_password"];
|
||||
$keyValueData['APP_NAME'] = $_POST["app_name"];
|
||||
$keyValueData['APP_URL'] = $_POST["app_url"];
|
||||
$keyValueData['APP_CURRENCY'] = $_POST["app_currency"];
|
||||
$keyValueData['APP_LOCALE'] = $_POST["app_locale"];
|
||||
$keyValueData['APP_TIMEZONE'] = $_POST["app_timezone"];
|
||||
$keyValueData['DB_CONNECTION'] = $_POST["database_connection"];
|
||||
$keyValueData['DB_PORT'] = $_POST["port_name"];
|
||||
// checking database connection(mysql only)
|
||||
if ($_POST["database_connection"] == 'mysql') {
|
||||
// create connection
|
||||
@$conn = new mysqli($_POST["host_name"], $_POST["user_name"], $_POST["user_password"], $_POST["database_name"], $_POST['port_name']);
|
||||
|
||||
// making key/value pair with form-data for env
|
||||
$changedData = [];
|
||||
foreach ($keyValueData as $key => $value) {
|
||||
$changedData[] = $key . '=' . $value;
|
||||
}
|
||||
|
||||
// inserting new form-data to env
|
||||
$changedData = implode(PHP_EOL, $changedData);
|
||||
file_put_contents($envFile, $changedData);
|
||||
|
||||
// checking database connection(mysql only)
|
||||
if ($_POST["database_connection"] == 'mysql') {
|
||||
// Create connection
|
||||
@$conn = new mysqli($_POST["host_name"], $_POST["user_name"], $_POST["user_password"], $_POST["database_name"], $_POST['port_name']);
|
||||
|
||||
// check connection
|
||||
if ($conn->connect_error) {
|
||||
$errors['database_error'] = $conn->connect_error;
|
||||
$data['errors'] = $errors;
|
||||
$data['success'] = false;
|
||||
} else {
|
||||
$data['success'] = true;
|
||||
$data['message'] = 'Success!';
|
||||
}
|
||||
// check connection
|
||||
if ($conn->connect_error) {
|
||||
$errors['database_error'] = $conn->connect_error;
|
||||
$data['errors'] = $errors;
|
||||
$data['success'] = false;
|
||||
} else {
|
||||
$data['success'] = true;
|
||||
$data['message'] = 'Success!';
|
||||
}
|
||||
|
||||
// show a message of success and provide a true success variable
|
||||
} else {
|
||||
$data['success'] = true;
|
||||
$data['message'] = 'Success!';
|
||||
}
|
||||
}
|
||||
|
||||
// return all our data to an AJAX call
|
||||
echo json_encode($data);
|
||||
// return all our data to an AJAX call
|
||||
echo json_encode($data);
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@
|
|||
<div id="app-settings">
|
||||
<div class="form-group" id="app_name">
|
||||
<label for="application_name" class="required">Application Name</label>
|
||||
<input type= "text" name= "app_name" id="application_name" class="form-control" value="Bagisto_" data-validation="required length"
|
||||
<input type= "text" name= "app_name" id="application_name" class="form-control" value="Bagisto_" data-validation="required length"
|
||||
data-validation-length="max20">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" id="app_url">
|
||||
<label for="application_url" class="required">Default URL</label>
|
||||
<input type="text" name="app_url" id="application_url" class="form-control" value="https://<?php echo $_SERVER['HTTP_HOST']; ?>"
|
||||
<input type="text" name="app_url" id="application_url" class="form-control" value="https://<?php echo $_SERVER['HTTP_HOST']; ?>"
|
||||
data-validation="required length" data-validation-length="max50">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" id="app_currency">
|
||||
<label for="application_currency" class="required">Default Currency</label>
|
||||
<select name="app_currency" id="application_currency" class="form-control" data-validation="required length" data-validation-length="max50">
|
||||
|
|
@ -28,15 +28,15 @@
|
|||
<option value="USD" selected>US Dollar</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" id="app_timezone">
|
||||
<label for="application_timezone" class="required">Default Timezone</label>
|
||||
<select name="app_timezone" id="application_timezone" class="js-example-basic-single">
|
||||
<?php
|
||||
<?php
|
||||
date_default_timezone_set('UTC');
|
||||
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
|
||||
$current = date_default_timezone_get();
|
||||
|
||||
|
||||
foreach($tzlist as $key => $value) {
|
||||
if(!$value === $current) {
|
||||
echo "<option value='$value' selected>" . $value . "</option>";
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" id="app_locale">
|
||||
<label for="application_locale" class="required">Default Locale</label>
|
||||
<select name="app_locale" id="application_locale" class="form-control" data-validation="required">
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
|
||||
<div id="database-settings">
|
||||
<div class="databse-error" id="database_error"></div>
|
||||
|
||||
|
||||
<div class="form-group" id="database_connection">
|
||||
<label for="db_connection" class="required">Database Connection</label>
|
||||
<select name="database_connection" id="db_connection" class="form-control">
|
||||
|
|
@ -80,26 +80,32 @@
|
|||
<div class="form-row">
|
||||
<div class="form-group col-md-6" id="host_name">
|
||||
<label for="db_hostname" class="required">Database Hostname</label>
|
||||
<input type="text" name="host_name" id="db_hostname" class="form-control" value="127.0.0.1"
|
||||
<input type="text" name="host_name" id="db_hostname" class="form-control" value="127.0.0.1"
|
||||
data-validation="required length" data-validation-length="max50">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group col-md-6" id="port_name">
|
||||
<label for="db_port" class="required">Database Port</label>
|
||||
<input type="text" name="port_name" id="db_port" class="form-control" value="3306"
|
||||
<input type="text" name="port_name" id="db_port" class="form-control" value="3306"
|
||||
data-validation="required alphanumeric number length" data-validation-length="max5">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="database_name">
|
||||
<label for="db_name" class="required">Database Name</label>
|
||||
<input type="text" name="database_name" id="db_name" class="form-control"
|
||||
<input type="text" name="database_name" id="db_name" class="form-control"
|
||||
data-validation="length required" data-validation-length="max50">
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="database_prefix">
|
||||
<label for="database_prefix">Database Prefix</label>
|
||||
<input type="text" name="database_prefix" id="database_prefix" class="form-control"
|
||||
data-validation="length" data-validation-length="max50">
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="user_name">
|
||||
<label for="db_username" class="required">Database Username</label>
|
||||
<input type="text" name="user_name" id="db_username" class="form-control"
|
||||
<input type="text" name="user_name" id="db_username" class="form-control"
|
||||
data-validation="length required" data-validation-length="max50">
|
||||
</div>
|
||||
|
||||
|
|
@ -130,12 +136,12 @@
|
|||
$('#database-settings').hide();
|
||||
$('#environment-next').click(function() {
|
||||
$('#app-settings').hide();
|
||||
$('#database-settings').show();
|
||||
$('#database-settings').show();
|
||||
});
|
||||
|
||||
$('#environment-first').click(function() {
|
||||
$('#app-settings').show();
|
||||
$('#database-settings').hide();
|
||||
$('#database-settings').hide();
|
||||
});
|
||||
|
||||
// process the form
|
||||
|
|
@ -144,7 +150,7 @@
|
|||
$('.form-error').remove(); // remove the error text
|
||||
|
||||
// get the form data
|
||||
var formData = {
|
||||
let formData = {
|
||||
'app_name' : $('input[name=app_name]').val(),
|
||||
'app_url' : $('input[name=app_url]').val(),
|
||||
'app_currency' : $('select[name=app_currency]').val(),
|
||||
|
|
@ -154,11 +160,12 @@
|
|||
'port_name' : $('input[name=port_name]').val(),
|
||||
'database_connection' : $("select[name=database_connection]" ).val(),
|
||||
'database_name' : $('input[name=database_name]').val(),
|
||||
'database_prefix' : $('input[name=database_prefix]').val(),
|
||||
'user_name' : $('input[name=user_name]').val(),
|
||||
'user_password' : $('input[name=user_password]').val(),
|
||||
};
|
||||
|
||||
var target = window.location.href.concat('/EnvConfig.php');
|
||||
let target = window.location.href.concat('/EnvConfig.php');
|
||||
|
||||
// process the form
|
||||
$.ajax({
|
||||
|
|
@ -171,7 +178,7 @@
|
|||
// using the done promise callback
|
||||
.done(function(data) {
|
||||
if (!data.success) {
|
||||
// handle errors
|
||||
// handle errors
|
||||
if (data.errors.app_name) {
|
||||
$('#app_name').addClass('has-error');
|
||||
$('#app_name').append('<div class="form-error">' + data.errors.app_name + '</div>');
|
||||
|
|
@ -183,7 +190,7 @@
|
|||
if (data.errors.app_timezone) {
|
||||
$('#app_timezone').addClass('has-error');
|
||||
$('#app_timezone').append('<div class="form-error">' + data.errors.app_timezone + '</div>');
|
||||
}
|
||||
}
|
||||
if (data.errors.host_name) {
|
||||
$('#host_name').addClass('has-error');
|
||||
$('#host_name').append('<div class="form-error">' + data.errors.host_name + '</div>');
|
||||
|
|
@ -228,6 +235,10 @@
|
|||
$('#database_name').addClass('has-error');
|
||||
$('#database_name').append('<div class="form-error">' + data.errors.database_name_space + '</div>');
|
||||
}
|
||||
if (data.errors.database_prefix_space) {
|
||||
$('#database_prefix').addClass('has-error');
|
||||
$('#database_prefix').append('<div class="form-error">' + data.errors.database_prefix_space + '</div>');
|
||||
}
|
||||
if (data.errors.user_password_space) {
|
||||
$('#user_password').addClass('has-error');
|
||||
$('#user_password').append('<div class="form-error">' + data.errors.user_password_space + '</div>');
|
||||
|
|
|
|||
Loading…
Reference in New Issue