dolibarr  13.0.2
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 $rowid = GETPOST('rowid', 'int');
37 $entity = GETPOST('entity', 'int');
38 $action = GETPOST('action', 'aZ09');
39 $update = GETPOST('update', 'alpha');
40 $delete = GETPOST('delete', 'none'); // Do not use alpha here
41 $debug = GETPOST('debug', 'int');
42 $consts = GETPOST('const', 'array');
43 $constname = GETPOST('constname', 'alphanohtml');
44 $constvalue = GETPOST('constvalue', 'restricthtml'); // We should be able to send everything here
45 $constnote = GETPOST('constnote', 'alpha');
46 
47 // Load variable for pagination
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if (empty($sortfield)) $sortfield = 'entity,name';
57 if (empty($sortorder)) $sortorder = 'ASC';
58 
59 
60 /*
61  * Actions
62  */
63 
64 if ($action == 'add' || (GETPOST('add') && $action != 'update'))
65 {
66  $error = 0;
67 
68  if (empty($constname))
69  {
70  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
71  $error++;
72  }
73  if ($constvalue == '')
74  {
75  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Value")), null, 'errors');
76  $error++;
77  }
78 
79  if (!$error)
80  {
81  if (dolibarr_set_const($db, $constname, $constvalue, 'chaine', 1, $constnote, $entity) >= 0)
82  {
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 {
97  $nbmodified = 0;
98  foreach ($consts as $const)
99  {
100  if (!empty($const["check"]))
101  {
102  if (dolibarr_set_const($db, $const["name"], $const["value"], $const["type"], 1, $const["note"], $const["entity"]) >= 0)
103  {
104  $nbmodified++;
105  } else {
106  dol_print_error($db);
107  }
108  }
109  }
110  if ($nbmodified > 0) setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
111  $action = '';
112 }
113 
114 // Mass delete
115 if (!empty($consts) && $action == 'delete')
116 {
117  $nbdeleted = 0;
118  foreach ($consts as $const)
119  {
120  if (!empty($const["check"])) // Is checkbox checked
121  {
122  if (dolibarr_del_const($db, $const["rowid"], -1) >= 0)
123  {
124  $nbdeleted++;
125  } else {
126  dol_print_error($db);
127  }
128  }
129  }
130  if ($nbdeleted > 0) setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
131  $action = '';
132 }
133 
134 // Delete line from delete picto
135 if ($action == 'delete')
136 {
137  if (dolibarr_del_const($db, $rowid, $entity) >= 0)
138  {
139  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
140  } else {
141  dol_print_error($db);
142  }
143 }
144 
145 
146 /*
147  * View
148  */
149 
150 $form = new Form($db);
151 
152 $wikihelp = 'EN:Setup_Other|FR:Paramétrage_Divers|ES:Configuración_Varios';
153 llxHeader('', $langs->trans("Setup"), $wikihelp);
154 
155 // Add logic to show/hide buttons
156 if ($conf->use_javascript_ajax)
157 {
158  ?>
159 <script type="text/javascript">
160 jQuery(document).ready(function() {
161  jQuery("#updateconst").hide();
162  jQuery("#delconst").hide();
163  jQuery(".checkboxfordelete").click(function() {
164  jQuery("#delconst").show();
165  jQuery("#action").val('delete');
166  });
167  jQuery(".inputforupdate").keyup(function() { // keypress does not support back
168  var field_id = jQuery(this).attr("id");
169  var row_num = field_id.split("_");
170  jQuery("#updateconst").show();
171  jQuery("#action").val('update');
172  jQuery("#check_" + row_num[1]).prop("checked",true);
173  });
174 });
175 </script>
176  <?php
177 }
178 
179 print load_fiche_titre($langs->trans("OtherSetup"), '', 'title_setup');
180 
181 print '<span class="opacitymedium">'.$langs->trans("ConstDesc")."</span><br>\n";
182 print "<br>\n";
183 
184 $param = '';
185 
186 print '<form action="'.$_SERVER["PHP_SELF"].((empty($user->entity) && $debug) ? '?debug=1' : '').'" method="POST">';
187 print '<input type="hidden" name="token" value="'.newToken().'">';
188 print '<input type="hidden" id="action" name="action" value="">';
189 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
190 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
191 
192 print '<div class="div-table-responsive-no-min">';
193 print '<table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print getTitleFieldOfList('Name', 0, $_SERVER['PHP_SELF'], 'name', '', $param, '', $sortfield, $sortorder, '')."\n";
196 print getTitleFieldOfList("Value", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
197 print getTitleFieldOfList("Comment", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
198 print getTitleFieldOfList('DateModificationShort', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
199 if (!empty($conf->multicompany->enabled) && !$user->entity)
200 {
201  print getTitleFieldOfList('Entity', 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
202 }
203 print getTitleFieldOfList("", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
204 print "</tr>\n";
205 
206 
207 // Line to add new record
208 print "\n";
209 
210 print '<tr class="oddeven nohover"><td>';
211 print '<input type="text" class="flat minwidth300" name="constname" value="'.$constname.'">';
212 print '</td>'."\n";
213 print '<td>';
214 print '<input type="text" class="flat minwidth100" name="constvalue" value="'.$constvalue.'">';
215 print '</td>';
216 print '<td>';
217 print '<input type="text" class="flat minwidth100" name="constnote" value="'.$constnote.'">';
218 print '</td>';
219 print '<td>';
220 print '</td>';
221 // Limit to superadmin
222 if (!empty($conf->multicompany->enabled) && !$user->entity)
223 {
224  print '<td>';
225  print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
226  print '</td>';
227  print '<td class="center">';
228 } else {
229  print '<td class="center">';
230  print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
231 }
232 print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="add">';
233 print "</td>\n";
234 print '</tr>';
235 
236 
237 // Show constants
238 $sql = "SELECT";
239 $sql .= " rowid";
240 $sql .= ", ".$db->decrypt('name')." as name";
241 $sql .= ", ".$db->decrypt('value')." as value";
242 $sql .= ", type";
243 $sql .= ", note";
244 $sql .= ", tms";
245 $sql .= ", entity";
246 $sql .= " FROM ".MAIN_DB_PREFIX."const";
247 $sql .= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
248 if ((empty($user->entity) || $user->admin) && $debug) {} // to force for superadmin to debug
249 elseif (!GETPOST('visible') || GETPOST('visible') != 'all') $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
250 if (GETPOST('name')) $sql .= natural_search("name", GETPOST('name'));
251 $sql .= $db->order($sortfield, $sortorder);
252 
253 dol_syslog("Const::listConstant", LOG_DEBUG);
254 $result = $db->query($sql);
255 if ($result)
256 {
257  $num = $db->num_rows($result);
258  $i = 0;
259 
260  while ($i < $num)
261  {
262  $obj = $db->fetch_object($result);
263 
264  print "\n";
265 
266  print '<tr class="oddeven"><td>'.$obj->name.'</td>'."\n";
267 
268  // Value
269  print '<td>';
270  print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
271  print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
272  print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
273  print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'">';
274  print '</td>';
275 
276  // Note
277  print '<td>';
278  print '<input type="text" id="note_'.$i.'" class="flat inputforupdate" size="40" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note, 1).'">';
279  print '</td>';
280 
281  // Date last change
282  print '<td>';
283  print dol_print_date($db->jdate($obj->tms), 'dayhour');
284  print '</td>';
285 
286  // Entity limit to superadmin
287  if (!empty($conf->multicompany->enabled) && !$user->entity)
288  {
289  print '<td>';
290  print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
291  print '</td>';
292  print '<td class="center">';
293  } else {
294  print '<td class="center">';
295  print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
296  }
297 
298  if ($conf->use_javascript_ajax)
299  {
300  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
301  } else {
302  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>';
303  }
304 
305  print "</td></tr>\n";
306 
307  print "\n";
308  $i++;
309  }
310 }
311 
312 
313 print '</table>';
314 print '</div>';
315 
316 if ($conf->use_javascript_ajax)
317 {
318  print '<br>';
319  print '<div id="updateconst" class="right">';
320  print '<input type="submit" name="update" class="button marginbottomonly" value="'.$langs->trans("Modify").'">';
321  print '</div>';
322  print '<div id="delconst" class="right">';
323  print '<input type="submit" name="delete" class="button marginbottomonly" value="'.$langs->trans("Delete").'">';
324  print '</div>';
325 }
326 
327 print "</form>\n";
328 
329 // End of page
330 llxFooter();
331 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $wikihelp
View.
Definition: agenda.php:120
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:499
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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 ...
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105