|
41 | 41 |
|
42 | 42 | PluginFormcreatorForm::header(); |
43 | 43 |
|
44 | | -if (isset($_REQUEST['id']) |
45 | | - && is_numeric($_REQUEST['id'])) { |
| 44 | +if (!isset($_REQUEST['id']) |
| 45 | + || !is_numeric($_REQUEST['id'])) { |
| 46 | + $message = __("The form has been successfully saved!"); |
| 47 | + Html::displayTitle($CFG_GLPI['root_doc']."/pics/ok.png", $message, $message); |
| 48 | +} |
46 | 49 |
|
47 | | - $criteria = [ |
48 | | - 'id' => (int) $_REQUEST['id'], |
49 | | - 'is_active' => '1', |
50 | | - 'is_deleted'=> '0', |
51 | | - ]; |
52 | | - $form = new PluginFormcreatorForm(); |
53 | | - if (!$form->getFromDBByCrit($criteria)) { |
54 | | - Html::displayNotFoundError(); |
55 | | - } |
| 50 | +$criteria = [ |
| 51 | + 'id' => (int) $_REQUEST['id'], |
| 52 | + 'is_active' => '1', |
| 53 | + 'is_deleted'=> '0', |
| 54 | +]; |
| 55 | +$form = new PluginFormcreatorForm(); |
| 56 | +if (!$form->getFromDBByCrit($criteria)) { |
| 57 | + Html::displayNotFoundError(); |
| 58 | +} |
56 | 59 |
|
57 | | - if ($form->fields['access_rights'] != PluginFormcreatorForm::ACCESS_PUBLIC) { |
58 | | - Session::checkLoginUser(); |
59 | | - if (!$form->checkEntity(true)) { |
60 | | - Html::displayRightError(); |
61 | | - exit(); |
62 | | - } |
| 60 | +if ($form->fields['access_rights'] != PluginFormcreatorForm::ACCESS_PUBLIC) { |
| 61 | + Session::checkLoginUser(); |
| 62 | + if (!$form->checkEntity(true)) { |
| 63 | + Html::displayRightError(); |
| 64 | + exit(); |
63 | 65 | } |
| 66 | +} |
64 | 67 |
|
65 | | - if ($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_RESTRICTED) { |
66 | | - $iterator = $DB->request(PluginFormcreatorForm_Profile::getTable(), [ |
67 | | - 'WHERE' => [ |
68 | | - 'profiles_id' => $_SESSION['glpiactiveprofile']['id'], |
69 | | - 'plugin_formcreator_forms_id' => $form->getID() |
70 | | - ], |
71 | | - 'LIMIT' => 1 |
72 | | - ]); |
73 | | - if (count($iterator) == 0) { |
74 | | - Html::displayRightError(); |
75 | | - exit(); |
76 | | - } |
| 68 | +if ($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_RESTRICTED) { |
| 69 | + $iterator = $DB->request(PluginFormcreatorForm_Profile::getTable(), [ |
| 70 | + 'WHERE' => [ |
| 71 | + 'profiles_id' => $_SESSION['glpiactiveprofile']['id'], |
| 72 | + 'plugin_formcreator_forms_id' => $form->getID() |
| 73 | + ], |
| 74 | + 'LIMIT' => 1 |
| 75 | + ]); |
| 76 | + if (count($iterator) == 0) { |
| 77 | + Html::displayRightError(); |
| 78 | + exit(); |
77 | 79 | } |
78 | | - if (($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC) && (!isset($_SESSION['glpiID']))) { |
79 | | - // If user is not authenticated, create temporary user |
80 | | - if (!isset($_SESSION['glpiname'])) { |
81 | | - $_SESSION['formcreator_forms_id'] = $form->getID(); |
82 | | - $_SESSION['glpiname'] = 'formcreator_temp_user'; |
83 | | - $_SESSION['valid_id'] = session_id(); |
84 | | - $_SESSION['glpiactiveentities'] = [$form->fields['entities_id']]; |
85 | | - $subentities = getSonsOf('glpi_entities', $form->fields['entities_id']); |
86 | | - $_SESSION['glpiactiveentities_string'] = (!empty($subentities)) |
87 | | - ? "'" . implode("', '", $subentities) . "'" |
88 | | - : "'" . $form->fields['entities_id'] . "'"; |
89 | | - } |
| 80 | +} |
| 81 | +if (($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC) && (!isset($_SESSION['glpiID']))) { |
| 82 | + // If user is not authenticated, create temporary user |
| 83 | + if (!isset($_SESSION['glpiname'])) { |
| 84 | + $_SESSION['formcreator_forms_id'] = $form->getID(); |
| 85 | + $_SESSION['glpiname'] = 'formcreator_temp_user'; |
| 86 | + $_SESSION['valid_id'] = session_id(); |
| 87 | + $_SESSION['glpiactiveentities'] = [$form->fields['entities_id']]; |
| 88 | + $subentities = getSonsOf('glpi_entities', $form->fields['entities_id']); |
| 89 | + $_SESSION['glpiactiveentities_string'] = (!empty($subentities)) |
| 90 | + ? "'" . implode("', '", $subentities) . "'" |
| 91 | + : "'" . $form->fields['entities_id'] . "'"; |
90 | 92 | } |
| 93 | +} |
91 | 94 |
|
92 | | - $form->displayUserForm(); |
| 95 | +$form->displayUserForm(); |
93 | 96 |
|
94 | | - // If user was not authenticated, remove temporary user |
95 | | - if ($_SESSION['glpiname'] == 'formcreator_temp_user') { |
96 | | - session_write_close(); |
97 | | - unset($_SESSION['glpiname']); |
98 | | - } |
99 | | -} else if (isset($_GET['answer_saved'])) { |
100 | | - $message = __("The form has been successfully saved!"); |
101 | | - Html::displayTitle($CFG_GLPI['root_doc']."/pics/ok.png", $message, $message); |
| 97 | +// If user was not authenticated, remove temporary user |
| 98 | +if ($_SESSION['glpiname'] == 'formcreator_temp_user') { |
| 99 | + session_write_close(); |
| 100 | + unset($_SESSION['glpiname']); |
102 | 101 | } |
103 | 102 |
|
104 | 103 | PluginFormcreatorForm::footer(); |
0 commit comments