actions_setmoduleoptions.inc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* Copyright (C) 2014-2017 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. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/actions_setmoduleoptions.inc.php
  20. * \brief Code for actions on setting notes of object page
  21. */
  22. // $action must be defined
  23. // $arrayofparameters must be set for action 'update'
  24. // $nomessageinupdate can be set to 1
  25. // $nomessageinsetmoduleoptions can be set to 1
  26. if ($action == 'update' && is_array($arrayofparameters))
  27. {
  28. $db->begin();
  29. $ok = true;
  30. foreach ($arrayofparameters as $key => $val)
  31. {
  32. // Modify constant only if key was posted (avoid resetting key to the null value)
  33. if (GETPOSTISSET($key))
  34. {
  35. $result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity);
  36. if ($result < 0)
  37. {
  38. $ok = false;
  39. break;
  40. }
  41. }
  42. }
  43. if (!$error)
  44. {
  45. $db->commit();
  46. if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  47. }
  48. else
  49. {
  50. $db->rollback();
  51. if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
  52. }
  53. }
  54. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  55. if ($action == 'setModuleOptions')
  56. {
  57. $db->begin();
  58. // Process common param fields
  59. if (is_array($_POST))
  60. {
  61. foreach ($_POST as $key => $val)
  62. {
  63. $reg = array();
  64. if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ...
  65. {
  66. $param = GETPOST("param".$reg[1], 'alpha');
  67. $value = GETPOST("value".$reg[1], 'alpha');
  68. if ($param)
  69. {
  70. $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity);
  71. if (!$res > 0) $error++;
  72. }
  73. }
  74. }
  75. }
  76. // Process upload fields
  77. if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09'))
  78. {
  79. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  80. $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09');
  81. $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir)));
  82. foreach ($listofdir as $key=>$tmpdir)
  83. {
  84. $tmpdir = trim($tmpdir);
  85. $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
  86. if (!$tmpdir) {
  87. unset($listofdir[$key]); continue;
  88. }
  89. if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
  90. else
  91. {
  92. $upload_dir = $tmpdir;
  93. }
  94. }
  95. if ($upload_dir)
  96. {
  97. $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
  98. if ($result <= 0) $error++;
  99. }
  100. }
  101. if (!$error)
  102. {
  103. $db->commit();
  104. if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  105. }
  106. else
  107. {
  108. $db->rollback();
  109. if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
  110. }
  111. }