actions_setmoduleoptions.inc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <http://www.gnu.org/licenses/>.
  16. * or see http://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. $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
  33. if ($result < 0)
  34. {
  35. $ok=false;
  36. break;
  37. }
  38. }
  39. if (! $error)
  40. {
  41. $db->commit();
  42. if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  43. }
  44. else
  45. {
  46. $db->rollback();
  47. if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
  48. }
  49. }
  50. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  51. if ($action == 'setModuleOptions')
  52. {
  53. $db->begin();
  54. // Process common param fields
  55. if (is_array($_POST))
  56. {
  57. foreach($_POST as $key => $val)
  58. {
  59. if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ...
  60. {
  61. $param=GETPOST("param".$reg[1],'alpha');
  62. $value=GETPOST("value".$reg[1],'alpha');
  63. if ($param)
  64. {
  65. $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  66. if (! $res > 0) $error++;
  67. }
  68. }
  69. }
  70. }
  71. // Process upload fields
  72. if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
  73. {
  74. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  75. $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
  76. $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
  77. foreach($listofdir as $key=>$tmpdir)
  78. {
  79. $tmpdir=trim($tmpdir);
  80. $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
  81. if (! $tmpdir) {
  82. unset($listofdir[$key]); continue;
  83. }
  84. if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
  85. else
  86. {
  87. $upload_dir=$tmpdir;
  88. }
  89. }
  90. if ($upload_dir)
  91. {
  92. $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
  93. if ($result <= 0) $error++;
  94. }
  95. }
  96. if (! $error)
  97. {
  98. $db->commit();
  99. if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  100. }
  101. else
  102. {
  103. $db->rollback();
  104. if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
  105. }
  106. }