dolibarr/htdocs/core/actions_setmoduleoptions.inc.php

128 lines
3.8 KiB
PHP
Raw Normal View History

<?php
2017-08-26 15:22:13 +02:00
/* Copyright (C) 2014-2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
2017-08-26 15:22:13 +02:00
* \file htdocs/core/actions_setmoduleoptions.inc.php
* \brief Code for actions on setting notes of object page
*/
2021-01-21 13:50:31 +01:00
// $error must have been initialized to 0
// $action must be defined
2017-08-26 15:22:13 +02:00
// $arrayofparameters must be set for action 'update'
// $nomessageinupdate can be set to 1
// $nomessageinsetmoduleoptions can be set to 1
2021-02-23 22:03:23 +01:00
if ($action == 'update' && is_array($arrayofparameters)) {
2017-08-26 15:22:13 +02:00
$db->begin();
2021-02-23 22:03:23 +01:00
foreach ($arrayofparameters as $key => $val) {
// Modify constant only if key was posted (avoid resetting key to the null value)
2021-02-23 22:03:23 +01:00
if (GETPOSTISSET($key)) {
2021-03-29 17:26:43 +02:00
if (preg_match('/category:/', $val['type'])) {
if (GETPOST($key, 'int') == '-1') {
$val_const = '';
} else {
$val_const = GETPOST($key, 'int');
}
} else {
$val_const = GETPOST($key, 'alpha');
}
$result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity);
2021-02-23 22:03:23 +01:00
if ($result < 0) {
2021-01-21 13:50:31 +01:00
$error++;
break;
}
2017-08-26 15:22:13 +02:00
}
}
2021-02-23 22:03:23 +01:00
if (!$error) {
2017-08-26 15:22:13 +02:00
$db->commit();
2021-02-23 22:03:23 +01:00
if (empty($nomessageinupdate)) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
2020-05-21 15:05:19 +02:00
} else {
2017-08-26 15:22:13 +02:00
$db->rollback();
2021-02-23 22:03:23 +01:00
if (empty($nomessageinupdate)) {
setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
}
2017-08-26 15:22:13 +02:00
}
}
// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
2021-02-23 22:03:23 +01:00
if ($action == 'setModuleOptions') {
$db->begin();
// Process common param fields
2021-02-23 22:03:23 +01:00
if (is_array($_POST)) {
foreach ($_POST as $key => $val) {
$reg = array();
2021-02-23 22:03:23 +01:00
if (preg_match('/^param(\d*)$/', $key, $reg)) { // Works for POST['param'], POST['param1'], POST['param2'], ...
$param = GETPOST("param".$reg[1], 'alpha');
$value = GETPOST("value".$reg[1], 'alpha');
2021-02-23 22:03:23 +01:00
if ($param) {
$res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity);
2021-02-23 22:03:23 +01:00
if (!($res > 0)) {
$error++;
}
}
}
}
}
// Process upload fields
2021-02-23 22:03:23 +01:00
if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09')) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09');
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir)));
2021-02-23 22:03:23 +01:00
foreach ($listofdir as $key => $tmpdir) {
$tmpdir = trim($tmpdir);
$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (!$tmpdir) {
2021-03-01 20:37:16 +01:00
unset($listofdir[$key]);
continue;
}
2021-01-21 13:50:31 +01:00
if (!is_dir($tmpdir)) {
if (empty($nomessageinsetmoduleoptions)) {
setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings');
}
2021-02-23 22:03:23 +01:00
} else {
$upload_dir = $tmpdir;
}
}
2021-02-23 22:03:23 +01:00
if ($upload_dir) {
2020-11-14 00:48:13 +01:00
$result = dol_add_file_process($upload_dir, 1, 1, 'uploadfile', '');
2021-02-23 22:03:23 +01:00
if ($result <= 0) {
$error++;
}
}
}
2021-02-23 22:03:23 +01:00
if (!$error) {
$db->commit();
2021-02-23 22:03:23 +01:00
if (empty($nomessageinsetmoduleoptions)) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
} else {
$db->rollback();
2021-02-23 22:03:23 +01:00
if (empty($nomessageinsetmoduleoptions)) {
setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
}
}
}