Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
4.0KB

  1. <?php
  2. /**
  3. * @param $ticket_request CreateTicketForCustomerModel
  4. */
  5. function create_ticket_for_customer($ticket_request, $hesk_settings, $modsForHesk_settings) {
  6. validate($ticket_request, false, $hesk_settings, $modsForHesk_settings);
  7. }
  8. /**
  9. * @param $ticket_request CreateTicketForCustomerModel
  10. * @param $staff bool
  11. * @return ValidationModel If errorKeys is empty, validation successful. Otherwise invalid ticket
  12. */
  13. function validate($ticket_request, $staff, $hesk_settings, $modsForHesk_settings) {
  14. require_once('../email_validators.php');
  15. //require_once('../category/retriever.php');
  16. //require_once('../bans/retriever.php');
  17. $TICKET_PRIORITY_CRITICAL = 0;
  18. $validationModel = new ValidationModel();
  19. if ($ticket_request->name === NULL || $ticket_request->name == '') {
  20. $validationModel->errorKeys[] = 'NO_NAME';
  21. }
  22. if (hesk_validateEmail($ticket_request->email, $hesk_settings['multi_eml'], false)) {
  23. $validationModel->errorKeys[] = 'INVALID_OR_MISSING_EMAIL';
  24. }
  25. if (intval($ticket_request->category) === 0) {
  26. // TODO add support for invalid category ID
  27. $validationModel->errorKeys[] = 'NO_CATEGORY';
  28. }
  29. // Don't allow critical priority tickets
  30. if ($hesk_settings['cust_urgency'] && intval($ticket_request->priority) === $TICKET_PRIORITY_CRITICAL) {
  31. $validationModel->errorKeys[] = 'CRITICAL_PRIORITY_FORBIDDEN';
  32. }
  33. if ($hesk_settings['require_subject'] === 1 &&
  34. ($ticket_request->subject === NULL || $ticket_request->subject === '')) {
  35. $validationModel->errorKeys[] = 'SUBJECT_REQUIRED';
  36. }
  37. if ($hesk_settings['require_message'] === 1 &&
  38. ($ticket_request->message === NULL || $ticket_request->message === '')) {
  39. $validationModel->errorKeys[] = 'MESSAGE_REQUIRED';
  40. }
  41. foreach ($hesk_settings['custom_fields'] as $key => $value) {
  42. // TODO Only check categories that apply to this custom field
  43. if ($value['use'] == 1 && hesk_is_custom_field_in_category($key, intval($ticket_request->category))) {
  44. $custom_field_value = $ticket_request->customFields[$key];
  45. if (empty($custom_field_value)) {
  46. $validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::NO_VALUE';
  47. continue;
  48. }
  49. switch($v['type']) {
  50. case 'date':
  51. if (!preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $custom_field_value)) {
  52. $validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::INVALID_DATE';
  53. } else {
  54. // Actually validate based on range
  55. $date = strtotime($custom_field_value . ' t00:00:00');
  56. $dmin = strlen($value['value']['dmin']) ? strtotime($value['value']['dmin'] . ' t00:00:00') : false;
  57. $dmax = strlen($value['value']['dmax']) ? strtotime($value['value']['dmax'] . ' t00:00:00') : false;
  58. if ($dmin && $dmin > $date) {
  59. $validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::DATE_BEFORE_MIN::MIN-' . $dmin . '::ENTERED-' . $date;
  60. } elseif ($dmax && $dmax < $date) {
  61. $validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::DATE_AFTER_MAX::MAX-' . $dmax . '::ENTERED-' . $date;
  62. }
  63. }
  64. break;
  65. case 'email':
  66. if (!hesk_validateEmail($custom_field_value, $value['value']['multiple'], false)) {
  67. $validationModel->errorKeys[] = 'CUSTOM_FIELD_' . $key . '_INVALID::INVALID_OR_MISSING_EMAIL';
  68. }
  69. break;
  70. }
  71. }
  72. }
  73. // TODO Check bans (email only; don't check IP on REST requests as they'll most likely be sent via servers)
  74. // TODO submit_ticket.php:320-322
  75. // TODO Check if we're at the max number of tickets
  76. // TODO submit_ticket.php:325-334
  77. return $validationModel;
  78. }