calendarweek.php
3 years ago
cart.php
1 month ago
confirmapp.php
2 years ago
empattachser.php
4 years ago
empeditcoupon.php
4 years ago
empeditcustfield.php
4 years ago
empeditlocation.php
4 years ago
empeditpay.php
4 years ago
empeditprofile.php
5 months ago
empeditservice.php
4 years ago
empeditwdays.php
4 years ago
emplocwdays.php
4 years ago
emplogin.php
2 years ago
employeesearch.php
2 years ago
employeeslist.php
4 years ago
empmakerecur.php
1 month ago
empmanres.php
1 month ago
empsettings.php
2 years ago
empsubscr.php
4 years ago
empsubscrorder.php
1 year ago
index.html
6 years ago
modules.php
1 year ago
order.php
5 months ago
packages.php
4 years ago
packagesconfirm.php
4 years ago
packagesorder.php
1 year ago
servicesearch.php
2 years ago
subscriptions.php
4 years ago
subscrpayment.php
1 year ago
userprofile.php
5 months ago
waitinglist.php
4 years ago
empattachser.php
153 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | VAPLoader::import('libraries.employee.area.controller'); |
| 15 | |
| 16 | /** |
| 17 | * Employee area attach services controller. |
| 18 | * |
| 19 | * @since 1.6 |
| 20 | */ |
| 21 | class VikAppointmentsControllerEmpattachser extends VAPEmployeeAreaController |
| 22 | { |
| 23 | /** |
| 24 | * Task used to access the creation page of a new record. |
| 25 | * |
| 26 | * @return boolean |
| 27 | * |
| 28 | * @since 1.7 |
| 29 | */ |
| 30 | public function add() |
| 31 | { |
| 32 | $app = JFactory::getApplication(); |
| 33 | $auth = VAPEmployeeAuth::getInstance(); |
| 34 | |
| 35 | // check user permissions |
| 36 | if (!$auth->isEmployee() || !$auth->attachServices()) |
| 37 | { |
| 38 | // back to main list, not authorised to edit records |
| 39 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 40 | $this->cancel(); |
| 41 | |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | $this->setRedirect('index.php?option=com_vikappointments&view=empattachser'); |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Task used to save the record data set in the request. |
| 52 | * After saving, the user is redirected to the main list. |
| 53 | * |
| 54 | * @return void |
| 55 | * |
| 56 | * @since 1.7 |
| 57 | */ |
| 58 | public function saveclose() |
| 59 | { |
| 60 | if ($this->save()) |
| 61 | { |
| 62 | $this->cancel(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Save employee-services assignments. |
| 68 | * |
| 69 | * @return void |
| 70 | */ |
| 71 | public function save() |
| 72 | { |
| 73 | $app = JFactory::getApplication(); |
| 74 | $input = $app->input; |
| 75 | $auth = VAPEmployeeAuth::getInstance(); |
| 76 | |
| 77 | /** |
| 78 | * Added token validation. |
| 79 | * |
| 80 | * @since 1.7 |
| 81 | */ |
| 82 | if (!JSession::checkToken()) |
| 83 | { |
| 84 | // back to main list, missing CSRF-proof token |
| 85 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 86 | $this->cancel(); |
| 87 | |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // check user permissions |
| 92 | if (!$auth->isEmployee() || !$auth->attachServices()) |
| 93 | { |
| 94 | // back to main list, not authorised to edit records |
| 95 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 96 | $this->cancel(); |
| 97 | |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | // always set redirect to edit page |
| 102 | $this->setRedirect('index.php?option=com_vikappointments&view=empattachser'); |
| 103 | |
| 104 | $services = $input->get('services', array(), 'uint'); |
| 105 | |
| 106 | // get service model |
| 107 | $model = $this->getModel(); |
| 108 | |
| 109 | // try to attach the services |
| 110 | $count = $model->save(array('services' => $services)); |
| 111 | |
| 112 | if (!$count) |
| 113 | { |
| 114 | // get string error |
| 115 | $error = $model->getError(null, true); |
| 116 | |
| 117 | if ($error) |
| 118 | { |
| 119 | // display error message |
| 120 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 121 | } |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | // display generic successful message |
| 127 | $app->enqueueMessage(JText::translate('VAPEMPATTACHSERCREATED')); |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Redirects the users to the main records list. |
| 134 | * |
| 135 | * @param array $query An array of query arguments. |
| 136 | * |
| 137 | * @return void |
| 138 | * |
| 139 | * @since 1.7 |
| 140 | */ |
| 141 | public function cancel(array $query = array()) |
| 142 | { |
| 143 | $url = 'index.php?option=com_vikappointments&view=empserviceslist'; |
| 144 | |
| 145 | if ($query) |
| 146 | { |
| 147 | $url .= '&' . http_build_query($query); |
| 148 | } |
| 149 | |
| 150 | $this->setRedirect($url); |
| 151 | } |
| 152 | } |
| 153 |