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