PageRenderTime 336ms CodeModel.GetById 141ms app.highlight 12ms RepoModel.GetById 99ms app.codeStats 0ms

/htdocs/admin/const.php

https://github.com/asterix14/dolibarr
PHP | 282 lines | 198 code | 47 blank | 37 comment | 36 complexity | a83bf828b595343bf251bd99742cb98f MD5 | raw file
  1<?php
  2/* Copyright (C) 2003		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2011	Laurent Destailleur		<eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2011	Regis Houssin			<regis@dolibarr.fr>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 2 of the License, or
  9 * (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20/**
 21 *	\file       htdocs/admin/const.php
 22 *	\ingroup    setup
 23 *	\brief      Admin page to define miscellaneous constants
 24 */
 25
 26require("../main.inc.php");
 27require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
 28
 29$langs->load("admin");
 30
 31if (! $user->admin) accessforbidden();
 32
 33$action = GETPOST('action');
 34
 35$typeconst=array('yesno','texte','chaine');
 36
 37
 38/*
 39 * Actions
 40 */
 41
 42if ($action == 'add')
 43{
 44	$error=0;
 45
 46	if (empty($_POST["constname"]))
 47	{
 48		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'</div>';
 49		$error++;
 50	}
 51	if ($_POST["constvalue"]=='')
 52	{
 53		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'</div>';
 54		$error++;
 55	}
 56
 57	if (! $error)
 58	{
 59		if (dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],1,isset($_POST["constnote"])?$_POST["constnote"]:'',$_POST["entity"]) < 0)
 60		{
 61			dolibarr_print_error($db);
 62		}
 63	}
 64}
 65
 66if (($_POST["const"] && isset($_POST["update"]) && $_POST["update"] == $langs->trans("Modify")))
 67{
 68	foreach($_POST["const"] as $const)
 69	{
 70		if ($const["check"])
 71		{
 72			if (dolibarr_set_const($db, $const["name"],$const["value"],$const["type"],1,$const["note"],$const["entity"]) < 0)
 73			{
 74				dolibarr_print_error($db);
 75			}
 76		}
 77	}
 78}
 79
 80// Delete several lines at once
 81if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
 82{
 83	foreach($_POST["const"] as $const)
 84	{
 85		if ($const["check"])	// Is checkbox checked
 86		{
 87			if (dolibarr_del_const($db, $const["rowid"], -1) < 0)
 88			{
 89				dolibarr_print_error($db);
 90			}
 91		}
 92	}
 93}
 94
 95// Delete line from delete picto
 96if ($action == 'delete')
 97{
 98	if (dolibarr_del_const($db, $_GET["rowid"], $_GET["entity"]) < 0)
 99	{
100		dolibarr_print_error($db);
101	}
102}
103
104
105/*
106 * View
107 */
108
109llxHeader('',$langs->trans("OtherSetup"));
110
111// Add logic to show/hide buttons
112if ($conf->use_javascript_ajax)
113{
114?>
115<script type="text/javascript">
116jQuery(document).ready(function() {
117	jQuery("#updateconst").hide();
118	jQuery("#delconst").hide();
119	jQuery(".checkboxfordelete").click(function() {
120		jQuery("#delconst").show();
121	});
122	jQuery(".inputforupdate").keypress(function() {
123		var field_id = jQuery(this).attr("id");
124		var row_num = field_id.split("_");
125		jQuery("#updateconst").show();
126		jQuery("#check_" + row_num[1]).attr("checked",true);
127	});
128});
129</script>
130<?php
131}
132
133print_fiche_titre($langs->trans("OtherSetup"),'','setup');
134
135print $langs->trans("ConstDesc")."<br>\n";
136print "<br>\n";
137
138if ($mesg) print $mesg;
139
140print '<table class="noborder" width="100%">';
141print '<tr class="liste_titre">';
142print '<td>'.$langs->trans("Name").'</td>';
143print '<td>'.$langs->trans("Value").'</td>';
144print '<td>'.$langs->trans("Comment").'</td>';
145if (! empty($conf->multicompany->enabled) && !$user->entity) print '<td>'.$langs->trans("Entity").'</td>';
146print '<td align="center">'.$langs->trans("Action").'</td>';
147print "</tr>\n";
148
149
150$form = new Form($db);
151
152
153// Line to add new record
154$var=false;
155print "\n";
156print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
157print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
158print '<input type="hidden" name="action" value="add">';
159
160print '<tr '.$bc[$var].'><td><input type="text" class="flat" size="24" name="constname" value=""></td>'."\n";
161print '<td>';
162print '<input type="text" class="flat" size="30" name="constvalue" value="">';
163print '</td><td>';
164print '<input type="text" class="flat" size="40" name="constnote" value="">';
165print '</td>';
166// Limit to superadmin
167if (! empty($conf->multicompany->enabled) && !$user->entity)
168{
169	print '<td>';
170	print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
171	print '</td>';
172}
173else
174{
175	print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
176}
177print '<td align="center">';
178print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="Button">';
179print "</td>\n";
180print '</tr>';
181
182print '</form>';
183print "\n";
184
185print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
186print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
187
188// Show constants
189$sql = "SELECT";
190$sql.= " rowid";
191$sql.= ", ".$db->decrypt('name')." as name";
192$sql.= ", ".$db->decrypt('value')." as value";
193$sql.= ", type";
194$sql.= ", note";
195$sql.= ", entity";
196$sql.= " FROM ".MAIN_DB_PREFIX."const";
197$sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
198if ($user->entity || empty($conf->multicompany->enabled)) $sql.= " AND visible = 1";
199$sql.= " ORDER BY entity, name ASC";
200
201dol_syslog("Const::listConstant sql=".$sql);
202$result = $db->query($sql);
203if ($result)
204{
205	$num = $db->num_rows($result);
206	$i = 0;
207	$var=false;
208
209	while ($i < $num)
210	{
211		$obj = $db->fetch_object($result);
212		$var=!$var;
213
214		print "\n";
215		print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
216		print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->name.'">';
217		print '<input type="hidden" name="const['.$i.'][type]" value="'.$obj->type.'">';
218
219		print '<tr '.$bc[$var].'><td>'.$obj->name.'</td>'."\n";
220
221		// Value
222		print '<td>';
223		print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.htmlspecialchars($obj->value).'"';
224		print '>';
225		print '</td><td>';
226
227		// Note
228		print '<input type="text" id="note_'.$i.'"class="flat inputforupdate" size="40" name="const['.$i.'][note]" value="'.htmlspecialchars($obj->note,1).'"';
229		print '>';
230		print '</td>';
231
232		// Entity limit to superadmin
233		if (! empty($conf->multicompany->enabled) && !$user->entity)
234		{
235			print '<td>';
236			print '<input type="text" class="flat" size="1" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
237			print '</td>';
238		}
239		else
240		{
241			print '<input type="hidden" name="const['.$i.'][entity]" value="'.$obj->entity.'">';
242		}
243
244		print '<td align="center">';
245		if ($conf->use_javascript_ajax)
246		{
247			print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
248			print ' &nbsp; ';
249		}
250		else
251		{
252			print '<a href="const.php?rowid='.$obj->rowid.'&entity='.$obj->entity.'&action=delete">'.img_delete().'</a>';
253		}
254
255		print "</td></tr>\n";
256
257		print "\n";
258		$i++;
259	}
260}
261
262
263print '</table>';
264
265if ($conf->use_javascript_ajax)
266{
267	print '<br>';
268	print '<div id="updateconst" align="right">';
269	print '<input type="submit" name="update" class="button" value="'.$langs->trans("Modify").'">';
270	print '</div>';
271	print '<div id="delconst" align="right">';
272	print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
273	print '</div>';
274}
275
276print "</form>\n";
277
278
279$db->close();
280
281llxFooter();
282?>