Вы находитесь на странице: 1из 14

GLPI v0.72.

Plugin Reports
Créer un rapport

Plugin Reports – Tutoriel v1.1 Page 1


Sommaire
Introduction : ...................................................................................................................................................... 3
Création des fichiers : ........................................................................................................................................ 4
1. Le fichier « historiquedescontrats.php » : ............................................................................................... 5
1) Déclarations obligatoires: ................................................................................................................ 5
2) Instanciation: ................................................................................................................................... 6
3) Critères de recherche: ...................................................................................................................... 7
4) Déclaration des colonnes: ................................................................................................................ 8
5) Requête : .......................................................................................................................................... 9
6) Exécution: ...................................................................................................................................... 10
2. Les fichiers de langue: .......................................................................................................................... 11
Fichier final: ..................................................................................................................................................... 12
1. Code : ............................................................................................................................................. 12
2. Résultat: ......................................................................................................................................... 13
Conclusion ....................................................................................................................................................... 14

Plugin Reports – Tutoriel v1.1 Page 2


Introduction :

Le plugin Reports de GLPI permet, via l’ajout d’un fichier PHP et d’un ou plusieurs fichiers de
langue associés, de créer facilement des rapports. Ce tutoriel a pour but d’expliquer la méthode de création
d’un rapport.

Plugin Reports – Tutoriel v1.1 Page 3


Création des fichiers :

Prenons l’exemple d’un rapport qui dresserait la liste des ordinateurs sous contrat avec une date de
début d’utilisation paramétrable, nous l’appellerons « historiquedescontrats ». Il sera disponible en français
et en anglais.

Les fichiers nécessaires sont donc :

+ historiquedescontrats

 historiquedescontrats.php
 historiquedescontrats.fr_FR.php
 historiquedescontrats.en_GB.php

Le fichier principal est historiquedescontrats.php, c’est lui qui contient la requête à exécuter. Pour
fonctionner, il a besoin d’au moins un fichier de langue. Dans notre cas, nous en avons deux.

Tous ces fichiers sont placés dans un dossier qui porte le même nom que le rapport. Ce qui nous donne
l’arborescence suivante :

Plugin Reports – Tutoriel v1.1 Page 4


1. Le fichier « historiquedescontrats.php » :

1) Déclarations obligatoires:

Ces déclarations sont nécessaires à GLPI. Elles permettent d’initialiser les variables globales et
d’inclure le fichier de configuration.

Code :

$NEEDED_ITEMS = array("search");

$USEDBREPLICATE = 1;
$DBCONNECTION_REQUIRED = 0;

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

Plugin Reports – Tutoriel v1.1 Page 5


2) Instanciation:

Le rapport doit être instancié pour pourvoir hériter des méthodes déjà implémentées.

Code :

$report = new AutoReport(‘historiquedescontrats’);

Plugin Reports – Tutoriel v1.1 Page 6


3) Critères de recherche:

Le plugin Reports permet d’ajouter des critères de recherche pour un rapport donné. Ces critères
doivent être déclarés avant la requête.

Code (pour un seul champ):

new DateIntervalCriteria($report,"glpi_contracts.begin_date");

$report->displayCriteriasForm($_SERVER['PHP_SELF']);

Code (pour un plusieurs champs):

new DateIntervalCriteria($report,"glpi_contracts.begin_date");
new StringCriteria($report,"name");

$report->displayCriteriasForm($_SERVER['PHP_SELF']);

Il existe plusieurs critères, en voici une liste non exhaustive :

- DateIntervalCriteria (pour un intervalle de date)


- StringCriteria (pour un champ texte)
- IntegerCriteria (pour un champ numérique)
- TimeIntervalCriteria (pour un intervalle d’heure)
- PriorityCriteria (priorités des tickets)
- TicketStatusCriteria (status des tickets)
- StatusCriteria (status des items)
- …

Plugin Reports – Tutoriel v1.1 Page 7


4) Déclaration des colonnes:

Il est nécessaire de déclarer toutes les colonnes qui seront retournées par la requête. Ces colonnes
doivent avoir le même nom que celui utilisé dans la requête. Si la colonne de la table n’a pas un nom assez
explicite, il peut être utile de la renommer via un alias (SELECT monChamp AS champ)

