glpi-plugin-auf : ajout des champs AUF
[auf-serveur.git] / glpi-plugin-auf / plugin / inc / computer.class.php
1 <?php
2 /*
3 AUF plugin for GLPI
4 Copyright (C) 2014 AUF -- www.auf.org
5 */
6 if (!defined('GLPI_ROOT')) {
7 die("Sorry. You can't access directly to this file");
8 }
9
10 class PluginAufComputer extends CommonDBTM {
11
12 static function canCreate() {
13 if (isset($_SESSION["glpi_plugin_auf_profile"])) {
14 return ($_SESSION["glpi_plugin_auf_profile"]['auf'] == 'w');
15 }
16 return false;
17 }
18
19 static function canView() {
20 if (isset($_SESSION["glpi_plugin_auf_profile"])) {
21 return ($_SESSION["glpi_plugin_auf_profile"]['auf'] == 'w'
22 || $_SESSION["glpi_plugin_auf_profile"]['auf'] == 'r');
23 }
24 return false;
25 }
26
27 function createInfos($ID) {
28 $this->add(array('id' => $ID));
29 }
30
31 function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
32 if ($item->getType() == 'Computer') {
33 return "Infos AUF";
34 }
35 return '';
36 }
37
38 static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
39 if ($item->getType() == 'Computer') {
40 $ID = $item->getID();
41 $computer = new self();
42 // si la machine n'existe pas dans la base, je l'ajoute
43 if (!$computer->GetfromDB($ID)) {
44 $computer->createInfos($ID);
45 }
46 $computer->showForm($ID);
47 }
48 return true;
49 }
50
51 function showForm($id, $options=array()) {
52 $target = $this->getFormURL();
53 if (isset($options['target'])) {
54 $target = $options['target'];
55 }
56
57 if (!Session::haveRight("computer", "r")) {
58 return false;
59 }
60
61 $canedit = Session::haveRight("computer", "w");
62 $computer = new Computer();
63 if ($id){
64 $this->getFromDB($id);
65 $computer->getFromDB($id);
66 }
67
68 echo "<form action='".$target."' method='post'>";
69 echo "<table class='tab_cadre_fixe'>";
70 echo "<tr><th colspan='4'>Infos AUF</th></tr>";
71
72 echo "<tr class='tab_bg_1'>";
73 echo "<td>Catégorie</td><td>";
74 // $elements = getDataFromTable("glpi_plugin_auf_categories");
75 $elements = array("0"=>"-----", "1"=>"Infrastructure", "2"=>"Poste interne", "3"=>"Poste public");
76 Dropdown::showFromArray("auf_categories_id", $elements,
77 array("value" => $this->fields["auf_categories_id"]));
78 echo "</td>";
79 echo "<td>Utilisation</td><td>";
80 // $elements = getDataFromTable("glpi_plugin_auf_utilisations");
81 $elements = array("0"=>"-----", "1"=>"Production", "2"=>"Test", "3"=>"Réserve (stock, mission, formation, …)");
82 Dropdown::showFromArray("auf_utilisations_id", $elements,
83 array("value" => $this->fields["auf_utilisations_id"]));
84 echo "</td>";
85 echo "</tr>";
86
87 echo "<tr class='tab_bg_1'>";
88 echo "<td>Machine virtuelle</td><td>";
89 Dropdown::showYesNo('est_virtuel', $this->fields["est_virtuel"]);
90 echo "</td>";
91 echo "<td>Année d'acquisition</td><td>";
92 echo "<input size='4' name='annee_acquisition' value='".$this->fields["annee_acquisition"]."' />";
93 echo "</td>";
94 echo "</tr>";
95
96 if ($canedit) {
97 echo "<tr class='tab_bg_1'>";
98 echo "<td class='center' colspan='4'>";
99 echo "<input type='hidden' name='id' value=$id>";
100 echo "<input type='submit' name='update_computer' value='Mettre à jour' class='submit'>";
101 echo "</td></tr>";
102 }
103
104 echo "</table>";
105 Html::closeForm();
106 }
107
108 }
109
110 ?>