33
33
// Minimal GLPI version, inclusive
34
34
define ("PLUGIN_FIELDS_MIN_GLPI " , "10.0.0 " );
35
35
// Maximum GLPI version, exclusive
36
- define ("PLUGIN_FIELDS_MAX_GLPI " , "10.0 .99 " );
36
+ define ("PLUGIN_FIELDS_MAX_GLPI " , "10.1 .99 " );
37
37
38
38
if (!defined ("PLUGINFIELDS_DIR " )) {
39
39
define ("PLUGINFIELDS_DIR " , Plugin::getPhpDir ("fields " ));
63
63
mkdir (PLUGINFIELDS_FRONT_PATH );
64
64
}
65
65
66
+ use Glpi \Plugin \Hooks ;
66
67
use Symfony \Component \Yaml \Yaml ;
67
68
68
69
/**
@@ -85,102 +86,106 @@ function plugin_init_fields()
85
86
$ pluginfields_autoloader = new PluginFieldsAutoloader ([PLUGINFIELDS_CLASS_PATH ]);
86
87
$ pluginfields_autoloader ->register ();
87
88
88
- if (Session::getLoginUserID () && Plugin::isPluginActive ('fields ' )) {
89
- // Init hook about itemtype(s) for plugin fields
90
- if (!isset ($ PLUGIN_HOOKS ['plugin_fields ' ])) {
91
- $ PLUGIN_HOOKS ['plugin_fields ' ] = [];
92
- }
89
+ if (Plugin::isPluginActive ('fields ' )) {
90
+ // This API integration cannot be done inside a login check since the plugin is initialized before the Router handles authentication
91
+ $ PLUGIN_HOOKS [Hooks::REDEFINE_API_SCHEMAS ]['fields ' ] = 'plugin_fields_redefine_api_schemas ' ;
92
+ if (Session::getLoginUserID ()) {
93
+ // Init hook about itemtype(s) for plugin fields
94
+ if (!isset ($ PLUGIN_HOOKS ['plugin_fields ' ])) {
95
+ $ PLUGIN_HOOKS ['plugin_fields ' ] = [];
96
+ }
93
97
94
- // When a Category is changed during ticket creation
95
- if (
96
- isset ($ _POST ) && !empty ($ _POST )
97
- && isset ($ _POST ['_plugin_fields_type ' ])
98
- && $ _SERVER ['REQUEST_URI ' ] ?? '' == Ticket::getFormURL ()
99
- ) {
100
- foreach ($ _POST as $ key => $ value ) {
101
- if (!is_array ($ value )) {
102
- $ _SESSION ['plugin ' ]['fields ' ]['values_sent ' ][$ key ] = stripcslashes ($ value );
98
+ // When a Category is changed during ticket creation
99
+ if (
100
+ isset ($ _POST ) && !empty ($ _POST )
101
+ && isset ($ _POST ['_plugin_fields_type ' ])
102
+ && $ _SERVER ['REQUEST_URI ' ] ?? '' == Ticket::getFormURL ()
103
+ ) {
104
+ foreach ($ _POST as $ key => $ value ) {
105
+ if (!is_array ($ value )) {
106
+ $ _SESSION ['plugin ' ]['fields ' ]['values_sent ' ][$ key ] = stripcslashes ($ value );
107
+ }
103
108
}
104
109
}
105
- }
106
-
107
- if (Plugin::isPluginActive ('fusioninventory ' )) {
108
- $ PLUGIN_HOOKS ['fusioninventory_inventory ' ]['fields ' ]
109
- = ['PluginFieldsInventory ' , 'updateInventory ' ];
110
- }
111
110
112
- // complete rule engine
113
- $ PLUGIN_HOOKS ['use_rules ' ]['fields ' ] = ['PluginFusioninventoryTaskpostactionRule ' ];
114
- $ PLUGIN_HOOKS ['rule_matched ' ]['fields ' ] = 'plugin_fields_rule_matched ' ;
115
-
116
- if (isset ($ _SESSION ['glpiactiveentities ' ])) {
117
- // add link in plugin page
118
- $ PLUGIN_HOOKS ['config_page ' ]['fields ' ] = 'front/container.php ' ;
119
-
120
- // add entry to configuration menu
121
- $ PLUGIN_HOOKS ["menu_toadd " ]['fields ' ] = ['config ' => 'PluginFieldsMenu ' ];
122
-
123
- // add tabs to itemtypes
124
- Plugin::registerClass (
125
- 'PluginFieldsContainer ' ,
126
- ['addtabon ' => array_unique (PluginFieldsContainer::getEntries ())]
127
- );
128
-
129
- //include js and css
130
- $ debug = (isset ($ _SESSION ['glpi_use_mode ' ])
131
- && $ _SESSION ['glpi_use_mode ' ] == Session::DEBUG_MODE ? true : false );
132
- if (!$ debug && file_exists (__DIR__ . '/css/fields.min.css ' )) {
133
- $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.min.css ' ;
134
- } else {
135
- $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.css ' ;
111
+ if (Plugin::isPluginActive ('fusioninventory ' )) {
112
+ $ PLUGIN_HOOKS ['fusioninventory_inventory ' ]['fields ' ]
113
+ = ['PluginFieldsInventory ' , 'updateInventory ' ];
136
114
}
137
115
138
- // Add/delete profiles to automaticaly to container
139
- $ PLUGIN_HOOKS ['item_add ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "addNewProfile " ];
140
- $ PLUGIN_HOOKS ['pre_item_purge ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "deleteProfile " ];
116
+ // complete rule engine
117
+ $ PLUGIN_HOOKS ['use_rules ' ]['fields ' ] = ['PluginFusioninventoryTaskpostactionRule ' ];
118
+ $ PLUGIN_HOOKS ['rule_matched ' ]['fields ' ] = 'plugin_fields_rule_matched ' ;
119
+
120
+ if (isset ($ _SESSION ['glpiactiveentities ' ])) {
121
+ // add link in plugin page
122
+ $ PLUGIN_HOOKS ['config_page ' ]['fields ' ] = 'front/container.php ' ;
123
+
124
+ // add entry to configuration menu
125
+ $ PLUGIN_HOOKS ["menu_toadd " ]['fields ' ] = ['config ' => 'PluginFieldsMenu ' ];
126
+
127
+ // add tabs to itemtypes
128
+ Plugin::registerClass (
129
+ 'PluginFieldsContainer ' ,
130
+ ['addtabon ' => array_unique (PluginFieldsContainer::getEntries ())]
131
+ );
132
+
133
+ //include js and css
134
+ $ debug = (isset ($ _SESSION ['glpi_use_mode ' ])
135
+ && $ _SESSION ['glpi_use_mode ' ] == Session::DEBUG_MODE ? true : false );
136
+ if (!$ debug && file_exists (__DIR__ . '/css/fields.min.css ' )) {
137
+ $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.min.css ' ;
138
+ } else {
139
+ $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.css ' ;
140
+ }
141
+
142
+ // Add/delete profiles to automaticaly to container
143
+ $ PLUGIN_HOOKS ['item_add ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "addNewProfile " ];
144
+ $ PLUGIN_HOOKS ['pre_item_purge ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "deleteProfile " ];
141
145
142
- //load drag and drop javascript library on Package Interface
143
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = "lib/redips-drag-min.js " ;
144
- if (!$ debug && file_exists (__DIR__ . '/js/drag-field-row.min.js ' )) {
145
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.min.js ' ;
146
- } else {
147
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.js ' ;
146
+ //load drag and drop javascript library on Package Interface
147
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = "lib/redips-drag-min.js " ;
148
+ if (!$ debug && file_exists (__DIR__ . '/js/drag-field-row.min.js ' )) {
149
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.min.js ' ;
150
+ } else {
151
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.js ' ;
152
+ }
148
153
}
149
- }
150
154
151
- // Add Fields to Datainjection
152
- if (Plugin::isPluginActive ('datainjection ' )) {
153
- $ PLUGIN_HOOKS ['plugin_datainjection_populate ' ]['fields ' ] = "plugin_datainjection_populate_fields " ;
154
- }
155
+ // Add Fields to Datainjection
156
+ if (Plugin::isPluginActive ('datainjection ' )) {
157
+ $ PLUGIN_HOOKS ['plugin_datainjection_populate ' ]['fields ' ] = "plugin_datainjection_populate_fields " ;
158
+ }
155
159
156
- //Retrieve dom container
157
- $ itemtypes = PluginFieldsContainer::getUsedItemtypes ();
158
- if ($ itemtypes !== false ) {
159
- foreach ($ itemtypes as $ itemtype ) {
160
- $ PLUGIN_HOOKS ['pre_item_update ' ]['fields ' ][$ itemtype ] = [
161
- "PluginFieldsContainer " ,
162
- "preItemUpdate "
163
- ];
164
- $ PLUGIN_HOOKS ['pre_item_add ' ]['fields ' ][$ itemtype ] = [
165
- "PluginFieldsContainer " ,
166
- "preItem "
167
- ];
168
- $ PLUGIN_HOOKS ['item_add ' ]['fields ' ][$ itemtype ] = [
169
- "PluginFieldsContainer " ,
170
- "postItemAdd "
171
- ];
172
- $ PLUGIN_HOOKS ['pre_item_purge ' ] ['fields ' ][$ itemtype ] = [
173
- "PluginFieldsContainer " ,
174
- "preItemPurge "
175
- ];
160
+ //Retrieve dom container
161
+ $ itemtypes = PluginFieldsContainer::getUsedItemtypes ();
162
+ if ($ itemtypes !== false ) {
163
+ foreach ($ itemtypes as $ itemtype ) {
164
+ $ PLUGIN_HOOKS ['pre_item_update ' ]['fields ' ][$ itemtype ] = [
165
+ "PluginFieldsContainer " ,
166
+ "preItemUpdate "
167
+ ];
168
+ $ PLUGIN_HOOKS ['pre_item_add ' ]['fields ' ][$ itemtype ] = [
169
+ "PluginFieldsContainer " ,
170
+ "preItem "
171
+ ];
172
+ $ PLUGIN_HOOKS ['item_add ' ]['fields ' ][$ itemtype ] = [
173
+ "PluginFieldsContainer " ,
174
+ "postItemAdd "
175
+ ];
176
+ $ PLUGIN_HOOKS ['pre_item_purge ' ] ['fields ' ][$ itemtype ] = [
177
+ "PluginFieldsContainer " ,
178
+ "preItemPurge "
179
+ ];
180
+ }
176
181
}
177
- }
178
182
179
- // Display fields in any existing tab
180
- $ PLUGIN_HOOKS ['post_item_form ' ]['fields ' ] = [
181
- 'PluginFieldsField ' ,
182
- 'showForTab '
183
- ];
183
+ // Display fields in any existing tab
184
+ $ PLUGIN_HOOKS ['post_item_form ' ]['fields ' ] = [
185
+ 'PluginFieldsField ' ,
186
+ 'showForTab '
187
+ ];
188
+ }
184
189
}
185
190
}
186
191
0 commit comments