ajax.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/public/ticket/ajax/ajax.php
  20. * \brief Ajax component for Ticket.
  21. *
  22. * This ajax component is called only by the create ticket public page. And only if TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST is set.
  23. * This option TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST has been removed because it is a security hole.
  24. */
  25. if (!defined('NOTOKENRENEWAL')) {
  26. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1');
  30. }
  31. if (!defined('NOREQUIREAJAX')) {
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. if (!defined('NOREQUIRESOC')) {
  35. define('NOREQUIRESOC', '1');
  36. }
  37. // You can get information if module "Agenda" has been enabled by reading the
  38. if (!defined('NOREQUIREMENU')) {
  39. define('NOREQUIREMENU', '1');
  40. }
  41. if (!defined("NOLOGIN")) {
  42. define("NOLOGIN", '1');
  43. }
  44. if (!defined('NOIPCHECK')) {
  45. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  46. }
  47. if (!defined('NOBROWSERNOTIF')) {
  48. define('NOBROWSERNOTIF', '1');
  49. }
  50. include_once '../../../main.inc.php'; // Load $user and permissions
  51. $action = GETPOST('action', 'aZ09');
  52. $id = GETPOST('id', 'int');
  53. $email = GETPOST('email', 'custom', 0, FILTER_VALIDATE_EMAIL);
  54. if (!isModEnabled('ticket')) {
  55. httponly_accessforbidden('Module Ticket not enabled');
  56. }
  57. if (empty($conf->global->TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST)) {
  58. httponly_accessforbidden('Option TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST of module ticket is not enabled');
  59. }
  60. /*
  61. * View
  62. */
  63. top_httphead();
  64. if ($action == 'getContacts') {
  65. $return = array(
  66. 'contacts' => array(),
  67. 'error' => '',
  68. );
  69. if (!empty($email)) {
  70. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  71. $ticket = new Ticket($db);
  72. $arrayofcontacts = $ticket->searchContactByEmail($email);
  73. if (is_array($arrayofcontacts)) {
  74. $arrayofminimalcontacts = array();
  75. foreach ($arrayofcontacts as $tmpval) {
  76. $tmpresult = new stdClass();
  77. $tmpresult->id = $tmpval->id;
  78. $tmpresult->firstname = $tmpval->firstname;
  79. $tmpresult->lastname = $tmpval->lastname;
  80. $arrayofminimalcontacts[] = $tmpresult;
  81. }
  82. $return['contacts'] = $arrayofminimalcontacts;
  83. } else {
  84. $return['error'] = $ticket->errorsToString();
  85. }
  86. }
  87. echo json_encode($return);
  88. exit();
  89. }