You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2020-04-15 11:38:18

bruno.desmet
Member
From: LILLE
Registered: 2013-10-15
Posts: 156

sélection du format pour export

Bonjour,

Je n'ai pas trouvé le moyen de récupérer la liste de choix et les traitements qui vont bien pour exporter les données. J'ai cherché dans front et inc ....

Mon but serait d'inclure cette fonction pour exporter directement un tableau généré par un plugin qui affiche les données autrement que par new PluginReportsAutoReport();

Merci pour votre aide


En Prod : Windows Server 2016 IIS PHP 7.3.4 MySQL Enterprise Server 8.0.17 GLPI 9.4.6 75 entités 18603 postes 19031 Moniteurs 739 imprimantes 11278 périphériques pour 12223 utilisateurs plugins : injection de fichier, impression pdf, rapports

Offline

#2 2020-04-15 13:53:49

ec2311
Member
Registered: 2016-04-07
Posts: 305

Re: sélection du format pour export

Bonjour
A priori vous parlez du plugin reports.

Ce dont vous parlez est un plugin existant ou que vous avez ecrit ?

en général vous avez les lignes de selection (lieu, logiciels) dans les premieres lignes du plugin, puis vous avez une requete type SQL.


GLPI 10.0.10
GLPIinventory 1.3.4

Agents : FI (2.6, 2.5) et Glpiagents (1.7)

Offline

#3 2020-04-15 15:55:10

bruno.desmet
Member
From: LILLE
Registered: 2013-10-15
Posts: 156

Re: sélection du format pour export

Merci pour l'attention que vous avez accordé à ma question.

Je reformule. Je voudrais utiliser la liste de choix qui se trouve sur le formulaire entre "afficher n élément et le compteur de page. Donc quelque chose qui existe en dehors des plugin dans un plugin report de type nombre de ....le nom du fichier semble être pcsbyentity

Cordialement


En Prod : Windows Server 2016 IIS PHP 7.3.4 MySQL Enterprise Server 8.0.17 GLPI 9.4.6 75 entités 18603 postes 19031 Moniteurs 739 imprimantes 11278 périphériques pour 12223 utilisateurs plugins : injection de fichier, impression pdf, rapports

Offline

#4 2020-04-15 17:57:20

bruno.desmet
Member
From: LILLE
Registered: 2013-10-15
Posts: 156

Re: sélection du format pour export

pour information le rapport :

