Skip to content

Commit

Permalink
Fix #73
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
tsmr committed Feb 27, 2023
1 parent e30dc47 commit c84cf4b
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 299 deletions.
232 changes: 113 additions & 119 deletions ajax/addform.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,84 +42,81 @@
$fields = new PluginMetademandsField();

if (isset($_POST['save_form'])) {
$nblines = 0;
$KO = false;

if ($nblines == 0) {
$post = $_POST['field'];
$nblines = 1;
}

if ($KO === false) {

$checks = [];
$content = [];

for ($i = 0; $i < $nblines; $i++) {

$_POST['field'] = $post;
$metademands_data = $metademands->constructMetademands($_POST['metademands_id']);
if (count($metademands_data)) {
foreach ($metademands_data as $form_step => $data) {
$docitem = null;
foreach ($data as $form_metademands_id => $line) {
foreach ($line['form'] as $id => $value) {
if (!isset($post[$id])) {
if (isset($_SESSION['plugin_metademands']['fields'][$id])
&& $value['plugin_metademands_metademands_id'] != $_POST['form_metademands_id']) {
$_POST['field'][$id] = $_SESSION['plugin_metademands']['fields'][$id];
} else {
$_POST['field'][$id] = [];
}
} else {
$_SESSION['plugin_metademands']['fields'][$id] = $post[$id];
}
$nblines = 0;
$KO = false;

if ($value['type'] == 'radio') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = NULL;
}
}
if ($value['type'] == 'checkbox') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = 0;
}
}
if ($value['type'] == 'informations'
|| $value['type'] == 'title') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = 0;
}
}
if ($value['item'] == 'ITILCategory_Metademands') {
$_POST['field'][$id] = $_POST['field_plugin_servicecatalog_itilcategories_id'] ?? 0;
}
}
if ($nblines == 0) {
$post = $_POST['field'];
$nblines = 1;
}

if ($KO === false) {
$checks = [];
$content = [];

}
for ($i = 0; $i < $nblines; $i++) {
$_POST['field'] = $post;
$metademands_data = $metademands->constructMetademands($_POST['metademands_id']);
if (count($metademands_data)) {
foreach ($metademands_data as $form_step => $data) {
$docitem = null;
foreach ($data as $form_metademands_id => $line) {
foreach ($line['form'] as $id => $value) {
if (!isset($post[$id])) {
if (isset($_SESSION['plugin_metademands']['fields'][$id])
&& $value['plugin_metademands_metademands_id'] != $_POST['form_metademands_id']) {
$_POST['field'][$id] = $_SESSION['plugin_metademands']['fields'][$id];
} else {
$_POST['field'][$id] = [];
}
} else {
$_SESSION['plugin_metademands']['fields'][$id] = $post[$id];
}

if ($value['type'] == 'radio') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = null;
}
}
if ($value['type'] == 'checkbox') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = 0;
}
}
if ($value['type'] == 'informations'
|| $value['type'] == 'title') {
if (!isset($_POST['field'][$id])) {
$_POST['field'][$id] = 0;
}
}
if ($value['item'] == 'ITILCategory_Metademands') {
$_POST['field'][$id] = $_POST['field_plugin_servicecatalog_itilcategories_id'] ?? 0;
}
}
}
}
}
}
$metademands->getFromDB($_POST['metademands_id']);
if ($KO === false) {
// Save requester user
$_SESSION['plugin_metademands']['fields']['_users_id_requester'] = $_POST['_users_id_requester'];
// Case of simple ticket convertion
if (isset($_POST['items_id']) && $_POST['itemtype'] == 'Ticket') {
$_SESSION['plugin_metademands']['fields']['tickets_id'] = $_POST['items_id'];
$metademands->getFromDB($_POST['metademands_id']);
if ($KO === false) {
// Save requester user
$_SESSION['plugin_metademands']['fields']['_users_id_requester'] = $_POST['_users_id_requester'];
// Case of simple ticket convertion
if (isset($_POST['items_id']) && $_POST['itemtype'] == 'Ticket') {
$_SESSION['plugin_metademands']['fields']['tickets_id'] = $_POST['items_id'];
}
// Resources id
$_SESSION['plugin_metademands']['fields']['resources_id'] = $_POST['resources_id'];
// Resources step
$_SESSION['plugin_metademands']['fields']['resources_step'] = $_POST['resources_step'];

//Category id if have category field
$_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] = $_POST['field_plugin_servicecatalog_itilcategories_id'] ?? 0;
$_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] =
(isset($_POST['basket_plugin_servicecatalog_itilcategories_id']) && $_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] == 0) ? $_POST['basket_plugin_servicecatalog_itilcategories_id'] : 0;
$_SESSION['plugin_metademands']['field_type'] = $metademands->fields['type'];
}
// Resources id
$_SESSION['plugin_metademands']['fields']['resources_id'] = $_POST['resources_id'];
// Resources step
$_SESSION['plugin_metademands']['fields']['resources_step'] = $_POST['resources_step'];

