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