Skip to content

Commit

Permalink
feat: compatibility with GLPI's marketplace
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jun 8, 2020
1 parent 0d7c4dd commit 04374b9
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 62 deletions.
2 changes: 1 addition & 1 deletion ajax/homepage_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
include ('../../../inc/includes.php');

echo '<li id="menu5">";
<a href="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/front/formlist.php" class="itemP">'.
<a href="'.FORMCREATOR_ROOTDOC.'/front/formlist.php" class="itemP">'.
_n('Form', 'Forms', 2, 'formcreator').
'</a>
</li>';
4 changes: 2 additions & 2 deletions front/form.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// Add a new Form
Session::checkRight('entity', UPDATE);
$newID = $form->add($_POST);
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.form.php?id=' . $newID);
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.form.php?id=' . $newID);

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

} else if (isset($_POST['filetype_create'])) {
$documentType = new DocumentType();
Expand Down
2 changes: 1 addition & 1 deletion front/issue.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
if (plugin_formcreator_replaceHelpdesk()) {
PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));
} else {
Html::redirect($CFG_GLPI["root_doc"]."/front/helpdesk.public.php");
Html::redirect($CFG_GLPI['root_doc']."/front/helpdesk.public.php");
}

$issue->getFromDBByCrit([
Expand Down
2 changes: 1 addition & 1 deletion front/question.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@


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

2 changes: 1 addition & 1 deletion front/section.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

} else {
// Return to form list
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.php');
Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.php');
}

// Or display a "Not found" error
Expand Down
2 changes: 1 addition & 1 deletion front/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}

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

PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));
Expand Down
2 changes: 1 addition & 1 deletion front/wizardfeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}

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

if (RSSFeed::canView()) {
Expand Down
4 changes: 1 addition & 3 deletions inc/fields/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-description-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-description-field.png" title="" />';
}

public function isVisibleField()
Expand Down
4 changes: 1 addition & 3 deletions inc/fields/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-float-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-float-field.png" title="" />';
}

public function isVisibleField()
Expand Down
4 changes: 1 addition & 3 deletions inc/fields/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-glpiselect-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-glpiselect-field.png" title="" />';
}
}
4 changes: 1 addition & 3 deletions inc/fields/integerfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ public function greaterThan($value) {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-integer-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-integer-field.png" title="" />';
}
}
4 changes: 1 addition & 3 deletions inc/fields/multiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public static function getName() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-multiselect-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-multiselect-field.png" title="" />';
}
}
4 changes: 1 addition & 3 deletions inc/fields/selectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public function equals($value) {


public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-select-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-select-field.png" title="" />';
}
}
4 changes: 1 addition & 3 deletions inc/fields/tagfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-tag-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-tag-field.png" title="" />';
}

public function isVisibleField()
Expand Down
4 changes: 1 addition & 3 deletions inc/fields/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-textarea-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-textarea-field.png" title="" />';
}
}
4 changes: 1 addition & 3 deletions inc/fields/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ public function isAnonymousFormCompatible() {
}

public function getHtmlIcon() {
global $CFG_GLPI;

return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/ui-text-field.png" title="" />';
return '<img src="' . FORMCREATOR_ROOTDOC . '/pics/ui-text-field.png" title="" />';
}

public function isVisibleField()
Expand Down
16 changes: 6 additions & 10 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ public static function getTypeName($nb = 0) {
}

