diff --git a/main/admin/session_add.php b/main/admin/session_add.php index adb0f9093c2..1671485cf87 100755 --- a/main/admin/session_add.php +++ b/main/admin/session_add.php @@ -96,55 +96,65 @@ function fill_coach_field (username) { if (isset($_POST['formSent']) && $_POST['formSent']) { - $formSent = 1; - $name = $_POST['name']; - $year_start = $_POST['year_start']; - $month_start = $_POST['month_start']; - $day_start = $_POST['day_start']; - $year_end = $_POST['year_end']; - $month_end = $_POST['month_end']; - $day_end = $_POST['day_end']; - $nb_days_acess_before = $_POST['nb_days_acess_before']; - $nb_days_acess_after = $_POST['nb_days_acess_after']; - $coach_username = $_POST['coach_username']; - $id_session_category = $_POST['session_category']; - $id_visibility = $_POST['session_visibility']; - $end_limit = $_POST['end_limit']; - $start_limit = $_POST['start_limit']; - $duration = isset($_POST['duration']) ? $_POST['duration'] : null; - - if (empty($end_limit) && empty($start_limit)) { - $nolimit = 1; + $check = Security::check_token('post'); + Security::clear_token(); + if ($check) { + $formSent = 1; + $name = $_POST['name']; + $year_start = $_POST['year_start']; + $month_start = $_POST['month_start']; + $day_start = $_POST['day_start']; + $year_end = $_POST['year_end']; + $month_end = $_POST['month_end']; + $day_end = $_POST['day_end']; + $nb_days_acess_before = $_POST['nb_days_acess_before']; + $nb_days_acess_after = $_POST['nb_days_acess_after']; + $coach_username = $_POST['coach_username']; + $id_session_category = $_POST['session_category']; + $id_visibility = $_POST['session_visibility']; + $end_limit = $_POST['end_limit']; + $start_limit = $_POST['start_limit']; + $duration = isset($_POST['duration']) ? $_POST['duration'] : null; + + if (empty($end_limit) && empty($start_limit)) { + $nolimit = 1; + } else { + $nolimit = null; + } + + $return = SessionManager::create_session( + $name, + $year_start, + $month_start, + $day_start, + $year_end, + $month_end, + $day_end, + $nb_days_acess_before, + $nb_days_acess_after, + $nolimit, + $coach_username, + $id_session_category, + $id_visibility, + $start_limit, + $end_limit, + $duration + ); + + if ($return == strval(intval($return))) { + // integer => no error on session creation + header('Location: add_courses_to_session.php?id_session=' . $return . '&add=true&msg='); + exit(); + } } else { - $nolimit = null; + header('Location: '.api_get_self()); + exit(); } - - $return = SessionManager::create_session( - $name, - $year_start, - $month_start, - $day_start, - $year_end, - $month_end, - $day_end, - $nb_days_acess_before, - $nb_days_acess_after, - $nolimit, - $coach_username, - $id_session_category, - $id_visibility, - $start_limit, - $end_limit, - $duration - ); - - if ($return == strval(intval($return))) { - // integer => no error on session creation - header('Location: add_courses_to_session.php?id_session='.$return.'&add=true&msg='); - exit(); - } } +$token = Security::get_token(); + + global $_configuration; $defaultBeforeDays = isset($_configuration['session_days_before_coach_access']) ? $_configuration['session_days_before_coach_access'] : 0; @@ -168,16 +178,16 @@ function fill_coach_field (username) { echo '
'; - ?>