* Completed main flow of installation use case.

This commit is contained in:
alextselegidis@gmail.com 2013-10-16 15:53:26 +00:00
parent a5ef8fb491
commit dcecfd896d
7 changed files with 206 additions and 89 deletions

View file

@ -617,28 +617,73 @@ class Appointments extends CI_Controller {
try { try {
if (!$this->db->table_exists('ea_users')) { if (!$this->db->table_exists('ea_users')) {
// This is the first time the website is launched an the user needs to set // This is the first time the website is launched an the user needs to set
// the basic settings. // the basic settings. Display the installation view page.
// We will use mysqli to create the database structure from the "structure.sql" file.
require_once dirname(dirname(dirname(__FILE__))) . '/configuration.php';
$mysqli = new mysqli(SystemConfiguration::$db_host, SystemConfiguration::$db_username,
SystemConfiguration::$db_password, SystemConfiguration::$db_name);
$structure = file_get_contents($this->config->item('base_url') . 'assets/sql/structure.sql');
$mysqli->multi_query($structure);
$mysqli->close();
// Display the installation view page.
$view['base_url'] = $this->config->item('base_url'); $view['base_url'] = $this->config->item('base_url');
$this->load->view('general/installation', $view); $this->load->view('general/installation', $view);
return FALSE; // Do not display the book appointment view file. return FALSE; // Do not display the book appointment view file.
} else { } else {
return TRUE; return TRUE; // Application installed, continue ...
} }
} catch(Exception $exc) { } catch(Exception $exc) {
echo $exc->getTrace(); echo $exc->getTrace();
} }
} }
/**
* Installs Easy!Appointments on server.
*
* @param array $_POST['admin'] Contains the initial admin user data. System needs at least
* one admin user to work.
* @param array $_POST['company'] Contains the basic company data.
*/
public function ajax_install() {
try {
// 2nd method using the ci database class.
$file_contents = file_get_contents($this->config->item('base_url') . 'assets/sql/structure.sql');
$sql_queries = explode(';', $file_contents);
array_pop($sql_queries);
foreach($sql_queries as $query) {
$this->db->query($query);
}
//$this->db->reconnect();
$admin = json_decode($_POST['admin'], true);
$admin_role_id = $this->db->get_where('ea_roles', array('slug' => DB_SLUG_ADMIN))->row()->id;
$admin = json_decode($_POST['admin'], true);
$this->db->query('INSERT INTO `ea_users` (`first_name`, `last_name`, `email`, `phone_number`, `id_roles`) VALUES '
. '("' . $admin['first_name'] . '", "' . $admin['last_name'] . '", "' . $admin['email'] . '", "' . $admin['phone_number'] . '", "' . $admin_role_id . '");');
$this->db->query('INSERT INTO `ea_user_settings` (`id_users`, `username`, `password`) VALUES '
. '("' . $this->db->insert_id() . '", "' . $admin['username'] . '", "' . $admin['password'] . '");');
// // Insert admin
// $this->load->model('admins_model');
// $admin = json_decode($_POST['admin'], true);
// $admin['settings']['username'] = $admin['username'];
// $admin['settings']['password'] = $admin['password'];
// unset($admin['username'], $admin['password']);
// $this->admins_model->add($admin);
// Save company settings
$company = json_decode($_POST['company'], true);
$this->db->query('INSERT INTO `ea_settings` (`name`, `value`) VALUES '
. '("company_name", "' . $company['company_name'] . '"),'
. '("company_email", "' . $company['company_email'] . '"),'
. '("company_link", "' . $company['company_link'] . '");');
// $this->load->model('settings_model');
// $company = json_decode($_POST['company'], true);
// $this->settings_model->set_setting('company_name', $company['company_name']);
// $this->settings_model->set_setting('company_email', $company['company_email']);
// $this->settings_model->set_setting('company_link', $company['company_link']);
echo json_encode(AJAX_SUCCESS);
} catch (Exception $exc) {
echo json_encode(array(
'exceptions' => array(exceptionToJavaScript($exc))
));
}
}
} }
/* End of file appointments.php */ /* End of file appointments.php */

