dolibarr  9.0.0
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 <http://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','alpha');
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','alpha');
44 $constvalue=GETPOST('constvalue','none'); // We shoul dbe able to send everything here
45 $constnote=GETPOST('constnote','alpha');
46 
47 
48 
49 /*
50  * Actions
51  */
52 
53 if ($action == 'add' || (GETPOST('add') && $action != 'update'))
54 {
55  $error=0;
56 
57  if (empty($constname))
58  {
59  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
60  $error++;
61  }
62  if ($constvalue == '')
63  {
64  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Value")), null, 'errors');
65  $error++;
66  }
67 
68  if (! $error)
69  {
70  if (dolibarr_set_const($db, $constname, $constvalue, 'chaine', 1, $constnote, $entity) >= 0)
71  {
72  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
73  $action="";
74  $constname="";
75  $constvalue="";
76  $constnote="";
77  }
78  else
79  {
80  dol_print_error($db);
81  }
82  }
83 }
84 
85 // Mass update
86 if (! empty($consts) && $action == 'update')
87 {
88  $nbmodified=0;
89  foreach($consts as $const)
90  {
91  if (! empty($const["check"]))
92  {
93  if (dolibarr_set_const($db, $const["name"], $const["value"], $const["type"], 1, $const["note"], $const["entity"]) >= 0)
94  {
95  $nbmodified++;
96  }
97  else
98  {
99  dol_print_error($db);
100  }
101  }
102  }
103  if ($nbmodified > 0) setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
104  $action='';
105 }
106 
107 // Mass delete
108 if (! empty($consts) && $action == 'delete')
109 {
110 
111  $nbdeleted=0;
112  foreach($consts as $const)
113  {
114  if (! empty($const["check"])) // Is checkbox checked
115  {
116  if (dolibarr_del_const($db, $const["rowid"], -1) >= 0)
117  {
118  $nbdeleted++;
119  }
120  else
121  {
122  dol_print_error($db);
123  }
124  }
125  }
126  if ($nbdeleted > 0) setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
127  $action='';
128 }
129 
130 // Delete line from delete picto
131 if ($action == 'delete')
132 {
133  if (dolibarr_del_const($db, $rowid, $entity) >= 0)
134  {
135  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
136  }
137  else
138  {
139  dol_print_error($db);
140  }
141 }
142 
143 
144 /*
145  * View
146  */
147 
148 $form = new Form($db);
149 
150 $wikihelp='EN:Setup_Other|FR:Paramétrage_Divers|ES:Configuración_Varios';
151 llxHeader('',$langs->trans("Setup"),$wikihelp);
152 
153 // Add logic to show/hide buttons
154 if ($conf->use_javascript_ajax)
155 {
156 ?>
157 <script type="text/javascript">
158 jQuery(document).ready(function() {
159  jQuery("#updateconst").hide();
160  jQuery("#delconst").hide();
161  jQuery(".checkboxfordelete").click(function() {
162  jQuery("#delconst").show();
163  jQuery("#action").val('delete');
164  });
165  jQuery(".inputforupdate").keyup(function() { // keypress does not support back
166  var field_id = jQuery(this).attr("id");
167  var row_num = field_id.split("_");
168  jQuery("#updateconst").show();
169  jQuery("#action").val('update');
170  jQuery("#check_" + row_num[1]).prop("checked",true);
171  });
172 });
173 </script>
174 <?php
175 }
176 
177 print load_fiche_titre($langs->trans("OtherSetup"),'','title_setup');
178 
179 print $langs->trans("ConstDesc")."<br>\n";
180 print "<br>\n";
181 
182 print '<form action="'.$_SERVER["PHP_SELF"].((empty($user->entity) && $debug)?'?debug=1':'').'" method="POST">';
183 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
184 print '<input type="hidden" id="action" name="action" value="">';
185 
186 print '<div class="div-table-responsive-no-min">';
187 print '<table class="noborder" width="100%">';
188 print '<tr class="liste_titre">';
189 print '<td>'.$langs->trans("Name").'</td>';
190 print '<td>'.$langs->trans("Value").'</td>';
191 print '<td>'.$langs->trans("Comment").'</td>';
192 if (! empty($conf->multicompany->enabled) && !$user->entity) print '<td>'.$langs->trans("Entity").'</td>';
193 print '<td align="center">'.$langs->trans("Action").'</td>';
194 print "</tr>\n";
195 
196 
197 // Line to add new record
198 $var=false;
199 print "\n";
200 
201 print '<tr class="oddeven"><td><input type="text" class="flat" size="24" name="constname" value="'.$constname.'"></td>'."\n";
202 print '<td>';
203 print '<input type="text" class="flat" size="30" name="constvalue" value="'.$constvalue.'">';
204 print '</td><td>';
205 print '<input type="text" class="flat" size="40" name="constnote" value="'.$constnote.'">';
206 print '</td>';
207 // Limit to superadmin
208 if (! empty($conf->multicompany->enabled) && !$user->entity)
209 {
210  print '<td>';
211  print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
212  print '</td>';
213  print '<td align="center">';
214 }
215 else
216 {
217  print '<td align="center">';
218  print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
219 }
220 print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="add">';
221 print "</td>\n";
222 print '</tr>';
223 
224 
225 // Show constants
226 $sql = "SELECT";
227 $sql.= " rowid";
228 $sql.= ", ".$db->decrypt('name')." as name";
229 $sql.= ", ".$db->decrypt('value')." as value";
230 $sql.= ", type";
231 $sql.= ", note";
232 $sql.= ", entity";
233 $sql.= " FROM ".MAIN_DB_PREFIX."const";
234 $sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
235 if ((empty($user->entity) || $user->admin) && $debug) {} // to force for superadmin to debug
236 else if (! 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
237 if (GETPOST('name')) $sql.=natural_search("name", GETPOST('name'));
238 $sql.= " ORDER BY entity, name ASC";
239 
240 dol_syslog("Const::listConstant", LOG_DEBUG);
241 $result = $db->query($sql);
242 if ($result)
243 {
244  $num = $db->num_rows($result);
245  $i = 0;
246  $var=false;
247 
248  while ($i < $num)
249  {
250  $obj = $db->fetch_object($result);
251 
252 
253  print "\n";
254 
255  print '<tr class="oddeven"><td>'.$obj->name.'</td>'."\n";
256 
257  // Value
258  print '<td>';
259  print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
260  print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
261  print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
262  print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'">';
263  print '</td>';
264 
265  // Note
266  print '<td>';
267  print '<input type="text" id="note_'.$i.'" class="flat inputforupdate" size="40" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note,1).'">';
268  print '</td>';
269 
270  // Entity limit to superadmin
271  if (! empty($conf->multicompany->enabled) && !$user->entity)
272  {
273  print '<td>';
274  print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
275  print '</td>';
276  print '<td align="center">';
277  }
278  else
279  {
280  print '<td align="center">';
281  print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
282  }
283 
284  if ($conf->use_javascript_ajax)
285  {
286  print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
287  }
288  else
289  {
290  print '<a href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&action=delete'.((empty($user->entity) && $debug)?'&debug=1':'').'">'.img_delete().'</a>';
291  }
292 
293  print "</td></tr>\n";
294 
295  print "\n";
296  $i++;
297  }
298 }
299 
300 
301 print '</table>';
302 print '</div>';
303 
304 if ($conf->use_javascript_ajax)
305 {
306  print '<br>';
307  print '<div id="updateconst" align="right">';
308  print '<input type="submit" name="update" class="button" value="'.$langs->trans("Modify").'">';
309  print '</div>';
310  print '<div id="delconst" align="right">';
311  print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
312  print '</div>';
313 }
314 
315 print "</form>\n";
316 
317 // End of page
318 llxFooter();
319 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
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