objectonoff.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // Load Dolibarr environment
  41. require '../../main.inc.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
  43. $action = GETPOST('action', 'aZ09');
  44. $id = GETPOST('id', 'int');
  45. $value = GETPOST('value', 'int');
  46. $field = GETPOST('field', 'alpha');
  47. $element = GETPOST('element', 'alpha');
  48. $format = 'int';
  49. $object = new GenericObject($db);
  50. $tablename = $element;
  51. if ($tablename == 'websitepage') {
  52. $tablename = 'website_page';
  53. }
  54. $object->table_element = $tablename;
  55. $object->id = $id;
  56. $object->fields[$field] = array('type' => $format, 'enabled' => 1);
  57. // Security check
  58. if (!empty($user->socid)) {
  59. $socid = $user->socid;
  60. }
  61. //$user->hasRight('societe', 'lire') = 0;$user->rights->fournisseur->lire = 0;
  62. //restrictedArea($user, 'societe', $id);
  63. if (in_array($field, array('status'))) {
  64. restrictedArea($user, $element, $id);
  65. } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
  66. restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid');
  67. } else {
  68. httponly_accessforbidden("Bad value for combination of parameters element/field.");
  69. }
  70. /*
  71. * View
  72. */
  73. top_httphead();
  74. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  75. // Registering new values
  76. if (($action == 'set') && !empty($id)) {
  77. $triggerkey = strtoupper($element).'_UPDATE';
  78. // Special case
  79. if ($triggerkey == 'SOCIETE_UPDATE') {
  80. $triggerkey = 'COMPANY_MODIFY';
  81. }
  82. if ($triggerkey == 'PRODUCT_UPDATE') {
  83. $triggerkey = 'PRODUCT_MODIFY';
  84. }
  85. $object->setValueFrom($field, $value, $tablename, $id, $format, '', $user, $triggerkey);
  86. }