Commit | Line | Data |
---|---|---|
277feb35 P |
1 | <?php |
2 | /* | |
3 | AUF plugin for GLPI | |
4 | Copyright (C) 2014 AUF -- www.auf.org | |
5 | */ | |
6 | ||
749e76d6 P |
7 | function plugin_auf_getAddSearchOptions($itemtype) { |
8 | $sopt = array(); | |
9 | if ($itemtype == 'Computer') { | |
10 | $i = 5250; | |
11 | $sopt[$i]['table'] = 'glpi_plugin_auf_categories'; | |
12 | $sopt[$i]['field'] = 'name'; | |
13 | $sopt[$i]['linkfield'] = 'auf_categories_id'; | |
14 | $sopt[$i]['name'] = 'AUF - Catégorie'; | |
15 | $sopt[$i]['datatype'] = 'dropdown'; | |
16 | $sopt[$i]['massiveaction'] = FALSE; | |
17 | $sopt[$i]['joinparams'] = array('beforejoin' | |
18 | => array('table' => 'glpi_plugin_auf_computers', | |
19 | 'joinparams' => array('jointype' => 'child', | |
20 | 'linkfield' => 'id') ) ); | |
21 | $i++; | |
22 | $sopt[$i]['table'] = 'glpi_plugin_auf_utilisations'; | |
23 | $sopt[$i]['field'] = 'name'; | |
24 | $sopt[$i]['linkfield'] = 'auf_utilisations_id'; | |
25 | $sopt[$i]['name'] = 'AUF - Utilisation'; | |
26 | $sopt[$i]['datatype'] = 'dropdown'; | |
27 | $sopt[$i]['massiveaction'] = FALSE; | |
28 | $sopt[$i]['joinparams'] = array('beforejoin' | |
29 | => array('table' => 'glpi_plugin_auf_computers', | |
30 | 'joinparams' => array('jointype' => 'child', | |
31 | 'linkfield' => 'id') ) ); | |
32 | $i++; | |
33 | $sopt[$i]['table'] = 'glpi_plugin_auf_computers'; | |
34 | $sopt[$i]['field'] = 'annee_acquisition'; | |
35 | $sopt[$i]['linkfield'] = 'id'; | |
36 | $sopt[$i]['name'] = 'AUF - Année d\'acquisition'; | |
37 | $sopt[$i]['datatype'] = 'number'; | |
38 | $sopt[$i]['massiveaction'] = FALSE; | |
39 | $i++; | |
40 | $sopt[$i]['table'] = 'glpi_plugin_auf_computers'; | |
41 | $sopt[$i]['field'] = 'est_virtuel'; | |
42 | $sopt[$i]['linkfield'] = 'id'; | |
43 | $sopt[$i]['name'] = 'AUF - Virtuel'; | |
44 | $sopt[$i]['datatype'] = 'bool'; | |
45 | // $sopt[$i]['joinparams'] = array('jointype' => 'child'); | |
46 | $sopt[$i]['massiveaction'] = FALSE; | |
47 | } | |
48 | return $sopt; | |
49 | } | |
50 | ||
277feb35 | 51 | function plugin_auf_install() { |
749e76d6 P |
52 | global $DB; |
53 | ||
54 | $migration = new Migration(100); | |
55 | // Création de la table uniquement lors de la première installation | |
56 | if (!TableExists("glpi_plugin_auf_profiles")) { | |
57 | // requête de création de la table | |
58 | $query = "CREATE TABLE `glpi_plugin_auf_profiles` ( | |
59 | `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)', | |
60 | `right` char(1) collate utf8_unicode_ci default NULL, | |
61 | PRIMARY KEY (`id`) | |
62 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; | |
63 | $DB->queryOrDie($query, $DB->error()); | |
64 | $migration->migrationOneTable("glpi_plugin_auf_profiles"); | |
65 | // creation du premier accès nécessaire lors de l'installation du plugin | |
66 | include_once(GLPI_ROOT."/plugins/auf/inc/profile.class.php"); | |
67 | PluginAufProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']); | |
68 | } | |
69 | ||
70 | if (!TableExists("glpi_plugin_auf_computers")) { | |
71 | // requête de création de la table | |
72 | $query = "CREATE TABLE `glpi_plugin_auf_computers` ( | |
73 | `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_computers (id)', | |
74 | `auf_categories_id` int(11) NOT NULL DEFAULT '0', | |
75 | `auf_utilisations_id` int(11) NOT NULL DEFAULT '0', | |
76 | `annee_acquisition` int(11) NOT NULL DEFAULT '0', | |
77 | `est_virtuel` tinyint(1) NOT NULL DEFAULT '0', | |
78 | `affectation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, | |
79 | PRIMARY KEY (`id`) | |
80 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; | |
81 | $DB->queryOrDie($query, $DB->error()); | |
82 | } | |
83 | ||
84 | if (!TableExists("glpi_plugin_auf_categories")) { | |
85 | // requête de création de la table | |
86 | $query = "CREATE TABLE `glpi_plugin_auf_categories` ( | |
87 | `id` int(11) NOT NULL AUTO_INCREMENT, | |
88 | `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, | |
89 | `comment` text DEFAULT NULL, | |
90 | PRIMARY KEY (`id`), | |
91 | KEY `name` (`name`) | |
92 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; | |
93 | $DB->queryOrDie($query, $DB->error()); | |
94 | $query = "INSERT INTO `glpi_plugin_auf_categories` VALUES | |
95 | (1, 'Infrastructure', ''), | |
96 | (2, 'Poste interne', ''), | |
97 | (3, 'Poste public', '')"; | |
98 | $DB->queryOrDie($query, $DB->error()); | |
99 | } | |
100 | ||
101 | if (!TableExists("glpi_plugin_auf_utilisations")) { | |
102 | // requête de création de la table | |
103 | $query = "CREATE TABLE `glpi_plugin_auf_utilisations` ( | |
104 | `id` int(11) NOT NULL AUTO_INCREMENT, | |
105 | `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, | |
106 | `comment` text DEFAULT NULL, | |
107 | PRIMARY KEY (`id`), | |
108 | KEY `name` (`name`) | |
109 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; | |
110 | $DB->queryOrDie($query, $DB->error()); | |
111 | $query = "INSERT INTO `glpi_plugin_auf_utilisations` VALUES | |
112 | (1, 'Production', ''), | |
113 | (2, 'Test', ''), | |
114 | (3, 'Réserve', 'stock, mission, formation, …')"; | |
115 | $DB->queryOrDie($query, $DB->error()); | |
116 | } | |
117 | ||
118 | $migration->executeMigration(); | |
277feb35 P |
119 | return TRUE; |
120 | } | |
121 | ||
122 | function plugin_auf_uninstall() { | |
749e76d6 P |
123 | global $DB; |
124 | ||
125 | $tables = array(); // "glpi_plugin_auf_profiles", // "glpi_plugin_auf_computers", | |
126 | // "glpi_plugin_auf_categories", "glpi_plugin_auf_utilisations"); | |
127 | foreach($tables as $table) { | |
128 | $DB->query("DROP TABLE IF EXISTS `$table`;"); | |
129 | } | |
130 | ||
277feb35 P |
131 | return TRUE; |
132 | } | |
133 | ||
134 | ?> |