calendarweek.php
2 days ago
cart.php
2 days ago
confirmapp.php
2 days ago
empattachser.php
2 days ago
empeditcoupon.php
2 days ago
empeditcustfield.php
2 days ago
empeditlocation.php
2 days ago
empeditpay.php
2 days ago
empeditprofile.php
2 days ago
empeditservice.php
2 days ago
empeditwdays.php
2 days ago
emplocwdays.php
2 days ago
emplogin.php
2 days ago
employeesearch.php
2 days ago
employeeslist.php
2 days ago
empmakerecur.php
2 days ago
empmanres.php
2 days ago
empsettings.php
2 days ago
empsubscr.php
2 days ago
empsubscrorder.php
2 days ago
index.html
2 days ago
modules.php
2 days ago
order.php
2 days ago
packages.php
2 days ago
packagesconfirm.php
2 days ago
packagesorder.php
2 days ago
servicesearch.php
2 days ago
subscriptions.php
2 days ago
subscrpayment.php
2 days ago
userprofile.php
2 days ago
waitinglist.php
2 days ago
empeditwdays.php
406 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 working days controller. |
| 18 | * |
| 19 | * @since 1.6 |
| 20 | */ |
| 21 | class VikAppointmentsControllerEmpeditwdays 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 | // unset user state for being recovered again |
| 36 | $app->setUserState('vap.emparea.worktime.data', array()); |
| 37 | |
| 38 | // check user permissions |
| 39 | if (!$auth->isEmployee() || !$auth->manageWorkDays()) |
| 40 | { |
| 41 | // back to main list, not authorised to edit records |
| 42 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 43 | $this->cancel(); |
| 44 | |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | $id_service = $app->input->getUint('id_service', 0); |
| 49 | |
| 50 | $this->setRedirect('index.php?option=com_vikappointments&view=empeditwdays' . ($id_service ? '&id_service=' . $id_service : '')); |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Task used to access the management page of an existing record. |
| 57 | * |
| 58 | * @return boolean |
| 59 | * |
| 60 | * @since 1.7 |
| 61 | */ |
| 62 | public function edit() |
| 63 | { |
| 64 | $app = JFactory::getApplication(); |
| 65 | $auth = VAPEmployeeAuth::getInstance(); |
| 66 | |
| 67 | // unset user state for being recovered again |
| 68 | $app->setUserState('vap.emparea.worktime.data', array()); |
| 69 | |
| 70 | // check user permissions |
| 71 | if (!$auth->isEmployee() || !$auth->manageWorkDays()) |
| 72 | { |
| 73 | // back to main list, not authorised to edit records |
| 74 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 75 | $this->cancel(); |
| 76 | |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | $cid = $app->input->getUint('cid', array(0)); |
| 81 | |
| 82 | $id_service = $app->input->getUint('id_service', 0); |
| 83 | |
| 84 | $this->setRedirect('index.php?option=com_vikappointments&view=empeditwdays&cid[]=' . $cid[0] . ($id_service ? '&id_service=' . $id_service : '')); |
| 85 | |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Task used to save the record data set in the request. |
| 91 | * After saving, the user is redirected to the main list. |
| 92 | * |
| 93 | * @return void |
| 94 | * |
| 95 | * @since 1.7 |
| 96 | */ |
| 97 | public function saveclose() |
| 98 | { |
| 99 | if ($this->save()) |
| 100 | { |
| 101 | $this->cancel(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Save employee working day. |
| 107 | * |
| 108 | * @return void |
| 109 | */ |
| 110 | public function save() |
| 111 | { |
| 112 | $app = JFactory::getApplication(); |
| 113 | $input = $app->input; |
| 114 | $auth = VAPEmployeeAuth::getInstance(); |
| 115 | |
| 116 | /** |
| 117 | * Added token validation. |
| 118 | * |
| 119 | * @since 1.7 |
| 120 | */ |
| 121 | if (!JSession::checkToken()) |
| 122 | { |
| 123 | // back to main list, missing CSRF-proof token |
| 124 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 125 | $this->cancel(); |
| 126 | |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | $id_worktime = $input->getUint('id', 0); |
| 131 | |
| 132 | // check user permissions |
| 133 | if (!$auth->manageWorkDays($id_worktime)) |
| 134 | { |
| 135 | // back to main list, not authorised to edit records |
| 136 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 137 | $this->cancel(); |
| 138 | |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | $id_service = $input->getUint('id_service', 0); |
| 143 | |
| 144 | // check user permissions |
| 145 | if ($id_service && !$auth->manageServices($id_service, $readOnly = true)) |
| 146 | { |
| 147 | // back to main list, not authorised to edit records |
| 148 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 149 | $this->cancel(); |
| 150 | |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | $args = array(); |
| 155 | $args['type'] = $input->getUint('type', 1); |
| 156 | $args['day'] = $input->getUint('day', 0); |
| 157 | $args['fromts'] = $input->getUint('fromts'); |
| 158 | $args['endts'] = $input->getUint('endts'); |
| 159 | $args['closed'] = $input->getUint('closed', 0); |
| 160 | $args['date'] = $input->getString('date_from', ''); |
| 161 | $args['date_to'] = $input->getString('date_to', ''); |
| 162 | $args['id_location'] = $input->getUint('id_location', 0); |
| 163 | $args['id'] = $id_worktime; |
| 164 | |
| 165 | if ($id_service) |
| 166 | { |
| 167 | // create/update only for the specified service |
| 168 | $args['id_service'] = $id_service; |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | // join to the specified services |
| 173 | $args['services'] = $input->getUint('services', array()); |
| 174 | } |
| 175 | |
| 176 | // get working day model |
| 177 | $model = $this->getModel(); |
| 178 | |
| 179 | // try to save arguments |
| 180 | $id = $model->save($args); |
| 181 | |
| 182 | if (!$id) |
| 183 | { |
| 184 | // get string error |
| 185 | $error = $model->getError(null, true); |
| 186 | |
| 187 | // display error message |
| 188 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 189 | |
| 190 | $url = 'index.php?option=com_vikappointments&view=empeditwdays'; |
| 191 | |
| 192 | if ($args['id']) |
| 193 | { |
| 194 | $url .= '&cid[]=' . $args['id']; |
| 195 | } |
| 196 | |
| 197 | if ($id_service) |
| 198 | { |
| 199 | $url .= '&id_service=' . $id_service; |
| 200 | } |
| 201 | |
| 202 | // redirect to edit page |
| 203 | $this->setRedirect($url); |
| 204 | |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | // display generic successful message |
| 209 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 210 | |
| 211 | // redirect to edit page |
| 212 | $this->setRedirect('index.php?option=com_vikappointments&task=empeditwdays.edit&cid[]=' . $id . ($id_service ? '&id_service=' . $id_service : '')); |
| 213 | |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Deletes a list of records set in the request. |
| 219 | * |
| 220 | * @return boolean |
| 221 | */ |
| 222 | public function delete() |
| 223 | { |
| 224 | $app = JFactory::getApplication(); |
| 225 | $cid = $app->input->get('cid', array(), 'uint'); |
| 226 | |
| 227 | if ($id = $app->input->getUint('id')) |
| 228 | { |
| 229 | $cid[] = $id; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Added token validation. |
| 234 | * Both GET and POST are supported. |
| 235 | * |
| 236 | * @since 1.7 |
| 237 | */ |
| 238 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 239 | { |
| 240 | // back to main list, missing CSRF-proof token |
| 241 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 242 | $this->cancel(); |
| 243 | |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | try |
| 248 | { |
| 249 | // delete selected records |
| 250 | if ($this->getModel()->delete($cid)) |
| 251 | { |
| 252 | $app->enqueueMessage(JText::translate('VAPEMPWDREMOVED1')); |
| 253 | } |
| 254 | } |
| 255 | catch (Exception $e) |
| 256 | { |
| 257 | // an error occurred |
| 258 | $app->enqueueMessage($e->getMessage(), 'error'); |
| 259 | $this->cancel(); |
| 260 | |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | // back to main list (reset list limit) |
| 265 | $this->cancel(['listlimit' => 0]); |
| 266 | |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Clones the specified working day. |
| 272 | * |
| 273 | * @return void |
| 274 | */ |
| 275 | public function duplicate() |
| 276 | { |
| 277 | $app = JFactory::getApplication(); |
| 278 | $cid = $app->input->get('cid', array(), 'uint'); |
| 279 | |
| 280 | if ($id = $app->input->getUint('id')) |
| 281 | { |
| 282 | $cid[] = $id; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Added token validation. |
| 287 | * Both GET and POST are supported. |
| 288 | * |
| 289 | * @since 1.7 |
| 290 | */ |
| 291 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 292 | { |
| 293 | // back to main list, missing CSRF-proof token |
| 294 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 295 | $this->cancel(); |
| 296 | |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | try |
| 301 | { |
| 302 | // duplicate selected records |
| 303 | if ($this->getModel()->duplicate($cid)) |
| 304 | { |
| 305 | $app->enqueueMessage(JText::translate('VAPEMPWDCREATED1')); |
| 306 | } |
| 307 | } |
| 308 | catch (Exception $e) |
| 309 | { |
| 310 | // an error occurred |
| 311 | $app->enqueueMessage($e->getMessage(), 'error'); |
| 312 | $this->cancel(); |
| 313 | |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | // back to main list |
| 318 | $this->cancel(); |
| 319 | |
| 320 | return true; |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Restores the default working days. |
| 325 | * |
| 326 | * @return void |
| 327 | * |
| 328 | * @since 1.7 |
| 329 | */ |
| 330 | public function restore() |
| 331 | { |
| 332 | $app = JFactory::getApplication(); |
| 333 | |
| 334 | /** |
| 335 | * Added token validation. |
| 336 | * Both GET and POST are supported. |
| 337 | * |
| 338 | * @since 1.7 |
| 339 | */ |
| 340 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 341 | { |
| 342 | // back to main list, missing CSRF-proof token |
| 343 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 344 | $this->cancel(); |
| 345 | |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | $id_service = $app->input->getUint('id_service', 0); |
| 350 | |
| 351 | try |
| 352 | { |
| 353 | if ($this->getModel()->restore($id_service)) |
| 354 | { |
| 355 | $app->enqueueMessage(JText::translate('VAPSERWORKDAYSRESTORED1')); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | $app->enqueueMessage(JText::translate('VAPSERWORKDAYSRESTORED0'), 'warning'); |
| 360 | } |
| 361 | } |
| 362 | catch (Exception $e) |
| 363 | { |
| 364 | // an error occurred |
| 365 | $app->enqueueMessage($e->getMessage(), 'error'); |
| 366 | $this->cancel(); |
| 367 | |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | // back to main list (reset list limit) |
| 372 | $this->cancel(['listlimit' => 0]); |
| 373 | |
| 374 | return true; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Redirects the users to the main records list. |
| 379 | * |
| 380 | * @param array $query An array of query arguments. |
| 381 | * |
| 382 | * @return void |
| 383 | * |
| 384 | * @since 1.7 |
| 385 | */ |
| 386 | public function cancel(array $query = array()) |
| 387 | { |
| 388 | $url = 'index.php?option=com_vikappointments&view=empwdays'; |
| 389 | |
| 390 | $input = JFactory::getApplication()->input; |
| 391 | |
| 392 | if ($id_service = $input->getUint('id_service')) |
| 393 | { |
| 394 | // include service ID in redirect URL |
| 395 | $query['id_service'] = $id_service; |
| 396 | } |
| 397 | |
| 398 | if ($query) |
| 399 | { |
| 400 | $url .= '&' . http_build_query($query); |
| 401 | } |
| 402 | |
| 403 | $this->setRedirect($url); |
| 404 | } |
| 405 | } |
| 406 |