2021-11-22 09:36:05 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-11-22 09:36:05 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-12-18 20:25:03 +03:00
|
|
|
* Account controller.
|
2021-11-22 09:36:05 +03:00
|
|
|
*
|
2021-12-18 20:25:03 +03:00
|
|
|
* Handles current account related operations.
|
2021-11-22 09:36:05 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2021-12-18 20:25:03 +03:00
|
|
|
class Account extends EA_Controller {
|
2021-11-22 09:36:05 +03:00
|
|
|
/**
|
2021-12-18 20:25:03 +03:00
|
|
|
* Account constructor.
|
2021-11-22 09:36:05 +03:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->model('appointments_model');
|
|
|
|
$this->load->model('customers_model');
|
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('providers_model');
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
$this->load->model('settings_model');
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
$this->load->library('google_sync');
|
|
|
|
$this->load->library('notifications');
|
|
|
|
$this->load->library('synchronization');
|
|
|
|
$this->load->library('timezones');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the settings page.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2021-12-18 20:25:03 +03:00
|
|
|
session(['dest_url' => site_url('account')]);
|
2021-11-22 09:36:05 +03:00
|
|
|
|
2021-12-07 13:09:34 +03:00
|
|
|
if (cannot('view', PRIV_USER_SETTINGS))
|
2021-11-22 09:36:05 +03:00
|
|
|
{
|
2021-12-18 20:25:03 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-22 09:36:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$user_id = session('user_id');
|
|
|
|
|
2021-12-18 20:25:03 +03:00
|
|
|
$account = $this->users_model->find($user_id);
|
|
|
|
|
|
|
|
script_vars([
|
|
|
|
'account' => $account,
|
|
|
|
]);
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
html_vars([
|
2021-11-22 09:36:05 +03:00
|
|
|
'page_title' => lang('settings'),
|
|
|
|
'active_menu' => PRIV_SYSTEM_SETTINGS,
|
|
|
|
'user_display_name' => $this->accounts->get_user_display_name($user_id),
|
|
|
|
'timezones' => $this->timezones->to_array(),
|
|
|
|
]);
|
2021-12-18 19:22:40 +03:00
|
|
|
|
2021-12-18 20:25:03 +03:00
|
|
|
$this->load->view('pages/account', html_vars());
|
2021-11-22 09:36:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save general settings.
|
|
|
|
*/
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-07 13:09:34 +03:00
|
|
|
if (cannot('edit', PRIV_USER_SETTINGS))
|
2021-11-22 09:36:05 +03:00
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
|
|
|
}
|
|
|
|
|
2021-12-18 20:25:03 +03:00
|
|
|
$account = request('account');
|
2021-11-22 09:36:05 +03:00
|
|
|
|
2021-12-18 20:25:03 +03:00
|
|
|
$this->users_model->save($account);
|
2021-11-22 09:36:05 +03:00
|
|
|
|
|
|
|
session([
|
2021-12-18 20:25:03 +03:00
|
|
|
'user_email' => $account['email'],
|
|
|
|
'username' => $account['settings']['username'],
|
|
|
|
'timezone' => $account['timezone'],
|
2021-11-22 09:36:05 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
response();
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-12-18 20:55:58 +03:00
|
|
|
|
|
|
|
/**
|
2022-01-17 19:42:47 +03:00
|
|
|
* Make sure the username is valid and unique in the database.
|
2021-12-18 20:55:58 +03:00
|
|
|
*/
|
|
|
|
public function validate_username()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$username = request('username');
|
|
|
|
|
|
|
|
$user_id = request('user_id');
|
|
|
|
|
|
|
|
$is_valid = $this->users_model->validate_username($username, $user_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'is_valid' => $is_valid,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2022-01-17 19:42:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change system language for current user.
|
|
|
|
*
|
|
|
|
* The language setting is stored in session data and retrieved every time the user visits any of the system pages.
|
|
|
|
*/
|
|
|
|
public function change_language()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Check if language exists in the available languages.
|
|
|
|
|
|
|
|
$found = FALSE;
|
|
|
|
|
|
|
|
foreach (config('available_languages') as $lang)
|
|
|
|
{
|
|
|
|
if ($lang == request('language'))
|
|
|
|
{
|
|
|
|
$found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $found)
|
|
|
|
{
|
|
|
|
throw new Exception('Translations for the given language does not exist (' . request('language') . ').');
|
|
|
|
}
|
|
|
|
|
|
|
|
$language = request('language');
|
|
|
|
|
|
|
|
session(['language' => $language]);
|
|
|
|
|
|
|
|
config(['language' => $language]);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 09:36:05 +03:00
|
|
|
}
|