forked from pluginsGLPI/mreporting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
185 lines (150 loc) · 7.06 KB
/
setup.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
Mreporting plugin for GLPI
Copyright (C) 2003-2011 by the mreporting Development Team.
https://forge.indepnet.net/projects/mreporting
-------------------------------------------------------------------------
LICENSE
This file is part of mreporting.
mreporting 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.
mreporting 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 mreporting. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (!defined('PLUGIN_MREPORTING_TEMPLATE_DIR')) {
define ("PLUGIN_MREPORTING_TEMPLATE_DIR", GLPI_ROOT."/plugins/mreporting/templates/");
}
if (!defined('PLUGIN_MREPORTING_TEMPLATE_EXTENSION')) {
define ("PLUGIN_MREPORTING_TEMPLATE_EXTENSION", "odt");
}
if(isset($_SESSION['glpi_use_mode']) && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
define('DEBUG_MREPORTING', true);
} else {
define('DEBUG_MREPORTING', false);
}
// Init the hooks of the plugins -Needed
function plugin_init_mreporting() {
global $PLUGIN_HOOKS,$CFG_GLPI, $LANG;
$plugin = new Plugin();
/* CRSF */
$PLUGIN_HOOKS['csrf_compliant']['mreporting'] = true;
if ($plugin->isInstalled("mreporting")
&& $plugin->isActivated("mreporting")) {
//Load additionnal language files in needed
includeAdditionalLanguageFiles();
if(Session::getLoginUserID()) {
/* Profile */
$PLUGIN_HOOKS['change_profile']['mreporting'] = array('PluginMreportingProfile',
'changeProfile');
$PLUGIN_HOOKS['redirect_page']['mreporting'] = 'front/download.php';
Plugin::registerClass('PluginMreportingNotification',
array('notificationtemplates_types' => true));
Plugin::registerClass('PluginMreportingDashboard', array ('addtabon' => array('Central')));
if (Session::getLoginUserID()) {
Plugin::registerClass('PluginMreportingProfile',
array('addtabon' => 'Profile'));
Plugin::registerClass('PluginMreportingPreference',
array('addtabon' => array('Preference')));
/* Menu */
$PLUGIN_HOOKS['menu_toadd']['mreporting'] = array('tools' => 'PluginMreportingCommon');
/* Show Reports in standart stats page */
$mreporting_common = new PluginMreportingCommon();
$reports = $mreporting_common->getAllReports();
if ($reports !== false) {
foreach($reports as $report) {
foreach($report['functions'] as $func) {
$PLUGIN_HOOKS['stats']['mreporting'][$func['min_url_graph']] = $func['title'];
}
}
}
$PLUGIN_HOOKS['pre_item_purge']['mreporting']
= array('Profile' => array('PluginMreportingProfile', 'purgeProfiles'),
'PluginMreportingConfig' => array('PluginMreportingProfile',
'purgeProfilesByReports'));
$PLUGIN_HOOKS['item_add']['mreporting']
= array('Profile' => array('PluginMreportingProfile', 'addProfiles'),
'PluginMreportingConfig' => array('PluginMreportingProfile', 'addReport'));
}
}
// Add specific files to add to the header : javascript
$PLUGIN_HOOKS['add_javascript']['mreporting'] = array();
$PLUGIN_HOOKS['add_javascript']['mreporting'][] = "lib/protovis/protovis.min.js";
$PLUGIN_HOOKS['add_javascript']['mreporting'][] = "lib/protovis-msie/protovis-msie.min.js";
if (isset($_SESSION['glpiactiveprofile']['id'])
&& $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
if (PluginMreportingCommon::canAccessAtLeastOneReport($_SESSION['glpiactiveprofile']['id'])) {
$PLUGIN_HOOKS['add_javascript']['mreporting'][] = 'scripts/helpdesk-menu.js';
$PLUGIN_HOOKS["helpdesk_menu_entry"]['mreporting'] = false;
}
} else {
$PLUGIN_HOOKS["helpdesk_menu_entry"]['mreporting'] = true;
}
//Add specific files to add to the header : css
$PLUGIN_HOOKS['add_css']['mreporting'] = array ();
$PLUGIN_HOOKS['add_css']['mreporting'][] = "mreporting.css";
$PLUGIN_HOOKS['add_css']['mreporting'][] = "lib/font-awesome-4.2.0/css/font-awesome.min.css";
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && isset($_SESSION['glpimenu'])) {
unset($_SESSION['glpimenu']);
}
}
}
// Get the name and the version of the plugin - Needed
function plugin_version_mreporting() {
return array('name' => __("More Reporting", 'mreporting'),
'version' => "0.90+1.0",
'author' => "<a href='http://www.teclib.com'>Teclib'</a>
& <a href='http://www.infotel.com'>Infotel</a>",
'homepage' => "https://forge.indepnet.net/projects/mreporting",
'license' => 'GPLv2+',
'minGlpiVersion' => "0.85");
}
function includeAdditionalLanguageFiles() {
if (isset($_SESSION["glpilanguage"])) {
$template = "*_".$_SESSION["glpilanguage"].".php";
foreach (glob(GLPI_ROOT.'/plugins/mreporting/locales/reports_locales/'.$template) as $path) {
include_once($path);
}
}
}
// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_mreporting_check_prerequisites() {
if (version_compare(GLPI_VERSION,'0.85','lt')) {
echo "This plugin requires GLPI >= 0.85";
} else {
return true;
}
return false;
}
// Check configuration process for plugin : need to return true if succeeded
// Can display a message only if failure and $verbose is true
function plugin_mreporting_check_config($verbose=false) {
if (true) { // Your configuration check
return true;
}
if ($verbose) {
echo _x('plugin', 'Installed / not configured');
}
return false;
}
function plugin_mreporting_haveRight($module,$right) {
$matches=array(
"" => array("","r","w"), // ne doit pas arriver normalement
"r" => array("r","w"),
"w" => array("w"),
"1" => array("1"),
"0" => array("0","1"), // ne doit pas arriver non plus
);
if (isset($_SESSION["glpi_plugin_mreporting_profile"][$module])
&& in_array($_SESSION["glpi_plugin_mreporting_profile"][$module],$matches[$right]))
return true;
else return false;
}