From d61c8a07d5b1c1121a3163a4e8e583e6c086d3df Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 18 Dec 2009 14:34:25 +0000 Subject: [PATCH] New: affichage de toutes les constantes uniquement pour le superadmin New: possibilite de modifier/supprimer plusieurs constantes d'un seul coup Todo: ajouter fenetre de confirmation --- htdocs/admin/const.php | 82 ++++++++++++++++++++++---------- htdocs/admin/system/constall.php | 36 +++++++------- htdocs/lib/admin.lib.php | 3 +- htdocs/lib/lib_head.js | 52 ++++++++++++++++++++ 4 files changed, 129 insertions(+), 44 deletions(-) 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 ''; # Affiche lignes des constantes $sql = "SELECT"; $sql.= " rowid"; $sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; $sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; +$sql.= ", type"; $sql.= ", note"; $sql.= ", entity"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; -$sql.= " WHERE entity IN (0,".$conf->entity.")"; -if (empty($all)) $sql.= " AND visible = 1"; -$sql.= " ORDER BY name ASC"; +$sql.= " WHERE entity IN (".$user->entity.",".$conf->entity.")"; +if ($user->entity) $sql.= " AND visible = 1"; +$sql.= " ORDER BY entity, name ASC"; dol_syslog("Const::listConstant sql=".$sql); $result = $db->query($sql); @@ -137,41 +165,37 @@ if ($result) $var=!$var; print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print "$obj->name\n"; // Value print ''; - print ''; + print ''; print ''; // Note - print ''; + print ''; print ''; - // Entity - if ($conf->multicompany->enabled) + // Entity limit to superadmin + if ($conf->multicompany->enabled && !$user->entity) { print ''; - print ''; + print ''; print ''; } else { - print ''; + print ''; } print ''; - print '   '; - print ''.img_delete().''; + print ''; print "\n"; - print '
'; print "\n"; $i++; } @@ -180,6 +204,16 @@ if ($result) 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 ''; print ''; -print ''; +if (!$user->entity) print ''; 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 ''."\n"; - print ''."\n"; - print ''."\n"; - print "\n"; - - $i++; + $obj = $db->fetch_object($result); + $var=!$var; + + print ''; + print ''."\n"; + print ''."\n"; + if (!$user->entity) print ''."\n"; + print "\n"; + + $i++; } } -$var=!$var; - print '
'.$langs->trans("Parameter").''.$langs->trans("Value").''.$langs->trans("Entity").''.$langs->trans("Entity").'
'.$obj->name.''.$obj->value.''.$obj->entity.'
'.$obj->name.''.$obj->value.''.$obj->entity.'
'; 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