From 749e76d682401a11cd8978e4c4de545995254821 Mon Sep 17 00:00:00 2001
From: Progfou
Date: Mon, 28 Apr 2014 15:34:11 -0400
Subject: [PATCH] glpi-plugin-auf : ajout des champs AUF
---
glpi-plugin-auf/plugin/front/computer.form.php | 12 ++
glpi-plugin-auf/plugin/front/profile.form.php | 12 ++
glpi-plugin-auf/plugin/hook.php | 119 ++++++++++++++++++++
glpi-plugin-auf/plugin/inc/computer.class.php | 110 ++++++++++++++++++
glpi-plugin-auf/plugin/inc/profile.class.php | 112 ++++++++++++++++++
glpi-plugin-auf/plugin/rapport.migrationubuntu.php | 21 +++-
glpi-plugin-auf/plugin/report.computers.php | 13 +--
glpi-plugin-auf/plugin/report.operatingsystems.php | 7 +-
glpi-plugin-auf/plugin/setup.php | 23 +++-
9 files changed, 410 insertions(+), 19 deletions(-)
create mode 100644 glpi-plugin-auf/plugin/front/computer.form.php
create mode 100644 glpi-plugin-auf/plugin/front/profile.form.php
create mode 100644 glpi-plugin-auf/plugin/inc/computer.class.php
create mode 100644 glpi-plugin-auf/plugin/inc/profile.class.php
diff --git a/glpi-plugin-auf/plugin/front/computer.form.php b/glpi-plugin-auf/plugin/front/computer.form.php
new file mode 100644
index 0000000..8e473a0
--- /dev/null
+++ b/glpi-plugin-auf/plugin/front/computer.form.php
@@ -0,0 +1,12 @@
+update($_POST);
+ Html::back();
+}
+?>
diff --git a/glpi-plugin-auf/plugin/front/profile.form.php b/glpi-plugin-auf/plugin/front/profile.form.php
new file mode 100644
index 0000000..8b387df
--- /dev/null
+++ b/glpi-plugin-auf/plugin/front/profile.form.php
@@ -0,0 +1,12 @@
+update($_POST);
+ Html::back();
+}
+?>
diff --git a/glpi-plugin-auf/plugin/hook.php b/glpi-plugin-auf/plugin/hook.php
index 1275775..98fbe7f 100644
--- a/glpi-plugin-auf/plugin/hook.php
+++ b/glpi-plugin-auf/plugin/hook.php
@@ -4,11 +4,130 @@
Copyright (C) 2014 AUF -- www.auf.org
*/
+function plugin_auf_getAddSearchOptions($itemtype) {
+ $sopt = array();
+ if ($itemtype == 'Computer') {
+ $i = 5250;
+ $sopt[$i]['table'] = 'glpi_plugin_auf_categories';
+ $sopt[$i]['field'] = 'name';
+ $sopt[$i]['linkfield'] = 'auf_categories_id';
+ $sopt[$i]['name'] = 'AUF - Catégorie';
+ $sopt[$i]['datatype'] = 'dropdown';
+ $sopt[$i]['massiveaction'] = FALSE;
+ $sopt[$i]['joinparams'] = array('beforejoin'
+ => array('table' => 'glpi_plugin_auf_computers',
+ 'joinparams' => array('jointype' => 'child',
+ 'linkfield' => 'id') ) );
+ $i++;
+ $sopt[$i]['table'] = 'glpi_plugin_auf_utilisations';
+ $sopt[$i]['field'] = 'name';
+ $sopt[$i]['linkfield'] = 'auf_utilisations_id';
+ $sopt[$i]['name'] = 'AUF - Utilisation';
+ $sopt[$i]['datatype'] = 'dropdown';
+ $sopt[$i]['massiveaction'] = FALSE;
+ $sopt[$i]['joinparams'] = array('beforejoin'
+ => array('table' => 'glpi_plugin_auf_computers',
+ 'joinparams' => array('jointype' => 'child',
+ 'linkfield' => 'id') ) );
+ $i++;
+ $sopt[$i]['table'] = 'glpi_plugin_auf_computers';
+ $sopt[$i]['field'] = 'annee_acquisition';
+ $sopt[$i]['linkfield'] = 'id';
+ $sopt[$i]['name'] = 'AUF - Année d\'acquisition';
+ $sopt[$i]['datatype'] = 'number';
+ $sopt[$i]['massiveaction'] = FALSE;
+ $i++;
+ $sopt[$i]['table'] = 'glpi_plugin_auf_computers';
+ $sopt[$i]['field'] = 'est_virtuel';
+ $sopt[$i]['linkfield'] = 'id';
+ $sopt[$i]['name'] = 'AUF - Virtuel';
+ $sopt[$i]['datatype'] = 'bool';
+ // $sopt[$i]['joinparams'] = array('jointype' => 'child');
+ $sopt[$i]['massiveaction'] = FALSE;
+ }
+ return $sopt;
+}
+
function plugin_auf_install() {
+ global $DB;
+
+ $migration = new Migration(100);
+ // Création de la table uniquement lors de la première installation
+ if (!TableExists("glpi_plugin_auf_profiles")) {
+ // requête de création de la table
+ $query = "CREATE TABLE `glpi_plugin_auf_profiles` (
+ `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',
+ `right` char(1) collate utf8_unicode_ci default NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+ $DB->queryOrDie($query, $DB->error());
+ $migration->migrationOneTable("glpi_plugin_auf_profiles");
+ // creation du premier accès nécessaire lors de l'installation du plugin
+ include_once(GLPI_ROOT."/plugins/auf/inc/profile.class.php");
+ PluginAufProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']);
+ }
+
+ if (!TableExists("glpi_plugin_auf_computers")) {
+ // requête de création de la table
+ $query = "CREATE TABLE `glpi_plugin_auf_computers` (
+ `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_computers (id)',
+ `auf_categories_id` int(11) NOT NULL DEFAULT '0',
+ `auf_utilisations_id` int(11) NOT NULL DEFAULT '0',
+ `annee_acquisition` int(11) NOT NULL DEFAULT '0',
+ `est_virtuel` tinyint(1) NOT NULL DEFAULT '0',
+ `affectation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ if (!TableExists("glpi_plugin_auf_categories")) {
+ // requête de création de la table
+ $query = "CREATE TABLE `glpi_plugin_auf_categories` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `comment` text DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `name` (`name`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+ $DB->queryOrDie($query, $DB->error());
+ $query = "INSERT INTO `glpi_plugin_auf_categories` VALUES
+ (1, 'Infrastructure', ''),
+ (2, 'Poste interne', ''),
+ (3, 'Poste public', '')";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ if (!TableExists("glpi_plugin_auf_utilisations")) {
+ // requête de création de la table
+ $query = "CREATE TABLE `glpi_plugin_auf_utilisations` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `comment` text DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `name` (`name`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+ $DB->queryOrDie($query, $DB->error());
+ $query = "INSERT INTO `glpi_plugin_auf_utilisations` VALUES
+ (1, 'Production', ''),
+ (2, 'Test', ''),
+ (3, 'Réserve', 'stock, mission, formation, â¦')";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ $migration->executeMigration();
return TRUE;
}
function plugin_auf_uninstall() {
+ global $DB;
+
+ $tables = array(); // "glpi_plugin_auf_profiles", // "glpi_plugin_auf_computers",
+ // "glpi_plugin_auf_categories", "glpi_plugin_auf_utilisations");
+ foreach($tables as $table) {
+ $DB->query("DROP TABLE IF EXISTS `$table`;");
+ }
+
return TRUE;
}
diff --git a/glpi-plugin-auf/plugin/inc/computer.class.php b/glpi-plugin-auf/plugin/inc/computer.class.php
new file mode 100644
index 0000000..6b6841d
--- /dev/null
+++ b/glpi-plugin-auf/plugin/inc/computer.class.php
@@ -0,0 +1,110 @@
+add(array('id' => $ID));
+ }
+
+ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
+ if ($item->getType() == 'Computer') {
+ return "Infos AUF";
+ }
+ return '';
+ }
+
+ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
+ if ($item->getType() == 'Computer') {
+ $ID = $item->getID();
+ $computer = new self();
+ // si la machine n'existe pas dans la base, je l'ajoute
+ if (!$computer->GetfromDB($ID)) {
+ $computer->createInfos($ID);
+ }
+ $computer->showForm($ID);
+ }
+ return true;
+ }
+
+ function showForm($id, $options=array()) {
+ $target = $this->getFormURL();
+ if (isset($options['target'])) {
+ $target = $options['target'];
+ }
+
+ if (!Session::haveRight("computer", "r")) {
+ return false;
+ }
+
+ $canedit = Session::haveRight("computer", "w");
+ $computer = new Computer();
+ if ($id){
+ $this->getFromDB($id);
+ $computer->getFromDB($id);
+ }
+
+ echo "
";
+
+echo "Les données du rapport de migration Ubuntu seront disponibles à partir du lundi 21 avril 2014.
En attendant vous pouvez déjà consulter les rapports sur le parc machine et sur les systèmes d'exploitation.
";
+
+Html::footer();
+?>
diff --git a/glpi-plugin-auf/plugin/report.computers.php b/glpi-plugin-auf/plugin/report.computers.php
index 106d895..39192dc 100644
--- a/glpi-plugin-auf/plugin/report.computers.php
+++ b/glpi-plugin-auf/plugin/report.computers.php
@@ -14,11 +14,6 @@ Report::title();
$computer = new Computer();
-$state_sql = "";
-if (($state != "") AND ($state != "0")) {
- $state_sql = " AND `states_id` = '".$state."' ";
-}
-
$itemtype = 'Computer';
$table_item = getTableForItemType($itemtype);
@@ -54,7 +49,7 @@ function svg_pie_chart($values, $size=16) {
return $svg;
}
-echo "\nOrdinateurs par implantation
";
+//echo "\nOrdinateurs par implantation
";
echo "";
echo "Implantation | ";
echo "".svg_circle('red')." Serveurs | ";
@@ -65,8 +60,12 @@ echo "".svg_circle('blue')." Virtuels |
";
echo "Total | Production | ";
echo "Total | Attribué | Total | Attribué |
\n";
+$grand_serveurs_total = 0; $grand_serveurs_prod = 0;
+$grand_internes_total = 0; $grand_internes_prod = 0;
+$grand_publics_total = 0; $grand_publics_prod = 0;
+$grand_total = 0; $grand_virtuels_total = 0;
+$grand_autres_total = 0;
# récupération de la liste des régions
-$grand_total = 0;
$query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)";
$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
$region_result = $DB->query($query);
diff --git a/glpi-plugin-auf/plugin/report.operatingsystems.php b/glpi-plugin-auf/plugin/report.operatingsystems.php
index 52502c6..83b765d 100644
--- a/glpi-plugin-auf/plugin/report.operatingsystems.php
+++ b/glpi-plugin-auf/plugin/report.operatingsystems.php
@@ -14,15 +14,10 @@ Report::title();
$computer = new Computer();
-$state_sql = "";
-if (($state != "") AND ($state != "0")) {
- $state_sql = " AND `states_id` = '".$state."' ";
-}
-
$itemtype = 'Computer';
$table_item = getTableForItemType($itemtype);
-echo "Systèmes d'exploitation par implantation
";
+//echo "Systèmes d'exploitation par implantation
";
echo "";
echo "Implantation | Système d'exploitation | Quantité |
";
$green_grand_total = 0;
diff --git a/glpi-plugin-auf/plugin/setup.php b/glpi-plugin-auf/plugin/setup.php
index 8bd15e9..e81f7ce 100644
--- a/glpi-plugin-auf/plugin/setup.php
+++ b/glpi-plugin-auf/plugin/setup.php
@@ -11,10 +11,22 @@ function plugin_init_auf() {
$PLUGIN_HOOKS['csrf_compliant']['auf'] = TRUE;
$Plugin = new Plugin();
+ $moduleId = 0;
if ($Plugin->isActivated('auf')) { // check if plugin is active
- if (Session::getLoginUserID()) {
- $PLUGIN_HOOKS['add_css']['auf'] = "auf.css";
- }
+
+ Plugin::registerClass('PluginAufProfile',
+ array('addtabon'=>array('Profile')));
+ Plugin::registerClass('PluginAufComputer',
+ array('addtabon'=>array('Computer')));
+
+
+ $PLUGIN_HOOKS['change_profile']['auf'] = array('PluginAufProfile', 'changeProfile');
+
+ $PLUGIN_HOOKS['add_css']['auf'] = "auf.css";
+
+ // if (Session::getLoginUserID()) {
+ // }
+
if (isset($_SESSION["glpiname"])) {
$report_list = array();
if (Session::haveRight("computer", "r")) {
@@ -41,13 +53,14 @@ function plugin_version_auf() {
// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_auf_check_prerequisites() {
if (version_compare(GLPI_VERSION,'0.84','lt') || version_compare(GLPI_VERSION,'0.85','ge')) {
- _e('This plugin requires GLPI >= 0.84', 'auf');
+ echo 'This plugin requires GLPI >= 0.84 and GLPI < 0.85';
return FALSE;
}
return TRUE;
}
-// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect
+// Uninstall process for plugin : need to return true if succeeded ;
+// may display messages or add to message after redirect
function plugin_auf_check_config() {
return TRUE;
}
--
1.7.10.4