Skip to content

Commit

Permalink
refactor(form): simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jul 24, 2020
1 parent 16fd205 commit ca600d4
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions front/form.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,47 @@

} else if (isset($_POST['submit_formcreator'])) {
// Save form to target
if ($form->getFromDB($_POST['plugin_formcreator_forms_id'])) {
if (!$form->getFromDB($_POST['plugin_formcreator_forms_id'])) {
Html::back();
}

// If user is not authenticated, create temporary user
if (!isset($_SESSION['glpiname'])) {
$_SESSION['glpiname'] = 'formcreator_temp_user';
}
// If user is not authenticated, create temporary user
if (!isset($_SESSION['glpiname'])) {
$_SESSION['glpiname'] = 'formcreator_temp_user';
}

// Save form
$formAnswer = new PluginFormcreatorFormAnswer();
if ($formAnswer->add($_POST) === false) {
Html::back();
}
$form->increaseUsageCount();
// Save form
$formAnswer = new PluginFormcreatorFormAnswer();
if ($formAnswer->add($_POST) === false) {
Html::back();
}
$form->increaseUsageCount();

if ($_SESSION['glpiname'] == 'formcreator_temp_user') {
// Form was saved by an annymous user
unset($_SESSION['glpiname']);
Html::redirect('formdisplay.php?answer_saved');
}
if ($_SESSION['glpiname'] == 'formcreator_temp_user') {
// Form was saved by an annymous user
unset($_SESSION['glpiname']);
Html::redirect('formdisplay.php?answer_saved');
}

// redirect to created item
if ($_SESSION['glpibackcreated']) {
if (count($formAnswer->targetList) == 1) {
$target = current($formAnswer->targetList);
Html::redirect($target->getFormURLWithID($target->getID()));
}
Html::redirect(PluginFormcreatorFormAnswer::getFormURLWithID($formAnswer->getID()));
// redirect to created item
if ($_SESSION['glpibackcreated']) {
if (count($formAnswer->targetList) == 1) {
$target = current($formAnswer->targetList);
Html::redirect($target->getFormURLWithID($target->getID()));
}
Html::redirect(PluginFormcreatorFormAnswer::getFormURLWithID($formAnswer->getID()));
}

if (plugin_formcreator_replaceHelpdesk()) {
// Form was saved from the service catalog
Html::redirect('issue.php');
}
if (strpos($_SERVER['HTTP_REFERER'], 'formdisplay.php') !== false) {
// Form was saved from helpdesk (assistance > forms)
Html::redirect('formlist.php');
}
// Form was saved from preview tab, go back to the preview
Html::back();
if (plugin_formcreator_replaceHelpdesk()) {
// Form was saved from the service catalog
Html::redirect('issue.php');
}
if (strpos($_SERVER['HTTP_REFERER'], 'formdisplay.php') !== false) {
// Form was saved from helpdesk (assistance > forms)
Html::redirect('formlist.php');
}
// Form was saved from preview tab, go back to the preview
Html::back();

} else {
// Show forms form
Expand Down

0 comments on commit ca600d4

Please sign in to comment.