Skip to content

Commit ae1cdf6

Browse files
committed
feat(targetticket,targetchange): conditions to generate the targets
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 9ed9e87 commit ae1cdf6

25 files changed

+833
-468
lines changed

ajax/condition.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,51 @@
5353
http_response_code(400);
5454
exit;
5555
}
56-
56+
$item = new $itemtype();
57+
$parentType = $item::$itemtype;
58+
$parent = new $parentType();
59+
$parentFk = $parent::getForeignKeyField();
60+
if (!$item->getFromDB($itemId)) {
61+
// check for existence of container object
62+
if (!isset($_REQUEST[$parentFk])) {
63+
http_response_code(400);
64+
exit;
65+
}
66+
$parentId = (int) $_REQUEST[$parentFk];
67+
if (!$parent->getFromDB($parentId)) {
68+
http_response_code(400);
69+
exit;
70+
}
71+
// Set the relation of the empty item with the container
72+
$item->getEmpty();
73+
$item->fields[$parentFk] = $parentId;
74+
} else {
75+
$parentId = $item->fields[$parentFk];
76+
if (!$parent->getFromDB($parentId)) {
77+
http_response_code(400);
78+
exit;
79+
}
80+
}
5781
$form = new PluginFormcreatorForm();
5882
switch ($itemtype) {
5983
case PluginFormcreatorQuestion::class:
60-
if (!isset($_REQUEST['plugin_formcreator_sections_id'])) {
61-
http_response_code(400);
62-
exit;
63-
}
64-
$sectionId = (int) $_REQUEST['plugin_formcreator_sections_id'];
65-
$section = new PluginFormcreatorSection();
66-
$section->getFromDB($sectionId);
67-
$form->getFromDBBySection($section);
84+
85+
$form->getFromDBBySection($parent);
6886
break;
69-
case PluginFormcreatorSection::class:
70-
if (!isset($_REQUEST['plugin_formcreator_forms_id'])) {
71-
http_response_code(400);
72-
exit;
73-
}
74-
$formId = (int) $_REQUEST['plugin_formcreator_forms_id'];
75-
$form->getFromDB($formId);
87+
case PluginFormcreatorSection::class:
88+
case PluginFormcreatorTargetTicket::class:
89+
case PluginFormcreatorTargetChange::class:
90+
$form->getFromDB($parentId);
7691
break;
92+
default:
93+
http_response_code(400);
94+
exit;
7795
}
78-
7996
if ($form->isNewItem()) {
8097
http_response_code(400);
8198
exit;
8299
}
83100

84101
// get an empty condition HTML table row
85-
$item = new $itemtype();
86-
$item->getFromDB($itemId);
87102
$condition = new PluginFormcreatorCondition();
88-
echo $condition->getConditionHtml($form, $itemtype, $itemId);
103+
echo $condition->getConditionHtml($item);

