forked from pluginsGLPI/formcreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
166 lines (146 loc) · 6.28 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
<?php
/**
* Define the plugin's version and informations
*
* @return Array [name, version, author, homepage, license, minGlpiVersion]
*/
function plugin_version_formcreator ()
{
return array('name' => _n('Form', 'Forms', 2, 'formcreator'),
'version' => '0.90-1.2.5',
'author' => '<a href="mailto:jmoreau@teclib.com">Jérémy MOREAU</a>
- <a href="http://www.teclib.com">Teclib\'</a>',
'homepage' => 'https://github.com/TECLIB/formcreator',
'license' => '<a href="../plugins/formcreator/LICENSE" target="_blank">GPLv2</a>',
'minGlpiVersion' => "0.85");
}
/**
* Check plugin's prerequisites before installation
*
* @return boolean
*/
function plugin_formcreator_check_prerequisites ()
{
if (version_compare(GLPI_VERSION,'0.85','lt') || version_compare(GLPI_VERSION,'0.91','ge')) {
echo 'This plugin requires GLPI >= 0.85 and GLPI < 0.91';
} else {
return true;
}
return false;
}
/**
* Check plugin's config before activation (if needed)
*
* @param string $verbose Set true to show all messages (false by default)
* @return boolean
*/
function plugin_formcreator_check_config($verbose=false)
{
return true;
}
/**
* Initialize all classes and generic variables of the plugin
*/
function plugin_init_formcreator ()
{
global $PLUGIN_HOOKS;
// Set the plugin CSRF compliance (required since GLPI 0.84)
$PLUGIN_HOOKS['csrf_compliant']['formcreator'] = true;
$plugin = new Plugin();
if (isset($_SESSION['glpiID'])
&& $plugin->isInstalled('formcreator') && $plugin->isActivated('formcreator')) {
// Massive Action definition
$PLUGIN_HOOKS['use_massive_action']['formcreator'] = 1;
// If user have acces to one form or more, add link
$form_table = getTableForItemType('PluginFormcreatorForm');
$table_fp = getTableForItemType('PluginFormcreatorFormprofiles');
$where = getEntitiesRestrictRequest( "", $form_table, "", "", true, false);
$query = "SELECT COUNT($form_table.id)
FROM $form_table
WHERE $form_table.`is_active` = 1
AND $form_table.`is_deleted` = 0
AND $form_table.`helpdesk_home` = 1
AND ($form_table.`language` = '{$_SESSION['glpilanguage']}' OR $form_table.`language` = '')
AND $where
AND ($form_table.`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR $form_table.`id` IN (
SELECT plugin_formcreator_forms_id
FROM $table_fp
WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))";
$result = $GLOBALS['DB']->query($query);
list($nb) = $GLOBALS['DB']->fetch_array($result);
if ($nb > 0) {
$PLUGIN_HOOKS['menu_toadd']['formcreator']['helpdesk'] = 'PluginFormcreatorFormlist';
}
if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator") !== false
|| strpos($_SERVER['REQUEST_URI'], "central.php") !== false
|| isset($_SESSION['glpiactiveprofile']) &&
$_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
// Add specific CSS
$PLUGIN_HOOKS['add_css']['formcreator'][] = "css/styles.css";
$PLUGIN_HOOKS['add_css']['formcreator'][] = 'lib/pqselect/pqselect.min.css';
$PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'lib/pqselect/pqselect.min.js';
// Add specific JavaScript
$PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/forms-validation.js.php';
$PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/scripts.js.php';
}
// Add a link in the main menu plugins for technician and admin panel
$PLUGIN_HOOKS['menu_entry']['formcreator'] = 'front/formlist.php';
// Config page
$plugin = new Plugin();
$links = array();
if (Session::haveRight('entity', UPDATE)) {
$PLUGIN_HOOKS['config_page']['formcreator'] = 'front/form.php';
$PLUGIN_HOOKS['menu_toadd']['formcreator']['admin'] = 'PluginFormcreatorForm';
$links['config'] = '/plugins/formcreator/front/form.php';
$links['add'] = '/plugins/formcreator/front/form.form.php';
}
$img = '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/check.png"
title="' . __('Forms waiting for validation', 'formcreator') . '" alt="Waiting forms list" />';
$links[$img] = '/plugins/formcreator/front/formanswer.php';
// Set options for pages (title, links, buttons...)
$links['search'] = '/plugins/formcreator/front/formlist.php';
$PLUGIN_HOOKS['submenu_entry']['formcreator']['options'] = array(
'config' => array('title' => __('Setup'),
'page' => '/plugins/formcreator/front/form.php',
'links' => $links),
'options' => array('title' => _n('Form', 'Forms', 2, 'formcreator'),
'links' => $links),
);
// Load field class and all its method to manage fields
Plugin::registerClass('PluginFormcreatorFields');
// Notification
Plugin::registerClass('PluginFormcreatorFormanswer', array(
'notificationtemplates_types' => true
));
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && isset($_SESSION['glpimenu'])) {
unset($_SESSION['glpimenu']);
}
}
}
/**
* Encode special chars
*
* @param String $string The string to encode
* @return String The encoded string
*/
function plugin_formcreator_encode($string)
{
$string = stripcslashes($string);
$string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
$string = str_replace(''', "'", $string);
$string = htmlentities($string, ENT_QUOTES, 'UTF-8');
return $string;
}
/**
* Encode special chars
*
* @param String $string The string to encode
* @return String The encoded string
*/
function plugin_formcreator_decode($string)
{
$string = stripcslashes($string);
$string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
$string = str_replace(''', "'", $string);
return $string;
}