Code (avec critères) :

if ($report->criteriasValidated())
{
$report->setColumnsNames(array( 'serial' => "Numéro de série",
'name' => 'Nom',
'ID' => 'ID'));

Code (sans critère) :

$report->setColumnsNames(array( 'serial' => "Numéro de série",


'name' => 'Nom',
'ID' => 'ID'));

Plugin Reports – Tutoriel v1.1 Page 8


5) Requête :

La requête est écrite tout simplement sous la forme d’une chaîne de caractères associée à une
variable.

Code (attention à la gestion des critères) :

$query = "SELECT `glpi_computers`.serial , `glpi_computers`.name , `glpi_computers`.ID


FROM glpi_computers
WHERE `glpi_computers`.ID IN
(
SELECT `glpi_contract_device`.`FK_device`
FROM glpi_contract_device INNER JOIN `glpi_contracts` ON
glpi_contract_device.FK_contract = `glpi_contracts`.ID ";

// La ligne ci-dessous est nécessaire lors de l’utilisation de critères


$query .= $report->addSqlCriteriasRestriction("WHERE");

$query .= " AND `glpi_contract_device`.device_type=1


)";

Les critères sont intégrés à la requête de manière automatique grâce à la fonction


addSqlCriteriasRestriction("WHERE");

Plugin Reports – Tutoriel v1.1 Page 9


6) Exécution:

Ces deux lignes permettent d’enregistrer la requête dans l’attribut de la classe et d’exécuter la
requête.

Code (avec critères) :

$report->setSqlRequest($query);
$report->execute();
}

Remarque : L’accolade fermante est présente pour fermer celle qui a été ouverte au paragraphe 5-
Déclaration des colonnes

Code (sans critère) :

$report->setSqlRequest($query);
$report->execute();

Plugin Reports – Tutoriel v1.1 Page 10


2. Les fichiers de langue:

Les fichiers de langue doivent contenir au moins cette ligne, elle indique le nom du rapport. Il faut
ajouter ensuite autant de ligne qu’il y a de texte traductible dans le rapport.

testcount.fr_FR.php

$LANG['plugin_reports']["historiquedescontrats"][1]=" MIPIH - Liste des machines sous contrats (Paramétrable)";

testcount.en_GB.php

$LANG['plugin_reports']["historiquedescontrats"][1]=" MIPIH - Computers with contract (With params)";

Il est possible d’ajouter d’autres lignes qui seront susceptibles d’être traduites en plusieurs langues.

Plugin Reports – Tutoriel v1.1 Page 11


Fichier final:

1. Code :

Voici le fichier tel qu’il doit être à la fin du tutoriel. Ce fichier prend en compte les critères utilisés
tout au long du tutoriel.

Code :

$NEEDED_ITEMS = array("search");

$USEDBREPLICATE = 1;
$DBCONNECTION_REQUIRED = 0;

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

$report = new AutoReport(‘historiquedescontrats’);

if ($report->criteriasValidated())
{
$report->setColumnsNames(array( 'serial' => "Numéro de série",
'name' => 'Nom',
'ID' => 'ID'));

$query = "SELECT `glpi_computers`.serial , `glpi_computers`.name , `glpi_computers`.ID


FROM glpi_computers
WHERE `glpi_computers`.ID IN
(
SELECT `glpi_contract_device`.`FK_device`
FROM glpi_contract_device INNER JOIN `glpi_contracts` ON
glpi_contract_device.FK_contract = `glpi_contracts`.ID ";
$query .= $report->addSqlCriteriasRestriction("WHERE");
$query .= " AND `glpi_contract_device`.device_type=1
)";

$report->setSqlRequest($query);
$report->execute();
}

Plugin Reports – Tutoriel v1.1 Page 12


2. Résultat:

Plugin Reports – Tutoriel v1.1 Page 13


Conclusion

Le tutoriel est terminé, il a permit d’expliquer comment utiliser le plugin Reports afin de pouvoir
créer des rapports personnalisés. Il faut noter que GLPI est en constante évolution et que par conséquent, le
plugin ainsi que ses méthodes sont susceptibles de changer.

