objectonoff.php 2.8 KB

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