dolibarr  21.0.0-alpha
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 // Load Dolibarr environment
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
31 
32 // Load translation files required by the page
33 $langs->load("admin");
34 
35 $rowid = GETPOSTINT('rowid');
36 $entity = GETPOSTINT('entity');
37 $action = GETPOST('action', 'aZ09');
38 $debug = GETPOSTINT('debug');
39 $consts = GETPOST('const', 'array');
40 $constname = GETPOST('constname', 'alphanohtml');
41 $constvalue = GETPOST('constvalue', 'restricthtml'); // We should be able to send everything here
42 $constnote = GETPOST('constnote', 'alpha');
43 // Load variable for pagination
44 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
45 $sortfield = GETPOST('sortfield', 'aZ09comma');
46 $sortorder = GETPOST('sortorder', 'aZ09comma');
47 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
48 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
49  $page = 0;
50 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if (empty($sortfield)) {
55  $sortfield = 'entity,name';
56 }
57 if (empty($sortorder)) {
58  $sortorder = 'ASC';
59 }
60 
61 if ($action == 'add' && GETPOST('update')) { // Click on button update must be used in priority before param $action
62  $action = 'update';
63 }
64 if ($action == 'add' && GETPOST('delete')) { // Click on button update must be used in priority before param $action
65  $action = 'delete';
66 }
67 /*if ($action == 'update' && GETPOST('add')) { // 'add' button is always clicked as it is the first in form.
68  $action = 'add';
69 }*/
70 if ($action == 'delete' && GETPOST('add')) { // Click on button add must be used in priority before param $action
71  $action = 'add';
72 }
73 
74 if (!$user->admin) {
76 }
77 
78 
79 /*
80  * Actions
81  */
82 
83 // Add a new record
84 if ($action == 'add') {
85  $error = 0;
86 
87  if (empty($constname)) {
88  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
89  $error++;
90  }
91  if ($constvalue == '') {
92  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Value")), null, 'errors');
93  $error++;
94  }
95 
96  if (!$error) {
97  if (dolibarr_set_const($db, $constname, $constvalue, 'chaine', 1, $constnote, $entity) >= 0) {
98  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
99  $action = "";
100  $constname = "";
101  $constvalue = "";
102  $constnote = "";
103  } else {
104  dol_print_error($db);
105  }
106  }
107 }
108 
109 // Mass update
110 if (!empty($consts) && $action == 'update') {
111  $nbmodified = 0;
112  foreach ($consts as $const) {
113  if (!empty($const["check"])) {
114  if (dolibarr_set_const($db, $const["name"], $const["value"], $const["type"], 1, $const["note"], $const["entity"]) >= 0) {
115  $nbmodified++;
116  } else {
117  dol_print_error($db);
118  }
119  }
120  }
121  if ($nbmodified > 0) {
122  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
123  }
124  $action = '';
125 }
126 
127 // Mass delete
128 if (!empty($consts) && $action == 'delete') {
129  $nbdeleted = 0;
130  foreach ($consts as $const) {
131  if (!empty($const["check"])) { // Is checkbox checked
132  if (dolibarr_del_const($db, $const["rowid"], -1) >= 0) {
133  $nbdeleted++;
134  } else {
135  dol_print_error($db);
136  }
137  }
138  }
139  if ($nbdeleted > 0) {
140  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
141  }
142  $action = '';
143 }
144 
145 // Delete line from delete picto
146 if ($action == 'delete') {
147  if (dolibarr_del_const($db, $rowid, $entity) >= 0) {
148  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
149  } else {
150  dol_print_error($db);
151  }
152 }
153 
154 
155 /*
156  * View
157  */
158 
159 $form = new Form($db);
160 
161 $wikihelp = 'EN:Setup_Other|FR:Paramétrage_Divers|ES:Configuración_Varios';
162 llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-const');
163 
164 // Add logic to show/hide buttons
165 if ($conf->use_javascript_ajax) {
166  ?>
167 <script type="text/javascript">
168 jQuery(document).ready(function() {
169  jQuery("#updateconst").hide();
170  jQuery("#delconst").hide();
171  jQuery(".checkboxfordelete").click(function() {
172  jQuery("#delconst").show();
173  });
174  jQuery(".inputforupdate").keyup(function() { // keypress does not support back
175  var field_id = jQuery(this).attr("id");
176  var row_num = field_id.split("_");
177  jQuery("#updateconst").show();
178  jQuery("#action").val('update'); // so default action if we type enter will be update, but correct action is also detected correctly without that when clicking on "Update" button.
179  jQuery("#check_" + row_num[1]).prop("checked",true);
180  });
181 });
182 </script>
183  <?php
184 }
185 
186 print load_fiche_titre($langs->trans("OtherSetup"), '', 'title_setup');
187 
188 print '<span class="opacitymedium">'.$langs->trans("ConstDesc")."</span><br>\n";
189 print "<br>\n";
190 print "<br>\n";
191 
192 $param = '';
193 
194 print '<form action="'.$_SERVER["PHP_SELF"].((empty($user->entity) && $debug) ? '?debug=1' : '').'" method="POST">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196 print '<input type="hidden" id="action" name="action" value="add">';
197 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
198 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
199 
200 print '<div class="div-table-responsive-no-min">';
201 print '<table class="noborder centpercent">';
202 print '<tr class="liste_titre">';
203 print getTitleFieldOfList('Name', 0, $_SERVER['PHP_SELF'], 'name', '', $param, '', $sortfield, $sortorder, '') . "\n";
204 print getTitleFieldOfList("Value", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
205 print getTitleFieldOfList("Comment", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
206 print getTitleFieldOfList('DateModificationShort', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ') . "\n";
207 if (isModEnabled('multicompany') && !$user->entity) {
208  print getTitleFieldOfList('Entity', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ') . "\n";
209 }
210 print getTitleFieldOfList("", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
211 print "</tr>\n";
212 
213 
214 // Line to add new record
215 print "\n";
216 
217 print '<tr class="oddeven nohover"><td>';
218 print '<input type="text" class="flat minwidth300" name="constname" value="'.$constname.'">';
219 print '</td>'."\n";
220 print '<td>';
221 print '<input type="text" class="flat minwidth100" name="constvalue" value="'.$constvalue.'">';
222 print '</td>';
223 print '<td>';
224 print '<input type="text" class="flat minwidth100" name="constnote" value="'.$constnote.'">';
225 print '</td>';
226 print '<td>';
227 print '</td>';
228 // Limit to superadmin
229 if (isModEnabled('multicompany') && !$user->entity) {
230  print '<td>';
231  print '<input type="text" class="flat" size="1" name="entity" value="' . $conf->entity . '">';
232  print '</td>';
233  print '<td class="center">';
234 } else {
235  print '<td class="center">';
236  print '<input type="hidden" name="entity" value="' . $conf->entity . '">';
237 }
238 print '<input type="submit" class="button button-add small" id="add" name="add" value="'.$langs->trans("Add").'">';
239 print "</td>\n";
240 print '</tr>';
241 
242 
243 // Show constants
244 $sql = "SELECT";
245 $sql .= " rowid";
246 $sql .= ", ".$db->decrypt('name')." as name";
247 $sql .= ", ".$db->decrypt('value')." as value";
248 $sql .= ", type";
249 $sql .= ", note";
250 $sql .= ", tms";
251 $sql .= ", entity";
252 $sql .= " FROM ".MAIN_DB_PREFIX."const";
253 $sql .= " WHERE entity IN (".$db->sanitize($user->entity.",".$conf->entity).")";
254 if ((empty($user->entity) || $user->admin) && $debug) {
255 } elseif (!GETPOST('visible') || GETPOST('visible') != 'all') {
256  // to force for superadmin to debug
257  $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
258 }
259 if (GETPOST('name')) {
260  $sql .= natural_search("name", GETPOST('name'));
261 }
262 $sql .= $db->order($sortfield, $sortorder);
263 
264 dol_syslog("Const::listConstant", LOG_DEBUG);
265 $result = $db->query($sql);
266 if ($result) {
267  $num = $db->num_rows($result);
268  $i = 0;
269 
270  while ($i < $num) {
271  $obj = $db->fetch_object($result);
272 
273  $value = dolDecrypt($obj->value);
274 
275  print "\n";
276 
277  print '<tr class="oddeven" data-checkbox-id="check_'.$i.'"><td>'.dol_escape_htmltag($obj->name).'</td>'."\n";
278 
279  // Value
280  print '<td>';
281  print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
282  print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
283  print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
284  print '<input type="text" id="value_'.$i.'" class="flat inputforupdate minwidth150" name="const['.$i.'][value]" value="'.(isset($value) ? htmlspecialchars($value) : '').'">';
285  print '</td>';
286 
287  // Note
288  print '<td>';
289  print '<input type="text" id="note_'.$i.'" class="flat inputforupdate minwidth200" name="const['.$i.'][note]" value="'.(empty($obj->note) ? '' : htmlspecialchars($obj->note, 1)).'">';
290  print '</td>';
291 
292  // Date last change
293  print '<td class="nowraponall center">';
294  print dol_print_date($db->jdate($obj->tms), 'dayhour');
295  print '</td>';
296 
297  // Entity limit to superadmin
298  if (isModEnabled('multicompany') && empty($user->entity)) {
299  print '<td>';
300  print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.((int) $obj->entity).'">';
301  print '</td>';
302  print '<td class="center">';
303  } else {
304  print '<td class="center">';
305  print '<input type="hidden" name="const['.$i.'][entity]" value="'.((int) $obj->entity).'">';
306  }
307 
308  if (!empty($conf->use_javascript_ajax)) {
309  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
310  } else {
311  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>';
312  }
313 
314  print "</td></tr>\n";
315 
316  print "\n";
317  $i++;
318  }
319 }
320 
321 
322 print '</table>';
323 print '</div>';
324 
325 if ($conf->use_javascript_ajax) {
326  print '<br>';
327  print '<div id="updateconst" class="right">';
328  print '<input type="submit" class="button button-edit marginbottomonly" name="update" value="'.$langs->trans("Modify").'">';
329  print '</div>';
330  print '<div id="delconst" class="right">';
331  print '<input type="submit" class="button button-cancel marginbottomonly" name="delete" value="'.$langs->trans("Delete").'">';
332  print '</div>';
333 }
334 
335 print "</form>\n";
336 
337 // End of page
338 llxFooter();
339 $db->close();
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:656
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:580
if(GETPOSTISSET('MAIN_AGENDA_XCAL_EXPORTKEY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_PAST_DELAY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_CACHE')) if(GETPOSTISSET('AGENDA_EXPORT_FIX_TZ')) if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:90
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:139
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.