objectonoff.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* Copyright (C) 2015-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/ajax/objectonoff.php
  19. * \brief File to set status for an object
  20. * This Ajax service is called when option MAIN_DIRECT_STATUS_UPDATE is set.
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. }
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1');
  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. if (!defined('NOREQUIRETRAN')) {
  38. define('NOREQUIRETRAN', '1');
  39. }
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
  42. $action = GETPOST('action', 'aZ09');
  43. $id = GETPOST('id', 'int');
  44. $value = GETPOST('value', 'int');
  45. $field = GETPOST('field', 'alpha');
  46. $element = GETPOST('element', 'alpha');
  47. $format = 'int';
  48. $object = new GenericObject($db);
  49. $tablename = $element;
  50. if ($tablename == 'websitepage') {
  51. $tablename = 'website_page';
  52. }
  53. $object->table_element = $tablename;
  54. $object->id = $id;
  55. $object->fields[$field] = array('type' => $format, 'enabled' => 1);
  56. // Security check
  57. if (!empty($user->socid)) {
  58. $socid = $user->socid;
  59. }
  60. //$user->rights->societe->lire = 0;$user->rights->fournisseur->lire = 0;
  61. //restrictedArea($user, 'societe', $id);
  62. if (in_array($field, array('status'))) {
  63. restrictedArea($user, $element, $id);
  64. } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
  65. restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid');
  66. } else {
  67. httponly_accessforbidden("Bad value for combination of parameters element/field.");
  68. }
  69. /*
  70. * View
  71. */
  72. top_httphead();
  73. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  74. // Registering new values
  75. if (($action == 'set') && !empty($id)) {
  76. $triggerkey = strtoupper($element).'_UPDATE';
  77. // Special case
  78. if ($triggerkey == 'SOCIETE_UPDATE') {
  79. $triggerkey = 'COMPANY_MODIFY';
  80. }
  81. if ($triggerkey == 'PRODUCT_UPDATE') {
  82. $triggerkey = 'PRODUCT_MODIFY';
  83. }
  84. $object->setValueFrom($field, $value, $tablename, $id, $format, '', $user, $triggerkey);
  85. }