Skip to content

Commit 04374b9

Browse files
committed
feat: compatibility with GLPI's marketplace
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 0d7c4dd commit 04374b9

21 files changed

+40
-62
lines changed

ajax/homepage_link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
include ('../../../inc/includes.php');
3434

3535
echo '<li id="menu5">";
36-
<a href="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/front/formlist.php" class="itemP">'.
36+
<a href="'.FORMCREATOR_ROOTDOC.'/front/formlist.php" class="itemP">'.
3737
_n('Form', 'Forms', 2, 'formcreator').
3838
'</a>
3939
</li>';

front/form.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// Add a new Form
4545
Session::checkRight('entity', UPDATE);
4646
$newID = $form->add($_POST);
47-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.form.php?id=' . $newID);
47+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.form.php?id=' . $newID);
4848

4949
} else if (isset($_POST['update'])) {
5050
// Edit an existing form
@@ -78,7 +78,7 @@
7878
} else if (isset($_POST['delete_target'])) {
7979
Session::checkRight('entity', UPDATE);
8080
$form->deleteTarget($_POST);
81-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
81+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
8282

8383
} else if (isset($_POST['filetype_create'])) {
8484
$documentType = new DocumentType();

front/issue.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
if (plugin_formcreator_replaceHelpdesk()) {
5858
PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));
5959
} else {
60-
Html::redirect($CFG_GLPI["root_doc"]."/front/helpdesk.public.php");
60+
Html::redirect($CFG_GLPI['root_doc']."/front/helpdesk.public.php");
6161
}
6262

6363
$issue->getFromDBByCrit([

front/question.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242

4343

4444
// Return to form list
45-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.php');
45+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.php');
4646

front/section.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
} else {
5555
// Return to form list
56-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.php');
56+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.php');
5757
}
5858

5959
// Or display a "Not found" error

front/wizard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040

4141
if (! plugin_formcreator_replaceHelpdesk()) {
42-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/formlist.php');
42+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/formlist.php');
4343
}
4444

4545
PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));

front/wizardfeeds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040

4141
if (! plugin_formcreator_replaceHelpdesk()) {
42-
Html::redirect($CFG_GLPI["root_doc"]."/front/helpdesk.public.php");
42+
Html::redirect($CFG_GLPI['root_doc']."/front/helpdesk.public.php");
4343
}
4444

4545
if (RSSFeed::canView()) {

inc/fields/descriptionfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public function isAnonymousFormCompatible() {
132132
}
133133

134134
public function getHtmlIcon() {
135-
global $CFG_GLPI;
136-
137-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-description-field.png" title="" />';
135+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-description-field.png" title="" />';
138136
}
139137

140138
public function isVisibleField()

inc/fields/floatfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ public function isAnonymousFormCompatible() {
278278
}
279279

280280
public function getHtmlIcon() {
281-
global $CFG_GLPI;
282-
283-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-float-field.png" title="" />';
281+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-float-field.png" title="" />';
284282
}
285283

286284
public function isVisibleField()

inc/fields/glpiselectfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ public function isAnonymousFormCompatible() {
183183
}
184184

185185
public function getHtmlIcon() {
186-
global $CFG_GLPI;
187-
188-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-glpiselect-field.png" title="" />';
186+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-glpiselect-field.png" title="" />';
189187
}
190188
}

inc/fields/integerfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ public function greaterThan($value) {
137137
}
138138

139139
public function getHtmlIcon() {
140-
global $CFG_GLPI;
141-
142-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-integer-field.png" title="" />';
140+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-integer-field.png" title="" />';
143141
}
144142
}

inc/fields/multiselectfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public static function getName() {
7171
}
7272

7373
public function getHtmlIcon() {
74-
global $CFG_GLPI;
75-
76-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-multiselect-field.png" title="" />';
74+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-multiselect-field.png" title="" />';
7775
}
7876
}

inc/fields/selectfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public function equals($value) {
106106

107107

108108
public function getHtmlIcon() {
109-
global $CFG_GLPI;
110-
111-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-select-field.png" title="" />';
109+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-select-field.png" title="" />';
112110
}
113111
}

inc/fields/tagfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ public function isAnonymousFormCompatible() {
229229
}
230230

231231
public function getHtmlIcon() {
232-
global $CFG_GLPI;
233-
234-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-tag-field.png" title="" />';
232+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-tag-field.png" title="" />';
235233
}
236234

237235
public function isVisibleField()

inc/fields/textareafield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ public function isAnonymousFormCompatible() {
202202
}
203203