//Category id if have category field
$_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] = $_POST['field_plugin_servicecatalog_itilcategories_id'] ?? 0;
$_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] =
(isset($_POST['basket_plugin_servicecatalog_itilcategories_id']) && $_SESSION['plugin_metademands']['field_plugin_servicecatalog_itilcategories_id'] == 0) ? $_POST['basket_plugin_servicecatalog_itilcategories_id'] : 0;
$_SESSION['plugin_metademands']['field_type'] = $metademands->fields['type'];
}

$forms = new PluginMetademandsForm();

$forms = new PluginMetademandsForm();
// if (isset($_POST['plugin_metademands_forms_id'])
// && !empty($_POST['plugin_metademands_forms_id'])) {
// $form_id = $_POST['plugin_metademands_forms_id'];
Expand All @@ -138,57 +135,54 @@
// PluginMetademandsForm_Value::loadFormValues($form_id);
// $_POST['form_name'] = $forms->getField('name');
// } else {
if (!isset($_POST['form_name']) || (isset($_POST['form_name']) && empty($_POST['form_name']))) {
Session::addMessageAfterRedirect(__('Form name is required', 'metademands'), false, ERROR);
break;
}
$inputs = [];
$inputs['name'] = Toolbox::addslashes_deep($_POST['form_name']);
$inputs['users_id'] = Session::getLoginUserID();
$inputs['plugin_metademands_metademands_id'] = $_POST['metademands_id'];
$inputs['date'] = date('Y-m-d H:i:s');
if (isset($_POST['is_model'])) {
$inputs['is_model'] = $_POST['is_model'];
}

if (isset($_POST['resources_id']) && $_POST['resources_id'] > 0) {
$resForm = $forms->find(['plugin_metademands_metademands_id' => $_POST['metademands_id'],
'resources_id' => $_POST['resources_id']]);
if (count($resForm)) {
foreach ($resForm as $res) {
$last = $res['id'];
}
} else {
$last = 0;
if (!isset($_POST['form_name']) || (isset($_POST['form_name']) && empty($_POST['form_name']))) {
Session::addMessageAfterRedirect(__('Form name is required', 'metademands'), false, ERROR);
break;
}
$inputs = [];
$inputs['name'] = Toolbox::addslashes_deep($_POST['form_name']);
$inputs['users_id'] = Session::getLoginUserID();
$inputs['plugin_metademands_metademands_id'] = $_POST['metademands_id'];
$inputs['date'] = date('Y-m-d H:i:s');
if (isset($_POST['is_model'])) {
$inputs['is_model'] = $_POST['is_model'];
}
$_SESSION['plugin_metademands']['form_to_compare'] = $last;
}

if ($form_new_id = $forms->add($inputs)) {
$_SESSION['plugin_metademands']['plugin_metademands_forms_id'] = $form_new_id;
$_SESSION['plugin_metademands']['plugin_metademands_forms_name'] = $_POST['form_name'];
if (isset($_POST['resources_id']) && $_POST['resources_id'] > 0) {
$resForm = $forms->find(['plugin_metademands_metademands_id' => $_POST['metademands_id'],
'resources_id' => $_POST['resources_id']]);
if (count($resForm)) {
foreach ($resForm as $res) {
$last = $res['id'];
}
} else {
$last = 0;
}
$_SESSION['plugin_metademands']['form_to_compare'] = $last;
}

$metademands_data = $metademands->constructMetademands($_POST['metademands_id']);
if (count($metademands_data) && $form_new_id > 0) {
foreach ($metademands_data as $form_step => $data) {
$docitem = null;
foreach ($data as $form_metademands_id => $line) {
PluginMetademandsForm_Value::setFormValues($line['form'], $_POST['field'], $form_new_id);
}
}
if ($form_new_id = $forms->add($inputs)) {
$_SESSION['plugin_metademands']['plugin_metademands_forms_id'] = $form_new_id;
$_SESSION['plugin_metademands']['plugin_metademands_forms_name'] = $_POST['form_name'];

$metademands_data = $metademands->constructMetademands($_POST['metademands_id']);
if (count($metademands_data) && $form_new_id > 0) {
foreach ($metademands_data as $form_step => $data) {
$docitem = null;
foreach ($data as $form_metademands_id => $line) {
PluginMetademandsForm_Value::setFormValues($line['form'], $_POST['field'], $form_new_id);
}
}
}
} else {
$KO = false;
}
} else {
$KO = false;
}
// }
}
}
}
}
}
if ($KO === false) {
echo 0;
echo 0;
} else {
echo $KO;
echo $KO;
}



Loading

0 comments on commit c84cf4b

Please sign in to comment.