2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @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
|
2015-07-20 22:41:24 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Backend API controller
|
2015-07-08 01:33:33 +03:00
|
|
|
*
|
2021-10-28 15:01:17 +03:00
|
|
|
* Handles the backend API related operations.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2015-07-08 01:33:33 +03:00
|
|
|
* @package Controllers
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2020-11-16 11:29:36 +03:00
|
|
|
class Backend_api extends EA_Controller {
|
2016-04-27 09:21:40 +03:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-10-28 15:01:17 +03:00
|
|
|
protected $permissions;
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2016-04-27 09:21:40 +03:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Backend_api constructor.
|
2016-04-27 09:21:40 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
parent::__construct();
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->model('admins_model');
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->load->model('appointments_model');
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->model('consents_model');
|
|
|
|
$this->load->model('customers_model');
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->load->model('providers_model');
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->model('roles_model');
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->load->model('secretaries_model');
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->load->model('service_categories_model');
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('settings_model');
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->load->model('users_model');
|
|
|
|
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->library('google_sync');
|
|
|
|
$this->load->library('ics_file');
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->load->library('notifications');
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->library('synchronization');
|
|
|
|
$this->load->library('timezones');
|
2017-08-01 09:39:03 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$role_slug = session('role_slug');
|
|
|
|
|
|
|
|
if ($role_slug)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->permissions = $this->roles_model->get_permissions_by_slug($role_slug);
|
2017-08-01 09:39:03 +03:00
|
|
|
}
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2016-07-17 19:51:46 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Get Calendar Events
|
2016-07-17 19:51:46 +03:00
|
|
|
*
|
|
|
|
* This method will return all the calendar events within a specified period.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_get_calendar_events()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$start_date = request('startDate') . ' 00:00:00';
|
|
|
|
|
|
|
|
$end_date = request('endDate') . ' 23:59:59';
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
$response = [
|
2021-10-28 15:01:17 +03:00
|
|
|
'appointments' => $this->appointments_model->get([
|
2017-09-15 14:36:37 +03:00
|
|
|
'is_unavailable' => FALSE,
|
2020-12-05 12:46:05 +03:00
|
|
|
'start_datetime >=' => $start_date,
|
|
|
|
'end_datetime <=' => $end_date
|
2016-07-17 19:51:46 +03:00
|
|
|
]),
|
2021-10-28 15:01:17 +03:00
|
|
|
'unavailability_events' => $this->appointments_model->get([
|
2017-09-15 14:36:37 +03:00
|
|
|
'is_unavailable' => TRUE,
|
2020-12-05 12:46:05 +03:00
|
|
|
'start_datetime >=' => $start_date,
|
|
|
|
'end_datetime <=' => $end_date
|
2016-07-17 19:51:46 +03:00
|
|
|
])
|
|
|
|
];
|
|
|
|
|
2020-12-14 21:41:21 +03:00
|
|
|
foreach ($response['appointments'] as &$appointment)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider']);
|
|
|
|
$appointment['service'] = $this->services_model->find($appointment['id_services']);
|
|
|
|
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer']);
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
unset($appointment);
|
|
|
|
|
|
|
|
$user_id = session('user_id');
|
|
|
|
|
|
|
|
$role_slug = session('role_slug');
|
2016-07-20 23:33:24 +03:00
|
|
|
|
2020-03-29 16:08:07 +03:00
|
|
|
// If the current user is a provider he must only see his own appointments.
|
2020-12-02 20:50:17 +03:00
|
|
|
if ($role_slug === DB_SLUG_PROVIDER)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
foreach ($response['appointments'] as $index => $appointment)
|
|
|
|
{
|
2020-12-05 12:46:05 +03:00
|
|
|
if ((int)$appointment['id_users_provider'] !== (int)$user_id)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2016-07-20 23:33:24 +03:00
|
|
|
unset($response['appointments'][$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:44:35 +03:00
|
|
|
foreach ($response['unavailability_events'] as $index => $unavailability_event)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-12-05 12:46:05 +03:00
|
|
|
if ((int)$unavailability_event['id_users_provider'] !== (int)$user_id)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-10-21 21:44:35 +03:00
|
|
|
unset($response['unavailability_events'][$index]);
|
2016-07-20 23:33:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the current user is a secretary he must only see the appointments of his providers.
|
2020-12-02 20:50:17 +03:00
|
|
|
if ($role_slug === DB_SLUG_SECRETARY)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$providers = $this->secretaries_model->find($user_id)['providers'];
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($response['appointments'] as $index => $appointment)
|
|
|
|
{
|
|
|
|
if ( ! in_array((int)$appointment['id_users_provider'], $providers))
|
|
|
|
{
|
2016-07-20 23:33:24 +03:00
|
|
|
unset($response['appointments'][$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:44:35 +03:00
|
|
|
foreach ($response['unavailability_events'] as $index => $unavailability_event)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-10-21 21:44:35 +03:00
|
|
|
if ( ! in_array((int)$unavailability_event['id_users_provider'], $providers))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-10-21 21:44:35 +03:00
|
|
|
unset($response['unavailability_events'][$index]);
|
2016-07-20 23:33:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response($response);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Get the registered appointments for the given date period and record.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2021-10-28 15:01:17 +03:00
|
|
|
* This method returns the database appointments and unavailable periods for the user selected date period and
|
|
|
|
* record type (provider or service).
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_get_calendar_appointments()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_APPOINTMENTS]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$filter_type = request('filter_type');
|
|
|
|
|
|
|
|
if ( ! $filter_type)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'appointments' => [],
|
|
|
|
'unavailables' => []
|
|
|
|
]);
|
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($filter_type == FILTER_TYPE_PROVIDER)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-07-09 08:43:59 +03:00
|
|
|
$where_id = 'id_users_provider';
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
|
|
|
else
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-07-09 08:43:59 +03:00
|
|
|
$where_id = 'id_services';
|
2015-11-05 22:38:13 +03:00
|
|
|
}
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// Get appointments
|
2021-10-28 15:01:17 +03:00
|
|
|
$record_id = $this->db->escape(request('record_id'));
|
|
|
|
$start_date = $this->db->escape(request('start_date'));
|
|
|
|
$end_date = $this->db->escape(date('Y-m-d', strtotime(request('end_date') . ' +1 day')));
|
2018-02-02 16:49:06 +03:00
|
|
|
|
|
|
|
$where_clause = $where_id . ' = ' . $record_id . '
|
|
|
|
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
|
|
|
|
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
|
|
|
|
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
|
|
|
|
AND is_unavailable = 0
|
|
|
|
';
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$response['appointments'] = $this->appointments_model->get($where_clause);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($response['appointments'] as &$appointment)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider']);
|
|
|
|
$appointment['service'] = $this->services_model->find($appointment['id_services']);
|
|
|
|
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer']);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// Get unavailable periods (only for provider).
|
2020-11-22 00:09:27 +03:00
|
|
|
$response['unavailables'] = [];
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($filter_type == FILTER_TYPE_PROVIDER)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2018-02-02 16:49:06 +03:00
|
|
|
$where_clause = $where_id . ' = ' . $record_id . '
|
|
|
|
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
|
|
|
|
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
|
|
|
|
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
|
|
|
|
AND is_unavailable = 1
|
|
|
|
';
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$response['unavailables'] = $this->appointments_model->get($where_clause);
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-12-14 21:41:21 +03:00
|
|
|
foreach ($response['unavailables'] as &$unavailable)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$unavailable['provider'] = $this->providers_model->find($unavailable['id_users_provider']);
|
2020-12-14 21:41:21 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response($response);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save appointment changes that are made from the backend calendar page.
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_appointment()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
// Save customer changes to the database.
|
2021-10-28 15:01:17 +03:00
|
|
|
$customer_data = request('customer_data');
|
|
|
|
|
|
|
|
if ($customer_data)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$customer = json_decode($customer_data, TRUE);
|
|
|
|
|
|
|
|
$required_permissions = ( ! isset($customer['id']))
|
|
|
|
? $this->permissions[PRIV_CUSTOMERS]['add']
|
|
|
|
: $this->permissions[PRIV_CUSTOMERS]['edit'];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($required_permissions == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$customer['id'] = $this->customers_model->save($customer);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
// Save appointment changes to the database.
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment_data = request('appointment_data');
|
|
|
|
|
|
|
|
$manage_mode = ! empty($appointment_data['id']);
|
|
|
|
|
|
|
|
if ($appointment_data)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment = json_decode($appointment_data, TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = ( ! isset($appointment['id']))
|
|
|
|
? $this->permissions[PRIV_APPOINTMENTS]['add']
|
|
|
|
: $this->permissions[PRIV_APPOINTMENTS]['edit'];
|
|
|
|
|
|
|
|
if ($required_permissions == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
// If the appointment does not contain the customer record id, then it means that is going to be
|
|
|
|
// inserted.
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! isset($appointment['id_users_customer']))
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment['id_users_customer'] = $customer['id'] ?? $customer_data['id'];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment['id'] = $this->appointments_model->save($appointment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($appointment['id']))
|
|
|
|
{
|
|
|
|
throw new RuntimeException('The appointment ID is not available.');
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment = $this->appointments_model->find($appointment['id']);
|
|
|
|
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
|
|
|
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
|
|
|
$service = $this->services_model->find($appointment['id_services']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-09-23 12:42:18 +03:00
|
|
|
$settings = [
|
2021-10-28 15:01:17 +03:00
|
|
|
'company_name' => setting('company_name'),
|
|
|
|
'company_link' => setting('company_link'),
|
|
|
|
'company_email' => setting('company_email'),
|
|
|
|
'date_format' => setting('date_format'),
|
|
|
|
'time_format' => setting('time_format')
|
2017-09-15 14:36:37 +03:00
|
|
|
];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-12-09 15:07:01 +03:00
|
|
|
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2020-12-05 12:46:05 +03:00
|
|
|
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete appointment from the database.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2017-09-06 16:22:11 +03:00
|
|
|
* This method deletes an existing appointment from the database. Once this action is finished it cannot be undone.
|
|
|
|
* Notification emails are send to both provider and customer and the delete action is executed to the Google
|
|
|
|
* Calendar account of the provider, if the "google_sync" setting is enabled.
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_appointment()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if (cannot('delete', 'appointments'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment_id = request('appointment_id');
|
|
|
|
|
|
|
|
if (empty($appointment_id))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-07-09 08:43:59 +03:00
|
|
|
throw new Exception('No appointment id provided.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
// Store appointment data for later use in this method.
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment = $this->appointments_model->find($appointment_id);
|
|
|
|
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
|
|
|
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
|
|
|
$service = $this->services_model->find($appointment['id_services']);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2020-09-23 12:42:18 +03:00
|
|
|
$settings = [
|
2021-10-28 15:01:17 +03:00
|
|
|
'company_name' => setting('company_name'),
|
|
|
|
'company_email' => setting('company_email'),
|
|
|
|
'company_link' => setting('company_link'),
|
|
|
|
'date_format' => setting('date_format'),
|
|
|
|
'time_format' => setting('time_format')
|
2017-09-15 14:36:37 +03:00
|
|
|
];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
// Delete appointment record from the database.
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->appointments_model->delete($appointment_id);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-04 10:26:12 +03:00
|
|
|
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);
|
2020-09-23 12:42:18 +03:00
|
|
|
|
2021-10-04 10:26:12 +03:00
|
|
|
$this->synchronization->sync_appointment_deleted($appointment, $provider);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Disable a providers sync setting.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2021-10-28 15:01:17 +03:00
|
|
|
* This method deletes the "google_sync" and "google_token" settings from the database.
|
|
|
|
*
|
|
|
|
* After that the provider's appointments will be no longer synced with Google Calendar.
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_disable_provider_sync()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
|
|
|
|
|
|
|
if ( ! $provider_id)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-07-09 08:43:59 +03:00
|
|
|
throw new Exception('Provider id not specified.');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$user_id = session('user_id');
|
|
|
|
|
|
|
|
if (
|
|
|
|
$this->permissions[PRIV_USERS]['edit'] === FALSE
|
|
|
|
&& (int)$user_id !== (int)$provider_id)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-11-07 13:25:59 +02:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->providers_model->set_setting($provider_id, 'google_sync', FALSE);
|
|
|
|
|
|
|
|
$this->providers_model->set_setting($provider_id, 'google_token', NULL);
|
|
|
|
|
|
|
|
$this->appointments_model->clear_google_sync_ids($provider_id);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter the customer records with the given key string.
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_customers()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_CUSTOMERS]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
|
|
|
|
2016-03-10 17:55:00 +02:00
|
|
|
$key = strtoupper($key);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-06 21:34:32 +03:00
|
|
|
$where =
|
2017-09-15 14:36:37 +03:00
|
|
|
'(first_name LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'last_name LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'email LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'phone_number LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'address LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'city LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'zip_code LIKE upper("%' . $key . '%") OR ' .
|
|
|
|
'notes LIKE upper("%' . $key . '%"))';
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-06 21:34:32 +03:00
|
|
|
$order_by = 'first_name ASC, last_name ASC';
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$limit = request('limit');
|
2020-04-06 21:34:32 +03:00
|
|
|
|
|
|
|
if ($limit === NULL)
|
|
|
|
{
|
|
|
|
$limit = 1000;
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$customers = $this->customers_model->get($where, $limit, NULL, $order_by);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($customers as &$customer)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointments = $this->appointments_model->get(['id_users_customer' => $customer['id']]);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($appointments as &$appointment)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->appointments_model->attach($appointment, [
|
|
|
|
'service',
|
|
|
|
'provider',
|
|
|
|
]);
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-15 17:27:19 +03:00
|
|
|
$customer['appointments'] = $appointments;
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response($customers);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Insert of update unavailable time period to database.
|
2013-07-09 17:46:48 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_unavailable()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
// Check privileges
|
2021-10-28 15:01:17 +03:00
|
|
|
$unavailable = json_decode(request('unavailable'), TRUE);
|
|
|
|
|
|
|
|
$required_permissions = ( ! isset($unavailable['id']))
|
|
|
|
? $this->permissions[PRIV_APPOINTMENTS]['add']
|
|
|
|
: $this->permissions[PRIV_APPOINTMENTS]['edit'];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider = $this->providers_model->find($unavailable['id_users_provider']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
// Add appointment
|
2015-11-05 22:38:13 +03:00
|
|
|
$unavailable['id'] = $this->appointments_model->add_unavailable($unavailable);
|
2021-10-28 15:01:17 +03:00
|
|
|
$unavailable = $this->appointments_model->find($unavailable['id']); // fetch all inserted data
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
// Google Sync
|
2017-09-15 14:36:37 +03:00
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting($unavailable['id_users_provider'], 'google_sync');
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$google_token = json_decode($this->providers_model->get_setting($unavailable['id_users_provider'], 'google_token'));
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($unavailable['id_google_calendar'] == NULL)
|
|
|
|
{
|
2013-12-26 15:32:25 +02:00
|
|
|
$google_event = $this->google_sync->add_unavailable($provider, $unavailable);
|
2013-07-10 16:57:24 +03:00
|
|
|
$unavailable['id_google_calendar'] = $google_event->id;
|
|
|
|
$this->appointments_model->add_unavailable($unavailable);
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
|
|
|
else
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->google_sync->update_unavailable($provider, $unavailable);
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$warnings[] = $e;
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'warnings' => $warnings ?? []
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete an unavailable time period from database.
|
2013-07-09 17:46:48 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_unavailable()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_APPOINTMENTS]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$unavailable_id = request('unavailable_id');
|
|
|
|
|
|
|
|
$unavailable = $this->appointments_model->find($unavailable_id);
|
|
|
|
|
|
|
|
$provider = $this->providers_model->find($unavailable['id_users_provider']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$this->appointments_model->delete_unavailable($unavailable['id']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
// Google Sync
|
2017-09-15 14:36:37 +03:00
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting($provider['id'], 'google_sync');
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync == TRUE)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$google_token = json_decode($this->providers_model->get_setting($provider['id'], 'google_token'));
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2013-12-26 15:32:25 +02:00
|
|
|
$this->google_sync->delete_unavailable($provider, $unavailable['id_google_calendar']);
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$warnings[] = $e;
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'warnings' => $warnings ?? []
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2020-10-20 16:03:48 +03:00
|
|
|
* Insert of update working plan exceptions to database.
|
2018-04-12 16:03:46 +03:00
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
public function ajax_save_working_plan_exception()
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = $this->permissions[PRIV_USERS]['edit'];
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $required_permissions)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$date = request('date');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$working_plan_exception = request('working_plan_exception');
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
|
|
|
|
|
|
|
$this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Delete a working plan exceptions time period to database.
|
2018-04-12 16:03:46 +03:00
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
public function ajax_delete_working_plan_exception()
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = $this->permissions[PRIV_USERS]['edit'];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $required_permissions)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$date = request('date');
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->providers_model->delete_working_plan_exception($provider_id, $date);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2013-07-15 17:27:19 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) a customer record.
|
2013-07-15 17:27:19 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_customer()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$customer = json_decode(request('customer'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = ( ! isset($customer['id']))
|
|
|
|
? $this->permissions[PRIV_CUSTOMERS]['add']
|
|
|
|
: $this->permissions[PRIV_CUSTOMERS]['edit'];
|
|
|
|
|
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$customer_id = $this->customers_model->save($customer);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2020-04-22 22:48:56 +03:00
|
|
|
'id' => $customer_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-15 17:27:19 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete customer from database.
|
2013-07-15 17:27:19 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_customer()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_CUSTOMERS]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->customers_model->delete(request('customer_id'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
response();
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) service record.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_service()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$service = json_decode(request('service'), TRUE);
|
|
|
|
|
|
|
|
$required_permissions = ( ! isset($service['id']))
|
|
|
|
? $this->permissions[PRIV_SERVICES]['add']
|
|
|
|
: $this->permissions[PRIV_SERVICES]['edit'];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$service_id = $this->services_model->save($service);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2020-04-22 22:48:56 +03:00
|
|
|
'id' => $service_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete service record from database.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_service()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SERVICES]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$service_id = request('service_id');
|
|
|
|
|
|
|
|
$this->services_model->delete($service_id);
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter service records by given key string.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_services()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SERVICES]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
$where =
|
2017-09-15 14:36:37 +03:00
|
|
|
'(name LIKE "%' . $key . '%" OR duration LIKE "%' . $key . '%" OR ' .
|
|
|
|
'price LIKE "%' . $key . '%" OR currency LIKE "%' . $key . '%" OR ' .
|
|
|
|
'description LIKE "%' . $key . '%")';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$services = $this->services_model->get($where);
|
|
|
|
|
|
|
|
json_response($services);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) category record.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_service_category()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$category = json_decode(request('category'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = ( ! isset($category['id']))
|
|
|
|
? $this->permissions[PRIV_SERVICES]['add']
|
|
|
|
: $this->permissions[PRIV_SERVICES]['edit'];
|
|
|
|
|
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$category_id = $this->service_categories_model->save($category);
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2020-04-22 22:48:56 +03:00
|
|
|
'id' => $category_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete category record from database.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_service_category()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SERVICES]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$service_category_id = request('category_id');
|
|
|
|
|
|
|
|
$this->service_categories_model->delete($service_category_id);
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-19 18:29:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter services categories with key string.
|
2013-07-19 18:29:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_service_categories()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SERVICES]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
$where = '(name LIKE "%' . $key . '%" OR description LIKE "%' . $key . '%")';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$service_categories = $this->service_categories_model->get($where);
|
|
|
|
|
|
|
|
json_response($service_categories);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter admin records with string key.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_admins()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
$where =
|
|
|
|
'(first_name LIKE "%' . $key . '%" OR last_name LIKE "%' . $key . '%" ' .
|
|
|
|
'OR email LIKE "%' . $key . '%" OR mobile_number LIKE "%' . $key . '%" ' .
|
2013-09-03 21:58:56 +03:00
|
|
|
'OR phone_number LIKE "%' . $key . '%" OR address LIKE "%' . $key . '%" ' .
|
|
|
|
'OR city LIKE "%' . $key . '%" OR state LIKE "%' . $key . '%" ' .
|
|
|
|
'OR zip_code LIKE "%' . $key . '%" OR notes LIKE "%' . $key . '%")';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$admins = $this->admins_model->get($where);
|
|
|
|
|
|
|
|
json_response($admins);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) admin record into database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_admin()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$admin = json_decode(request('admin'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = ( ! isset($admin['id']))
|
|
|
|
? $this->permissions[PRIV_USERS]['add']
|
|
|
|
: $this->permissions[PRIV_USERS]['edit'];
|
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$admin_id = $this->admins_model->save($admin);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2015-11-05 22:38:13 +03:00
|
|
|
'id' => $admin_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete an admin record from the database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_admin()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$admin_id = request('admin_id');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->admins_model->delete($admin_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter provider records with string key.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_providers()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
$where =
|
|
|
|
'(first_name LIKE "%' . $key . '%" OR last_name LIKE "%' . $key . '%" ' .
|
|
|
|
'OR email LIKE "%' . $key . '%" OR mobile_number LIKE "%' . $key . '%" ' .
|
2013-09-03 21:58:56 +03:00
|
|
|
'OR phone_number LIKE "%' . $key . '%" OR address LIKE "%' . $key . '%" ' .
|
|
|
|
'OR city LIKE "%' . $key . '%" OR state LIKE "%' . $key . '%" ' .
|
|
|
|
'OR zip_code LIKE "%' . $key . '%" OR notes LIKE "%' . $key . '%")';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$providers = $this->providers_model->get($where);
|
|
|
|
|
|
|
|
json_response($providers);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) a provider record into database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_provider()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider = json_decode(request('provider'), TRUE);
|
|
|
|
|
|
|
|
$required_permissions = ( ! isset($provider['id']))
|
|
|
|
? $this->permissions[PRIV_USERS]['add']
|
|
|
|
: $this->permissions[PRIV_USERS]['edit'];
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if (empty($provider['settings']['working_plan']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider['settings']['working_plan'] = setting('company_working_plan');
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = $this->providers_model->save($provider);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2020-04-22 22:48:56 +03:00
|
|
|
'id' => $provider_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete a provider record from the database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_provider()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->providers_model->delete($provider_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Filter secretary records with string key.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_secretaries()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['view'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$key = $this->db->escape_str(request('key'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
$where =
|
|
|
|
'(first_name LIKE "%' . $key . '%" OR last_name LIKE "%' . $key . '%" ' .
|
|
|
|
'OR email LIKE "%' . $key . '%" OR mobile_number LIKE "%' . $key . '%" ' .
|
2013-09-03 21:58:56 +03:00
|
|
|
'OR phone_number LIKE "%' . $key . '%" OR address LIKE "%' . $key . '%" ' .
|
|
|
|
'OR city LIKE "%' . $key . '%" OR state LIKE "%' . $key . '%" ' .
|
|
|
|
'OR zip_code LIKE "%' . $key . '%" OR notes LIKE "%' . $key . '%")';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$secretaries = $this->secretaries_model->get($where);
|
|
|
|
|
|
|
|
json_response($secretaries);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save (insert or update) a secretary record into database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_secretary()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$secretary = json_decode(request('secretary'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$required_permissions = ( ! isset($secretary['id']))
|
|
|
|
? $this->permissions[PRIV_USERS]['add']
|
|
|
|
: $this->permissions[PRIV_USERS]['edit'];
|
|
|
|
if ( ! $required_permissions)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$secretary_id = $this->secretaries_model->save($secretary);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
2020-04-22 22:48:56 +03:00
|
|
|
'id' => $secretary_id
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Delete a secretary record from the database.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_delete_secretary()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_USERS]['delete'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$secretary_id = request('secretary_id');
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->secretaries_model->delete($secretary_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2013-07-16 17:21:33 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Save a setting or multiple settings in the database.
|
2013-09-14 19:10:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_save_settings()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$type = request('type');
|
|
|
|
|
|
|
|
if ($type == SETTINGS_SYSTEM)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SYSTEM_SETTINGS]['edit'] == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$settings = json_decode(request('settings', FALSE), TRUE);
|
|
|
|
|
|
|
|
// Check if phone number settings are valid.
|
|
|
|
|
|
|
|
$phone_number_required = FALSE;
|
|
|
|
|
|
|
|
$phone_number_shown = FALSE;
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-05-30 14:27:39 +03:00
|
|
|
foreach ($settings as $setting)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($setting['name'] === 'require_phone_number')
|
|
|
|
{
|
2021-05-30 14:27:39 +03:00
|
|
|
$phone_number_required = $setting['value'];
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($setting['name'] === 'show_phone_number')
|
|
|
|
{
|
2021-05-30 14:27:39 +03:00
|
|
|
$phone_number_shown = $setting['value'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($phone_number_required && ! $phone_number_shown)
|
|
|
|
{
|
|
|
|
throw new RuntimeException('You cannot hide the phone number in the booking form while it\'s also required!');
|
2021-05-30 14:27:39 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
foreach ($settings as $setting)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
|
|
|
|
|
|
|
|
if ( ! empty($existing_setting))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$setting['id'] = $existing_setting['id'];
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->settings_model->save($setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($type == SETTINGS_USER)
|
|
|
|
{
|
|
|
|
if ($this->permissions[PRIV_USER_SETTINGS]['edit'] == FALSE)
|
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
|
|
|
}
|
2020-11-12 15:47:15 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$settings = json_decode(request('settings'), TRUE);
|
2020-11-12 15:47:15 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->users_model->save($settings);
|
|
|
|
|
|
|
|
session([
|
|
|
|
'user_email' => $settings['email'],
|
|
|
|
'username' => $settings['settings']['username'],
|
|
|
|
'timezone' => $settings['timezone'],
|
|
|
|
]);
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
response();
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* This method checks whether the username already exists in the database.
|
2013-09-23 18:42:36 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_validate_username()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
// We will only use the function in the admins_model because it is sufficient for the rest user types for
|
|
|
|
// now (providers, secretaries).
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$username = request('username');
|
|
|
|
|
|
|
|
$user_id = request('user_id');
|
|
|
|
|
|
|
|
$is_valid = $this->admins_model->validate_username($username, $user_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'is_valid' => $is_valid,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-12-23 18:55:42 +02:00
|
|
|
/**
|
2020-04-22 22:48:56 +03:00
|
|
|
* Change system language for current user.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2017-09-06 16:22:11 +03:00
|
|
|
* The language setting is stored in session data and retrieved every time the user visits any of the system pages.
|
2013-12-23 18:55:42 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_change_language()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-12-26 02:57:59 +02:00
|
|
|
// Check if language exists in the available languages.
|
2017-09-15 14:36:37 +03:00
|
|
|
$found = FALSE;
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2020-12-02 23:12:54 +03:00
|
|
|
foreach (config('available_languages') as $lang)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($lang == request('language'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$found = TRUE;
|
2013-12-26 02:57:59 +02:00
|
|
|
break;
|
2015-11-05 22:38:13 +03:00
|
|
|
}
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! $found)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('Translations for the given language does not exist (' . request('language') . ').');
|
2017-09-06 16:22:11 +03:00
|
|
|
}
|
2013-12-26 02:57:59 +02:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$language = request('language');
|
|
|
|
|
|
|
|
session(['language' => $language]);
|
2013-12-26 02:57:59 +02:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
config(['language' => $language]);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2013-12-23 18:55:42 +02:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-12-25 03:22:37 +02:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* This method will return a list of the available Google Calendars.
|
2015-11-05 22:38:13 +03:00
|
|
|
*
|
2017-09-06 16:22:11 +03:00
|
|
|
* The user will need to select a specific calendar from this list to sync his appointments with. Google access must
|
|
|
|
* be already granted for the specific provider.
|
2013-12-25 03:22:37 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_get_google_calendars()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! request('provider_id'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-12-26 02:57:59 +02:00
|
|
|
throw new Exception('Provider id is required in order to fetch the google calendars.');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2013-12-26 02:57:59 +02:00
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
// Check if selected provider has sync enabled.
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting($provider_id, 'google_sync');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ( ! $google_sync)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => FALSE
|
|
|
|
]);
|
|
|
|
|
|
|
|
return;
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
|
|
|
|
$google_token = json_decode($this->providers_model->get_setting($provider_id, 'google_token'));
|
|
|
|
|
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
|
|
|
|
|
|
|
$calendars = $this->google_sync->get_google_calendars();
|
|
|
|
|
|
|
|
json_response($calendars);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2013-12-25 03:22:37 +02:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-12-26 02:57:59 +02:00
|
|
|
/**
|
2015-11-05 22:38:13 +03:00
|
|
|
* Select a specific google calendar for a provider.
|
|
|
|
*
|
2013-12-26 02:57:59 +02:00
|
|
|
* All the appointments will be synced with this particular calendar.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_select_google_calendar()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$provider_id = request('provider_id');
|
|
|
|
|
|
|
|
$user_id = session('user_id');
|
|
|
|
|
|
|
|
if ($this->permissions[PRIV_USERS]['edit'] == FALSE && (int)$user_id !== (int)$provider_id)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$calendar_id = request('calendar_id');
|
|
|
|
|
|
|
|
$this->providers_model->set_setting($provider_id, 'google_calendar', $calendar_id);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-29 20:25:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply global working plan to all providers.
|
|
|
|
*/
|
|
|
|
public function ajax_apply_global_working_plan()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($this->permissions[PRIV_SYSTEM_SETTINGS]['edit'] == FALSE)
|
2020-03-29 20:25:23 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new Exception('You do not have the required permissions for this task.');
|
2020-03-29 20:25:23 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$working_plan = request('working_plan');
|
2020-03-29 20:25:23 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$providers = $this->providers_model->get();
|
2020-03-29 20:25:23 +03:00
|
|
|
|
|
|
|
foreach ($providers as $provider)
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->providers_model->set_setting($provider['id'], 'working_plan', $working_plan);
|
2020-03-29 20:25:23 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
response();
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2020-03-29 20:25:23 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2020-03-29 20:25:23 +03:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|