204204
public function getHtmlIcon() {
205-
global $CFG_GLPI;
206-
207-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-textarea-field.png" title="" />';
205+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-textarea-field.png" title="" />';
208206
}
209207
}

inc/fields/textfield.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ public function isAnonymousFormCompatible() {
261261
}
262262

263263
public function getHtmlIcon() {
264-
global $CFG_GLPI;
265-
266-
return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-text-field.png" title="" />';
264+
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-text-field.png" title="" />';
267265
}
268266

269267
public function isVisibleField()

inc/form.class.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ public static function getTypeName($nb = 0) {
9494
}
9595

9696
static function getMenuContent() {
97-
global $CFG_GLPI;
98-
9997
$menu = parent::getMenuContent();
10098
$menu['icon'] = 'fas fa-edit';
101-
$validation_image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
99+
$validation_image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
102100
title="' . __('Forms waiting for validation', 'formcreator') . '">';
103-
$import_image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/import.png"
101+
$import_image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/import.png"
104102
title="' . __('Import forms', 'formcreator') . '">';
105103
$menu['links']['search'] = PluginFormcreatorFormList::getSearchURL(false);
106104
$menu['links']['config'] = PluginFormcreatorForm::getSearchURL(false);
@@ -619,8 +617,6 @@ public function showForm($ID, $options = []) {
619617
}
620618

621619
public function showTargets($ID, $options = []) {
622-
global $CFG_GLPI;
623-
624620
echo '<table class="tab_cadre_fixe">';
625621

626622
echo '<tr>';
@@ -643,13 +639,13 @@ public function showTargets($ID, $options = []) {
643639
echo '</td>';
644640

645641
echo '<td align="center" width="32">';
646-
echo '<img src="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/pics/edit.png"
642+
echo '<img src="'.FORMCREATOR_ROOTDOC.'/pics/edit.png"
647643
alt="*" title="'.__('Edit').'" ';
648644
echo 'onclick="document.location=\'' . $targetItemUrl . '\'" align="absmiddle" style="cursor: pointer" /> ';
649645
echo '</td>';
650646

651647
echo '<td align="center" width="32">';
652-
echo '<img src="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/pics/delete.png"
648+
echo '<img src="'.FORMCREATOR_ROOTDOC.'/pics/delete.png"
653649
alt="*" title="'.__('Delete', 'formcreator').'"
654650
onclick="plugin_formcreator_deleteTarget(\''. $target->getType() . '\', '.$targetId.', \''.$token.'\')" align="absmiddle" style="cursor: pointer" /> ';
655651
echo '</td>';
@@ -2047,8 +2043,8 @@ public function showForCentral() {
20472043
echo '<img src="' . $CFG_GLPI['root_doc'] . '/pics/plus.png" alt="+" title=""
20482044
onclick="showDescription(' . $row['id'] . ', this)" align="absmiddle" style="cursor: pointer">';
20492045
echo '&nbsp;';
2050-
echo '<a href="' . $CFG_GLPI['root_doc']
2051-
. '/plugins/formcreator/front/formdisplay.php?id=' . $row['id'] . '"
2046+
echo '<a href="' . FORMCREATOR_ROOTDOC
2047+
. '/front/formdisplay.php?id=' . $row['id'] . '"
20522048
title="' . $row['description'] . '">'
20532049
. $row['name']
20542050
. '</a></td>';

inc/form_profile.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
104104
$form_url = $CFG_GLPI['url_base'].'/plugins/formcreator/front/formdisplay.php?id='.$item->getID();
105105
echo '<a href="'.$form_url.'">'.$form_url.'</a>&nbsp;';
106106
echo '<a href="mailto:?subject='.$item->getName().'&body='.$form_url.'" target="_blank">';
107-
echo '<img src="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/pics/email.png" />';
107+
echo '<img src="'.FORMCREATOR_ROOTDOC.'/pics/email.png" />';
108108
echo '</a>';
109109
} else {
110110
echo __('Please active the form to view the link', 'formcreator');

inc/formanswer.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ public function rawSearchOptions() {
283283
* @return Mixed Value to be displayed
284284
*/
285285
public static function getSpecificValueToDisplay($field, $values, array $options = []) {
286-
global $CFG_GLPI;
287-
288286
if (!is_array($values)) {
289287
$language = $_SESSION["glpilanguage"];
290288
Session::loadLanguage('en_GB');
@@ -294,7 +292,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
294292
}
295293
switch ($field) {
296294
case 'status' :
297-
$output = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/' . strtolower($values[$field]) . '.png"
295+
$output = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/' . strtolower($values[$field]) . '.png"
298296
alt="' . __($values[$field], 'formcreator') . '" title="' . __($values[$field], 'formcreator') . '" /> ';
299297
return $output;
300298
break;

inc/formlist.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ public static function getTypeName($nb = 0) {
4747
}
4848

4949
static function getMenuContent() {
50-
global $CFG_GLPI;
51-
5250
$menu = parent::getMenuContent();
5351
$menu['title'] = static::getTypeName(2);
5452
$menu['page'] = '/plugins/formcreator/front/formlist.php';
5553
$menu['icon'] = 'fas fa-edit';
56-
$image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
54+
$image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
5755
title="' . __('Forms waiting for validation', 'formcreator') . '"
5856
alt="' . __('Forms waiting for validation', 'formcreator') . '">';
5957

setup.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444

4545
define ('PLUGIN_FORMCREATOR_TEXTAREA_FIX', true);
4646

47-
define('FORMCREATOR_ROOTDOC', $CFG_GLPI['root_doc'] . '/plugins/formcreator');
47+
if (method_exists(Plugin::class, 'getWebDir')) {
48+
define('FORMCREATOR_ROOTDOC', Plugin::getWebDir('formcreator'));
49+
} else {
50+
define('FORMCREATOR_ROOTDOC', $CFG_GLPI['root_doc'] . '/plugins/formcreator');
51+
}
4852

4953
/**
5054
* Define the plugin's version and informations
@@ -170,7 +174,7 @@ function plugin_init_formcreator() {
170174
&& isset($_SESSION['glpiactive_entity'])) {
171175
// Interface and active entity are set in session
172176
if (plugin_formcreator_replaceHelpdesk()) {
173-
Html::redirect($CFG_GLPI["root_doc"]."/plugins/formcreator/front/wizard.php");
177+
Html::redirect(FORMCREATOR_ROOTDOC."/front/wizard.php");
174178
}
175179
}
176180
}
@@ -184,18 +188,18 @@ function plugin_init_formcreator() {
184188
if (isset($decodedUrl['forcetab'])) {
185189
Session::setActiveTab(Ticket::class, $decodedUrl['forcetab']);
186190
}
187-
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/issue.form.php?id=' . $_GET['id'] . '&sub_itemtype=Ticket' . $forceTab);
191+
Html::redirect(FORMCREATOR_ROOTDOC . '/front/issue.form.php?id=' . $_GET['id'] . '&sub_itemtype=Ticket' . $forceTab);
188192
}
189193
}
190194

191195
$pages = [
192-
'front/reservationitem.php' => 'plugins/formcreator/front/reservationitem.php',
193-
'front/helpdesk.faq.php' => 'plugins/formcreator/front/wizard.php',
194-
'front/ticket.php' => 'plugins/formcreator/front/issue.php',
196+
'front/reservationitem.php' => FORMCREATOR_ROOTDOC . '/front/reservationitem.php',
197+
'front/helpdesk.faq.php' => FORMCREATOR_ROOTDOC . '/front/wizard.php',
198+
'front/ticket.php' => FORMCREATOR_ROOTDOC . '/front/issue.php',
195199
];
196200
foreach ($pages as $srcPage => $dstPage) {
197201
if (strpos($_SERVER['REQUEST_URI'], $srcPage) !== false && strpos($_SERVER['REQUEST_URI'], $dstPage) === false) {
198-
Html::redirect($CFG_GLPI["root_doc"] . '/' . $dstPage);
202+
Html::redirect($dstPage);
199203
break;
200204
}
201205
}
@@ -219,10 +223,10 @@ function plugin_init_formcreator() {
219223
if (Session::haveRight('entity', UPDATE)) {
220224
$PLUGIN_HOOKS['config_page']['formcreator'] = 'front/form.php';
221225
$PLUGIN_HOOKS['menu_toadd']['formcreator']['admin'] = 'PluginFormcreatorForm';
222-
$links['config'] = '/plugins/formcreator/front/form.php';
223-
$links['add'] = '/plugins/formcreator/front/form.form.php';
226+
$links['config'] = FORMCREATOR_ROOTDOC . '/front/form.php';
227+
$links['add'] = FORMCREATOR_ROOTDOC . '/front/form.form.php';
224228
}
225-
$img = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
229+
$img = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
226230
title="' . __('Forms waiting for validation', 'formcreator') . '" alt="Waiting forms list" />';
227231

228232
$links[$img] = '/plugins/formcreator/front/formanswer.php';

0 commit comments

Comments
 (0)