dolibarr  16.0.5
const.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 
30 // Load translation files required by the page
31 $langs->load("admin");
32 
33 if (!$user->admin) {
35 }
36 
37 $rowid = GETPOST('rowid', 'int');
38 $entity = GETPOST('entity', 'int');
39 $action = GETPOST('action', 'aZ09');
40 $debug = GETPOST('debug', 'int');
41 $consts = GETPOST('const', 'array');
42 $constname = GETPOST('constname', 'alphanohtml');
43 $constvalue = GETPOST('constvalue', 'restricthtml'); // We should be able to send everything here
44 $constnote = GETPOST('constnote', 'alpha');
45 
46 // Load variable for pagination
47 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
52  $page = 0;
53 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (empty($sortfield)) {
58  $sortfield = 'entity,name';
59 }
60 if (empty($sortorder)) {
61  $sortorder = 'ASC';
62 }
63 
64 
65 /*
66  * Actions
67  */
68 
69 if ($action == 'add' || (GETPOST('add') && $action != 'update')) {
70  $error = 0;
71 
72  if (empty($constname)) {
73  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
74  $error++;
75  }
76  if ($constvalue == '') {
77  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Value")), null, 'errors');
78  $error++;
79  }
80 
81  if (!$error) {
82  if (dolibarr_set_const($db, $constname, $constvalue, 'chaine', 1, $constnote, $entity) >= 0) {
83  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
84  $action = "";
85  $constname = "";
86  $constvalue = "";
87  $constnote = "";
88  } else {
89  dol_print_error($db);
90  }
91  }
92 }
93 
94 // Mass update
95 if (!empty($consts) && $action == 'update') {
96  $nbmodified = 0;
97  foreach ($consts as $const) {
98  if (!empty($const["check"])) {
99  if (dolibarr_set_const($db, $const["name"], $const["value"], $const["type"], 1, $const["note"], $const["entity"]) >= 0) {
100  $nbmodified++;
101  } else {
102  dol_print_error($db);
103  }
104  }
105  }
106  if ($nbmodified > 0) {
107  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
108  }
109  $action = '';
110 }
111 
112 // Mass delete
113 if (!empty($consts) && $action == 'delete') {
114  $nbdeleted = 0;
115  foreach ($consts as $const) {
116  if (!empty($const["check"])) { // Is checkbox checked
117  if (dolibarr_del_const($db, $const["rowid"], -1) >= 0) {
118  $nbdeleted++;
119  } else {
120  dol_print_error($db);
121  }
122  }
123  }
124  if ($nbdeleted > 0) {
125  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
126  }
127  $action = '';
128 }
129 
130 // Delete line from delete picto
131 if ($action == 'delete') {
132  if (dolibarr_del_const($db, $rowid, $entity) >= 0) {
133  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
134  } else {
135  dol_print_error($db);
136  }
137 }
138 
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 
146 $wikihelp = 'EN:Setup_Other|FR:Paramétrage_Divers|ES:Configuración_Varios';
147 llxHeader('', $langs->trans("Setup"), $wikihelp);
148 
149 // Add logic to show/hide buttons
150 if ($conf->use_javascript_ajax) {
151  ?>
152 <script type="text/javascript">
153 jQuery(document).ready(function() {
154  jQuery("#updateconst").hide();
155  jQuery("#delconst").hide();
156  jQuery(".checkboxfordelete").click(function() {
157  jQuery("#delconst").show();
158  jQuery("#action").val('delete');
159  });
160  jQuery(".inputforupdate").keyup(function() { // keypress does not support back
161  var field_id = jQuery(this).attr("id");
162  var row_num = field_id.split("_");
163  jQuery("#updateconst").show();
164  jQuery("#action").val('update');
165  jQuery("#check_" + row_num[1]).prop("checked",true);
166  });
167 });
168 </script>
169  <?php
170 }
171 
172 print load_fiche_titre($langs->trans("OtherSetup"), '', 'title_setup');
173 
174 print '<span class="opacitymedium">'.$langs->trans("ConstDesc")."</span><br>\n";
175 print "<br>\n";
176 
177 $param = '';
178 
179 print '<form action="'.$_SERVER["PHP_SELF"].((empty($user->entity) && $debug) ? '?debug=1' : '').'" method="POST">';
180 print '<input type="hidden" name="token" value="'.newToken().'">';
181 print '<input type="hidden" id="action" name="action" value="">';
182 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
183 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
184 
185 print '<div class="div-table-responsive-no-min">';
186 print '<table class="noborder centpercent">';
187 print '<tr class="liste_titre">';
188 print getTitleFieldOfList('Name', 0, $_SERVER['PHP_SELF'], 'name', '', $param, '', $sortfield, $sortorder, '')."\n";
189 print getTitleFieldOfList("Value", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
190 print getTitleFieldOfList("Comment", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
191 print getTitleFieldOfList('DateModificationShort', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
192 if (!empty($conf->multicompany->enabled) && !$user->entity) {
193  print getTitleFieldOfList('Entity', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
194 }
195 print getTitleFieldOfList("", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
196 print "</tr>\n";
197 
198 
199 // Line to add new record
200 print "\n";
201 
202 print '<tr class="oddeven nohover"><td>';
203 print '<input type="text" class="flat minwidth300" name="constname" value="'.$constname.'">';
204 print '</td>'."\n";
205 print '<td>';
206 print '<input type="text" class="flat minwidth100" name="constvalue" value="'.$constvalue.'">';
207 print '</td>';
208 print '<td>';
209 print '<input type="text" class="flat minwidth100" name="constnote" value="'.$constnote.'">';
210 print '</td>';
211 print '<td>';
212 print '</td>';
213 // Limit to superadmin
214 if (!empty($conf->multicompany->enabled) && !$user->entity) {
215  print '<td>';
216  print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
217  print '</td>';
218  print '<td class="center">';
219 } else {
220  print '<td class="center">';
221  print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
222 }
223 print '<input type="submit" class="button button-add small" name="add" value="'.$langs->trans("Add").'">';
224 print "</td>\n";
225 print '</tr>';
226 
227 
228 // Show constants
229 $sql = "SELECT";
230 $sql .= " rowid";
231 $sql .= ", ".$db->decrypt('name')." as name";
232 $sql .= ", ".$db->decrypt('value')." as value";
233 $sql .= ", type";
234 $sql .= ", note";
235 $sql .= ", tms";
236 $sql .= ", entity";
237 $sql .= " FROM ".MAIN_DB_PREFIX."const";
238 $sql .= " WHERE entity IN (".$db->sanitize($user->entity.",".$conf->entity).")";
239 if ((empty($user->entity) || $user->admin) && $debug) {
240 } elseif (!GETPOST('visible') || GETPOST('visible') != 'all') {
241  // to force for superadmin to debug
242  $sql .= " AND visible = 1"; // We must always have this. Otherwise, array is too large and submitting data fails due to apache POST or GET limits
243 }
244 if (GETPOST('name')) {
245  $sql .= natural_search("name", GETPOST('name'));
246 }
247 $sql .= $db->order($sortfield, $sortorder);
248 
249 dol_syslog("Const::listConstant", LOG_DEBUG);
250 $result = $db->query($sql);
251 if ($result) {
252  $num = $db->num_rows($result);
253  $i = 0;
254 
255  while ($i < $num) {
256  $obj = $db->fetch_object($result);
257 
258  print "\n";
259 
260  print '<tr class="oddeven" data-checkbox-id="check_'.$i.'"><td>'.$obj->name.'</td>'."\n";
261 
262  // Value
263  print '<td>';
264  print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
265  print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
266  print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
267  print '<input type="text" id="value_'.$i.'" class="flat inputforupdate minwidth150" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'">';
268  print '</td>';
269 
270  // Note
271  print '<td>';
272  print '<input type="text" id="note_'.$i.'" class="flat inputforupdate minwidth200" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note, 1).'">';
273  print '</td>';
274 
275  // Date last change
276  print '<td class="nowraponall center">';
277  print dol_print_date($db->jdate($obj->tms), 'dayhour');
278  print '</td>';
279 
280  // Entity limit to superadmin
281  if (!empty($conf->multicompany->enabled) && !$user->entity) {
282  print '<td>';
283  print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
284  print '</td>';
285  print '<td class="center">';
286  } else {
287  print '<td class="center">';
288  print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
289  }
290 
291  if ($conf->use_javascript_ajax) {
292  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
293  } else {
294  print '<a href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&action=delete&token='.newToken().((empty($user->entity) && $debug) ? '&debug=1' : '').'">'.img_delete().'</a>';
295  }
296 
297  print "</td></tr>\n";
298 
299  print "\n";
300  $i++;
301  }
302 }
303 
304 
305 print '</table>';
306 print '</div>';
307 
308 if ($conf->use_javascript_ajax) {
309  print '<br>';
310  print '<div id="updateconst" class="right">';
311  print '<input type="submit" class="button button-edit marginbottomonly" name="update" value="'.$langs->trans("Modify").'">';
312  print '</div>';
313  print '<div id="delconst" class="right">';
314  print '<input type="submit" class="button button-cancel marginbottomonly" name="delete" value="'.$langs->trans("Delete").'">';
315  print '</div>';
316 }
317 
318 print "</form>\n";
319 
320 // End of page
321 llxFooter();
322 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dolibarr_set_const
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:627
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
natural_search
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Definition: functions.lib.php:9420
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59