diff --git a/hook.php b/hook.php index b49f598f5..efee6708f 100644 --- a/hook.php +++ b/hook.php @@ -375,11 +375,12 @@ function plugin_formcreator_MassiveActions($itemtype) { switch ($itemtype) { case PluginFormcreatorForm::class: return [ - 'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'), - 'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'), - 'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'), + PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'), + PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'), + PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'), + PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'AccessRights' => _sx('button', 'Access rights'), ]; - } + } return []; } @@ -803,4 +804,4 @@ function plugin_formcreator_transfer(array $options) { 'tickets_id' => $options['newID'], ]); } -} \ No newline at end of file +} diff --git a/inc/form.class.php b/inc/form.class.php index 1edf569ac..c5132b639 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -220,7 +220,7 @@ public function rawSearchOptions() { '0' => 'equals', '1' => 'notequals' ], - 'massiveaction' => true + 'massiveaction' => false ]; $tab[] = [ @@ -1195,16 +1195,16 @@ public function prepareInputForUpdate($input) { return false; } - if (!$this->checkConditionSettings($input)) { - $input['show_rule'] = PluginFormcreatorCondition::SHOW_RULE_ALWAYS; - } + // if (!$this->checkConditionSettings($input)) { + // $input['show_rule'] = PluginFormcreatorCondition::SHOW_RULE_ALWAYS; + // } - if (!$this->checkValidators($input)) { - $input['validation_required'] = self::VALIDATION_NONE; - } + // if (!$this->checkValidators($input)) { + // $input['validation_required'] = self::VALIDATION_NONE; + // } } - return $input; + // return $input; } // Control fields values : @@ -1239,6 +1239,13 @@ public function prepareInputForUpdate($input) { } } + if (isset($input['restrictions'])) { + $input['users'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], User::class); + $input['groups'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], Group::class); + $input['profiles'] = AbstractRightsDropdown::getPostedIds($input['restrictions'], Profile::class); + unset($input['restrictions']); + } + return $input; } @@ -1458,6 +1465,35 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) { ]); echo '

' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']); return true; + + case 'AccessRights': + echo '

'; + Dropdown::showFromArray( + 'access_rights', + PluginFormcreatorForm::getEnumAccessType(), + [ + 'value' => PluginFormcreatorForm::ACCESS_PRIVATE, + 'on_change' => 'plugin_formcreator.showMassiveRestrictions(this)', + ] + ); + echo '

'; + echo ''; + echo ''; + echo ''; + echo '

' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']); + return true; + } return parent::showMassiveActionsSubForm($ma); } @@ -1511,6 +1547,18 @@ public static function processMassiveActionsForOneItemtype(MassiveAction $ma, Co Html::redirect(FORMCREATOR_ROOTDOC."/front/export.php?".Toolbox::append_params($listOfId)); header("Content-disposition:attachment filename=\"test\""); return; + + case 'AccessRights': + foreach ($ids as $id) { + if ($item->getFromDB($id) && $item->update($ma->POST + ['id' => $id])) { + Session::addMessageAfterRedirect(sprintf(__('Form updated: %s', 'formcreator'), $item->getName())); + $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); + } else { + // Example of ko count + $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); + } + } + return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); } diff --git a/inc/formaccesstype.class.php b/inc/formaccesstype.class.php index 19b4a66e0..dc4350769 100644 --- a/inc/formaccesstype.class.php +++ b/inc/formaccesstype.class.php @@ -71,7 +71,8 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { 'access_rights', PluginFormcreatorForm::getEnumAccessType(), [ - 'value' => (isset($item->fields['access_rights'])) ? $item->fields['access_rights'] : '1', + 'value' => $item->fields['access_rights'] ?? PluginFormcreatorForm::ACCESS_PRIVATE, + 'on_change' => 'plugin_formcreator.showMassiveRestrictions(this)', ] ); echo ''; @@ -94,26 +95,32 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { echo ''; // Captcha - if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC) { - echo ''; + $is_visible = $item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC; + // if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_PUBLIC) { + echo ''; echo '' . __('Enable captcha', 'formcreator') . ''; echo ''; Dropdown::showYesNo('is_captcha_enabled', $item->fields['is_captcha_enabled']); echo ''; echo ''; - } + // } - if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) { - echo ''.self::getTypeName(2).''; - echo ''; + $is_visible = $item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED; + // if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) { + echo ''; + echo '' . self::getTypeName(2) . ''; + echo ''; + echo ''; echo ''; - echo '' . PluginFormcreatorRestrictedFormDropdown::show('restrictions', [ + echo ''; + echo PluginFormcreatorRestrictedFormDropdown::show('restrictions', [ 'users_id' => $item->fields['users'] ?? [], 'groups_id' => $item->fields['groups'] ?? [], 'profiles_id' => $item->fields['profiles'] ?? [], - ]) . ''; + ]); // Does not supports display parameter to return the output instead of printing it + echo ''; echo ''; - } + // } $formFk = PluginFormcreatorForm::getForeignKeyField(); echo ''; diff --git a/js/scripts.js b/js/scripts.js index 8b1a836b3..4abe046af 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -1416,6 +1416,18 @@ var plugin_formcreator = new function() { return item.name != '_glpi_csrf_token'; }); } + + this.showMassiveRestrictions = function (item) { + document.querySelector('#plugin_formcreator_restrictions_head').style.display = 'none'; + document.querySelector('#plugin_formcreator_restrictions').style.display = 'none'; + document.querySelector('#plugin_formcreator_captcha').style.display = 'none'; + if (item.value == 2 /* PluginFormcreatorForm::ACCESS_RESTRICTED */) { + document.querySelector('#plugin_formcreator_restrictions').style.display = 'block'; + document.querySelector('#plugin_formcreator_restrictions_head').style.display = 'block'; + } else if (item.value == 0 /* PluginFormcreatorForm::ACCESS_PUBLIC */) { + document.querySelector('#plugin_formcreator_captcha').style.display = 'block'; + } + } } // === TARGETS ===