2021-11-18 08:23:21 +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-18 08:23:21 +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-18 08:23:21 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secretaries controller.
|
|
|
|
*
|
|
|
|
* Handles the secretaries related operations.
|
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
|
|
|
class Secretaries extends EA_Controller {
|
|
|
|
/**
|
|
|
|
* Secretaries constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->model('secretaries_model');
|
|
|
|
$this->load->model('providers_model');
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
$this->load->library('timezones');
|
2022-06-19 20:05:45 +03:00
|
|
|
$this->load->library('webhooks_client');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the backend secretaries page.
|
|
|
|
*
|
2022-01-07 11:44:51 +03:00
|
|
|
* On this page secretary users will be able to manage secretaries, which are eventually selected by customers during the
|
2021-11-18 08:23:21 +03:00
|
|
|
* booking process.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
session(['dest_url' => site_url('secretaries')]);
|
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
$user_id = session('user_id');
|
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_USERS))
|
2021-11-18 08:23:21 +03:00
|
|
|
{
|
2022-01-17 20:24:02 +03:00
|
|
|
if ($user_id)
|
|
|
|
{
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
}
|
2021-11-18 08:23:21 +03:00
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
redirect('login');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 08:23:21 +03:00
|
|
|
|
|
|
|
$role_slug = session('role_slug');
|
|
|
|
|
2022-01-07 11:44:51 +03:00
|
|
|
$providers = $this->providers_model->get();
|
|
|
|
|
|
|
|
foreach ($providers as &$provider)
|
|
|
|
{
|
|
|
|
$this->providers_model->only($provider, [
|
|
|
|
'id',
|
|
|
|
'first_name',
|
|
|
|
'last_name'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
script_vars([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'role_slug' => $role_slug,
|
2022-01-10 11:36:11 +03:00
|
|
|
'timezones' => $this->timezones->to_array(),
|
2022-01-07 11:44:51 +03:00
|
|
|
'min_password_length' => MIN_PASSWORD_LENGTH,
|
|
|
|
'providers' => $providers,
|
|
|
|
]);
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
html_vars([
|
2021-11-18 08:23:21 +03:00
|
|
|
'page_title' => lang('secretaries'),
|
|
|
|
'active_menu' => PRIV_USERS,
|
|
|
|
'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-18 08:23:21 +03:00
|
|
|
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
|
|
|
|
'providers' => $this->providers_model->get(),
|
2022-01-07 11:44:51 +03:00
|
|
|
]);
|
|
|
|
|
2022-01-19 12:21:05 +03:00
|
|
|
$this->load->view('pages/secretaries');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter secretaries by the provided keyword.
|
|
|
|
*/
|
|
|
|
public function search()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_USERS))
|
2021-11-18 08:23:21 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$keyword = request('keyword', '');
|
|
|
|
|
|
|
|
$order_by = 'first_name ASC, last_name ASC, email ASC';
|
|
|
|
|
|
|
|
$limit = request('limit', 1000);
|
2022-01-07 11:44:51 +03:00
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
$secretaries = $this->secretaries_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
|
|
json_response($secretaries);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a secretary.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('add', PRIV_USERS))
|
2021-11-18 08:23:21 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
2022-03-25 14:50:40 +03:00
|
|
|
$secretary = request('secretary');
|
|
|
|
|
2023-01-14 11:38:49 +03:00
|
|
|
$this->secretaries_model->only($secretary, [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'alt_number',
|
|
|
|
'phone_number',
|
|
|
|
'address',
|
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'zip_code',
|
|
|
|
'notes',
|
|
|
|
'timezone',
|
|
|
|
'language',
|
|
|
|
'is_private',
|
|
|
|
'id_roles',
|
|
|
|
'settings',
|
2023-04-15 15:33:40 +03:00
|
|
|
'providers',
|
2023-01-14 11:38:49 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->secretaries_model->only($secretary['settings'], [
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'notifications',
|
|
|
|
'calendar_view'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->secretaries_model->optional($secretary, [
|
|
|
|
'providers' => [],
|
|
|
|
]);
|
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
$secretary_id = $this->secretaries_model->save($secretary);
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$secretary = $this->secretaries_model->find($secretary_id);
|
|
|
|
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_SAVE, $secretary);
|
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $secretary_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a secretary.
|
|
|
|
*/
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('edit', PRIV_USERS))
|
2021-11-18 08:23:21 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
2022-03-25 14:50:40 +03:00
|
|
|
$secretary = request('secretary');
|
2023-01-14 11:38:49 +03:00
|
|
|
|
|
|
|
$this->secretaries_model->only($secretary, [
|
|
|
|
'id',
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'alt_number',
|
|
|
|
'phone_number',
|
|
|
|
'address',
|
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'zip_code',
|
|
|
|
'notes',
|
|
|
|
'timezone',
|
|
|
|
'language',
|
|
|
|
'is_private',
|
|
|
|
'id_roles',
|
|
|
|
'settings',
|
2023-04-15 15:33:40 +03:00
|
|
|
'providers',
|
2023-01-14 11:38:49 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->secretaries_model->only($secretary['settings'], [
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'notifications',
|
|
|
|
'calendar_view'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->secretaries_model->optional($secretary, [
|
|
|
|
'providers' => [],
|
|
|
|
]);
|
|
|
|
|
2022-03-25 14:50:40 +03:00
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
$secretary_id = $this->secretaries_model->save($secretary);
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$secretary = $this->secretaries_model->find($secretary_id);
|
|
|
|
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_SAVE, $secretary);
|
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $secretary_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a secretary.
|
|
|
|
*/
|
|
|
|
public function destroy()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('delete', PRIV_USERS))
|
2021-11-18 08:23:21 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$secretary_id = request('secretary_id');
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$secretary = $this->secretaries_model->find($secretary_id);
|
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
$this->secretaries_model->delete($secretary_id);
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_DELETE, $secretary);
|
|
|
|
|
2021-11-18 08:23:21 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 09:18:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a secretary.
|
|
|
|
*/
|
|
|
|
public function find()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_USERS))
|
2021-12-14 09:18:46 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-12-14 09:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$secretary_id = request('secretary_id');
|
|
|
|
|
|
|
|
$secretary = $this->secretaries_model->find($secretary_id);
|
|
|
|
|
|
|
|
json_response($secretary);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 08:23:21 +03:00
|
|
|
}
|