View file

@ -148,7 +148,7 @@
'<p>' + '<p>' +
'Your appointment has successfully been added to ' + 'Your appointment has successfully been added to ' +
'your Google Calendar account. <br>' + 'your Google Calendar account. <br>' +
'<a href="' + response.htmlLink + '">' + '<a href="' + response.htmlLink + '" target="_blank">' +
'Click here to view your appointment on Google ' + 'Click here to view your appointment on Google ' +
'Calendar.' + 'Calendar.' +
'</a>' + '</a>' +

View file

@ -62,21 +62,21 @@
</legend> </legend>
<label for="company-name">Company Name *</label> <label for="company-name">Company Name *</label>
<input type="text" id="company-name" data-field="company_name" class="required"> <input type="text" id="company-name" data-field="company_name" class="required span4">
<span class="help-block">Company name will be displayed everywhere on the system <span class="help-block">Company name will be displayed everywhere on the system
(required).</span> (required).</span>
<br> <br>
<label for="company-email">Company Email *</label> <label for="company-email">Company Email *</label>
<input type="text" id="company-email" data-field="company_email" class="required"> <input type="text" id="company-email" data-field="company_email" class="required span4">
<span class="help-block">This will be the company email address. It will be used <span class="help-block">This will be the company email address. It will be used
as the sender and the reply address of the system emails (required).</span> as the sender and the reply address of the system emails (required).</span>
<br> <br>
<label for="company-link">Company Link *</label> <label for="company-link">Company Link *</label>
<input type="text" id="company-link" data-field="company_link" class="required"> <input type="text" id="company-link" data-field="company_link" class="required span4">
<span class="help-block">Company link should point to the official website of <span class="help-block">Company link should point to the official website of
the company (optional).</span> the company (optional).</span>

View file

