Skip to content

Commit

Permalink
feat(targetproblem): target problem
Browse files Browse the repository at this point in the history
  • Loading branch information
btry authored Dec 17, 2021
1 parent 58a9b04 commit e9af413
Show file tree
Hide file tree
Showing 14 changed files with 1,667 additions and 76 deletions.
95 changes: 95 additions & 0 deletions front/targetproblem.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @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();
}
26 changes: 26 additions & 0 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,8 @@ public function getFields() : array {
public static function getTargetTypes() : array {
return [
PluginFormcreatorTargetTicket::class,
PluginFormcreatorTargetChange::class
PluginFormcreatorTargetChange::class,
PluginFormcreatorTargetProblem::class,
];
}

Expand Down
28 changes: 0 additions & 28 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ public function showForm($ID, $options = []) {
$title = __('Edit a target', 'formcreator');
}

// TODO: remive the fixed width
echo '<form name="form_"'
. ' method="post"'
. ' action="' . self::getFormURL() . '"'
Expand All @@ -427,7 +426,6 @@ public function showForm($ID, $options = []) {
echo '<tr><th colspan="2">' . $title . '</th></tr>';
echo '<tr>';
echo '<td width="15%"><strong>' . __('Name') . ' <span style="color:red;">*</span></strong></td>';
// TODO: remive the fixed width
echo '<td>';
echo Html::input('name', [
'id' => 'name',
Expand Down Expand Up @@ -901,30 +899,4 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {

return $change;
}

/**
* get all target changes for a form
*
* @param int $formId
* @return array
*/
public function getTargetsForForm($formId) {
global $DB;

$targets = [];
$rows = $DB->request([
'SELECT' => ['id'],
'FROM' => self::getTable(),
'WHERE' => [
'plugin_formcreator_forms_id' => $formId
],
]);
foreach ($rows as $row) {
$target = new self();
$target->getFromDB($row['id']);
$targets[$row['id']] = $target;
}

return $targets;
}
}
Loading

0 comments on commit e9af413

Please sign in to comment.