forked from pluginsGLPI/itilcategorygroups
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
124 lines (106 loc) · 4.6 KB
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/*
* @version $Id: setup.php 19 2012-06-27 09:19:05Z walid $
LICENSE
This file is part of the itilcategorygroups plugin.
Order plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Order plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI; along with itilcategorygroups. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package itilcategorygroups
@author the itilcategorygroups plugin team
@copyright Copyright (c) 2010-2011 itilcategorygroups plugin team
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://forge.indepnet.net/projects/itilcategorygroups
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */
function plugin_itilcategorygroups_install() {
$migration = new Migration("0.84");
//order is important for install
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/category.class.php");
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/category_group.class.php");
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/group_level.class.php");
PluginItilcategorygroupsCategory::install($migration);
PluginItilcategorygroupsCategory_Group::install($migration);
PluginItilcategorygroupsGroup_Level::install($migration);
return true;
}
function plugin_itilcategorygroups_uninstall() {
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/category_group.class.php");
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/category.class.php");
include_once(GLPI_ROOT."/plugins/itilcategorygroups/inc/group_level.class.php");
PluginItilcategorygroupsCategory_Group::uninstall();
PluginItilcategorygroupsCategory::uninstall();
PluginItilcategorygroupsGroup_Level::uninstall();
return true;
}
function plugin_itilcategorygroups_getAddSearchOptions($itemtype) {
if (isset($_SESSION['glpiactiveentities'])) {
$options = PluginItilcategorygroupsGroup_Level::getAddSearchOptions($itemtype);
return $options;
} else {
return NULL;
}
}
function plugin_itilcategorygroups_giveItem($type, $ID, $data, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
$value = $data['raw']["ITEM_$num"];
switch ($table.'.'.$field) {
case "glpi_plugin_itilcategorygroups_groups_levels.lvl" :
switch ($value) {
case 1:
case 2:
case 3:
case 4:
return __('Level '.$value, 'itilcategorygroups');
}
}
return "";
}
// Display specific massive actions for plugin fields
function plugin_itilcategorygroups_MassiveActionsFieldsDisplay($options=array()) {
$table = $options['options']['table'];
$field = $options['options']['field'];
$linkfield = $options['options']['linkfield'];
// Table fields
switch ($table.".".$field) {
case "glpi_plugin_itilcategorygroups_groups_levels.lvl" :
Dropdown::showFromArray('lvl',
array(NULL => "---",
1 => __('Level 1', 'itilcategorygroups'),
2 => __('Level 2', 'itilcategorygroups'),
3 => __('Level 3', 'itilcategorygroups'),
4 => __('Level 4', 'itilcategorygroups')));
return true;
}
// Need to return false on non display item
return false;
}
// Hook done on update item case
function plugin_pre_item_update_itilcategorygroups($item) {
if (isset($_REQUEST['massiveaction'])
&& isset($_REQUEST['lvl'])
&& $item instanceof Group) {
$group_level = new PluginItilcategorygroupsGroup_Level();
if(! $group_level->getFromDB($item->fields['id'])) {
$group_level->add(array('groups_id'=> $item->fields['id'],
'lvl' => $_REQUEST['lvl']));
} else {
$group_level->update(array('groups_id'=> $item->fields['id'],
'lvl' => $_REQUEST['lvl']));
}
}
return $item;
}
?>