@ -19,7 +19,7 @@
<link <link
rel="icon" rel="icon"
type="image/x-icon" type="image/x-icon"
href="<?php echo $base_url(); ?>assets/images/favicon.ico"> href="<?php echo $base_url; ?>assets/images/favicon.ico">
<?php // INCLUDE SCRIPTS ?> <?php // INCLUDE SCRIPTS ?>
<script <script
@ -41,21 +41,38 @@
'baseUrl': <?php echo '"' . $base_url . '"'; ?> 'baseUrl': <?php echo '"' . $base_url . '"'; ?>
}; };
var MIN_PASSWORD_LENGTH = 7;
var AJAX_SUCCESS = 'SUCCESS';
var AJAX_FAILURE = 'FAILURE';
/** /**
* Event: Install System "Click" * Event: Install Easy!Appointments Button "Click"
*/ */
$('#install').click(function() { $('#install').click(function() {
if (!validate()) return; if (!validate()) return;
var postUrl = GlobalVariables.baseUrl + 'ajax_install'; var postUrl = GlobalVariables.baseUrl + 'appointments/ajax_install';
var postData = { var postData = {
'admin': getAdminData(), 'admin': JSON.stringify(getAdminData()),
'company': getCompanyDate() 'company': JSON.stringify(getCompanyData())
}; };
$.post(postUrl, postData, function(response) { $.post(postUrl, postData, function(response) {
//////////////////////////////////////////////////////
}); console.log('Ajax Install E!A Response:', response);
//////////////////////////////////////////////////////
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
if (response == AJAX_SUCCESS) {
$('.alert').text('Easy!Appointments has been success fully installed!');
$('.alert').addClass('alert-success');
$('.alert').show();
setTimeout(function() {
window.location.href = GlobalVariables.baseUrl + 'backend';
}, 1000);
}
}, 'json');
}); });
/** /**
@ -65,12 +82,12 @@
*/ */
function validate() { function validate() {
try { try {
$('.alert').fadeOut(); $('.alert').hide();
$('input[type="text"]').css('border', ''); $('input').css('border', '');
// Check for empty fields. // Check for empty fields.
var missingRequired = false; var missingRequired = false;
$('input[type="text"]').each(function() { $('input').each(function() {
if ($(this).val() == '') { if ($(this).val() == '') {
$(this).css('border', '2px solid red'); $(this).css('border', '2px solid red');
missingRequired = true; missingRequired = true;
@ -87,16 +104,27 @@
throw 'Passwords do not match!'; throw 'Passwords do not match!';
} }
if ($('#password').val().length < MIN_PASSWORD_LENGTH) {
$('#password').css('border', '2px solid red');
$('#retype-password').css('border', '2px solid red');
throw 'The password must be at least ' + MIN_PASSWORD_LENGTH + ' characters long.';
}
// Validate Email // Validate Email
if (!GeneralFunctions.validateEmail($('#email').val())) { if (!GeneralFunctions.validateEmail($('#email').val())) {
$('#email').css('border', '2px solid red'); $('#email').css('border', '2px solid red');
throw 'The email addres is invalid!'; throw 'The email address is invalid!';
}
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
$('#company-email').css('border', '2px solid red');
throw 'The email address is invalid!';
} }
return true; return true;
} catch(exc) { } catch(exc) {
$('.alert').txt(exc); $('.alert').text(exc);
$('.alert').fadeIn(); $('.alert').show();
return false; return false;
} }
} }
@ -125,10 +153,39 @@
* @returns {object} * @returns {object}
*/ */
function getCompanyData() { function getCompanyData() {
var company = {
'company_name': $('#company-name').val(),
'company_email': $('#company-email').val(),
'company_link': $('#company-link').val()
};
return company;
} }
}); });
</script> </script>
<style>
header {
background: #DAFFEB;
margin-bottom: 25px;
}
.content {
margin: 32px;
max-width: 980px;
}
.alert {
margin: 25px 0 10px 0;
}
footer {
padding: 10px 35px;
background-color: #FAFAFA;
margin-top: 20px;
border-top: 1px solid #EEE;
}
</style>
</head> </head>
<body> <body>
<header> <header>
@ -136,76 +193,81 @@
<img src="<?php echo $base_url; ?>assets/images/installation-banner.png" alt="Easy!Appointents Installation Banner"> <img src="<?php echo $base_url; ?>assets/images/installation-banner.png" alt="Easy!Appointents Installation Banner">
</a> </a>
</header> </header>
<div class="content"> <div class="content">
<div class="welcome"> <div class="welcome">
<h2>Welcome To The Easy!Appointments Installation Page</h2> <h2>Welcome to the Easy!Appointments installation page.</h2>
<p> <p>
This page will help you set the main settings of your Easy!Appointments installation. This page will help you set the main settings of your Easy!Appointments installation.
You will be able to edit these settings and many more in the backend session of your You will be able to edit these settings and many more in the backend session of your
system. Remember to use the <span class="label label-info"><?php echo $base_url; ?> system. Remember to use the <span class="text-error"><?php echo $base_url; ?>backend</span>
backend</span> url to connect to the backend section of Easy!Appointments. url to connect to the backend section of Easy!Appointments.
If you face any problems during the usage of Easy!Appointments you can always check If you face any problems during the usage of Easy!Appointments you can always check
the official <a href="https://code.google.com/p/easy-appointments/w/list">Wiki Pages</a> the official <a href="https://code.google.com/p/easy-appointments/w/list">Wiki Pages</a>
and the <a href="http://groups.google.com/group/easy-appointments">Support Group</a> and <a href="http://groups.google.com/group/easy-appointments">Support Group</a>
for getting help. You may also submit new issues on the for getting help. You may also submit new issues on
<a href="https://code.google.com/p/easy-appointments/issues/list">Google Code Issues</a> <a href="https://code.google.com/p/easy-appointments/issues/list">Google Code</a>
page, in order to help our development process. in order to help our development process.
</p> </p>
</div> </div>
<hr> <div class="alert" style="display:none"></div>
<div class="alert" style="display: none"></div> <div class="row-fluid">
<div class="admin-settings span5">
<div class="admin-settings"> <h3>Administrator</h3>
<h2>Administrator Settings</h2> <label for="first-name">First Name</label>
<label for="first-name">First Name</label> <input type="text" id="first-name" class="span10" />
<input type="text" id="first-name" />
<label for="last-name">Last Name</label>
<label for="last-name">Last Name</label> <input type="text" id="last-name" class="span10" />
<input type="text" id="last-name" />
<label for="email">Email</label>
<label for="email">Email</label> <input type="text" id="email" class="span10" />
<input type="text" id="email" />
<label for="phone-number">Phone Number</label>
<label for="phone-number">Phone Number</label> <input type="text" id="phone-number" class="span10" />
<input type="text" id="phone-number" />
<label for="username">Username</label>
<label for="username">Username</label> <input type="text" id="username" class="span10" />
<input type="text" id="username" />
<label for="password">Password</label>
<label for="password">Password</label> <input type="password" id="password" class="span10" />
<input type="password" id="password" />
<label for="retype-password">Retype Password</label>
<label for="retype-password">Retype Password</label> <input type="password" id="retype-password" class="span10" />
<input type="password" id="retype-password" /> </div>
</div>
<div class="company-settings span5">
<hr> <h3>Company</h3>
<label for="company-name">Company Name</label>
<div class="company-settings"> <input type="text" id="company-name" class="span10" />
<h2>Company Settings</h2>
<label for="company-name">Company Name</label> <label for="company-email">Company Email</label>
<input type="text" id="company-name"> <input type="text" id="company-email" class="span10" />
<label for="company-email">Company Email</label> <label for="company-link">Company Link</label>
<input type="text" id="company-email"> <input type="text" id="company-link" class="span10" />
<label for="company-link">Company Link</label>
<input type="text" id="company-link">
<div class="alert alert-info">
You will be able to set your business logic in the backend settings page after
the installation is complete.
</div> </div>
</div> </div>
<center> <br>
<button type="button" id="install" class="btn btn-success btn-large">
<i class="icon-white icon-ok"></i> <p>
Install</button> You will be able to set your business logic in the backend settings page
</center> after the installation is complete.
<br>
Press the following button to complete the installation process.
</p>
<br>
<button type="button" id="install" class="btn btn-success btn-large">
<i class="icon-white icon-ok"></i>
Install Easy!Appointments</button>
</div> </div>
<footer> <footer>

