-
Notifications
You must be signed in to change notification settings - Fork 1
/
hook.php
89 lines (70 loc) · 3.03 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
<?php
/**
* -------------------------------------------------------------------------
* RacksDirections plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of the RacksDirections plugin for GLPI.
*
* RacksDirections 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.
*
* RacksDirections 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 RacksDirections. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2023 by Dimitri Mestdagh.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/d1m007/RacksDirections
* -------------------------------------------------------------------------
*/
/**
* Called when user clicks on Install - REQUIRED
*/
function plugin_RacksDirections_install() {
// Create database table:
$rd = new PluginRacksDirections;
$rd->installPluginDB();
// Backup original GLPI '/src/Item_Rack.php' file:
// rename(GLPI_ROOT . '/src/Item_Rack.php', GLPI_ROOT . '/src/Item_Rack.bak.php');
// Replace original GLPI '/src/Item_Rack.php' file with custom file from plugin:
copy(PLUGIN_RACKSDIRECTIONS_DIR . '/files/src/Item_Rack.reverse.php', GLPI_ROOT . '/src/Item_Rack.php');
// Add custom file from plugin to GLPI '/js' dir:
copy(PLUGIN_RACKSDIRECTIONS_DIR . '/files/js/rack.reverse.js', GLPI_ROOT . '/js/rack.reverse.js');
return true;
}
/**
* Called when user click on Uninstall - REQUIRED
*/
function plugin_RacksDirections_uninstall() {
// If the 'Preserve plugin database' checkbos is not checked:
$rd = new PluginRacksDirections;
if(!$rd->getPluginSetting('preservePluginDB')) $rd->dropPluginDB();
// Reset modified SESSION parameter:
$_SESSION['glpi_js_toload']['rack'][] = 'js/rack.js';
// Delete custom '/src/Item_Rack.php' file:
unlink(GLPI_ROOT . '/src/Item_Rack.php');
if (file_exists(GLPI_ROOT . '/src/Item_Rack.bak.php')) {
unlink(GLPI_ROOT . '/src/Item_Rack.bak.php');
}
// Restore original GLPI '/src/Item_Rack.php' file with last version:
copy(PLUGIN_RACKSDIRECTIONS_DIR . '/files/src/Item_Rack_v10.0.9.php', GLPI_ROOT . '/src/Item_Rack.php');
// Delete custom file '/js/rack.reverse.js' dir:
unlink(GLPI_ROOT . '/js/rack.reverse.js');
return true;
}
/**
* Called when plugin is init - REQUIRED
*/
function plugin_RacksDirections_postinit() {
// set default SESSION parameter:
$_SESSION['glpi_js_toload']['rack'][] = 'js/rack.js';
}