Plugin Reports – Tutoriel v1.1 Page 14

Вам также может понравиться

  • Apache Cgi 2022
    Apache Cgi 2022
    Документ7 страниц
    Apache Cgi 2022
    sarrfallou267
    Оценок пока нет
  • Cours Symfony
    Cours Symfony
    Документ30 страниц
    Cours Symfony
    harimanana edwinot
    Оценок пока нет
  • TP PHP PDF
    TP PHP PDF
    Документ22 страницы
    TP PHP PDF
    Hakkache Yassin
    Оценок пока нет
  • PHP Ex Codeigniter4
    PHP Ex Codeigniter4
    Документ11 страниц
    PHP Ex Codeigniter4
    RaliteraToky
    Оценок пока нет
  • 1 TP1 Generalites
    1 TP1 Generalites
    Документ17 страниц
    1 TP1 Generalites
    maskkaa
    Оценок пока нет
  • TP Symfony
    TP Symfony
    Документ10 страниц
    TP Symfony
    Souleymane Traore
    Оценок пока нет
  • Cours Spring MVC
    Cours Spring MVC
    Документ82 страницы
    Cours Spring MVC
    nabilovic01
    Оценок пока нет
  • Tp2jee 2023
    Tp2jee 2023
    Документ22 страницы
    Tp2jee 2023
    azouzimohamed068
    Оценок пока нет
  • Api Laravel
    Api Laravel
    Документ19 страниц
    Api Laravel
    pape saliou wade
    Оценок пока нет
  • Angular 6
    Angular 6
    Документ59 страниц
    Angular 6
    Goku&Boruto Fan ANIME HD
    Оценок пока нет
  • GestionBD Partie2
    GestionBD Partie2
    Документ24 страницы
    GestionBD Partie2
    Oussama Dariàoui
    100% (1)
  • Cours Django
    Cours Django
    Документ13 страниц
    Cours Django
    Diak Flair
    Оценок пока нет
  • 1 - Presentation Nagios
    1 - Presentation Nagios
    Документ55 страниц
    1 - Presentation Nagios
    Doha Timorika
    0% (1)
  • Tuto Django Intro 2020
    Tuto Django Intro 2020
    Документ7 страниц
    Tuto Django Intro 2020
    Ben Ahmed Sakkari Mohamed
    Оценок пока нет
  • Cours Symfony
    Cours Symfony
    Документ28 страниц
    Cours Symfony
    Parfait Sandiwidi
    Оценок пока нет
  • Correction Type Examen DAW 2022 2023
    Correction Type Examen DAW 2022 2023
    Документ8 страниц
    Correction Type Examen DAW 2022 2023
    Saida Benaouda
    Оценок пока нет
  • tp5 LP Et
    tp5 LP Et
    Документ5 страниц
    tp5 LP Et
    metokcedricj
    Оценок пока нет
  • 2 Examen 2016 SI
    2 Examen 2016 SI
    Документ6 страниц
    2 Examen 2016 SI
    Younouss KEITA
    Оценок пока нет
  • Eloquent Eager Limit
    Eloquent Eager Limit
    Документ12 страниц
    Eloquent Eager Limit
    codeur.onimamy
    Оценок пока нет
  • Twig
    Twig
    Документ36 страниц
    Twig
    mariem labbouz
    Оценок пока нет
  • Extrait Du Livre
    Extrait Du Livre
    Документ6 страниц
    Extrait Du Livre
    Jalal Dziri
    Оценок пока нет
  • Datatables Tutoriel
    Datatables Tutoriel
    Документ11 страниц
    Datatables Tutoriel
    Martin Brait
    Оценок пока нет
  • Manuel CI4
    Manuel CI4
    Документ16 страниц
    Manuel CI4
    Herman Kamwa
    Оценок пока нет
  • Exercice C#
    Exercice C#
    Документ5 страниц
    Exercice C#
    Boroma
    Оценок пока нет
  • Ma Arch
    Ma Arch
    Документ30 страниц
    Ma Arch
    Babacar Sakho
    100% (1)
  • Projet PHP
    Projet PHP
    Документ13 страниц
    Projet PHP
    Houdadine Abdou
    Оценок пока нет
  • Readme
    Readme
    Документ15 страниц
    Readme
    Med Madrid
    Оценок пока нет
  • Examen Angular v5
    Examen Angular v5
    Документ8 страниц
    Examen Angular v5
    eya.somai
    Оценок пока нет
  • Laravel
    Laravel
    Документ17 страниц
    Laravel
    Ñou Fel Bfs
    Оценок пока нет
  • Mise en Place D'une API Rest Avec Spring
    Mise en Place D'une API Rest Avec Spring
    Документ6 страниц
    Mise en Place D'une API Rest Avec Spring
    jean rudel
    Оценок пока нет
  • Rapport Tp4
    Rapport Tp4
    Документ11 страниц
    Rapport Tp4
    Yaya 1370
    Оценок пока нет
  • Untitled
    Untitled
    Документ31 страница
    Untitled
    Ismail Baslam
    Оценок пока нет
  • Correction SAR 21-22 SP S1-1
    Correction SAR 21-22 SP S1-1
    Документ6 страниц
    Correction SAR 21-22 SP S1-1
    Islem Yacoubi
    Оценок пока нет
  • Cours PHP - PHP ET LES BASES DE DONNEES MYSQL
    Cours PHP - PHP ET LES BASES DE DONNEES MYSQL
    Документ13 страниц
    Cours PHP - PHP ET LES BASES DE DONNEES MYSQL
    Jaminben Gbego
    Оценок пока нет
  • Codeigniter
    Codeigniter
    Документ10 страниц
    Codeigniter
    Arri Tiana
    Оценок пока нет
  • TP SQL Server2005 Procédures Stockées Et Déclencheurs
    TP SQL Server2005 Procédures Stockées Et Déclencheurs
    Документ12 страниц
    TP SQL Server2005 Procédures Stockées Et Déclencheurs
    Mohamed Amine BEN BOUBKER
    Оценок пока нет
  • Examen Angular v5 Correction
    Examen Angular v5 Correction
    Документ9 страниц
    Examen Angular v5 Correction
    eya.somai
    Оценок пока нет
  • tp1 Angular
    tp1 Angular
    Документ13 страниц
    tp1 Angular
    Azeddine EL-MAMOUNI
    Оценок пока нет
  • FRAME
    FRAME
    Документ7 страниц
    FRAME
    Gerah
    Оценок пока нет
  • Examen Final NFP111 2010-2011-Session1
    Examen Final NFP111 2010-2011-Session1
    Документ3 страницы
    Examen Final NFP111 2010-2011-Session1
    Peter Bardawil
    Оценок пока нет
  • Procédure GLPI
    Procédure GLPI
    Документ13 страниц
    Procédure GLPI
    Ghoual Mohamed
    Оценок пока нет
  • TP10
    TP10
    Документ2 страницы
    TP10
    Amine Bouali
    Оценок пока нет
  • Cours
    Cours
    Документ10 страниц
    Cours
    Amine Mabrouki
    Оценок пока нет
  • Examen Blanc PCD
    Examen Blanc PCD
    Документ2 страницы
    Examen Blanc PCD
    richard mfomo
    Оценок пока нет
  • CodeIgniter PDF
    CodeIgniter PDF
    Документ26 страниц
    CodeIgniter PDF
    lov'me
    0% (1)
  • Prog en C 21
    Prog en C 21
    Документ176 страниц
    Prog en C 21
    Alassane Jules NIKIEMA
    Оценок пока нет
  • Chapitre 2
    Chapitre 2
    Документ14 страниц
    Chapitre 2
    marie naj
    Оценок пока нет
  • Programmation Structurée en T-SQL
    Programmation Structurée en T-SQL
    Документ8 страниц
    Programmation Structurée en T-SQL
    Warsaww
    Оценок пока нет
  • Installation Glpifusion
    Installation Glpifusion
    Документ20 страниц
    Installation Glpifusion
    saida.darani
    Оценок пока нет
  • Note
    Note
    Документ12 страниц
    Note
    idrissa cisse
    Оценок пока нет
  • Presentation Nagios
     Presentation Nagios
    Документ55 страниц
    Presentation Nagios
    chekir
    Оценок пока нет
  • Terminale 2022 Asie Jour 1
    Terminale 2022 Asie Jour 1
    Документ13 страниц
    Terminale 2022 Asie Jour 1
    sarra
    Оценок пока нет
  • Glpi Final
    Glpi Final
    Документ15 страниц
    Glpi Final
    api-358853016
    Оценок пока нет
  • Tutorial Part 1
    Tutorial Part 1
    Документ9 страниц
    Tutorial Part 1
    Ahmed Amine Anoubl
    Оценок пока нет
  • Tutorielqtdesignerv 2
    Tutorielqtdesignerv 2
    Документ9 страниц
    Tutorielqtdesignerv 2
    Luis Angel Reyes
    Оценок пока нет
  • Nagios Supervision
    Nagios Supervision
    Документ8 страниц
    Nagios Supervision
    api-312739131
    Оценок пока нет
  • Mini PROJET
    Mini PROJET
    Документ8 страниц
    Mini PROJET
    TECH NEWS
    Оценок пока нет
  • 2 Python Les Sous Programmes
    2 Python Les Sous Programmes
    Документ28 страниц
    2 Python Les Sous Programmes
    Mohamed Khefacha
    Оценок пока нет
  • Exercice Requête SQL
    Exercice Requête SQL
    Документ2 страницы
    Exercice Requête SQL
    Nesrine Eglantine
    Оценок пока нет
  • Programmer en JavaScript
    Programmer en JavaScript
    От Everand
    Programmer en JavaScript
    Рейтинг: 4.5 из 5 звезд
    4.5/5 (2)
  • Solution Exercice Interpolation
    Solution Exercice Interpolation
    Документ4 страницы
    Solution Exercice Interpolation
    Nivek Lenasarien
    Оценок пока нет
  • Cours de Statisques Descriptives Et Inférentielles IUT2
    Cours de Statisques Descriptives Et Inférentielles IUT2
    Документ31 страница
    Cours de Statisques Descriptives Et Inférentielles IUT2
    Patman Mutombo
    Оценок пока нет
  • Exam Proba ENIT Avril 2021
    Exam Proba ENIT Avril 2021
    Документ3 страницы
    Exam Proba ENIT Avril 2021
    Sadok Bouzid
    Оценок пока нет
  • RNIS
    RNIS
    Документ18 страниц
    RNIS
    Best Wishes
    Оценок пока нет
  • Correction 1.1.4.6 Lab - Configuring Basic Router Settings With IOS CLI
    Correction 1.1.4.6 Lab - Configuring Basic Router Settings With IOS CLI
    Документ13 страниц
    Correction 1.1.4.6 Lab - Configuring Basic Router Settings With IOS CLI
    نوفل زعاج
    Оценок пока нет
  • Exercice VLSM 1
    Exercice VLSM 1
    Документ4 страницы
    Exercice VLSM 1
    ayoub atti
    Оценок пока нет
  • 1dlstdix12 N
    1dlstdix12 N
    Документ10 страниц
    1dlstdix12 N
    franckyves
    Оценок пока нет
  • Exposé RFI
    Exposé RFI
    Документ8 страниц
    Exposé RFI
    Ebenezer Egbakotan
    0% (1)
  • 1-Introduction Au Domaine Du Décisionnel
    1-Introduction Au Domaine Du Décisionnel
    Документ3 страницы
    1-Introduction Au Domaine Du Décisionnel
    Mohamed Hamrit
    Оценок пока нет
  • Strength Training Workshop by Slidesgo
    Strength Training Workshop by Slidesgo
    Документ48 страниц
    Strength Training Workshop by Slidesgo
    blilita soundous
    Оценок пока нет
  • Programme SAFEX
    Programme SAFEX
    Документ1 страница
    Programme SAFEX
    djmidou
    Оценок пока нет
  • Exercices Ondes
    Exercices Ondes
    Документ8 страниц
    Exercices Ondes
    Amine El Ameri
    Оценок пока нет
  • 35 Conseils Pour Réussir Un Lotissement PDF
    35 Conseils Pour Réussir Un Lotissement PDF
    Документ24 страницы
    35 Conseils Pour Réussir Un Lotissement PDF
    amical1955
    100% (1)
  • Construction Des Routes
    Construction Des Routes
    Документ32 страницы
    Construction Des Routes
    Omar Habyby
    Оценок пока нет
  • Electronique Numérique S1 2021
    Electronique Numérique S1 2021
    Документ52 страницы
    Electronique Numérique S1 2021
    Hamadoun Abba Kanne Diallo
    Оценок пока нет
  • API Sup Sie Wincc1
    API Sup Sie Wincc1
    Документ2 страницы
    API Sup Sie Wincc1
    nattab34
    Оценок пока нет
  • 25 Stromausfall GD FR
    25 Stromausfall GD FR
    Документ13 страниц
    25 Stromausfall GD FR
    MAX
    Оценок пока нет
  • Distributeru de Bonbons
    Distributeru de Bonbons
    Документ22 страницы
    Distributeru de Bonbons
    Kanouni Oussama
    Оценок пока нет
  • Partie Rhétorique
    Partie Rhétorique
    Документ6 страниц
    Partie Rhétorique
    Manal Yassine
    Оценок пока нет
  • Adénopathies Cervicofaciales
    Adénopathies Cervicofaciales
    Документ10 страниц
    Adénopathies Cervicofaciales
    Ýøů Çěf Gherras
    100% (1)
  • Process Legal de Construction en CI EAA 29 11 2023
    Process Legal de Construction en CI EAA 29 11 2023
    Документ31 страница
    Process Legal de Construction en CI EAA 29 11 2023
    kvistel1987
    100% (1)
  • Controle Qualité Produit Vf1
    Controle Qualité Produit Vf1
    Документ58 страниц
    Controle Qualité Produit Vf1
    Khaled Kalai
    Оценок пока нет
  • INTRODUCTION AU SYMBOLISME TOTÉMIQUE ANIMAL (PDF) (PDFDrive)
    INTRODUCTION AU SYMBOLISME TOTÉMIQUE ANIMAL (PDF) (PDFDrive)
    Документ170 страниц
    INTRODUCTION AU SYMBOLISME TOTÉMIQUE ANIMAL (PDF) (PDFDrive)
    cherruault
    Оценок пока нет
  • m5t-10-200k-vfr-12 21 Aa XX 112 31-bd Compressed
    m5t-10-200k-vfr-12 21 Aa XX 112 31-bd Compressed
    Документ8 страниц
    m5t-10-200k-vfr-12 21 Aa XX 112 31-bd Compressed
    Chef Sav Lift Yde
    Оценок пока нет
  • TP N°18.1 - Corrosion Et Protection Du Fer
    TP N°18.1 - Corrosion Et Protection Du Fer
    Документ14 страниц
    TP N°18.1 - Corrosion Et Protection Du Fer
    Wael Maatoug
    Оценок пока нет
  • TRAD Chap 21. Trapped in The Academy's Eroge
    TRAD Chap 21. Trapped in The Academy's Eroge
    Документ5 страниц
    TRAD Chap 21. Trapped in The Academy's Eroge
    Nicolas
    Оценок пока нет
  • Sohim 0398-3811 1985 Edc 7 1 939
    Sohim 0398-3811 1985 Edc 7 1 939
    Документ532 страницы
    Sohim 0398-3811 1985 Edc 7 1 939
    Zanj Al-Jahiz
    Оценок пока нет
  • Rapport Beni Idir
    Rapport Beni Idir
    Документ44 страницы
    Rapport Beni Idir
    gpmcsafi
    88% (8)
  • Rapport
    Rapport
    Документ19 страниц
    Rapport
    Guillaume Tassery
    Оценок пока нет
  • Exo13 Corigé
    Exo13 Corigé
    Документ76 страниц
    Exo13 Corigé
    Youssef EL Mlili
    Оценок пока нет