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
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
use EA\Engine\Notifications\Email as EmailClient;
|
2020-03-29 16:08:07 +03:00
|
|
|
use EA\Engine\Types\Email;
|
|
|
|
use EA\Engine\Types\Text;
|
2016-07-16 17:56:02 +03:00
|
|
|
|
2013-07-09 08:43:59 +03:00
|
|
|
/**
|
2015-11-05 22:38:13 +03:00
|
|
|
* Backend API Controller
|
2015-07-08 01:33:33 +03:00
|
|
|
*
|
|
|
|
* Contains all the backend AJAX callbacks.
|
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
|
|
|
|
*/
|
|
|
|
protected $privileges;
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2016-04-27 09:21:40 +03:00
|
|
|
/**
|
|
|
|
* Class Constructor
|
|
|
|
*/
|
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');
|
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('settings_model');
|
|
|
|
$this->load->model('user_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
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($this->session->userdata('role_slug'))
|
|
|
|
{
|
2017-08-01 09:39:03 +03:00
|
|
|
$this->privileges = $this->roles_model->get_privileges($this->session->userdata('role_slug'));
|
|
|
|
}
|
2022-02-23 16:54:41 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
show_error('Forbidden', 403);
|
|
|
|
}
|
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
|
|
|
|
{
|
2022-02-23 16:54:41 +03:00
|
|
|
if ($this->privileges[PRIV_APPOINTMENTS]['view'] == FALSE)
|
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
|
|
|
|
2020-12-05 12:46:05 +03:00
|
|
|
$start_date = $this->input->post('startDate') . ' 00:00:00';
|
|
|
|
$end_date = $this->input->post('endDate') . ' 23:59:59';
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
$response = [
|
|
|
|
'appointments' => $this->appointments_model->get_batch([
|
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
|
|
|
]),
|
2020-10-21 21:44:35 +03:00
|
|
|
'unavailability_events' => $this->appointments_model->get_batch([
|
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
|
|
|
{
|
2020-12-14 21:41:21 +03:00
|
|
|
$appointment['provider'] = $this->providers_model->get_row($appointment['id_users_provider']);
|
|
|
|
$appointment['service'] = $this->services_model->get_row($appointment['id_services']);
|
|
|
|
$appointment['customer'] = $this->customers_model->get_row($appointment['id_users_customer']);
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
2021-03-15 15:00:29 +03:00
|
|
|
unset ($appointment);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2020-12-05 12:46:05 +03:00
|
|
|
$user_id = $this->session->userdata('user_id');
|
2020-12-02 20:50:17 +03:00
|
|
|
$role_slug = $this->session->userdata('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
|
|
|
{
|
2020-12-05 12:46:05 +03:00
|
|
|
$providers = $this->secretaries_model->get_row($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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 13:42:30 +03:00
|
|
|
$response['appointments'] = array_values($response['appointments']);
|
|
|
|
|
|
|
|
$response['unavailability_events'] = array_values($response['unavailability_events']);
|
|
|
|
|
2016-07-17 19:51:46 +03:00
|
|
|
$this->output->set_output(json_encode($response));
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
*
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_APPOINTMENTS]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
if ( ! $this->input->post('filter_type'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2017-09-20 17:09:01 +03:00
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode(['appointments' => []]));
|
2015-11-05 22:38:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('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
|
2020-04-22 22:48:56 +03:00
|
|
|
$record_id = $this->db->escape($this->input->post('record_id'));
|
|
|
|
$start_date = $this->db->escape($this->input->post('start_date'));
|
|
|
|
$end_date = $this->db->escape(date('Y-m-d', strtotime($this->input->post('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
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$response['appointments'] = $this->appointments_model->get_batch($where_clause);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($response['appointments'] as &$appointment)
|
|
|
|
{
|
2013-07-10 16:57:24 +03:00
|
|
|
$appointment['provider'] = $this->providers_model->get_row($appointment['id_users_provider']);
|
|
|
|
$appointment['service'] = $this->services_model->get_row($appointment['id_services']);
|
|
|
|
$appointment['customer'] = $this->customers_model->get_row($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'] = [];
|
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('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
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$response['unavailables'] = $this->appointments_model->get_batch($where_clause);
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-12-14 21:41:21 +03:00
|
|
|
foreach ($response['unavailables'] as &$unavailable)
|
|
|
|
{
|
|
|
|
$unavailable['provider'] = $this->providers_model->get_row($unavailable['id_users_provider']);
|
|
|
|
}
|
|
|
|
|
2017-09-20 17:09:01 +03:00
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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.
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('customer_data'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$customer = json_decode($this->input->post('customer_data'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$required_privileges = ( ! isset($customer['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_CUSTOMERS]['add']
|
|
|
|
: $this->privileges[PRIV_CUSTOMERS]['edit'];
|
2020-10-21 21:37:47 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
$customer['id'] = $this->customers_model->add($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.
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('appointment_data'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$appointment = json_decode($this->input->post('appointment_data'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$required_privileges = ( ! isset($appointment['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_APPOINTMENTS]['add']
|
|
|
|
: $this->privileges[PRIV_APPOINTMENTS]['edit'];
|
2020-10-21 21:37:47 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
$manage_mode = isset($appointment['id']);
|
2020-11-22 00:08:07 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
// If the appointment does not contain the customer record id, then it means that is is going to be
|
|
|
|
// inserted. Get the customer's record ID.
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! isset($appointment['id_users_customer']))
|
|
|
|
{
|
2013-07-09 17:46:48 +03:00
|
|
|
$appointment['id_users_customer'] = $customer['id'];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
$appointment['id'] = $this->appointments_model->add($appointment);
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
$appointment = $this->appointments_model->get_row($appointment['id']);
|
|
|
|
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
|
|
|
|
$customer = $this->customers_model->get_row($appointment['id_users_customer']);
|
|
|
|
$service = $this->services_model->get_row($appointment['id_services']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-09-23 12:42:18 +03:00
|
|
|
$settings = [
|
2017-09-15 14:36:37 +03:00
|
|
|
'company_name' => $this->settings_model->get_setting('company_name'),
|
|
|
|
'company_link' => $this->settings_model->get_setting('company_link'),
|
2017-10-31 13:42:53 +03:00
|
|
|
'company_email' => $this->settings_model->get_setting('company_email'),
|
2018-03-06 14:20:47 +03:00
|
|
|
'date_format' => $this->settings_model->get_setting('date_format'),
|
|
|
|
'time_format' => $this->settings_model->get_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);
|
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
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_APPOINTMENTS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
if ( ! $this->input->post('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.
|
2017-09-19 16:44:32 +03:00
|
|
|
$appointment = $this->appointments_model->get_row($this->input->post('appointment_id'));
|
2013-07-10 16:57:24 +03:00
|
|
|
$provider = $this->providers_model->get_row($appointment['id_users_provider']);
|
|
|
|
$customer = $this->customers_model->get_row($appointment['id_users_customer']);
|
|
|
|
$service = $this->services_model->get_row($appointment['id_services']);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2020-09-23 12:42:18 +03:00
|
|
|
$settings = [
|
2013-07-09 08:43:59 +03:00
|
|
|
'company_name' => $this->settings_model->get_setting('company_name'),
|
|
|
|
'company_email' => $this->settings_model->get_setting('company_email'),
|
2017-10-31 13:42:53 +03:00
|
|
|
'company_link' => $this->settings_model->get_setting('company_link'),
|
2018-03-06 14:20:47 +03:00
|
|
|
'date_format' => $this->settings_model->get_setting('date_format'),
|
|
|
|
'time_format' => $this->settings_model->get_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.
|
2017-09-19 16:44:32 +03:00
|
|
|
$this->appointments_model->delete($this->input->post('appointment_id'));
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
// Sync removal with Google Calendar.
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($appointment['id_google_calendar'] != NULL)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-07-10 16:57:24 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting('google_sync', $provider['id']);
|
2013-07-09 08:43:59 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync == TRUE)
|
|
|
|
{
|
2013-07-09 08:43:59 +03:00
|
|
|
$google_token = json_decode($this->providers_model
|
2017-09-15 14:36:37 +03:00
|
|
|
->get_setting('google_token', $provider['id']));
|
2013-07-09 08:43:59 +03:00
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
2013-12-26 15:32:25 +02:00
|
|
|
$this->google_sync->delete_appointment($provider, $appointment['id_google_calendar']);
|
2015-11-05 22:38:13 +03:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$warnings[] = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
// Send notification emails to provider and customer.
|
2017-09-15 14:36:37 +03:00
|
|
|
try
|
|
|
|
{
|
2016-07-16 17:56:02 +03:00
|
|
|
$this->config->load('email');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$email = new EmailClient($this, $this->config->config);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
$send_provider = $this->providers_model
|
2017-09-15 14:36:37 +03:00
|
|
|
->get_setting('notifications', $provider['id']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ((bool)$send_provider === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-09-23 12:42:18 +03:00
|
|
|
$service, $customer, $settings, new Email($provider['email']),
|
2017-09-19 16:44:32 +03:00
|
|
|
new Text($this->input->post('delete_reason')));
|
2013-09-24 16:09:04 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2015-11-25 00:12:37 +02:00
|
|
|
$send_customer = $this->settings_model->get_setting('customer_notifications');
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ((bool)$send_customer === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-09-23 12:42:18 +03:00
|
|
|
$service, $customer, $settings, new Email($customer['email']),
|
2017-09-19 16:44:32 +03:00
|
|
|
new Text($this->input->post('delete_reason')));
|
2015-11-25 00:12:37 +02:00
|
|
|
}
|
2020-09-23 12:42:18 +03:00
|
|
|
|
|
|
|
// Notify admins
|
|
|
|
$admins = $this->admins_model->get_batch();
|
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
foreach ($admins as $admin)
|
2020-09-23 12:42:18 +03:00
|
|
|
{
|
2020-12-09 15:17:45 +03:00
|
|
|
if ( ! $admin['settings']['notifications'] === '0')
|
2020-09-23 12:42:18 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-09-23 12:42:18 +03:00
|
|
|
$service, $customer, $settings, new Email($admin['email']),
|
|
|
|
new Text($this->input->post('cancel_reason')));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify secretaries
|
|
|
|
$secretaries = $this->secretaries_model->get_batch();
|
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
foreach ($secretaries as $secretary)
|
2020-09-23 12:42:18 +03:00
|
|
|
{
|
2020-12-09 15:17:45 +03:00
|
|
|
if ( ! $secretary['settings']['notifications'] === '0')
|
2020-09-23 12:42:18 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($provider['id'], $secretary['providers']))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-09-23 12:42:18 +03:00
|
|
|
$service, $customer, $settings, new Email($secretary['email']),
|
|
|
|
new Text($this->input->post('cancel_reason')));
|
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$warnings[] = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
if (empty($warnings))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
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
|
|
|
$response = ['warnings' => $warnings];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
*
|
2017-09-06 16:22:11 +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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
if ( ! $this->input->post('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
|
|
|
|
2013-11-07 13:25:59 +02:00
|
|
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
2017-09-19 16:44:32 +03:00
|
|
|
&& $this->session->userdata('user_id') != $this->input->post('provider_id'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-11-07 13:25:59 +02:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-20 17:09:01 +03:00
|
|
|
$this->providers_model->set_setting('google_sync', FALSE, $this->input->post('provider_id'));
|
|
|
|
$this->providers_model->set_setting('google_token', NULL, $this->input->post('provider_id'));
|
|
|
|
$this->appointments_model->clear_google_sync_ids($this->input->post('provider_id'));
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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.
|
2017-09-06 16:22:11 +03:00
|
|
|
*
|
|
|
|
* Outputs the search results.
|
2013-07-09 08:43:59 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_filter_customers()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_CUSTOMERS]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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';
|
|
|
|
|
|
|
|
$limit = $this->input->post('limit');
|
|
|
|
|
|
|
|
if ($limit === NULL)
|
|
|
|
{
|
|
|
|
$limit = 1000;
|
|
|
|
}
|
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
$customers = $this->customers_model->get_batch($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)
|
|
|
|
{
|
2020-12-14 21:41:21 +03:00
|
|
|
$appointments = $this->appointments_model->get_batch(['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)
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$appointment['service'] = $this->services_model->get_row($appointment['id_services']);
|
|
|
|
$appointment['provider'] = $this->providers_model->get_row($appointment['id_users_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
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = $customers;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
2017-09-19 16:44:32 +03:00
|
|
|
$unavailable = json_decode($this->input->post('unavailable'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$required_privileges = ( ! isset($unavailable['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_APPOINTMENTS]['add']
|
|
|
|
: $this->privileges[PRIV_APPOINTMENTS]['edit'];
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-12-26 15:32:25 +02:00
|
|
|
$provider = $this->providers_model->get_row($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);
|
2013-09-26 19:06:57 +03:00
|
|
|
$unavailable = $this->appointments_model->get_row($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
|
|
|
|
{
|
2015-11-05 22:38:13 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting('google_sync',
|
2017-09-15 14:36:37 +03:00
|
|
|
$unavailable['id_users_provider']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync)
|
|
|
|
{
|
2013-07-09 17:46:48 +03:00
|
|
|
$google_token = json_decode($this->providers_model->get_setting('google_token',
|
2017-09-15 14:36:37 +03:00
|
|
|
$unavailable['id_users_provider']));
|
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
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$warnings[] = $exception;
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if (isset($warnings))
|
|
|
|
{
|
2017-09-20 17:09:01 +03:00
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode(['warnings' => $warnings]));
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
|
|
|
else
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2017-09-20 17:09:01 +03:00
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode(AJAX_SUCCESS));
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-07-01 09:49:17 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_APPOINTMENTS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$unavailable = $this->appointments_model->get_row($this->input->post('unavailable_id'));
|
2013-07-10 16:57:24 +03:00
|
|
|
$provider = $this->providers_model->get_row($unavailable['id_users_provider']);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
|
|
|
// Delete unavailable
|
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
|
|
|
|
{
|
2013-07-10 16:57:24 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting('google_sync', $provider['id']);
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync == TRUE)
|
|
|
|
{
|
2013-07-10 16:57:24 +03:00
|
|
|
$google_token = json_decode($this->providers_model->get_setting('google_token', $provider['id']));
|
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
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
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$warnings[] = $exception;
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
if (empty($warnings))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
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
|
|
|
$response = ['warnings' => $warnings];
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
// Check privileges
|
2020-10-20 16:03:48 +03:00
|
|
|
$required_privileges = $this->privileges[PRIV_USERS]['edit'];
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
$date = $this->input->post('date');
|
|
|
|
$working_plan_exception = $this->input->post('working_plan_exception');
|
|
|
|
$provider_id = $this->input->post('provider_id');
|
|
|
|
|
|
|
|
$success = $this->providers_model->save_working_plan_exception($date, $working_plan_exception, $provider_id);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($success)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-20 16:03:48 +03:00
|
|
|
$response = ['warnings' => 'Error on saving working plan exception.'];
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-20 16:03:48 +03:00
|
|
|
* Delete an 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
|
|
|
|
{
|
2020-10-20 16:03:48 +03:00
|
|
|
// Check privileges
|
|
|
|
$required_privileges = $this->privileges[PRIV_USERS]['edit'];
|
|
|
|
|
|
|
|
if ($required_privileges == FALSE)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
$date = $this->input->post('date');
|
2018-04-12 16:03:46 +03:00
|
|
|
$provider_id = $this->input->post('provider_id');
|
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
$success = $this->providers_model->delete_working_plan_exception($date, $provider_id);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($success)
|
2018-04-12 16:03:46 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-20 16:03:48 +03:00
|
|
|
$response = ['warnings' => 'Error on deleting working plan exception.'];
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
catch (Exception $exception)
|
|
|
|
{
|
|
|
|
$this->output->set_status_header(500);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
|
|
|
}
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$customer = json_decode($this->input->post('customer'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$required_privileges = ( ! isset($customer['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_CUSTOMERS]['add']
|
|
|
|
: $this->privileges[PRIV_CUSTOMERS]['edit'];
|
2020-10-21 21:37:47 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$customer_id = $this->customers_model->add($customer);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$response = [
|
|
|
|
'status' => AJAX_SUCCESS,
|
|
|
|
'id' => $customer_id
|
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_CUSTOMERS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$this->customers_model->delete($this->input->post('customer_id'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$response = AJAX_SUCCESS;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-09 17:46:48 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$service = json_decode($this->input->post('service'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$required_privileges = ( ! isset($service['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_SERVICES]['add']
|
|
|
|
: $this->privileges[PRIV_SERVICES]['edit'];
|
2020-10-21 21:37:47 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$service_id = $this->services_model->add($service);
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = [
|
|
|
|
'status' => AJAX_SUCCESS,
|
|
|
|
'id' => $service_id
|
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SERVICES]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->services_model->delete($this->input->post('service_id'));
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SERVICES]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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
|
|
|
|
|
|
|
$response = $this->services_model->get_batch($where);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$category = json_decode($this->input->post('category'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$required_privileges = ( ! isset($category['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_SERVICES]['add']
|
|
|
|
: $this->privileges[PRIV_SERVICES]['edit'];
|
2020-10-21 21:37:47 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$category_id = $this->services_model->add_category($category);
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = [
|
|
|
|
'status' => AJAX_SUCCESS,
|
|
|
|
'id' => $category_id
|
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SERVICES]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->services_model->delete_category($this->input->post('category_id'));
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SERVICES]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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
|
|
|
|
|
|
|
$response = $this->services_model->get_all_categories($where);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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
|
|
|
|
|
|
|
$response = $this->admins_model->get_batch($where);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$admin = json_decode($this->input->post('admin'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$required_privileges = ( ! isset($admin['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_USERS]['add']
|
|
|
|
: $this->privileges[PRIV_USERS]['edit'];
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$admin_id = $this->admins_model->add($admin);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$response = [
|
2013-09-25 18:43:17 +03:00
|
|
|
'status' => AJAX_SUCCESS,
|
2015-11-05 22:38:13 +03:00
|
|
|
'id' => $admin_id
|
2017-09-15 14:36:37 +03:00
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->admins_model->delete($this->input->post('admin_id'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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
|
|
|
|
|
|
|
$response = $this->providers_model->get_batch($where);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$provider = json_decode($this->input->post('provider'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$required_privileges = ( ! isset($provider['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_USERS]['add']
|
|
|
|
: $this->privileges[PRIV_USERS]['edit'];
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! isset($provider['settings']['working_plan']))
|
|
|
|
{
|
2013-09-23 18:42:36 +03:00
|
|
|
$provider['settings']['working_plan'] = $this->settings_model
|
2017-09-15 14:36:37 +03:00
|
|
|
->get_setting('company_working_plan');
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$provider_id = $this->providers_model->add($provider);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = [
|
|
|
|
'status' => AJAX_SUCCESS,
|
|
|
|
'id' => $provider_id
|
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->providers_model->delete($this->input->post('provider_id'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['view'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$key = $this->db->escape_str($this->input->post('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
|
|
|
|
|
|
|
$response = $this->secretaries_model->get_batch($where);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
$secretary = json_decode($this->input->post('secretary'), TRUE);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$required_privileges = ( ! isset($secretary['id']))
|
2017-09-15 14:36:37 +03:00
|
|
|
? $this->privileges[PRIV_USERS]['add']
|
|
|
|
: $this->privileges[PRIV_USERS]['edit'];
|
2020-04-22 22:48:56 +03:00
|
|
|
if ($required_privileges == FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$secretary_id = $this->secretaries_model->add($secretary);
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
$response = [
|
2020-04-22 22:48:56 +03:00
|
|
|
'status' => AJAX_SUCCESS,
|
|
|
|
'id' => $secretary_id
|
|
|
|
];
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USERS]['delete'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->secretaries_model->delete($this->input->post('secretary_id'));
|
2017-09-20 17:09:01 +03:00
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('type') == SETTINGS_SYSTEM)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SYSTEM_SETTINGS]['edit'] == FALSE)
|
|
|
|
{
|
2013-09-26 19:06:57 +03:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2020-09-23 13:44:12 +03:00
|
|
|
$settings = json_decode($this->input->post('settings', FALSE), TRUE);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2013-09-18 19:36:29 +03:00
|
|
|
$this->settings_model->save_settings($settings);
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
|
|
|
else
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2017-09-19 16:44:32 +03:00
|
|
|
if ($this->input->post('type') == SETTINGS_USER)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_USER_SETTINGS]['edit'] == FALSE)
|
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2020-11-12 15:47:15 +03:00
|
|
|
$settings = json_decode($this->input->post('settings'), TRUE);
|
|
|
|
|
|
|
|
$this->user_model->save_user($settings);
|
|
|
|
|
|
|
|
$this->session->set_userdata([
|
|
|
|
'user_email' => $settings['email'],
|
|
|
|
'username' => $settings['settings']['username'],
|
|
|
|
'timezone' => $settings['timezone'],
|
|
|
|
]);
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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).
|
2017-09-20 17:09:01 +03:00
|
|
|
$is_valid = $this->admins_model->validate_username($this->input->post('username'),
|
|
|
|
$this->input->post('user_id'));
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$response = $is_valid;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
2013-12-23 18:55:42 +02:00
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2013-12-25 03:22:37 +02:00
|
|
|
/**
|
2015-11-05 22:38:13 +03:00
|
|
|
* This method will return a list of the available google calendars.
|
|
|
|
*
|
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
|
|
|
|
{
|
2022-02-23 16:54:41 +03:00
|
|
|
$provider_id = $this->input->post('provider_id');
|
|
|
|
|
|
|
|
if ( ! $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
|
|
|
|
2022-02-23 16:54:41 +03:00
|
|
|
if ($this->privileges[PRIV_USERS]['view'] == FALSE && $provider_id !== $this->session->userdata('user_id'))
|
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
|
|
|
|
2015-11-05 22:38:13 +03:00
|
|
|
// Check if selected provider has sync enabled.
|
2022-02-23 16:54:41 +03:00
|
|
|
$google_sync = $this->providers_model->get_setting('google_sync', $provider_id);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($google_sync)
|
|
|
|
{
|
2017-09-20 17:09:01 +03:00
|
|
|
$google_token = json_decode($this->providers_model->get_setting('google_token',
|
2022-02-23 16:54:41 +03:00
|
|
|
$provider_id));
|
2013-12-26 02:57:59 +02:00
|
|
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2013-12-26 02:57:59 +02:00
|
|
|
$calendars = $this->google_sync->get_google_calendars();
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$response = $calendars;
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
|
|
|
else
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-12-09 15:17:45 +03:00
|
|
|
$response = AJAX_FAILURE;
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
2013-12-26 02:57:59 +02:00
|
|
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
2017-09-19 16:44:32 +03:00
|
|
|
&& $this->session->userdata('user_id') != $this->input->post('provider_id'))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2013-12-26 02:57:59 +02:00
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2017-09-19 16:44:32 +03:00
|
|
|
$result = $this->providers_model->set_setting('google_calendar', $this->input->post('calendar_id'),
|
|
|
|
$this->input->post('provider_id'));
|
2015-11-05 22:38:13 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$response = $result ? AJAX_SUCCESS : AJAX_FAILURE;
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
catch (Exception $exception)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2013-12-26 02:57:59 +02:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
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
|
|
|
|
{
|
|
|
|
if ($this->privileges[PRIV_SYSTEM_SETTINGS]['edit'] == FALSE)
|
|
|
|
{
|
|
|
|
throw new Exception('You do not have the required privileges for this task.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$working_plan = $this->input->post('working_plan');
|
|
|
|
|
|
|
|
$providers = $this->providers_model->get_batch();
|
|
|
|
|
|
|
|
foreach ($providers as $provider)
|
|
|
|
{
|
|
|
|
$this->providers_model->set_setting('working_plan', $working_plan, $provider['id']);
|
|
|
|
}
|
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
$response = AJAX_SUCCESS;
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
catch (Exception $exception)
|
2020-03-29 20:25:23 +03:00
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->output->set_status_header(500);
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'trace' => config('debug') ? $exception->getTrace() : []
|
|
|
|
];
|
2020-03-29 20:25:23 +03:00
|
|
|
}
|
2020-04-22 22:48:56 +03:00
|
|
|
|
|
|
|
$this->output
|
|
|
|
->set_content_type('application/json')
|
|
|
|
->set_output(json_encode($response));
|
2020-03-29 20:25:23 +03:00
|
|
|
}
|
2013-07-09 08:43:59 +03:00
|
|
|
}
|