-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
138 lines (113 loc) · 4.59 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
<?php
/*
-------------------------------------------------------------------------
MyCustomView plugin for GLPI
Copyright (C) 2023 by the MyCustomView Development Team.
https://github.com/pluginsGLPI/mycustomview
-------------------------------------------------------------------------
LICENSE
This file is part of MyCustomView.
MyCustomView 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 3 of the License, or
(at your option) any later version.
MyCustomView 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 MyCustomView. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/**
* Plugin install process
*
* @return boolean
*/
function plugin_mycustomview_install()
{
global $DB;
PluginMycustomviewProfile::createFirstAccess($_SESSION["glpiactiveprofile"]["id"]);
$default_charset = DBConnection::getDefaultCharset();
$default_collation = DBConnection::getDefaultCollation();
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();
// requete de création des tables
if (!$DB->TableExists("glpi_plugin_mycustomview_user_settings")) {
$query = "CREATE TABLE `glpi_plugin_mycustomview_user_settings` (
`id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT,
`user_id` INT {$default_key_sign} NOT NULL,
`default_page` TINYINT,
`list_limit` INT(11),
`settings_hidden` TINYINT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
$DB->query($query) or die("error creating glpi_plugin_mycustomview_user_settings " . $DB->error());
}
if (!$DB->TableExists("glpi_plugin_mycustomview_savedsearch_list")) {
$query = "CREATE TABLE `glpi_plugin_mycustomview_savedsearch_list` (
`id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT,
`user_id` INT {$default_key_sign} NOT NULL,
`savedsearch_id` INT(11) NOT NULL,
`order` TINYINT,
`screen_mode` TINYINT,
`height` INT(11),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
$DB->query($query) or die("error creating glpi_plugin_mycustomview_savedsearch_list " . $DB->error());
}
if (!$DB->TableExists("glpi_plugin_mycustomview_config")) {
$query = "CREATE TABLE `glpi_plugin_mycustomview_config` (
`id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT,
`max_filters` TINYINT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
$DB->query($query) or die("error creating glpi_plugin_mycustomview_config " . $DB->error());
$DB->insert(
'glpi_plugin_mycustomview_config',
[
'max_filters' => 6
]
);
}
return true;
}
/**
* Plugin uninstall process
*
* @return boolean
*/
function plugin_mycustomview_uninstall()
{
global $DB;
$tables = array("glpi_plugin_mycustomview_user_settings", "glpi_plugin_mycustomview_savedsearch", "glpi_plugin_mycustomview_savedsearch_list", "glpi_plugin_mycustomview_config", "glpi_plugin_mycustomview_profile_rights");
foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
}
global $DB;
$result = $DB->request([
'SELECT' => ['profiles_id'],
'FROM' => 'glpi_profilerights',
'WHERE' => ['name' => ['LIKE', 'plugin_mycustomview%']]
]);
foreach ($result as $id_profil) {
$DB->delete(
'glpi_profilerights', [
'name' => ['LIKE', 'plugin_mycustomview%'],
'profiles_id' => $id_profil
]
);
}
return true;
}
// vérification plugin activé + vérification du profil (si profil demandeur -> return)
function changePageOnHome()
{
$plugin = new Plugin();
if ($plugin->isActivated("mycustomview")) {
if (isset($_SESSION['glpiactiveprofile']['id'])) {
if ($_SESSION['glpiactiveprofile']['id'] == 1) {
return;
}
}
}
}