This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
151 lines (128 loc) · 4.26 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
function plugin_vip_install()
{
global $DB;
// Création de la table uniquement lors de la première installation
if (!$DB->tableExists("glpi_plugin_vip_groups")) {
$DB->runFile(PLUGIN_VIP_DIR . "/install/sql/empty-1.1.2.sql");
}
if ($DB->tableExists('glpi_plugin_vip_tickets')) {
$tables = array("glpi_plugin_vip_tickets");
foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
}
}
include_once(PLUGIN_VIP_DIR."/inc/profile.class.php");
PluginVipProfile::initProfile();
PluginVipProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
return true;
}
function plugin_vip_uninstall()
{
global $DB;
$tables = ["glpi_plugin_vip_profiles",
"glpi_plugin_vip_groups",
"glpi_plugin_vip_tickets"];
foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
}
return true;
}
function plugin_vip_getPluginsDatabaseRelations()
{
$plugin = new Plugin();
if ($plugin->isActivated("vip")) {
return array(
"glpi_groups" => array("glpi_plugin_vip_groups" => "id")
);
} else {
return array();
}
}
function plugin_vip_getAddSearchOptions($itemtype)
{
$options = [];
if ($_SESSION['glpiactiveprofile']['interface'] == 'central'
&& Session::haveRight('plugin_vip', READ)) {
switch ($itemtype) {
case 'Ticket':
$options[] = [
'id' => 10100,
'name' => 'VIP',
'table' => 'glpi_plugin_vip_groups',
'field' => 'isvip',
'massiveaction' => false,
'datatype' => 'bool'
];
break;
case 'Group':
$options[] = [
'id' => 150,
'name' => 'VIP',
'table' => 'glpi_plugin_vip_groups',
'field' => 'isvip',
'massiveaction' => false,
'datatype' => 'bool'
];
break;
}
}
return $options;
}
function plugin_vip_MassiveActions($type)
{
if ($type == 'Group') {
$vip = new PluginVipGroup();
return $vip->massiveActions();
}
return array();
}
function plugin_vip_addLeftJoin($type, $ref_table, $new_table, $linkfield, &$already_link_tables)
{
if ($ref_table == 'glpi_tickets') {
switch ($new_table) {
case "glpi_plugin_vip_groups":
$out = " LEFT JOIN `glpi_tickets_users` ON (`glpi_tickets`.`id` = `glpi_tickets_users`.`tickets_id` AND `glpi_tickets_users`.`type` = ".CommonITILActor::REQUESTER.") ";
$out .= " LEFT JOIN `glpi_groups_users` ON (`glpi_tickets_users`.`users_id` = `glpi_groups_users`.`users_id`)";
$out .= " LEFT JOIN `glpi_plugin_vip_groups` ON (`glpi_groups_users`.`groups_id` = `glpi_plugin_vip_groups`.`id`)";
return $out;
}
}
if ($ref_table == 'glpi_groups') {
switch ($new_table) {
case "glpi_plugin_vip_groups":
$out = " LEFT JOIN `glpi_plugin_vip_groups` ON (`glpi_groups`.`id` = `glpi_plugin_vip_groups`.`id`)";
return $out;
}
}
return "";
}
function plugin_vip_giveItem($type, $ID, $data, $num)
{
global $CFG_GLPI, $DB;
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
switch ($type) {
case 'Ticket':
switch ($table.'.'.$field) {
case "glpi_plugin_vip_groups.isvip":
//if (PluginVipTicket::isTicketVip($data[0][0]['name'])) {
if (PluginVipTicket::isTicketVip($data['id'])) {
return "<img src=\"".PLUGIN_VIP_WEB_DIR."/pics/vip.png\" alt='vip' >";
}
break;
}
break;
case 'Group':
switch ($table.'.'.$field) {
case "glpi_plugin_vip_groups.isvip":
if ($data[$num][0]['name']) {
return "<img src=\"".PLUGIN_VIP_WEB_DIR."/pics/vip.png\" alt='vip' >";
}
break;
}
break;
}
return " ";
}