forked from pluginsGLPI/formcreator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook.php
More file actions
205 lines (172 loc) · 6.44 KB
/
Copy pathhook.php
File metadata and controls
205 lines (172 loc) · 6.44 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
// [CRI] : Add Tab para Información de Pedido
function plugin_formcreator_postinit() {
global $CFG_GLPI, $PLUGIN_HOOKS;
foreach (PluginFormcreatorForm::getTypes(true) as $type) {
CommonGLPI::registerStandardTab($type, 'PluginFormcreatorForm');
}
}
/**
* Install all necessary elements for the plugin
*
* @return boolean True if success
*/
function plugin_formcreator_install()
{
$version = plugin_version_formcreator();
$migration = new Migration($version['version']);
// Parse inc directory
foreach (glob(dirname(__FILE__).'/inc/*') as $filepath) {
// Load *.class.php files and get the class name
if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
$classname = 'PluginFormcreator' . ucfirst($matches[1]);
include_once($filepath);
// If the install method exists, load it
if (method_exists($classname, 'install')) {
$classname::install($migration);
}
}
}
return true ;
}
/**
* Uninstall previously installed elements of the plugin
*
* @return boolean True if success
*/
function plugin_formcreator_uninstall()
{
// Parse inc directory
foreach (glob(dirname(__FILE__).'/inc/*') as $filepath) {
// Load *.class.php files and get the class name
if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
$classname = 'PluginFormcreator' . ucfirst($matches[1]);
include_once($filepath);
// If the install method exists, load it
if (method_exists($classname, 'uninstall')) {
$classname::uninstall();
}
}
}
return true ;
}
/**
* Define Dropdown tables to be manage in GLPI :
*/
function plugin_formcreator_getDropdown()
{
return array(
'PluginFormcreatorHeader' => _n('Header', 'Headers', 2, 'formcreator'),
'PluginFormcreatorCategory' => _n('Form category', 'Form categories', 2, 'formcreator'),
);
}
/**
* Define specific search request
*
* @param String $type Itemtype for the search engine
* @return String Specific search request
*/
function plugin_formcreator_addDefaultWhere($type)
{
switch ($type) {
case "PluginFormcreatorFormanswer" :
if (Session::haveRight('config', UPDATE)) {
return " 1=1 ";
} else if (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEINCIDENT)
|| Session::haveRight('ticketvalidation', TicketValidation::VALIDATEREQUEST)) {
return " `glpi_plugin_formcreator_formanswers`.`validator_id` = " . $_SESSION['glpiID'].
" OR `glpi_plugin_formcreator_formanswers`.`requester_id` = " . $_SESSION['glpiID'];
} else {
return " `glpi_plugin_formcreator_formanswers`.`requester_id` = " . $_SESSION['glpiID'];
}
break;
default:
return '';
}
}
// function plugin_formcreator_MassiveActions($type) {
// //option afficher dans la lsite des masive actions
// }
// function plugin_formcreator_MassiveActionsFieldDisplay($options=array()) {
// //formulaire pour l'action choisi par l'iutiliqsateur
// }
// function plugin_formcreator_MassiveActionsProcess($data) {
// //traitement effectuer a la validation du formulaire
// }
// Define actions :
function plugin_formcreator_MassiveActions($type) {
switch ($type) {
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
case 'PluginFormcreatorForm' :
return array('PluginFormcreatorForm'.MassiveAction::CLASS_ACTION_SEPARATOR.'Duplicate' =>
_x('button', 'Duplicate'));
break; // [CRI] : break
// [CRI] : Actions for types provided by the plugin are included inside the classes
case 'Ticket' :
return array("PluginFormcreatorForm".MassiveAction::CLASS_ACTION_SEPARATOR.'Pedido' => __('Pedido de catalogo','Pedido de catalogo'));
break;
default :
break;
}
return array();
}
// [CRI] : Add getAddSearchOptions
function plugin_formcreator_getAddSearchOptions($itemtype) {
global $CFG_GLPI;
$sopt = array();
if ($itemtype == 'Ticket') {
$sopt['informacionpedido'] = __('Informacion del pedido', 'Informacion del pedido');
// ID de la petición del catálogo.
$sopt[1500]['table'] = 'glpi_plugin_formcreator_forms';
$sopt[1500]['name'] = __('Pedido de Catalogo', 'Pedido de catalogo');
$sopt[1500]['field'] = "name";
$sopt[1500]['datatype'] = 'itemlink';
$sopt[1500]['massiveaction'] = true;
$sopt[1500]['itemlink_type'] = 'PluginFormcreatorForm';
$sopt[1500]['joinparams'] = array('beforejoin'
=> array('table' => 'glpi_plugin_formcreator_forms_items',
'joinparams' => array('jointype' => 'itemtype_item')));
}
return $sopt;
}
/**
* [CRI] : Add getAddSearchOptionsDefine dropdown relations
**/
function plugin_formcreator_getDatabaseRelations() {
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
return array('glpi_plugin_formcreator_form'
=> array('glpi_plugin_formcreator_form_items'
=> 'plugin_formcreator_forms_id'));
}
return array();
}
// // How to display specific update fields ?
// // options must contain at least itemtype and options array
// function plugin_formcreator_MassiveActionsFieldsDisplay($options=array()) {
// //$type,$table,$field,$linkfield
// $table = $options['options']['table'];
// $field = $options['options']['field'];
// $linkfield = $options['options']['linkfield'];
// if ($table == getTableForItemType($options['itemtype'])) {
// // Table fields
// switch ($table.".".$field) {
// case 'glpi_plugin_example_examples.serial' :
// _e("Not really specific - Just for example", 'example');
// //Html::autocompletionTextField($linkfield,$table,$field);
// // Dropdown::showYesNo($linkfield);
// // Need to return true if specific display
// return true;
// }
// } else {
// // Linked Fields
// switch ($table.".".$field) {
// case "glpi_plugin_example_dropdowns.name" :
// _e("Not really specific - Just for example", 'example');
// // Need to return true if specific display
// return true;
// }
// }
// // Need to return false on non display item
// return false;
// }