analytics.php
4 years ago
apiban.php
4 years ago
apilog.php
4 years ago
apiplugin.php
4 years ago
apiuser.php
4 years ago
backup.php
4 years ago
calendar.php
4 years ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
2 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
1 month ago
conversion.php
1 year ago
country.php
4 years ago
coupon.php
4 years ago
coupongroup.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
5 months ago
customf.php
1 year ago
dashboard.php
4 years ago
emplocwdays.php
4 years ago
employee.php
1 year ago
emprates.php
4 years ago
export.php
4 years ago
exportres.php
4 years ago
file.php
5 months ago
findreservation.php
1 month ago
group.php
4 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
4 years ago
langoptiongroup.php
4 years ago
langpackage.php
4 years ago
langpackgroup.php
4 years ago
langpayment.php
4 years ago
langservice.php
4 years ago
langstatuscode.php
4 years ago
langsubscr.php
4 years ago
langtax.php
4 years ago
location.php
4 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
4 years ago
multiorder.php
4 years ago
option.php
5 months ago
optiongroup.php
4 years ago
package.php
2 years ago
packgroup.php
4 years ago
packorder.php
1 year ago
payment.php
4 years ago
rate.php
4 years ago
reportsemp.php
4 years ago
reportsser.php
4 years ago
reservation.php
1 month ago
restriction.php
4 years ago
review.php
4 years ago
service.php
1 year ago
serworkday.php
5 months ago
state.php
4 years ago
statuscode.php
4 years ago
subscription.php
4 years ago
subscrorder.php
4 years ago
tag.php
4 years ago
tax.php
4 years ago
usernote.php
4 years ago
waitinglist.php
4 years ago
webhook.php
4 years ago
wizard.php
1 year ago
usernote.php
540 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.mvc.controllers.admin'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments user note controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerUsernote extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Task used to access the creation page of a new record. |
| 25 | * |
| 26 | * @return boolean |
| 27 | */ |
| 28 | public function add() |
| 29 | { |
| 30 | $app = JFactory::getApplication(); |
| 31 | $user = JFactory::getUser(); |
| 32 | |
| 33 | $data = array(); |
| 34 | |
| 35 | // preserve user ID, if set |
| 36 | $id_user = $app->input->getUint('id_user', 0); |
| 37 | |
| 38 | if ($id_user > 0) |
| 39 | { |
| 40 | $data['id_user'] = $id_user; |
| 41 | } |
| 42 | |
| 43 | // preserve parent ID, if set |
| 44 | $id_parent = $app->input->getUint('id_parent', 0); |
| 45 | |
| 46 | if ($id_parent > 0) |
| 47 | { |
| 48 | $data['id_parent'] = $id_parent; |
| 49 | } |
| 50 | |
| 51 | // preserve note group, if set |
| 52 | $group = $app->input->getString('group', ''); |
| 53 | |
| 54 | if ($group) |
| 55 | { |
| 56 | $data['group'] = $group; |
| 57 | } |
| 58 | |
| 59 | // unset user state for being recovered again |
| 60 | $app->setUserState('vap.usernote.data', $data); |
| 61 | |
| 62 | // check if we should use a blank template |
| 63 | $blank = $app->input->get('tmpl') === 'component'; |
| 64 | |
| 65 | // check user permissions |
| 66 | if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.customers', 'com_vikappointments')) |
| 67 | { |
| 68 | if ($blank) |
| 69 | { |
| 70 | // throw exception in order to avoid unexpected behaviors |
| 71 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), '403'); |
| 72 | } |
| 73 | |
| 74 | // back to main list, not authorised to create records |
| 75 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 76 | $this->cancel(); |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | $this->setRedirect('index.php?option=com_vikappointments&view=manageusernote' . ($blank ? '&tmpl=component' : '')); |
| 82 | |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Task used to access the management page of an existing record. |
| 88 | * |
| 89 | * @return boolean |
| 90 | */ |
| 91 | public function edit() |
| 92 | { |
| 93 | $app = JFactory::getApplication(); |
| 94 | $user = JFactory::getUser(); |
| 95 | |
| 96 | // unset user state for being recovered again |
| 97 | $app->setUserState('vap.usernote.data', array()); |
| 98 | |
| 99 | // check if we should use a blank template |
| 100 | $blank = $app->input->get('tmpl') === 'component'; |
| 101 | |
| 102 | // check user permissions |
| 103 | if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.customers', 'com_vikappointments')) |
| 104 | { |
| 105 | if ($blank) |
| 106 | { |
| 107 | // throw exception in order to avoid unexpected behaviors |
| 108 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), '403'); |
| 109 | } |
| 110 | |
| 111 | // back to main list, not authorised to edit records |
| 112 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 113 | $this->cancel(); |
| 114 | |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | $cid = $app->input->getUint('cid', array(0)); |
| 119 | |
| 120 | $this->setRedirect('index.php?option=com_vikappointments&view=manageusernote&cid[]=' . $cid[0] . ($blank ? '&tmpl=component' : '')); |
| 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Task used to save the record data set in the request. |
| 127 | * After saving, the user is redirected to the main list. |
| 128 | * |
| 129 | * @return void |
| 130 | */ |
| 131 | public function saveclose() |
| 132 | { |
| 133 | if ($this->save()) |
| 134 | { |
| 135 | $this->cancel(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Task used to save the record data set in the request. |
| 141 | * After saving, the user is redirected to the creation |
| 142 | * page of a new record. |
| 143 | * |
| 144 | * @return void |
| 145 | */ |
| 146 | public function savenew() |
| 147 | { |
| 148 | if ($this->save()) |
| 149 | { |
| 150 | $app = JFactory::getApplication(); |
| 151 | |
| 152 | $url = ''; |
| 153 | |
| 154 | // preserve user ID, if set |
| 155 | $id_user = $app->input->getUint('id_user', 0); |
| 156 | |
| 157 | if ($id_user > 0) |
| 158 | { |
| 159 | $url .= '&id_user=' . $id_user; |
| 160 | } |
| 161 | |
| 162 | // preserve parent ID, if set |
| 163 | $id_parent = $app->input->getUint('id_parent', 0); |
| 164 | |
| 165 | if ($id_parent > 0) |
| 166 | { |
| 167 | $url .= '&id_parent=' . $id_parent; |
| 168 | } |
| 169 | |
| 170 | // preserve note group, if set |
| 171 | $group = $app->input->getString('group', ''); |
| 172 | |
| 173 | if ($group) |
| 174 | { |
| 175 | $url .= '&group=' . $group; |
| 176 | } |
| 177 | |
| 178 | if ($url) |
| 179 | { |
| 180 | $this->setRedirect('index.php?option=com_vikappointments&task=usernote.add' . $url); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | $this->cancel(); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Task used to save the record data set in the request. |
| 191 | * After saving, the user is redirected to the management |
| 192 | * page of the record that has been saved. |
| 193 | * |
| 194 | * @param boolean $copy True to save the record as a copy. |
| 195 | * |
| 196 | * @return boolean |
| 197 | */ |
| 198 | public function save($copy = false) |
| 199 | { |
| 200 | $app = JFactory::getApplication(); |
| 201 | $input = $app->input; |
| 202 | $user = JFactory::getUser(); |
| 203 | |
| 204 | /** |
| 205 | * Added token validation. |
| 206 | * |
| 207 | * @since 1.7 |
| 208 | */ |
| 209 | if (!JSession::checkToken()) |
| 210 | { |
| 211 | // back to main list, missing CSRF-proof token |
| 212 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 213 | $this->cancel(); |
| 214 | |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | $args = array(); |
| 219 | $args['title'] = $input->getString('title', ''); |
| 220 | $args['content'] = JComponentHelper::filterText($input->getRaw('usernote_content', '')); |
| 221 | $args['status'] = $input->getUint('status', 0); |
| 222 | $args['tags'] = $input->getString('tags', ''); |
| 223 | $args['attachments'] = $input->getString('attachments', array()); |
| 224 | $args['notifycust'] = $input->getBool('notifycust', 0); |
| 225 | $args['id_user'] = $input->getUint('id_user', 0); |
| 226 | $args['id_parent'] = $input->getUint('id_parent', 0); |
| 227 | $args['group'] = $input->getString('group', ''); |
| 228 | $args['id'] = $input->getUint('id', 0); |
| 229 | |
| 230 | $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create'); |
| 231 | |
| 232 | // check if we should use a blank template |
| 233 | $blank = $app->input->get('tmpl') === 'component'; |
| 234 | |
| 235 | // check user permissions |
| 236 | if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.customers', 'com_vikappointments')) |
| 237 | { |
| 238 | if ($blank) |
| 239 | { |
| 240 | // throw exception in order to avoid unexpected behaviors |
| 241 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), '403'); |
| 242 | } |
| 243 | |
| 244 | // back to main list, not authorised to create/edit records |
| 245 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 246 | $this->cancel(); |
| 247 | |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | // get user note model |
| 252 | $usernote = $this->getModel(); |
| 253 | |
| 254 | // try to save arguments |
| 255 | $id = $usernote->save($args); |
| 256 | |
| 257 | if (!$id) |
| 258 | { |
| 259 | // get string error |
| 260 | $error = $usernote->getError(null, true); |
| 261 | |
| 262 | // display error message |
| 263 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 264 | |
| 265 | $url = 'index.php?option=com_vikappointments&view=manageusernote'; |
| 266 | |
| 267 | if ($args['id']) |
| 268 | { |
| 269 | $url .= '&cid[]=' . $args['id']; |
| 270 | } |
| 271 | |
| 272 | if ($blank) |
| 273 | { |
| 274 | $url .= '&tmpl=component'; |
| 275 | } |
| 276 | |
| 277 | // redirect to new/edit page |
| 278 | $this->setRedirect($url); |
| 279 | |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | // display generic successful message |
| 284 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 285 | |
| 286 | // redirect to edit page |
| 287 | $this->setRedirect('index.php?option=com_vikappointments&task=usernote.edit&cid[]=' . $id . ($blank ? '&tmpl=component' : '')); |
| 288 | |
| 289 | return true; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Deletes a list of records set in the request. |
| 294 | * |
| 295 | * @return boolean |
| 296 | */ |
| 297 | public function delete() |
| 298 | { |
| 299 | $app = JFactory::getApplication(); |
| 300 | $user = JFactory::getUser(); |
| 301 | |
| 302 | /** |
| 303 | * Added token validation. |
| 304 | * Both GET and POST are supported. |
| 305 | * |
| 306 | * @since 1.7 |
| 307 | */ |
| 308 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 309 | { |
| 310 | // back to main list, missing CSRF-proof token |
| 311 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 312 | $this->cancel(); |
| 313 | |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | $cid = $app->input->get('cid', array(), 'uint'); |
| 318 | |
| 319 | // check user permissions |
| 320 | if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.customers', 'com_vikappointments')) |
| 321 | { |
| 322 | // back to main list, not authorised to delete records |
| 323 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 324 | $this->cancel(); |
| 325 | |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | // delete selected records |
| 330 | $this->getModel()->delete($cid); |
| 331 | |
| 332 | // back to main list |
| 333 | $this->cancel(); |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Redirects the users to the main records list. |
| 340 | * |
| 341 | * @return void |
| 342 | */ |
| 343 | public function cancel() |
| 344 | { |
| 345 | $app = JFactory::getApplication(); |
| 346 | |
| 347 | $url = ''; |
| 348 | |
| 349 | // preserve user ID, if set |
| 350 | $id_user = $app->input->getUint('id_user', 0); |
| 351 | |
| 352 | if ($id_user > 0) |
| 353 | { |
| 354 | $url .= '&id_user=' . $id_user; |
| 355 | } |
| 356 | |
| 357 | // preserve parent ID, if set |
| 358 | $id_parent = $app->input->getUint('id_parent', 0); |
| 359 | |
| 360 | if ($id_parent > 0) |
| 361 | { |
| 362 | $url .= '&id_parent=' . $id_parent; |
| 363 | } |
| 364 | |
| 365 | // preserve note group, if set |
| 366 | $group = $app->input->getString('group', ''); |
| 367 | |
| 368 | if ($group) |
| 369 | { |
| 370 | $url .= '&group=' . $group; |
| 371 | } |
| 372 | |
| 373 | if ($url) |
| 374 | { |
| 375 | $this->setRedirect('index.php?option=com_vikappointments&view=usernotes' . $url); |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | $this->setRedirect('index.php?option=com_vikappointments&view=customers'); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Redirects the users to the parent page. |
| 385 | * |
| 386 | * @return void |
| 387 | */ |
| 388 | public function back() |
| 389 | { |
| 390 | $app = JFactory::getApplication(); |
| 391 | |
| 392 | $group = $app->input->getString('group', ''); |
| 393 | $id_parent = $app->input->getUint('id_parent', 0); |
| 394 | |
| 395 | if ($group == 'appointments') |
| 396 | { |
| 397 | // go to appointment management page |
| 398 | $this->setRedirect('index.php?option=com_vikappointments&task=reservation.edit&cid[]=' . $id_parent); |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | // go to customers page |
| 403 | $this->setRedirect('index.php?option=com_vikappointments&view=customers'); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Task used to upload files via AJAX. |
| 409 | * |
| 410 | * @return void |
| 411 | */ |
| 412 | public function dropupload() |
| 413 | { |
| 414 | $input = JFactory::getApplication()->input; |
| 415 | |
| 416 | /** |
| 417 | * Added token validation. |
| 418 | * |
| 419 | * @since 1.7 |
| 420 | */ |
| 421 | if (!JSession::checkToken()) |
| 422 | { |
| 423 | // missing CSRF-proof token |
| 424 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 425 | } |
| 426 | |
| 427 | $args = array(); |
| 428 | $args['file'] = 'file'; |
| 429 | $args['path'] = $input->get('path', null, 'base64'); |
| 430 | |
| 431 | if (!$args['path']) |
| 432 | { |
| 433 | // path not found, create it |
| 434 | $id_note = $input->get('id_note', 0, 'uint'); |
| 435 | |
| 436 | $options = array(); |
| 437 | $options['id_user'] = $input->get('id_user', 0, 'uint'); |
| 438 | $options['id_parent'] = $input->get('id_parent', 0, 'uint'); |
| 439 | $options['group'] = $input->get('group', '', 'string'); |
| 440 | |
| 441 | try |
| 442 | { |
| 443 | // get uploads path |
| 444 | $args['path'] = $this->getModel()->getUploadsPath($id_note, $options); |
| 445 | } |
| 446 | catch (Exception $e) |
| 447 | { |
| 448 | // unable to create uploads path, raise error |
| 449 | UIErrorFactory::raiseError($e->getCode(), $e->getMessage()); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | // get media model |
| 454 | $media = $this->getModel('media'); |
| 455 | |
| 456 | // try to upload file |
| 457 | $id = $media->save($args); |
| 458 | |
| 459 | if ($id === false) |
| 460 | { |
| 461 | // get string error |
| 462 | $error = $media->getError(null, true); |
| 463 | |
| 464 | // something went wrong, raise error |
| 465 | UIErrorFactory::raiseError(500, $error); |
| 466 | } |
| 467 | |
| 468 | // get saved data |
| 469 | $data = $media->getData(); |
| 470 | |
| 471 | // in case of success, retrieve media properties |
| 472 | $resp = AppointmentsHelper::getFileProperties($data['file']); |
| 473 | |
| 474 | if ($resp) |
| 475 | { |
| 476 | // include HTML preview of the media file |
| 477 | $resp['html'] = $media->renderMedia($resp['file']); |
| 478 | } |
| 479 | |
| 480 | $this->sendJSON($resp); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * AJAX end-point used to auto-save the user notes. |
| 485 | * |
| 486 | * @return void |
| 487 | */ |
| 488 | public function savedraftajax() |
| 489 | { |
| 490 | $app = JFactory::getApplication(); |
| 491 | $input = $app->input; |
| 492 | $user = JFactory::getUser(); |
| 493 | |
| 494 | /** |
| 495 | * Added token validation. |
| 496 | * |
| 497 | * @since 1.7 |
| 498 | */ |
| 499 | if (!JSession::checkToken()) |
| 500 | { |
| 501 | // missing CSRF-proof token |
| 502 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 503 | } |
| 504 | |
| 505 | $args = array(); |
| 506 | $args['content'] = $input->get('draft', '', 'string'); |
| 507 | $args['status'] = $input->get('status', 0, 'uint'); |
| 508 | $args['tags'] = $input->get('tags', array(), 'string'); |
| 509 | $args['id_user'] = $input->get('id_user', 0, 'uint'); |
| 510 | $args['id_parent'] = $input->get('id_parent', 0, 'uint'); |
| 511 | $args['group'] = $input->get('group', '', 'string'); |
| 512 | $args['id'] = $input->get('id', 0, 'uint'); |
| 513 | |
| 514 | $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create'); |
| 515 | |
| 516 | // check user permissions |
| 517 | if (!$user->authorise($rule, 'com_vikappointments')) |
| 518 | { |
| 519 | // raise AJAX error, not authorised to edit records |
| 520 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 521 | } |
| 522 | |
| 523 | // get user note model |
| 524 | $model = $this->getModel(); |
| 525 | |
| 526 | // try to save arguments |
| 527 | if (!$model->saveDraft($args)) |
| 528 | { |
| 529 | // get string error |
| 530 | $error = $model->getError(null, true); |
| 531 | |
| 532 | // raise returned error while saving the record |
| 533 | UIErrorFactory::raiseError(500, $error); |
| 534 | } |
| 535 | |
| 536 | // send response to caller |
| 537 | $this->sendJSON($model->getData()); |
| 538 | } |
| 539 | } |
| 540 |