mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 17:33:19 +03:00
82 lines
3 KiB
PHP
82 lines
3 KiB
PHP
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||
|
|
||
|
/* ----------------------------------------------------------------------------
|
||
|
* Easy!Appointments - Open Source Web Scheduler
|
||
|
*
|
||
|
* @package EasyAppointments
|
||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||
|
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||
|
* @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 {
|
||
|
|
||
|
/**
|
||
|
* Display the installation page.
|
||
|
*/
|
||
|
public function index() {
|
||
|
$view['base_url'] = $this->config->item('base_url');
|
||
|
$this->load->view('general/installation', $view);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* [AJAX] Installs Easy!Appointments on the server.
|
||
|
*
|
||
|
* @param array $_POST['admin'] Contains the initial admin user data. The App needs at
|
||
|
* least one admin user to work.
|
||
|
* @param array $_POST['company'] Contains the basic company data.
|
||
|
*/
|
||
|
public function ajax_install() {
|
||
|
try {
|
||
|
// Create E!A database structure.
|
||
|
$file_contents = file_get_contents(BASEPATH . 'assets/sql/structure.sql');
|
||
|
$sql_queries = explode(';', $file_contents);
|
||
|
array_pop($sql_queries);
|
||
|
foreach($sql_queries as $query) {
|
||
|
$this->db->query($query);
|
||
|
}
|
||
|
|
||
|
// 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']);
|
||
|
$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');
|
||
|
$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 installation.php */
|
||
|
/* Location: ./application/controllers/installation.php */
|