View file

@ -29,7 +29,7 @@ body {
#book-appointment-wizard #company-name { #book-appointment-wizard #company-name {
font-weight: bold; font-weight: bold;
color: #FFF; color: #FFF;
font-size: 27px; font-size: 22px;
margin: 27px 10px 0 14px; margin: 27px 10px 0 14px;
display: inline-block; display: inline-block;
text-shadow: 0px 1px 1px #8F8888; text-shadow: 0px 1px 1px #8F8888;

View file

@ -225,3 +225,13 @@ ALTER TABLE `ea_user_settings`
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
INSERT INTO `ea_roles` (`id`, `name`, `slug`, `is_admin`, `appointments`, `customers`, `services`, `users`, `system_settings`, `user_settings`) VALUES
(1, 'Administrator', 'admin', 1, 15, 15, 15, 15, 15, 15),
(2, 'Provider', 'provider', 0, 15, 15, 0, 0, 0, 15),
(3, 'Customer', 'customer', 0, 0, 0, 0, 0, 0, 0),
(4, 'Secretary', 'secretary', 0, 15, 15, 0, 0, 15, 15);
INSERT INTO `ea_settings` (`name`, `value`) VALUES
('company_working_plan', '{"monday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"tuesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"wednesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"thursday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"friday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"saturday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"sunday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]}}'),
('book_advance_timeout', '30');

View file

@ -5,7 +5,7 @@ class SystemConfiguration {
// Database Settings // Database Settings
public static $db_host = 'localhost'; public static $db_host = 'localhost';
public static $db_name = 'easy_appointments'; public static $db_name = 'new_ea'; //'easy_appointments';
public static $db_username = 'root'; public static $db_username = 'root';
public static $db_password = ''; public static $db_password = '';