You are not logged in.
Références:
http://www.glpi-project.org/forum/viewtopic.php?id=7285
https://forge.indepnet.net/issues/1292
Environnement: GLPI 0.72.3
Pour faire suite au message et au ticket référencés ci-dessus, voici un patch permettant de "donner" des consommables à des groupes tout en gardant la possibilité de les donner à des utilisateurs (lors de l'attribution, c'est soit l'un soit l'autre). Ce patch permet aussi d'intégrer les groupes à la page de synthèse (http://hostname/front/consumable.php?synthese=yes).
--- inc/consumable.function.php.ORIG 2009-10-27 18:18:21.000000000 +0100
+++ inc/consumable.function.php 2010-02-24 23:23:50.111910826 +0100
@@ -110,7 +110,7 @@
echo "</th></tr>";
}
else { // Old
- echo "<tr><th colspan='8'>";
+ echo "<tr><th colspan='9'>";
echo $LANG['consumables'][35];
echo "</th></tr>";
@@ -121,12 +121,16 @@
if ($show_old){
echo "<th>".$LANG['common'][34]."</th>";
+ echo "<th>".$LANG['common'][35]."</th>";
}
echo "<th>".$LANG['financial'][3]."</th>";
if (!$show_old&&$canedit){
echo "<th>";
+ dropdownValue("glpi_groups","FK_groups",0,1,$cartype->fields["FK_entities"]);
+ echo " <input type='submit' class='submit' name='give' value='".$LANG['consumables'][32]."'>";
+ echo "<br>";
dropdownAllUsers("id_user",0,1,$cartype->fields["FK_entities"]);
echo " <input type='submit' class='submit' name='give' value='".$LANG['consumables'][32]."'>";
echo "</th>";
@@ -153,6 +157,8 @@
$where= " AND date_out IS NOT NULL ORDER BY date_out DESC, date_in, ID";
$leftjoin=" LEFT JOIN glpi_users ON (glpi_users.ID = glpi_consumables.id_user) ";
$addselect= ", glpi_users.realname AS REALNAME, glpi_users.firstname AS FIRSTNAME, glpi_users.name AS USERNAME ";
+ $leftjoin.=" LEFT JOIN glpi_groups ON (glpi_groups.ID = glpi_consumables.FK_groups) ";
+ $addselect.= ", glpi_groups.name AS GROUPNAME";
}
$query = "SELECT glpi_consumables.* $addselect
@@ -184,6 +190,10 @@
}
else echo $data["USERNAME"];
echo "</td>";
+ echo "<td class='center'>";
+ if (!empty($data["GROUPNAME"]))
+ echo " ".$data["GROUPNAME"];
+ echo "</td>";
}
echo "<td class='center'>";
@@ -361,7 +371,7 @@
}
/**
- * Show the usage summary of consumables by user
+ * Show the usage summary of consumables by user and group
*
**/
function showConsumableSummary(){
@@ -369,19 +379,24 @@
if (!haveRight("consumable","r")) return false;
- $query = "SELECT COUNT(*) AS COUNT, FK_glpi_consumables_type, id_user
- FROM glpi_consumables
+ $query = "SELECT COUNT(*) AS COUNT, FK_glpi_consumables_type, id_user, FK_groups, g.name AS NAME
+ FROM glpi_consumables AS c
+ LEFT JOIN glpi_groups AS g ON c.FK_groups = g.ID
WHERE date_out IS NOT NULL
AND FK_glpi_consumables_type IN (SELECT ID
FROM glpi_consumables_type
".getEntitiesRestrictRequest("WHERE","glpi_consumables_type").")
- GROUP BY id_user,FK_glpi_consumables_type";
+ GROUP BY id_user,FK_groups,FK_glpi_consumables_type";
$used=array();
if ($result=$DB->query($query)){
if ($DB->numrows($result))
- while ($data=$DB->fetch_array($result))
- $used[$data["id_user"]][$data["FK_glpi_consumables_type"]]=$data["COUNT"];
+ while ($data=$DB->fetch_array($result)){
+ if ( $data["id_user"] )
+ $used[$data["id_user"]][$data["FK_glpi_consumables_type"]]=$data["COUNT"];
+ if ( $data["FK_groups"] )
+ $usedgroup[$data["NAME"]][$data["FK_glpi_consumables_type"]]=$data["COUNT"];
+ }
}
$query = "SELECT COUNT(*) AS COUNT, FK_glpi_consumables_type
@@ -415,9 +430,10 @@
// Produce headline
echo "<div class='center'><table class='tab_cadrehov'><tr>";
- // Type
- echo "<th>";;
- echo $LANG['common'][34]."</th>";
+ // Type
+ echo "<th></th>";
+ echo "<th>".$LANG['common'][34]."</th>";
+ echo "<th>".$LANG['common'][35]."</th>";
foreach ($types as $key => $type){
echo "<th>$type</th>";
@@ -428,6 +444,7 @@
// new
echo "<tr class='tab_bg_2'><td><strong>".$LANG['consumables'][1]."</strong></td>";
+ echo "<td></td><td></td>";
$tot=0;
foreach ($types as $id_type => $type){
if (!isset($new[$id_type])) $new[$id_type]=0;
@@ -439,7 +456,19 @@
echo "</tr>";
foreach ($used as $id_user => $val){
- echo "<tr class='tab_bg_2'><td>".getUserName($id_user)."</td>";
+ echo "<tr class='tab_bg_2'><td></td><td>".getUserName($id_user)."</td><td></td>";
+ $tot=0;
+ foreach ($types as $id_type => $type){
+ if (!isset($val[$id_type])) $val[$id_type]=0;
+ echo "<td class='center'>".$val[$id_type]."</td>";
+ $total[$id_type]+=$val[$id_type];
+ $tot+=$val[$id_type];
+ }
+ echo "<td class='center'>".$tot."</td>";
+ echo "</tr>";
+ }
+ foreach ($usedgroup as $group => $val){
+ echo "<tr class='tab_bg_2'><td></td><td></td><td>".$group."</td>";
$tot=0;
foreach ($types as $id_type => $type){
if (!isset($val[$id_type])) $val[$id_type]=0;
@@ -450,7 +479,7 @@
echo "<td class='center'>".$tot."</td>";
echo "</tr>";
}
- echo "<tr class='tab_bg_1'><td><strong>".$LANG['common'][33]."</strong></td>";
+ echo "<tr class='tab_bg_1'><td colspan='3'><strong>".$LANG['common'][33]."</strong></td>";
$tot=0;
foreach ($types as $id_type => $type){
$tot+=$total[$id_type];
--- inc/consumable.class.php.ORIG 2009-10-27 18:18:21.000000000 +0100
+++ inc/consumable.class.php 2010-02-24 08:01:07.106920300 +0100
@@ -303,10 +303,10 @@
*@return boolean
*
**/
- function out($ID,$id_user=0) {
+ function out($ID,$id_user,$FK_groups) {
global $DB;
- $query = "UPDATE glpi_consumables SET date_out = '".date("Y-m-d")."', id_user='$id_user' WHERE ID='$ID'";
+ $query = "UPDATE glpi_consumables SET date_out = '".date("Y-m-d")."', id_user='$id_user', FK_groups = $FK_groups WHERE ID='$ID'";
if ($result = $DB->query($query)) {
return true;
--- front/consumable.edit.php.ORIG 2009-10-27 18:18:20.000000000 +0100
+++ front/consumable.edit.php 2010-02-23 22:17:47.839146371 +0100
@@ -68,12 +68,18 @@
{
$constype->check($_POST["tID"],'w');
- if ($_POST["id_user"]>0){
+ if ($_POST["id_user"]>0 || $_POST["FK_groups"]>0){
if (isset($_POST["out"]))
- foreach ($_POST["out"] as $key => $val)
- $con->out($key,$_POST["id_user"]);
+ foreach ($_POST["out"] as $key => $val) {
+ // PT 20100223
+ $id_user = 0;
+ $id_user = $_POST["id_user"];
+ $id_group = 0;
+ $id_group = $_POST["FK_groups"];
+ $con->out($key,$id_user,$id_group);
+ }
- logEvent($_POST["tID"], "consumables", 5, "inventory", $_SESSION["glpiname"]." ".$LANG['log'][97]." ".$_POST["id_user"]);
+ logEvent($_POST["tID"], "consumables", 5, "inventory", $_SESSION["glpiname"]." ".$LANG['log'][97]." ".$_POST["id_user"]. " " .$LANG['log'][47]. " " .$_POST["FK_groups"]);
}
glpi_header($_SERVER['HTTP_REFERER']);
}
Précision
Il faut bien évidement ajouter à la table glpi_consumables le champ FK_groups pour que cela fonctionne:
ALTER TABLE glpi_consumables ADD FK_groups int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_groups (ID)';
Last edited by pthoirey (2010-02-26 09:16:36)
Offline
Le patch proposé peut également s'appliquer à la version 0.72.4 disponible depuis peu. La commande est la suivante (à lancer à l'intérieur du répertoire glpi):
patch -p0 < consumable_patch.txt
avec consumable_patch.txt comme nom du fichier contenant le patch.
Last edited by pthoirey (2010-03-05 17:59:53)
Offline
Bonjour,
pourriez-vous m'indiquer si cette modification a du sens et une chance d'être intégrée?
Merci.
Offline
Bonjour,
Je suis également très intéressé par cette fonctionnalité et j'espère que ce patch sera pris en considération et que cette possibilité soit intégré assez rapidement.
Merci
Offline
J'ai relié votre proposition au ticket concerné.
On va regarder cela de plus prés.
JMD / Jean-Mathieu Doléans - Glpi-project.org - Association Indepnet
Apportez votre pierre au projet GLPI : Soutenir
Offline