2021-11-22 09:36:05 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-11-22 09:36:05 +03:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
$user_id = session('user_id');
|
2022-03-25 13:59:00 +03:00
|
|
|
|
2021-12-07 13:09:34 +03:00
|
|
|
if (cannot('view', PRIV_USER_SETTINGS))
|
2021-11-22 09:36:05 +03:00
|
|
|
{
|
2022-01-17 20:24:02 +03:00
|
|
|
if ($user_id)
|
|
|
|
{
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
}
|
2021-11-22 09:36:05 +03:00
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
redirect('login');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-11-22 09:36:05 +03:00
|
|
|
|
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'),
|
2022-05-22 15:39:19 +03:00
|
|
|
'theme' => setting('theme', 'default'),
|
2021-11-22 09:36:05 +03:00
|
|
|
'active_menu' => PRIV_SYSTEM_SETTINGS,
|
|
|
|
'user_display_name' => $this->accounts->get_user_display_name($user_id),
|
2022-03-29 11:16:07 +03:00
|
|
|
'grouped_timezones' => $this->timezones->to_grouped_array(),
|
2021-11-22 09:36:05 +03:00
|
|
|
]);
|
2021-12-18 19:22:40 +03:00
|
|
|
|
2022-01-19 12:21:05 +03:00
|
|
|
$this->load->view('pages/account');
|
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
|
|
|
|
2022-03-25 13:59:00 +03:00
|
|
|
$account['id'] = session('user_id');
|
|
|
|
|
|
|
|
$this->users_model->only($account, [
|
|
|
|
'id',
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'mobile_number',
|
|
|
|
'phone_number',
|
|
|
|
'address',
|
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'zip_code',
|
|
|
|
'notes',
|
|
|
|
'timezone',
|
|
|
|
'language',
|
|
|
|
'settings'
|
|
|
|
]);
|
2022-05-22 14:50:25 +03:00
|
|
|
|
2022-03-25 13:59:00 +03:00
|
|
|
$this->users_model->only($account['settings'], [
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'notifications',
|
|
|
|
'calendar_view'
|
|
|
|
]);
|
|
|
|
|
2022-05-22 14:50:25 +03:00
|
|
|
if (empty($account['password']))
|
|
|
|
{
|
|
|
|
unset($account['password']);
|
|
|
|
}
|
|
|
|
|
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'],
|
2022-05-22 14:50:25 +03:00
|
|
|
'language' => $account['language'],
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 09:36:05 +03:00
|
|
|
}
|