diff --git a/application/controllers/Providers.php b/application/controllers/Providers.php new file mode 100644 index 00000000..578622fa --- /dev/null +++ b/application/controllers/Providers.php @@ -0,0 +1,175 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @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. + * + * On this page admin users will be able to manage providers, which are eventually selected by customers during the + * booking process. + */ + public function index() + { + session(['dest_url' => site_url('providers')]); + + if (cannot('view', 'users')) + { + show_error('Forbidden', 403); + } + + $user_id = session('user_id'); + + $role_slug = session('role_slug'); + + $this->load->view('pages/providers/providers_page', [ + 'page_title' => lang('providers'), + 'active_menu' => PRIV_USERS, + '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), + 'services' => $this->services_model->get(), + ]); + } + + /** + * Filter providers by the provided keyword. + */ + public function search() + { + try + { + if (cannot('view', 'users')) + { + show_error('Forbidden', 403); + } + + $keyword = request('keyword', ''); + + $order_by = 'first_name ASC, last_name ASC, email ASC'; + + $limit = request('limit', 1000); + + $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 + { + $provider = json_decode(request('provider'), TRUE); + + if (cannot('add', 'users')) + { + show_error('Forbidden', 403); + } + + $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 + { + $provider = json_decode(request('provider'), TRUE); + + if (cannot('edit', 'users')) + { + show_error('Forbidden', 403); + } + + $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 + { + if (cannot('delete', 'users')) + { + show_error('Forbidden', 403); + } + + $provider_id = request('provider_id'); + + $this->providers_model->delete($provider_id); + + json_response([ + 'success' => TRUE, + ]); + } + catch (Throwable $e) + { + json_exception($e); + } + } +} diff --git a/application/views/pages/providers/providers_page.php b/application/views/pages/providers/providers_page.php new file mode 100755 index 00000000..cb61dc5c --- /dev/null +++ b/application/views/pages/providers/providers_page.php @@ -0,0 +1,350 @@ + + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+ + +
+
+
+
+ +

+
+
+ +
+
+
+ + + +
+ + +
+ + + + + + + +
+
+

+ + + +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +

+
+
+
+
+ +
+

+ + + + + + + + + + +
+ +
+ +

+ +

+ +

+ +
+ +
+ +
+ + + + + + + + + + + +
+ +
+ +

+ +

+ +

+ +
+ +
+ +
+ + + + + + + + + + + +
+ + +
+
+
+
+
+ + + diff --git a/assets/js/backend_providers.js b/assets/js/backend_providers.js new file mode 100644 index 00000000..53b3e135 --- /dev/null +++ b/assets/js/backend_providers.js @@ -0,0 +1,143 @@ +/* ---------------------------------------------------------------------------- + * Easy!Appointments - Open Source Web Scheduler + * + * @package EasyAppointments + * @author A.Tselegidis + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.0.0 + * ---------------------------------------------------------------------------- */ + +window.BackendProviders = window.BackendProviders || {}; + +/** + * Backend Providers + * + * This module handles the js functionality of the providers backend page. + * + * @module BackendProviders + */ +(function (exports) { + 'use strict'; + + /** + * Minimum Password Length + * + * @type {Number} + */ + exports.MIN_PASSWORD_LENGTH = 7; + + /** + * Contains the current tab record methods for the page. + * + * @type {ProvidersHelper} + */ + var helper = {}; + + /** + * Use this class instance for performing actions on the working plan. + * + * @type {WorkingPlan} + */ + exports.wp = {}; + + /** + * Initialize the backend providers page. + * + * @param {Boolean} defaultEventHandlers (OPTIONAL) Whether to bind the default event handlers. + */ + exports.initialize = function (defaultEventHandlers) { + defaultEventHandlers = defaultEventHandlers || true; + + exports.wp = new WorkingPlan(); + exports.wp.bindEventHandlers(); + + // Instantiate default helper object (admin). + helper = new ProvidersHelper(); + helper.resetForm(); + helper.filter(''); + helper.bindEventHandlers(); + + // Fill the services and providers list boxes. + GlobalVariables.services.forEach(function (service) { + $('
', { + 'class': 'checkbox', + 'html': [ + $('
', { + 'class': 'checkbox form-check', + 'html': [ + $('', { + 'class': 'form-check-input', + 'type': 'checkbox', + 'data-id': service.id, + 'prop': { + 'disabled': true + } + }), + $('