Fix save thematic advance - BT#11358

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 914b0ed333
commit 814da60ba8
  1. 4
      main/course_progress/index.php
  2. 38
      main/course_progress/thematic_advance.php
  3. 61
      main/course_progress/thematic_controller.php

@ -50,8 +50,8 @@ $actions = array(
);
$action = 'thematic_details';
if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
$action = $_GET['action'];
if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], $actions)) {
$action = $_REQUEST['action'];
}
if (isset($_POST['action']) && $_POST['action'] == 'thematic_delete_select') {

@ -22,8 +22,7 @@ if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
$form = new FormValidator(
'thematic_advance',
'POST',
'index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq(
)
api_get_self() . '?' . api_get_cidreq()
);
$form->addElement('header', $header_form);
//$form->addElement('hidden', 'thematic_advance_token',$token);
@ -170,6 +169,41 @@ if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
}
}
$form->setDefaults($default);
if ($form->validate()) {
$values = $form->exportValues();
$thematic = new Thematic();
$thematic->set_thematic_advance_attributes(
isset($values['thematic_advance_id']) ? $values['thematic_advance_id']: null,
$values['thematic_id'],
$values['start_date_type'] == 1 && isset($values['attendance_select']) ? $values['attendance_select'] : 0,
$values['content'],
$values['start_date_type'] == 2 ? $values['custom_start_date'] : $values['start_date_by_attendance'],
$values['duration_in_hours']
);
$affected_rows = $thematic->thematic_advance_save();
if ($affected_rows) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
// update done advances with de current thematic list
if (!empty($last_done_thematic_advance)) {
$thematic->update_done_thematic_advances($last_done_thematic_advance);
}
}
$redirectUrlParams = 'course_progress/index.php?' . api_get_cidreq() . '&' .
http_build_query([
'action' => 'thematic_advance_list',
'thematic_id' => $values['thematic_id']
]);
header('Location: ' . api_get_path(WEB_CODE_PATH) . $redirectUrlParams);
exit;
}
$form->display();
} else if ($action == 'thematic_advance_list') {

@ -425,60 +425,13 @@ class ThematicController
exit;
}
if ((isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) ||
(!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours']))
) {
if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) {
$start_date_error = true;
$data['start_date_error'] = $start_date_error;
}
if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) {
$duration_error = true;
$data['duration_error'] = $duration_error;
}
$data['action'] = $_REQUEST['action'];
$data['thematic_id'] = $_REQUEST['thematic_id'];
$data['attendance_select'] = $attendance_select;
if (isset($_REQUEST['thematic_advance_id'])) {
$data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
$thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
$data['thematic_advance_data'] = $thematic_advance_data;
}
} else {
if (api_is_allowed_to_edit(null, true)) {
$thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? $_REQUEST['thematic_advance_id'] : null;
$thematic_id = $_REQUEST['thematic_id'];
$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null;
$duration = isset($_REQUEST['duration_in_hours']) ? $_REQUEST['duration_in_hours'] : null;
if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) {
$start_date = $_REQUEST['custom_start_date'];
$attendance_id = 0;
} else {
$start_date = isset($_REQUEST['start_date_by_attendance']) ? $_REQUEST['start_date_by_attendance'] : null;
$attendance_id = isset($_REQUEST['attendance_select']) ? $_REQUEST['attendance_select'] : null;
}
$thematic->set_thematic_advance_attributes(
$thematic_advance_id,
$thematic_id,
$attendance_id,
$content,
$start_date,
$duration
);
$affected_rows = $thematic->thematic_advance_save();
if ($affected_rows) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
// update done advances with de current thematic list
if (!empty($last_done_thematic_advance)) {
$thematic->update_done_thematic_advances($last_done_thematic_advance);
}
}
}
$data['action'] = $_REQUEST['action'];
$data['thematic_id'] = $_REQUEST['thematic_id'];
$data['attendance_select'] = $attendance_select;
if (isset($_REQUEST['thematic_advance_id'])) {
$data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
$thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
$data['thematic_advance_data'] = $thematic_advance_data;
}
break;
default:

Loading…
Cancel
Save