2017-09-15 14:44:40 +03:00
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
2015-10-18 20:18:02 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2017-01-31 09:35:34 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2017, Alex Tselegidis
|
2015-10-18 20:18:02 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.1.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installation Controller
|
|
|
|
*
|
|
|
|
* This controller will handle the installation procedure of Easy!Appointments
|
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
|
|
|
class Installation extends CI_Controller {
|
2015-10-18 21:00:01 +03:00
|
|
|
/**
|
|
|
|
* Class Constructor
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
2015-10-18 21:00:01 +03:00
|
|
|
parent::__construct();
|
|
|
|
$this->load->helper('installation');
|
2015-11-05 22:13:44 +03:00
|
|
|
$this->load->library('session');
|
|
|
|
|
|
|
|
// Set user's selected language.
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($this->session->userdata('language'))
|
|
|
|
{
|
2015-11-05 22:13:44 +03:00
|
|
|
$this->config->set_item('language', $this->session->userdata('language'));
|
|
|
|
$this->lang->load('translations', $this->session->userdata('language'));
|
2017-09-15 14:36:37 +03:00
|
|
|
} else
|
|
|
|
{
|
2015-11-05 22:13:44 +03:00
|
|
|
$this->lang->load('translations', $this->config->item('language')); // default
|
|
|
|
}
|
2015-10-18 21:00:01 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 20:18:02 +03:00
|
|
|
/**
|
|
|
|
* Display the installation page.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
if (is_ea_installed())
|
|
|
|
{
|
2015-10-18 21:00:01 +03:00
|
|
|
redirect('appointments/index');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$this->load->view('general/installation', [
|
2015-10-18 21:00:01 +03:00
|
|
|
'base_url' => $this->config->item('base_url')
|
2017-09-15 14:36:37 +03:00
|
|
|
]);
|
2015-10-18 20:18:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [AJAX] Installs Easy!Appointments on the server.
|
|
|
|
*
|
2017-09-06 16:22:11 +03:00
|
|
|
* Required POST Parameters
|
|
|
|
*
|
|
|
|
* - array $_POST['admin'] Contains the initial admin user data. The App needs at least one admin user to work.
|
|
|
|
* - array $_POST['company'] Contains the basic company data.
|
2015-10-18 20:18:02 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_install()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (is_ea_installed())
|
|
|
|
{
|
2015-10-18 21:00:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 20:18:02 +03:00
|
|
|
// Create E!A database structure.
|
2015-11-05 22:30:54 +03:00
|
|
|
$file_contents = file_get_contents(dirname(BASEPATH) . '/assets/sql/structure.sql');
|
2015-10-18 20:18:02 +03:00
|
|
|
$sql_queries = explode(';', $file_contents);
|
|
|
|
array_pop($sql_queries);
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($sql_queries as $query)
|
|
|
|
{
|
2015-10-18 20:18:02 +03:00
|
|
|
$this->db->query($query);
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:19:52 +03:00
|
|
|
// Insert default E!A entries into the database.
|
|
|
|
$file_contents = file_get_contents(dirname(BASEPATH) . '/assets/sql/data.sql');
|
|
|
|
$sql_queries = explode(';', $file_contents);
|
|
|
|
array_pop($sql_queries);
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($sql_queries as $query)
|
|
|
|
{
|
2015-11-05 23:19:52 +03:00
|
|
|
$this->db->query($query);
|
|
|
|
}
|
|
|
|
|
2015-10-18 20:18:02 +03:00
|
|
|
// Insert admin
|
|
|
|
$this->load->model('admins_model');
|
2017-09-19 16:44:32 +03:00
|
|
|
$admin = json_decode($this->input->post('admin'), TRUE);
|
2015-10-18 20:18:02 +03:00
|
|
|
$admin['settings']['username'] = $admin['username'];
|
|
|
|
$admin['settings']['password'] = $admin['password'];
|
2016-07-24 11:48:57 +03:00
|
|
|
$admin['settings']['calendar_view'] = CALENDAR_VIEW_DEFAULT;
|
2015-10-18 20:18:02 +03:00
|
|
|
unset($admin['username'], $admin['password']);
|
|
|
|
$admin['id'] = $this->admins_model->add($admin);
|
|
|
|
|
|
|
|
$this->load->library('session');
|
|
|
|
$this->session->set_userdata('user_id', $admin['id']);
|
|
|
|
$this->session->set_userdata('user_email', $admin['email']);
|
|
|
|
$this->session->set_userdata('role_slug', DB_SLUG_ADMIN);
|
|
|
|
$this->session->set_userdata('username', $admin['settings']['username']);
|
|
|
|
|
|
|
|
// Save company settings
|
|
|
|
$this->load->model('settings_model');
|
2017-09-19 16:44:32 +03:00
|
|
|
$company = json_decode($this->input->post('company'), TRUE);
|
2015-10-18 20:18:02 +03:00
|
|
|
$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']);
|
|
|
|
|
2016-01-01 17:45:01 +02:00
|
|
|
// Create sample records.
|
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('providers_model');
|
|
|
|
|
|
|
|
$sample_service = get_sample_service();
|
|
|
|
$sample_service['id'] = $this->services_model->add($sample_service);
|
|
|
|
$sample_provider = get_sample_provider();
|
|
|
|
$sample_provider['services'][] = $sample_service['id'];
|
|
|
|
$this->providers_model->add($sample_provider);
|
|
|
|
|
2015-10-18 20:18:02 +03:00
|
|
|
echo json_encode(AJAX_SUCCESS);
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
} catch (Exception $exc)
|
|
|
|
{
|
|
|
|
echo json_encode([
|
|
|
|
'exceptions' => [exceptionToJavaScript($exc)]
|
|
|
|
]);
|
2015-10-18 20:18:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|