diff --git a/ajax/gettranslationsvalues.php b/ajax/gettranslationsvalues.php index ac2d223a3..4e8dcfbee 100644 --- a/ajax/gettranslationsvalues.php +++ b/ajax/gettranslationsvalues.php @@ -33,7 +33,6 @@ // Direct access to file if (strpos($_SERVER['PHP_SELF'], 'gettranslationsvalues.php')) { - include ('../../../inc/includes.php'); header('Content-Type: application/json; charset=UTF-8'); Html::header_nocache(); } else if (!defined('GLPI_ROOT')) { diff --git a/css/styles.scss b/css/styles.scss index 2e59f3e39..4f3b2ac7d 100644 --- a/css/styles.scss +++ b/css/styles.scss @@ -421,6 +421,7 @@ form#plugin_formcreator_form { border-left: 4px solid #999; margin: 10px 15px; word-wrap: break-word; + padding-left: 12px; } #plugin_formcreator_form .form-group .form_field > input, diff --git a/inc/field/descriptionfield.class.php b/inc/field/descriptionfield.class.php index af643800e..9f62237e6 100644 --- a/inc/field/descriptionfield.class.php +++ b/inc/field/descriptionfield.class.php @@ -43,6 +43,11 @@ public function isPrerequisites(): bool { return true; } + public function show($domain, $canEdit = true) { + + return '
' . $this->getRenderedHtml($domain, $canEdit) . '
'; + } + public function getDesignSpecializationField(): array { $common = parent::getDesignSpecializationField(); $additions = $common['additions']; diff --git a/inc/field/ldapselectfield.class.php b/inc/field/ldapselectfield.class.php index 939e578f4..a8a6f86d7 100644 --- a/inc/field/ldapselectfield.class.php +++ b/inc/field/ldapselectfield.class.php @@ -41,6 +41,8 @@ use QuerySubQuery; use Session; use RuleRightParameter; +use PluginFormcreatorQuestion; +use PluginFormcreatorLdapDropdown; class LdapselectField extends SelectField { @@ -55,6 +57,7 @@ public function getDesignSpecializationField(): array { if ($ldap_values === null) { $ldap_values = []; } + $current_entity = Session::getActiveEntity(); $auth_ldap_condition = ''; if ($current_entity != 0) { @@ -124,6 +127,37 @@ public function getDesignSpecializationField(): array { ]; } + public function getRenderedHtml($domain, $canEdit = true): string { + if (!$canEdit) { + return $this->value . PHP_EOL; + } + + $html = ''; + $id = $this->question->getID(); + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + + if (!empty($this->question->fields['values'])) { + $options = [ + 'name' => $fieldName, + 'value' => $this->value, + 'rand' => $rand, + 'multiple' => false, + 'display' => false, + 'condition' => [ + PluginFormcreatorQuestion::getForeignKeyField() => $this->question->getID() + ] + ]; + $html .= PluginFormcreatorLdapDropdown::dropdown($options); + } + $html .= PHP_EOL; + $html .= Html::scriptBlock("$(function() { + pluginFormcreatorInitializeSelect('$fieldName', '$rand'); + });"); + + return $html; + } + public function getAvailableValues() { if (empty($this->question->fields['values'])) { return []; diff --git a/inc/form.class.php b/inc/form.class.php index 32752b6a3..113e5ff7f 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -2808,4 +2808,57 @@ public function getBestLanguage() { } return \Locale::lookup($availableLanguages, $_SESSION['glpilanguage'], false, $defaultLanguage); } + + /** + * Can the current user show the form to fill an assistance request + * + * @return boolean true if the user can use the form + */ + public function canViewForRequest(): bool { + global $PLUGIN_HOOKS; + + if ($this->isNewItem()) { + return false; + } + + // Public forms -> always visible + if ($this->fields['access_rights'] == self::ACCESS_PUBLIC) { + return true; + } + + // Restricted and private forms -> Check session + if (Session::getLoginUserID() === false || !$this->checkEntity(true)) { + return false; + } + + // Form administrators can always access any forms + if (self::canCreate()) { + return true; + } + + // Check restrictions if needed + if ($this->fields['access_rights'] == self::ACCESS_RESTRICTED + && !PluginFormcreatorFormAccessType::canSeeRestrictedForm($this) + ) { + return false; + } + + // Check plugins restrictions + if (isset($PLUGIN_HOOKS['formcreator_restrict_form'])) { + foreach ($PLUGIN_HOOKS['formcreator_restrict_form'] as $plugin => $callable) { + // Skip if invalid hook + if (!is_callable($callable)) { + trigger_error("formcreator_restrict_form[$plugin]: not a callable", E_USER_WARNING); + continue; + } + + if (!call_user_func($callable, $this)) { + return false; + } + } + } + + // All checks were succesful, display form + return true; + } } diff --git a/inc/item_targetticket.class.php b/inc/item_targetticket.class.php index 2b8a97fa1..bf01ada58 100644 --- a/inc/item_targetticket.class.php +++ b/inc/item_targetticket.class.php @@ -96,7 +96,7 @@ public function export(bool $remove_uuid = false) : array { return $item_targetTicket; } - public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0, $dryRun = false) { + public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) { if (!isset($input['uuid']) && !isset($input['id'])) { throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1))); } @@ -120,19 +120,17 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con } // set ID for linked objects - if (!$dryRun) { - $linkedItemtype = $input['itemtype']; - $linkedItemId = $input['items_id']; - $linkedItem = $linker->findObject($linkedItemtype, $linkedItemId, $idKey); - if ($linkedItem->isNewItem()) { - if (strpos($linkedItemtype, 'PluginFormcreator') === 0) { - // the linnked object belongs to the plugin, maybe the item will be imported later - $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); - return false; - } - // linked item is not an object of Formcreator, it will not be imported - throw new ImportFailureException('Failed to find a linked object to a target ticket'); + $linkedItemtype = $input['itemtype']; + $linkedItemId = $input['items_id']; + $linkedItem = $linker->findObject($linkedItemtype, $linkedItemId, $idKey); + if ($linkedItem->isNewItem()) { + if (strpos($linkedItemtype, 'PluginFormcreator') === 0) { + // the linnked object belongs to the plugin, maybe the item will be imported later + $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); + return false; } + // linked item is not an object of Formcreator, it will not be imported + throw new ImportFailureException('Failed to find a linked object to a target ticket'); } // Add or update diff --git a/inc/translation.class.php b/inc/translation.class.php index f723c9eec..059ac566e 100644 --- a/inc/translation.class.php +++ b/inc/translation.class.php @@ -29,6 +29,8 @@ * --------------------------------------------------------------------- */ +use Glpi\Toolbox\Sanitizer; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } @@ -88,9 +90,7 @@ public static function getDropdownValue($post, $json = true) { if (!$formLanguage->getFromDB($formLanguageId)) { return []; } - if (!isset($post['searchText'])) { - $post['searchText'] = ''; - } + $post['searchText'] = $post['searchText'] ?? ''; $form = new PluginFormcreatorForm(); $form->getFromDB($formLanguage->fields['plugin_formcreator_forms_id']);