diff --git a/htdocs/admin/const.php b/htdocs/admin/const.php
index 85938a02e66..52a3b2ac220 100644
--- a/htdocs/admin/const.php
+++ b/htdocs/admin/const.php
@@ -32,14 +32,14 @@ $langs->load("admin");
if (!$user->admin)
accessforbidden();
-
+//var_dump($_POST);
$typeconst=array('yesno','texte','chaine');
/*
* Actions
*/
-if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
+if ($_POST["action"] == 'add')
{
if (dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],1,isset($_POST["constnote"])?$_POST["constnote"]:'',$_POST["entity"]) < 0)
{
@@ -47,11 +47,31 @@ if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
}
}
-if ($_GET["action"] == 'delete')
+if (($_POST["const"] && isset($_POST["update"]) && $_POST["update"] == $langs->trans("Modify")))
{
- if (dolibarr_del_const($db, $_GET["rowid"],$_GET["entity"]) < 0)
+ foreach($_POST["const"] as $const)
{
- print $db->error();
+ if ($const["check"])
+ {
+ if (dolibarr_set_const($db, $const["name"],$const["value"],$const["type"],1,$const["note"],$const["entity"]) < 0)
+ {
+ print $db->error();
+ }
+ }
+ }
+}
+
+if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
+{
+ foreach($_POST["const"] as $const)
+ {
+ if ($const["check"])
+ {
+ if (dolibarr_del_const($db, $const["rowid"], -1) < 0)
+ {
+ print $db->error();
+ }
+ }
}
}
@@ -73,7 +93,7 @@ print '
';
print '| '.$langs->trans("Name").' | ';
print ''.$langs->trans("Value").' | ';
print ''.$langs->trans("Comment").' | ';
-if ($conf->multicompany->enabled) print ''.$langs->trans("Entity").' | ';
+if ($conf->multicompany->enabled && !$user->entity) print ''.$langs->trans("Entity").' | ';
print ''.$langs->trans("Action").' | ';
print "
\n";
@@ -93,7 +113,8 @@ print '';
print '';
print '';
print ' | ';
-if ($conf->multicompany->enabled)
+// Limit to superadmin
+if ($conf->multicompany->enabled && !$user->entity)
{
print '';
print '';
@@ -107,21 +128,28 @@ print ' | ';
print ' ';
print " | \n";
print '';
+print '';
+$colspan = 4;
+if ($conf->multicompany->enabled && !$user->entity) $colspan++;
+print '| |
';
print '';
+print '';
print "\n";
$i++;
}
@@ -180,6 +204,16 @@ if ($result)
print '';
+print '
';
+print '';
+print '';
+print '
';
+print '';
+print '';
+print '
';
+print "\n";
+
+
$db->close();
llxFooter('$Date$ - $Revision$');
diff --git a/htdocs/admin/system/constall.php b/htdocs/admin/system/constall.php
index 454629a93b2..70fbcad18d3 100644
--- a/htdocs/admin/system/constall.php
+++ b/htdocs/admin/system/constall.php
@@ -45,7 +45,7 @@ print '';
print '';
print '| '.$langs->trans("Parameter").' | ';
print ''.$langs->trans("Value").' | ';
-print ''.$langs->trans("Entity").' | ';
+if (!$user->entity) print ''.$langs->trans("Entity").' | ';
print "
\n";
$sql = "SELECT";
@@ -56,32 +56,30 @@ $sql.= ", type";
$sql.= ", note";
$sql.= ", entity";
$sql.= " FROM ".MAIN_DB_PREFIX."const";
-$sql.= " WHERE entity IN (0,".$conf->entity.")";
+$sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")";
$sql.= " ORDER BY entity, name ASC";
$result = $db->query($sql);
if ($result)
{
- $num = $db->num_rows();
- $i = 0;
- $var=True;
-
- while ($i < $num)
+ $num = $db->num_rows();
+ $i = 0;
+ $var=True;
+
+ while ($i < $num)
{
- $obj = $db->fetch_object($result);
- $var=!$var;
-
- print '';
- print '| '.$obj->name.' | '."\n";
- print ''.$obj->value.' | '."\n";
- print ''.$obj->entity.' | '."\n";
- print "
\n";
-
- $i++;
+ $obj = $db->fetch_object($result);
+ $var=!$var;
+
+ print '';
+ print '| '.$obj->name.' | '."\n";
+ print ''.$obj->value.' | '."\n";
+ if (!$user->entity) print ''.$obj->entity.' | '."\n";
+ print "
\n";
+
+ $i++;
}
}
-$var=!$var;
-
print '
';
diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php
index 4c3384664fc..ec62551ab66 100644
--- a/htdocs/lib/admin.lib.php
+++ b/htdocs/lib/admin.lib.php
@@ -321,7 +321,7 @@ function dolibarr_del_const($db, $name, $entity=1)
}
else
{
- $this->error=$db->lasterror();
+ dol_print_error($db);
return -1;
}
}
@@ -383,6 +383,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."'";
$sql.= " AND entity = ".$entity;
+
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
diff --git a/htdocs/lib/lib_head.js b/htdocs/lib/lib_head.js
index f17b648f165..0556beffe43 100644
--- a/htdocs/lib/lib_head.js
+++ b/htdocs/lib/lib_head.js
@@ -700,4 +700,56 @@ function displayMessage(fieldId,message) {
textbox.style.color = 'grey';
textbox.value = message;
}
+}
+
+/*=================================================================
+Purpose: To show an element
+Input: fieldId
+Author: Regis Houssin
+Licence: GPL
+==================================================================*/
+function displayElement(fieldId) {
+ var elementId = document.getElementById(fieldId);
+ if (elementId.style.visibility == 'hidden') {
+ elementId.style.visibility = 'visible';
+ }
+}
+
+/*=================================================================
+Purpose: To hide an element
+Input: fieldId
+Author: Regis Houssin
+Licence: GPL
+==================================================================*/
+function hideElement(fieldId) {
+ var elementId = document.getElementById(fieldId);
+ if (elementId.style.visibility == 'visible') {
+ elementId.style.visibility = 'hidden';
+ }
+}
+
+/*=================================================================
+Purpose: To check a checkbox
+Input: fieldId
+Author: Regis Houssin
+Licence: GPL
+==================================================================*/
+function checkBox(boxId) {
+ var elementId = document.getElementById(boxId);
+ if (elementId.checked == false) {
+ elementId.checked = true;
+ }
+}
+
+/*=================================================================
+Purpose: To uncheck a checkbox
+Input: fieldId
+Author: Regis Houssin
+Licence: GPL
+==================================================================*/
+function uncheckBox(boxId) {
+ var elementId = document.getElementById(boxId);
+ if (elementId.checked == true) {
+ elementId.checked = false;
+ }
}
\ No newline at end of file