2021-11-18 07:13:13 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-11-18 07:13:13 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Services controller.
|
|
|
|
*
|
|
|
|
* Handles the services related operations.
|
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
|
|
|
class Services extends EA_Controller {
|
|
|
|
/**
|
|
|
|
* Services constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
$this->load->library('timezones');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the backend services page.
|
|
|
|
*
|
2022-01-10 11:09:49 +03:00
|
|
|
* On this page admin users will be able to manage services, which are eventually selected by customers during the
|
2021-11-18 07:13:13 +03:00
|
|
|
* booking process.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
session(['dest_url' => site_url('services')]);
|
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
$user_id = session('user_id');
|
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_SERVICES))
|
2021-11-18 07:13:13 +03:00
|
|
|
{
|
2022-01-17 20:24:02 +03:00
|
|
|
if ($user_id)
|
|
|
|
{
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
}
|
2021-11-18 07:13:13 +03:00
|
|
|
|
2022-01-17 20:24:02 +03:00
|
|
|
redirect('login');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 07:13:13 +03:00
|
|
|
|
|
|
|
$role_slug = session('role_slug');
|
2022-01-10 11:09:49 +03:00
|
|
|
|
|
|
|
script_vars([
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'role_slug' => $role_slug,
|
|
|
|
]);
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
html_vars([
|
2021-11-18 07:13:13 +03:00
|
|
|
'page_title' => lang('services'),
|
|
|
|
'active_menu' => PRIV_SERVICES,
|
|
|
|
'user_display_name' => $this->accounts->get_user_display_name($user_id),
|
|
|
|
'timezones' => $this->timezones->to_array(),
|
|
|
|
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
|
|
|
|
]);
|
2021-12-18 19:22:40 +03:00
|
|
|
|
|
|
|
$this->load->view('pages/services', html_vars());
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter services by the provided keyword.
|
|
|
|
*/
|
|
|
|
public function search()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_SERVICES))
|
2021-11-18 07:13:13 +03:00
|
|
|
{
|
2021-12-18 19:22:40 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$keyword = request('keyword', '');
|
|
|
|
|
|
|
|
$order_by = 'name ASC';
|
|
|
|
|
|
|
|
$limit = request('limit', 1000);
|
2022-01-10 11:09:49 +03:00
|
|
|
|
2021-11-18 07:13:13 +03:00
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
$services = $this->services_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
|
|
json_response($services);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a service.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-01-10 11:09:49 +03:00
|
|
|
$service = request('service');
|
|
|
|
|
|
|
|
$service['id_categories'] = $service['id_categories'] ?: null;
|
2021-11-18 07:13:13 +03:00
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('add', PRIV_SERVICES))
|
2021-11-18 07:13:13 +03:00
|
|
|
{
|
2021-12-18 19:22:40 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$service_id = $this->services_model->save($service);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $service_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a service.
|
|
|
|
*/
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-01-10 11:09:49 +03:00
|
|
|
$service = request('service');
|
|
|
|
|
|
|
|
$service['id_categories'] = $service['id_categories'] ?: null;
|
2021-11-18 07:13:13 +03:00
|
|
|
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('edit', PRIV_SERVICES))
|
2021-11-18 07:13:13 +03:00
|
|
|
{
|
2021-12-18 19:22:40 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|
2022-01-10 11:09:49 +03:00
|
|
|
|
2021-11-18 07:13:13 +03:00
|
|
|
$service_id = $this->services_model->save($service);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $service_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a service.
|
|
|
|
*/
|
|
|
|
public function destroy()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('delete', PRIV_SERVICES))
|
2021-11-18 07:13:13 +03:00
|
|
|
{
|
2021-12-18 19:22:40 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$service_id = request('service_id');
|
|
|
|
|
|
|
|
$this->services_model->delete($service_id);
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 09:18:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a service.
|
|
|
|
*/
|
|
|
|
public function find()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (cannot('delete', PRIV_SERVICES))
|
|
|
|
{
|
2021-12-18 19:22:40 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-12-14 09:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$service_id = request('service_id');
|
|
|
|
|
|
|
|
$service = $this->services_model->find($service_id);
|
|
|
|
|
|
|
|
json_response($service);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 07:13:13 +03:00
|
|
|
}
|