static function getMenuContent() {
global $CFG_GLPI;

$menu = parent::getMenuContent();
$menu['icon'] = 'fas fa-edit';
$validation_image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
$validation_image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
title="' . __('Forms waiting for validation', 'formcreator') . '">';
$import_image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/import.png"
$import_image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/import.png"
title="' . __('Import forms', 'formcreator') . '">';
$menu['links']['search'] = PluginFormcreatorFormList::getSearchURL(false);
$menu['links']['config'] = PluginFormcreatorForm::getSearchURL(false);
Expand Down Expand Up @@ -619,8 +617,6 @@ public function showForm($ID, $options = []) {
}

public function showTargets($ID, $options = []) {
global $CFG_GLPI;

echo '<table class="tab_cadre_fixe">';

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

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

echo '<td align="center" width="32">';
echo '<img src="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/pics/delete.png"
echo '<img src="'.FORMCREATOR_ROOTDOC.'/pics/delete.png"
alt="*" title="'.__('Delete', 'formcreator').'"
onclick="plugin_formcreator_deleteTarget(\''. $target->getType() . '\', '.$targetId.', \''.$token.'\')" align="absmiddle" style="cursor: pointer" /> ';
echo '</td>';
Expand Down Expand Up @@ -2047,8 +2043,8 @@ public function showForCentral() {
echo '<img src="' . $CFG_GLPI['root_doc'] . '/pics/plus.png" alt="+" title=""
onclick="showDescription(' . $row['id'] . ', this)" align="absmiddle" style="cursor: pointer">';
echo '&nbsp;';
echo '<a href="' . $CFG_GLPI['root_doc']
. '/plugins/formcreator/front/formdisplay.php?id=' . $row['id'] . '"
echo '<a href="' . FORMCREATOR_ROOTDOC
. '/front/formdisplay.php?id=' . $row['id'] . '"
title="' . $row['description'] . '">'
. $row['name']
. '</a></td>';
Expand Down
2 changes: 1 addition & 1 deletion inc/form_profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
$form_url = $CFG_GLPI['url_base'].'/plugins/formcreator/front/formdisplay.php?id='.$item->getID();
echo '<a href="'.$form_url.'">'.$form_url.'</a>&nbsp;';
echo '<a href="mailto:?subject='.$item->getName().'&body='.$form_url.'" target="_blank">';
echo '<img src="'.$CFG_GLPI['root_doc'].'/plugins/formcreator/pics/email.png" />';
echo '<img src="'.FORMCREATOR_ROOTDOC.'/pics/email.png" />';
echo '</a>';
} else {
echo __('Please active the form to view the link', 'formcreator');
Expand Down
4 changes: 1 addition & 3 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ public function rawSearchOptions() {
* @return Mixed Value to be displayed
*/
public static function getSpecificValueToDisplay($field, $values, array $options = []) {
global $CFG_GLPI;

if (!is_array($values)) {
$language = $_SESSION["glpilanguage"];
Session::loadLanguage('en_GB');
Expand All @@ -294,7 +292,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
}
switch ($field) {
case 'status' :
$output = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/' . strtolower($values[$field]) . '.png"
$output = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/' . strtolower($values[$field]) . '.png"
alt="' . __($values[$field], 'formcreator') . '" title="' . __($values[$field], 'formcreator') . '" /> ';
return $output;
break;
Expand Down
4 changes: 1 addition & 3 deletions inc/formlist.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public static function getTypeName($nb = 0) {
}

static function getMenuContent() {
global $CFG_GLPI;

$menu = parent::getMenuContent();
$menu['title'] = static::getTypeName(2);
$menu['page'] = '/plugins/formcreator/front/formlist.php';
$menu['icon'] = 'fas fa-edit';
$image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
$image = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
title="' . __('Forms waiting for validation', 'formcreator') . '"
alt="' . __('Forms waiting for validation', 'formcreator') . '">';

Expand Down
24 changes: 14 additions & 10 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@

define ('PLUGIN_FORMCREATOR_TEXTAREA_FIX', true);

define('FORMCREATOR_ROOTDOC', $CFG_GLPI['root_doc'] . '/plugins/formcreator');
if (method_exists(Plugin::class, 'getWebDir')) {
define('FORMCREATOR_ROOTDOC', Plugin::getWebDir('formcreator'));
} else {
define('FORMCREATOR_ROOTDOC', $CFG_GLPI['root_doc'] . '/plugins/formcreator');
}

/**
* Define the plugin's version and informations
Expand Down Expand Up @@ -170,7 +174,7 @@ function plugin_init_formcreator() {
&& isset($_SESSION['glpiactive_entity'])) {
// Interface and active entity are set in session
if (plugin_formcreator_replaceHelpdesk()) {
Html::redirect($CFG_GLPI["root_doc"]."/plugins/formcreator/front/wizard.php");
Html::redirect(FORMCREATOR_ROOTDOC."/front/wizard.php");
}
}
}
Expand All @@ -184,18 +188,18 @@ function plugin_init_formcreator() {
if (isset($decodedUrl['forcetab'])) {
Session::setActiveTab(Ticket::class, $decodedUrl['forcetab']);
}
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/issue.form.php?id=' . $_GET['id'] . '&sub_itemtype=Ticket' . $forceTab);
Html::redirect(FORMCREATOR_ROOTDOC . '/front/issue.form.php?id=' . $_GET['id'] . '&sub_itemtype=Ticket' . $forceTab);
}
}

$pages = [
'front/reservationitem.php' => 'plugins/formcreator/front/reservationitem.php',
'front/helpdesk.faq.php' => 'plugins/formcreator/front/wizard.php',
'front/ticket.php' => 'plugins/formcreator/front/issue.php',
'front/reservationitem.php' => FORMCREATOR_ROOTDOC . '/front/reservationitem.php',
'front/helpdesk.faq.php' => FORMCREATOR_ROOTDOC . '/front/wizard.php',
'front/ticket.php' => FORMCREATOR_ROOTDOC . '/front/issue.php',
];
foreach ($pages as $srcPage => $dstPage) {
if (strpos($_SERVER['REQUEST_URI'], $srcPage) !== false && strpos($_SERVER['REQUEST_URI'], $dstPage) === false) {
Html::redirect($CFG_GLPI["root_doc"] . '/' . $dstPage);
Html::redirect($dstPage);
break;
}
}
Expand All @@ -219,10 +223,10 @@ function plugin_init_formcreator() {
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';
$links['config'] = FORMCREATOR_ROOTDOC . '/front/form.php';
$links['add'] = FORMCREATOR_ROOTDOC . '/front/form.form.php';
}
$img = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
$img = '<img src="' . FORMCREATOR_ROOTDOC . '/pics/check.png"
title="' . __('Forms waiting for validation', 'formcreator') . '" alt="Waiting forms list" />';

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

0 comments on commit 04374b9

Please sign in to comment.