ajax/question.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
$question_id = 0;
3838
$question->getEmpty();
3939
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
40-
$question->fields[$sectionFk] = (int) $_REQUEST['section_id'];
40+
$question->fields[$sectionFk] = (int) $_REQUEST['plugin_formcreator_sections_id'];
4141
} else {
4242
$question_id = (int) $_REQUEST['question_id'];
4343
$question->getFromDB($question_id);

ajax/question_add.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2019 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
Session::checkRight('entity', UPDATE);
34+
35+
$question = new PluginFormcreatorQuestion();
36+
if (!$question->canCreate()) {
37+
http_response_code(403);
38+
echo __('You don\'t have right for this action', 'formcreator');
39+
exit;
40+
}
41+
42+
if (!$question->add($_REQUEST)) {
43+
http_response_code(500);
44+
echo __('Could not add the question', 'formcreator');
45+
exit;
46+
}
47+
$json = [
48+
'y' => $question->fields['row'],
49+
'x' => $question->fields['col'],
50+
'width' => $question->fields['width'],
51+
'height' => '1',
52+
'html' => $question->getDesignHtml(),
53+
];
54+
echo json_encode($json);

ajax/question_update.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2019 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
Session::checkRight('entity', UPDATE);
34+
35+
if (!isset($_REQUEST['id'])) {
36+
echo __('Bad request', 'formcreator');
37+
http_response_code(400);
38+
exit();
39+
}
40+
$questionId = (int) $_REQUEST['id'];
41+
42+
$question = new PluginFormcreatorQuestion();
43+
if (!$question->getFromDB($questionId)) {
44+
http_response_code(404);
45+
echo __('Question not found', 'formcreator');
46+
exit;
47+
}
48+
49+
if (!$question->canUpdate()) {
50+
http_response_code(403);
51+
echo __('You don\'t have right for this action', 'formcreator');
52+
exit;
53+
}
54+
55+
$success = $question->update($_REQUEST);
56+
if (!$success) {
57+
http_response_code(500);
58+
exit();
59+
}
60+
echo $question->fields['name'];

ajax/section_add.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2019 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
Session::checkRight('entity', UPDATE);
34+
35+
$section = new PluginFormcreatorSection();
36+
if (!$section->canCreate()) {
37+
http_response_code(403);
38+
echo __('You don\'t have right for this action', 'formcreator');
39+
exit;
40+
}
41+
42+
if (!$section->add($_REQUEST)) {
43+
http_response_code(500);
44+
echo __('Could not add the section', 'formcreator');
45+
exit;
46+
}
47+
echo $section->getDesignHtml();

ajax/section_update.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2019 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
Session::checkRight('entity', UPDATE);
34+
35+
if (!isset($_REQUEST['id'])) {
36+
http_response_code(400);
37+
exit;
38+
}
39+
$sectionId = (int) $_REQUEST['id'];
40+
41+
$section = new PluginFormcreatorSection();
42+
if (!$section->canUpdate()) {
43+
http_response_code(403);
44+
echo __('You don\'t have right for this action', 'formcreator');
45+
exit;
46+
}
47+
48+
if (!$section->update($_REQUEST)) {
49+
http_response_code(500);
50+
echo __('Could not update the section', 'formcreator');
51+
exit;
52+
}
53+
echo $section->fields['name'];

front/question.form.php

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,7 @@
4040
Html::displayNotFoundError();
4141
}
4242

43-
$question = new PluginFormcreatorQuestion();
4443

45-
// force checks in PrepareInputForAdd or PrepareInputrForUpdate
46-
unset($_POST['_skip_checks']);
47-
if (isset($_POST['add'])) {
48-
// Add a new Question
49-
Session::checkRight('entity', UPDATE);
50-
if ($newid = $question->add($_POST)) {
51-
Session::addMessageAfterRedirect(__('The question has been successfully saved!', 'formcreator'), true, INFO);
52-
$_POST['id'] = $newid;
53-
$question->updateConditions($_POST);
54-
$question->updateParameters($_POST);
55-
}
56-
Html::back();
44+
// Return to form list
45+
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.php');
5746

58-
} else if (isset($_POST['update'])) {
59-
// Edit an existing Question
60-
Session::checkRight('entity', UPDATE);
61-
if ($question->update($_POST)) {
62-
Session::addMessageAfterRedirect(__('The question has been successfully updated!', 'formcreator'), true, INFO);
63-
$question->updateConditions($_POST);
64-
$question->updateParameters($_POST);
65-
}
66-
Html::back();
67-
68-
} else {
69-
// Return to form list
70-
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.php');
71-
}

front/section.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
// Add a new Section
4444
Session::checkRight('entity', UPDATE);
4545
$section->add($_POST);
46-
$section->updateConditions($_POST);
46+
//$section->updateConditions($_POST);
4747
Html::back();
4848

4949
} else if (isset($_POST['update'])) {
5050
// Edit an existing section
5151
Session::checkRight('entity', UPDATE);
5252
$section->update($_POST);
53-
$section->updateConditions($_POST);
53+
//$section->updateConditions($_POST);
5454
Html::back();
5555

5656
} else {

0 commit comments

Comments
 (0)