<?php
/*
* @version $Id: pcsbyentity.php 216 2012-03-01 17:20:30Z tsmr $
-------------------------------------------------------------------------
reports - Additional reports plugin for GLPI
Copyright (C) 2003-2011 by the reports Development Team.

https://forge.indepnet.net/projects/reports
-------------------------------------------------------------------------

LICENSE

This file is part of reports.

reports is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

reports is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with reports. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

// Original Author of file: Remi Collet
// Purpose of file:
// ----------------------------------------------------------------------

function cmpStat ($a, $b) {
   return $a["tot"] - $b["tot"];
}


function doStatBis ($table, $entities, $header) {
   global $DB, $LANG;

   // Compute stat
   $counts = array();
   foreach ($entities as $entity) {
      // Count for this entity
      $sql = "SELECT `states_id`, count(*) AS cpt
              FROM `$table`
              WHERE `is_deleted` = '0'
                    AND `is_template` = '0'
                    AND `entities_id` = '$entity'
              GROUP BY `states_id`";

      $result          = $DB->query($sql);
      $counts[$entity] = array();
      while ($data = $DB->fetch_array($result)) {
         $counts[$entity][$data["states_id"]] = $data["cpt"];
      }

      $counts[$entity]["tot"] = 0;
      foreach ($header as $id => $name) {
         if (isset($counts[$entity][$id])) {
            $counts[$entity]["tot"] += $counts[$entity][$id];
         } else {
            $counts[$entity][$id] = 0;
         }
      }
   }

   // Sort result
   uasort($counts,"cmpStat");

   // Display result
   $total["tot"] = 0;
   foreach ($header as $id => $name) {
      $total[$id] = 0;
   }
   foreach ($counts as $entity => $count) {
      if ($count["tot"]) {
         $Ent = new Entity();
         $Ent->getFromDB($entity);

         echo "<tr class='tab_bg_2'><td class='left'>";
         if ($entity) {
            echo $Ent->fields["name"] . "</td>";
         } else {
            echo $LANG["entity"][2] . "</td>";
         }
         echo "<td class='right'>" . $count["tot"] . "</td>";
         $total["tot"] += $count["tot"];
         foreach ($header as $id => $name) {
            echo "<td class='right'>" . $count[$id] . "</td>";
            $total[$id] += $count[$id];
         }
      }
      echo "</tr>\n";
   }

   // Display total
   if (count($entities) >1) {
      echo "<tr class='tab_bg_1'><td class='left'>".$LANG['plugin_reports']['pcsbyentity'][3]."</td>";
      echo "<td class='right'>" . $total["tot"] . "</td>";
      foreach ($header as $id => $name) {
         echo "<td class='right'>" . $total[$id] . "</td>";
      }
      echo "</tr>\n";
   }
}


function doStat ($table, $entity, $header, $level=0) {
   global $DB, $LANG;

   $Ent = new Entity();
   $Ent->getFromDB($entity);

   // Count for this entity
   $sql = "SELECT `states_id`, count(*) AS cpt
           FROM `$table`
           WHERE `is_deleted` = '0'
                 AND `is_template` = '0'
                 AND `entities_id` = '$entity'
           GROUP BY `states_id`";

   $result = $DB->query($sql);
   $count  = array();
   while ($data = $DB->fetch_array($result)) {
      $count[$data["states_id"]] = $data["cpt"];
   }

   $count["tot"] = 0;
   foreach ($header as $id => $name) {
      if (isset($count[$id])) {
         $count["tot"] += $count[$id];
      } else {
         $count[$id] = 0;
      }
   }

   // Display counters for this entity
   if ($count["tot"] >0) {
      echo "<tr class='tab_bg_2'><td>";
      for ($i=0 ; $i<$level ; $i++) {
         echo "&nbsp;&nbsp;&nbsp;";
      }
      if ($entity) {
         echo $Ent->fields["name"] . "</td>";
      }else {
         echo $LANG["entity"][2] . "</td>";
      }
      echo "<td class='right'>" . $count["tot"] . "</td>";
      foreach ($header as $id => $name) {
         echo "<td class='right'>" . $count[$id] . "</td>";
      }
      echo "</tr>\n";
   }

   // Call for Childs
   $save = $count["tot"];
   doStatChilds($table, $entity, $header, $count, $level+1);

   // Display total (Current+Childs)
   if ($save != $count["tot"]) {
      echo "<tr class='tab_bg_1'><td>";
      for ($i=0 ; $i<$level ; $i++) {
         echo "&nbsp;&nbsp;&nbsp;";
      }
      echo $LANG['plugin_reports']['pcsbyentity'][3] . " ";

      if ($entity) {
         echo $Ent->fields["name"] . "</td>";
      } else {
         echo $LANG["entity"][2] . "</td>";
      }
      echo "<td class='right'>" . $count["tot"] . "</td>";
      foreach ($header as $id => $name) {
         echo "<td class='right'>" . $count[$id] . "</td>";
      }
      echo "</tr>\n";
   }
   return $count;
}


function doStatChilds($table, $entity, $header, &$total, $level) {
   global $DB, $LANG;

   // Search child entities
   $sql = "SELECT `id`
           FROM `glpi_entities`
           WHERE `entities_id` = '$entity'
           ORDER BY `name`";
   $result = $DB->query($sql);

   while ($data = $DB->fetch_array($result)) {
      $fille = doStat($table, $data["id"], $header, $level);
      foreach ($header as $id => $name) {
         $total[$id] += $fille[$id];
      }
      $total["tot"] += $fille["tot"];
   }
}

//Options for GLPI 0.71 and newer : need slave db to access the report
$USEDBREPLICATE        = 1;
$DBCONNECTION_REQUIRED = 0;

define('GLPI_ROOT', '../../../..');
include (GLPI_ROOT . "/inc/includes.php");

plugin_reports_checkRight('reports', "pcsbyentity","r");
Html::header($LANG['plugin_reports']['pcsbyentity'][1], $_SERVER['PHP_SELF'], "utils", "report");

Report::title();

echo "<div class='center'>";

// ---------- Form ------------
echo "<form action='".$_SERVER["PHP_SELF"]."' method='post'>";
echo "<table class='tab_cadre' cellpadding='5'>\n";
echo "<tr class='tab_bg_1 center'><th colspan='2'>" . $LANG['plugin_reports']['pcsbyentity'][1] .
      "</th></tr>\n";
echo "<tr class='tab_bg_1'><td class='right'>" . $LANG['plugin_reports']['pcsbyentity'][2] .
      "&nbsp;:&nbsp;</td>";
echo "<td><select name='type'><option value=''>-----</option>";

$choix = array('Computer'         => $LANG["Menu"][0],
               'Monitor'          => $LANG["Menu"][3],
               'Printer'          => $LANG["Menu"][2],
               'NetworkEquipment' => $LANG["title"][6],
               'Phone'            => $LANG["help"][35]);

foreach ($choix as $id => $name) {
   $item = new $id();
   if ($item->canView()) {
      echo "<option value='" . $id;
      if (isset($_POST["type"]) && $_POST["type"]==$id) {
         echo "' selected='selected'>";
      } else {
         echo "'>";
      }
      echo $name . "</option>";
   }
}
echo "</select></td></tr>\n";

if (count($_SESSION["glpiactiveentities"]) > 1) {
   echo "<tr class='tab_bg_1'><td class='right'>" . $LANG['plugin_reports']['pcsbyentity'][5] .
         "&nbsp;:&nbsp;</td>";
   echo "<td><select name='sort'><option value='0'>".$LANG['plugin_reports']['pcsbyentity'][6].
         "</option>";
   $sel = (isset($_POST["sort"]) && $_POST["sort"] ? "selected='selected'" : "");

   echo "<option value='1' $sel>".$LANG['plugin_reports']['pcsbyentity'][7]."</option>".
        "</select></td></tr>\n";
}

echo "<tr class='tab_bg_1 center'>".
     "<td colspan='2'><input type='submit' value='valider' class='submit'/></td>";
echo "</tr>\n";
echo "</table>\n</form></div>\n";

// --------------- Result -------------
if (isset($_POST["type"]) && $_POST["type"] != '') {
   echo "<table class='tab_cadre'>\n";

   echo "<tr><th>".$LANG["entity"][0]. "</th>" .
         "<th>&nbsp;" . $LANG['plugin_reports']['pcsbyentity'][3] . "&nbsp;</th>" .
         "<th>&nbsp;" . $LANG['plugin_reports']['pcsbyentity'][4] . "&nbsp;</th>";

   $sql = "SELECT `id`, `name`
           FROM `glpi_states`
           ORDER BY `id`";
   $result = $DB->query($sql);

   $header[0] = $LANG['plugin_reports']['pcsbyentity'][4];
   while ($data = $DB->fetch_array($result)) {
      $header[$data["id"]] = $data["name"];
      echo "<th>&nbsp;" . $data["name"] . "&nbsp;</th>";
   }
   echo "</tr>\n";

   if (isset($_POST["sort"]) && $_POST["sort"] >0) {
      doStatBis(getTableForItemType($_POST["type"]), $_SESSION["glpiactiveentities"], $header);
   } else {
      doStat(getTableForItemType($_POST["type"]), $_SESSION["glpiactive_entity"], $header);
   }
   echo "</table></div>";
}

Html::footer();


En Prod : Windows Server 2016 IIS PHP 7.3.4 MySQL Enterprise Server 8.0.17 GLPI 9.4.6 75 entités 18603 postes 19031 Moniteurs 739 imprimantes 11278 périphériques pour 12223 utilisateurs plugins : injection de fichier, impression pdf, rapports

Offline

#5 2020-04-27 08:56:53

ec2311
Member
Registered: 2016-04-07
Posts: 305

Re: sélection du format pour export

Dans vos report ci-dessus, vous avez des requetes SQL, notamment
SELECT `states_id`, count(*) AS cpt
           FROM `$table`
           WHERE `is_deleted` = '0'
                 AND `is_template` = '0'
                 AND `entities_id` = '$entity'
           GROUP BY `states_id`";

vous n'avez pas moyen de vérifier quelle requete correspond au resultat attendu ?

Si vous avez la requete, vous avez alors la possiiblité de l'integrer dans un report PHP quelconque, en attaquant la BD


GLPI 10.0.10
GLPIinventory 1.3.4

Agents : FI (2.6, 2.5) et Glpiagents (1.7)

Offline

Board footer

Powered by FluxBB