iflrandevu/application/controllers/Installation.php

144 lines
4.3 KiB
PHP
Raw Normal View History

<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
2020-11-14 22:36:25 +03:00
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.1.0
* ---------------------------------------------------------------------------- */
/**
2021-11-06 18:21:27 +03:00
* Installation controller.
*
* Handles the installation related operations.
*
* @package Controllers
*/
class Installation extends EA_Controller {
/**
2020-12-02 21:04:06 +03:00
* Installation constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('admins_model');
$this->load->model('settings_model');
$this->load->model('services_model');
$this->load->model('providers_model');
$this->load->model('customers_model');
$this->load->library('instance');
}
/**
* Display the installation page.
*/
public function index()
{
2020-09-07 11:15:58 +03:00
if (is_app_installed())
{
redirect('');
return;
}
$this->load->view('pages/instance/instance_installation_page', [
'base_url' => config('base_url')
]);
}
/**
* Installs Easy!Appointments on the server.
*/
public function ajax_install()
{
try
{
2020-09-07 11:15:58 +03:00
if (is_app_installed())
{
return;
}
$admin = request('admin');
$company = request('company');
$this->instance->migrate();
2015-11-05 23:19:52 +03:00
// Insert admin
$admin['timezone'] = 'UTC';
$admin['settings']['username'] = $admin['username'];
$admin['settings']['password'] = $admin['password'];
2020-12-09 15:17:45 +03:00
$admin['settings']['notifications'] = TRUE;
$admin['settings']['calendar_view'] = CALENDAR_VIEW_DEFAULT;
unset($admin['username'], $admin['password']);
$admin['id'] = $this->admins_model->save($admin);
session([
'user_id' => $admin['id'],
'user_email' => $admin['email'],
'role_slug' => DB_SLUG_ADMIN,
'timezone' => $admin['timezone'],
'username' => $admin['settings']['username']
]);
// Save company settings
setting([
'company_name' => $company['company_name'],
'company_email' => $company['company_email'],
'company_link' => $company['company_link'],
]);
// Service
$service_id = $this->services_model->save([
'name' => 'Service',
'duration' => '30',
'price' => '0',
'currency' => '',
'availabilities_type' => 'flexible',
'attendants_number' => '1'
]);
// Provider
$this->providers_model->save([
'first_name' => 'Jane',
'last_name' => 'Doe',
'email' => 'jane@example.org',
'phone_number' => '+1 (000) 000-0000',
'services' => [
$service_id
],
'settings' => [
'username' => 'janedoe',
'password' => 'janedoe',
'working_plan' => setting('company_working_plan'),
'notifications' => TRUE,
'google_sync' => FALSE,
'sync_past_days' => 30,
'sync_future_days' => 90,
'calendar_view' => CALENDAR_VIEW_DEFAULT
],
]);
// Customer
$this->customers_model->save([
'first_name' => 'James',
'last_name' => 'Doe',
'email' => 'james@example.org',
'phone_number' => '+1 (000) 000-0000',
]);
json_response([
'success' => true
]);
2017-09-23 02:30:22 +03:00
}
catch (Throwable $e)
{
json_exception($e);
}
}
}