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