diff --git a/front/targetproblem.form.php b/front/targetproblem.form.php new file mode 100644 index 000000000..18ffb6ed8 --- /dev/null +++ b/front/targetproblem.form.php @@ -0,0 +1,95 @@ +. + * --------------------------------------------------------------------- + * @copyright Copyright © 2011 - 2021 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +include ('../../../inc/includes.php'); + +Session::checkRight('entity', UPDATE); + +// Check if plugin is activated... +if (!(new Plugin())->isActivated('formcreator')) { + Html::displayNotFoundError(); +} +$targetProblem = new PluginFormcreatorTargetProblem(); + +// Edit an existing target problem +if (isset($_POST['update'])) { + $targetProblem->update($_POST); + Html::back(); + +} else if (isset($_POST['actor_role'])) { + $id = (int) $_POST['id']; + $actor_value = isset($_POST['actor_value_' . $_POST['actor_type']]) + ? $_POST['actor_value_' . $_POST['actor_type']] + : ''; + $use_notification = ($_POST['use_notification'] == 0) ? 0 : 1; + $targetProblem_actor = new PluginFormcreatorTarget_Actor(); + $targetProblem_actor->add([ + 'itemtype' => $targetProblem->getType(), + 'items_id' => $id, + 'actor_role' => $_POST['actor_role'], + 'actor_type' => $_POST['actor_type'], + 'actor_value' => $actor_value, + 'use_notification' => $use_notification, + ]); + Html::back(); + +} else if (isset($_GET['delete_actor'])) { + $targetProblem_actor = new PluginFormcreatorTarget_Actor(); + $targetProblem_actor->delete([ + 'itemtype' => $targetProblem->getType(), + 'items_id' => $id, + 'id' => (int) $_GET['delete_actor'] + ]); + Html::back(); + + // Show target ticket form +} else { + Html::header( + __('Form Creator', 'formcreator'), + $_SERVER['PHP_SELF'], + 'admin', + 'PluginFormcreatorForm' + ); + + $itemtype = PluginFormcreatorTargetProblem::class; + $targetProblem->getFromDB((int) $_REQUEST['id']); + $form = $targetProblem->getForm(); + + $_SESSION['glpilisttitle'][$itemtype] = sprintf( + __('%1$s = %2$s'), + $form->getTypeName(1), $form->getName() + ); + $_SESSION['glpilisturl'][$itemtype] = $form->getFormURL()."?id=".$form->getID(); + + $targetProblem->display($_REQUEST); + + Html::footer(); +} diff --git a/inc/abstracttarget.class.php b/inc/abstracttarget.class.php index 1309b7355..53fd179e5 100644 --- a/inc/abstracttarget.class.php +++ b/inc/abstracttarget.class.php @@ -2473,4 +2473,30 @@ public function getDefaultData(PluginFormcreatorFormAnswer $formanswer): array { $data = array_merge($data, $predefined_fields); return $data; } + + /** + * get all target problems for a form + * + * @param int $formId + * @return array + */ + public function getTargetsForForm($formId) { + global $DB; + + $targets = []; + $rows = $DB->request([ + 'SELECT' => ['id'], + 'FROM' => static::getTable(), + 'WHERE' => [ + 'plugin_formcreator_forms_id' => $formId + ], + ]); + foreach ($rows as $row) { + $target = new static(); + $target->getFromDB($row['id']); + $targets[$row['id']] = $target; + } + + return $targets; + } } diff --git a/inc/form.class.php b/inc/form.class.php index 6cbe9ca06..87069404f 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -2238,7 +2238,8 @@ public function getFields() : array { public static function getTargetTypes() : array { return [ PluginFormcreatorTargetTicket::class, - PluginFormcreatorTargetChange::class + PluginFormcreatorTargetChange::class, + PluginFormcreatorTargetProblem::class, ]; } diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 8009bf610..086d25fd1 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -415,7 +415,6 @@ public function showForm($ID, $options = []) { $title = __('Edit a target', 'formcreator'); } - // TODO: remive the fixed width echo '