ajaxstatusprospect.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2010 Cyrille de Lambert <info@auguria.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/ajax/ajaxstatusprospect.php
  22. * \brief File to return Ajax response on third parties request
  23. */
  24. if (!defined('NOTOKENRENEWAL')) {
  25. define('NOTOKENRENEWAL', 1);
  26. } // Disables token renewal
  27. if (!defined('NOREQUIREMENU')) {
  28. define('NOREQUIREMENU', '1');
  29. }
  30. if (!defined('NOREQUIREHTML')) {
  31. define('NOREQUIREHTML', '1');
  32. }
  33. if (!defined('NOREQUIREAJAX')) {
  34. define('NOREQUIREAJAX', '1');
  35. }
  36. if (!defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  42. $idstatus = GETPOST('id', 'int');
  43. $idprospect = GETPOST('prospectid', 'int');
  44. $action = GETPOST('action', 'aZ09');
  45. $prospectstatic = new Client($db);
  46. // Security check
  47. if ($user->socid > 0) {
  48. if ($idprospect != $user->socid) {
  49. accessforbidden('Not allowed on this thirdparty');
  50. }
  51. }
  52. // var_dump( $user, 'societe', $idprospect, '&societe');
  53. $result = restrictedArea($user, 'societe', $idprospect, '&societe');
  54. $permisstiontoupdate = $user->hasRight('societe', 'creer');
  55. /*
  56. * View
  57. */
  58. top_httphead('application/json');
  59. if ($action === "updatestatusprospect" && $permisstiontoupdate) {
  60. $prospectstatic->client = 2;
  61. $prospectstatic->loadCacheOfProspStatus();
  62. $response = '';
  63. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
  64. $sql .= "fk_stcomm=".(int) $db->escape($idstatus);
  65. $sql .= " WHERE rowid = ".(int) $db->escape($idprospect);
  66. $resql = $db->query($sql);
  67. if (!$resql) {
  68. dol_print_error($db);
  69. } else {
  70. $num = $db->affected_rows($resql);
  71. $response = img_action('', $prospectstatic->cacheprospectstatus[$idstatus]['code'], $prospectstatic->cacheprospectstatus[$idstatus]['picto'], 'class="inline-block valignmiddle paddingright pictoprospectstatus"');
  72. }
  73. echo json_encode(array('img' => $response));
  74. }