dolibarr  7.0.0-beta
actions_setmoduleoptions.inc.php
Go to the documentation of this file.
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 
25 // $action must be defined
26 // $arrayofparameters must be set for action 'update'
27 // $nomessageinupdate can be set to 1
28 // $nomessageinsetmoduleoptions can be set to 1
29 
30 if ($action == 'update' && is_array($arrayofparameters))
31 {
32  $db->begin();
33 
34  $ok=True;
35  foreach($arrayofparameters as $key => $val)
36  {
37  $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
38  if ($result < 0)
39  {
40  $ok=False;
41  break;
42  }
43  }
44 
45  if (! $error)
46  {
47  $db->commit();
48  if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
49  }
50  else
51  {
52  $db->rollback();
53  if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
54  }
55 }
56 
57 // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
58 if ($action == 'setModuleOptions')
59 {
60  $db->begin();
61 
62  // Process common param fields
63  if (is_array($_POST))
64  {
65  foreach($_POST as $key => $val)
66  {
67  if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ...
68  {
69  $param=GETPOST("param".$reg[1],'alpha');
70  $value=GETPOST("value".$reg[1],'alpha');
71  if ($param)
72  {
73  $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
74  if (! $res > 0) $error++;
75  }
76  }
77  }
78  }
79 
80  // Process upload fields
81  if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
82  {
83  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
84  $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
85  $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
86  foreach($listofdir as $key=>$tmpdir)
87  {
88  $tmpdir=trim($tmpdir);
89  $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
90  if (! $tmpdir) {
91  unset($listofdir[$key]); continue;
92  }
93  if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
94  else
95  {
96  $upload_dir=$tmpdir;
97  }
98  }
99  if ($upload_dir)
100  {
101  $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
102  if ($result <= 0) $error++;
103  }
104  }
105 
106  if (! $error)
107  {
108  $db->commit();
109  if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
110  }
111  else
112  {
113  $db->rollback();
114  if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
115  }
116 }
117 
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:485
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1)
Get and save an upload file (for example after submitting a new file a mail form).
Definition: files.lib.php:1478