2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2015-10-05 01:32:47 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @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-10-05 01:32:47 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Appointments controller.
|
2021-10-28 15:01:17 +03:00
|
|
|
*
|
2021-11-18 09:12:16 +03:00
|
|
|
* Handles the appointments related operations.
|
|
|
|
*
|
|
|
|
* Notice: This file used to have the booking page related code which since v1.5 has now moved to the Booking.php
|
|
|
|
* controller for improved consistency.
|
2015-10-05 01:32:47 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2020-11-16 11:29:36 +03:00
|
|
|
class Appointments extends EA_Controller {
|
2015-10-18 21:00:01 +03:00
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Appointments constructor.
|
2015-10-18 21:00:01 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2015-10-18 21:00:01 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->load->model('appointments_model');
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->load->model('roles_model');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->load->library('accounts');
|
2020-05-12 21:50:55 +03:00
|
|
|
$this->load->library('timezones');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2015-10-05 01:32:47 +03:00
|
|
|
|
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Support backwards compatibility for appointment links that still point to this URL.
|
|
|
|
*
|
|
|
|
* @param string $appointment_hash
|
|
|
|
*
|
|
|
|
* @deprecated Since 1.5
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2021-10-28 15:01:17 +03:00
|
|
|
public function index(string $appointment_hash = '')
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-18 09:12:16 +03:00
|
|
|
redirect('booking/' . $appointment_hash);
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Filter appointments by the provided keyword.
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2021-11-18 09:12:16 +03:00
|
|
|
public function search()
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_APPOINTMENTS))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$keyword = request('keyword', '');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$order_by = 'name ASC';
|
2015-10-05 01:32:47 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$limit = request('limit', 1000);
|
|
|
|
|
|
|
|
$offset = 0;
|
2015-10-05 01:32:47 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointments = $this->appointments_model->search($keyword, $limit, $offset, $order_by);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response($appointments);
|
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-11-18 09:12:16 +03:00
|
|
|
json_exception($e);
|
2015-11-23 23:58:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 01:32:47 +03:00
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Create a appointment.
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2021-11-18 09:12:16 +03:00
|
|
|
public function create()
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment = json_decode(request('appointment'), TRUE);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('add', PRIV_APPOINTMENTS))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2015-12-11 00:29:15 +02:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment_id = $this->appointments_model->save($appointment);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $appointment_id
|
|
|
|
]);
|
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-11-12 19:23:43 +03:00
|
|
|
json_exception($e);
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 21:00:01 +03:00
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Update a appointment.
|
2020-04-22 22:48:56 +03:00
|
|
|
*/
|
2021-11-18 09:12:16 +03:00
|
|
|
public function update()
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment = json_decode(request('appointment'), TRUE);
|
2020-09-21 14:26:15 +03:00
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('edit', PRIV_APPOINTMENTS))
|
2020-09-21 14:26:15 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2020-09-21 14:26:15 +03:00
|
|
|
}
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment_id = $this->appointments_model->save($appointment);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $appointment_id
|
|
|
|
]);
|
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-11-12 19:23:43 +03:00
|
|
|
json_exception($e);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Remove a appointment.
|
2020-04-22 22:48:56 +03:00
|
|
|
*/
|
2021-11-18 09:12:16 +03:00
|
|
|
public function destroy()
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2021-11-18 09:12:16 +03:00
|
|
|
try
|
2020-11-12 15:46:51 +03:00
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('delete', PRIV_APPOINTMENTS))
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment_id = request('appointment_id');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->appointments_model->delete($appointment_id);
|
2020-10-21 21:37:47 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
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-11-12 19:23:43 +03:00
|
|
|
json_exception($e);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
2021-12-14 09:18:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an appointment.
|
|
|
|
*/
|
|
|
|
public function find()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_APPOINTMENTS))
|
2021-12-14 09:18:46 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-12-14 09:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$appointment_id = request('appointment_id');
|
|
|
|
|
|
|
|
$appointment = $this->appointments_model->find($appointment_id);
|
|
|
|
|
|
|
|
json_response($appointment);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|