/** * Récupère les infos d'une machine pour la réforme * @global type $DB * @param type $id * @return un tableau de valeur avec clé */ function getInfoMachine($id, $itemType) { global $DB; //Récupération des informations de configuration $configClass = new PluginReformeConfig(); $config = $configClass->getInfoAdministrative(); $retour['id'] = $id; $retour['name'] = ""; $retour['lieu'] = ""; $retour['numserie'] = ""; $retour['commentaire'] = ""; $retour['fournisseur'] = ""; $retour['dateachat'] = ""; $retour['immo'] = ""; $retour['statut'] = ""; if ($itemType == "Computer") { $retour['domain'] = $this->getDomain($id); } else { $retour['domain'] = ""; } $retour['des_bien'] = ""; $retour['ref_type'] = ""; $retour['num_commande'] = ""; $retour['num_facture'] = ""; // Récupération du nom de la machine $retour['name'] = $this->getItemName($id, $itemType); //définition des requêtes en fonction du type de l'item switch ($itemType) { case 'Computer': $query1 = "SELECT T2.name FROM glpi_computers as T1,glpi_locations as T2 " . "WHERE T1.id = '{$id}' AND T1.locations_id = T2.id"; $query2 = "SELECT serial,comment FROM glpi_computers WHERE id = '{$id}'"; $query3 = "SELECT name FROM glpi_infocoms as T1, glpi_suppliers " . "as T2 WHERE items_id = '{$id}' AND itemtype = 'Computer' " . "AND T1.suppliers_id = T2.id"; $query4 = "SELECT buy_date FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Computer'"; $query5 = "SELECT immo_number FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Computer'"; $query6 = "SELECT t2.id FROM glpi_computers as t1, glpi_states as t2 " . "WHERE t1.id={$id} AND t1.states_id=t2.id"; $query7 = "SELECT t2.name FROM glpi_computers as t1, glpi_computertypes as t2 " . "WHERE t1.id={$id} AND t1.computertypes_id=t2.id"; $query8 = "SELECT order_number FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Computer'"; $query9 = "SELECT bill FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Computer'"; $query10 = "SELECT t2.name FROM glpi_computers as t1, glpi_computermodels as t2 " . "WHERE t1.id={$id} AND t1.computermodels_id=t2.id"; break; case 'Monitor': $query1 = "SELECT T2.name FROM glpi_monitors as T1,glpi_locations as T2 " . "WHERE T1.id = '{$id}' AND T1.locations_id = T2.id"; $query2 = "SELECT serial,comment FROM glpi_monitors WHERE id = '{$id}'"; $query3 = "SELECT name FROM glpi_infocoms as T1, glpi_suppliers " . "as T2 WHERE items_id = '{$id}' AND itemtype = 'Monitor' " . "AND T1.suppliers_id = T2.id"; $query4 = "SELECT buy_date FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Monitor'"; $query5 = "SELECT immo_number FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Monitor'"; $query6 = "SELECT t2.id FROM glpi_monitors as t1, glpi_states as t2 " . "WHERE t1.id={$id} AND t1.states_id=t2.id"; $query7 = "SELECT t2.name FROM glpi_monitors as t1, glpi_monitortypes as t2 " . "WHERE t1.id={$id} AND t1.monitortypes_id=t2.id"; $query8 = "SELECT order_number FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Monitor'"; $query9 = "SELECT bill FROM glpi_infocoms WHERE items_id = '{$id}' " . "AND itemtype = 'Monitor'"; $query10 = "SELECT t2.name FROM glpi_monitors as t1, glpi_monitormodels as t2 " . "WHERE t1.id={$id} AND t1.monitormodels_id=t2.id"; break; default: break; } // Récupération du lieu de la machine if ($result = $DB->query($query1)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['name'])) { $retour['lieu'] = $row['name']; } } } // Récupération du numéro de série et commentaire de la machine if ($result = $DB->query($query2)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['serial'])) { $retour['numserie'] = $row['serial']; } if (!empty($row['comment'])) { $retour['commentaire'] = $row['comment']; } } } // Récupération du fournisseur de la machine if ($result = $DB->query($query3)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['name'])) { $retour['fournisseur'] = $row['name']; } } } // Récupération de la date d'achat de la machine if ($result = $DB->query($query4)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['buy_date'])) { $retour['dateachat'] = $row['buy_date']; } } } // Récupération du numéro d'immobilisation de la machine if ($result = $DB->query($query5)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['immo_number'])) { $retour['immo'] = $row['immo_number']; } } } // Récupération du statut de la machine if ($result = $DB->query($query6)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['id'])) { $retour['statut'] = $row['id']; } } } // Récupération du type de la machine if ($config["ref_type"]) { if ($result = $DB->query($query7)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['name'])) { $retour['ref_type'] = $row['name']; } } } } // Récupération du numéro de commande if ($config["num_commande"]) { if ($result = $DB->query($query8)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['order_number'])) { $retour['num_commande'] = $row['order_number']; } } } } if ($config["num_facture"]) { // Récupération du numéro de facture if ($result = $DB->query($query9)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['bill'])) { $retour['num_facture'] = $row['bill']; } } } } if ($config["des_bien"]) { // Récupération du modèle if ($result = $DB->query($query10)) { if ($DB->numrows($result) > 0) { $row = $DB->fetch_assoc($result); if (!empty($row['name'])) { $retour['des_bien'] = $row['name']; } } } } return $retour; }
} //Instanciation de la class config $config = new PluginReformeConfig(); //Gestion des images $logoOption['title'] = 'Logo'; $logoOption['alt'] = "Relancer le formulaire de configuration pour recharger l'image, puis faites F5"; $testOption['title'] = 'Tester'; $testOption['alt'] = "Tester"; $actualiserOption['title'] = "Modifier"; $actualiserOption['alt'] = "Modifier"; $menuaddOption['title'] = "Ajouter AD"; $menuaddOption['alt'] = "Ajouter AD"; $ajoutInfo = array(1 => 'Modèle du bien', 2 => 'Référence Type', 3 => 'Numéro de commande', 4 => 'Numéro de facture'); //Envoie des variables à Smarty $smarty->assign('ajoutInfo', $ajoutInfo); $smarty->assign('infoAdministrative', $config->getInfoAdministrative()); $smarty->assign('supp_ids', array(1, 0)); $smarty->assign('supp_names', array('Oui', 'Non')); $smarty->assign('infoStatut', $config->getStatutListe()); $smarty->assign('infoAD', $config->getAD()); $smarty->assign('targetForm', getHttpPath() . "plugins/reforme/front/config.form.php"); $smarty->assign('endform', HTML::closeForm(false)); $smarty->assign('testIMG', HTML::image(getHttpPath() . "plugins/reforme/images/test.png", $testOption)); $smarty->assign('logoIMG', HTML::image(getHttpPath() . "plugins/reforme/images/logo.png", $logoOption)); $smarty->assign('actualiserIMG', HTML::image(getHttpPath() . 'pics/actualiser.png', $actualiserOption)); $smarty->assign('menuaddIMG', HTML::image(getHttpPath() . 'pics/menu_add.png', $menuaddOption)); $smarty->assign('targetCSS', getHttpPath() . "plugins/reforme/css/reforme.css"); $smarty->assign('targetConfigAjax', getHttpPath() . "plugins/reforme/ajax/config.ajax.php"); $smarty->assign('addstatut', getHttpPath() . "front/state.php"); //Affichage de l'entête GLPI HTML::header('Configuration Plugin Reforme');