if (isset($_POST['form_sent']) && $_POST['form_sent']) {
    $form_sent = $_POST['form_sent'];
    $elements_posted = $_POST['elements_in_name'];
    if (!is_array($elements_posted)) {
        $elements_posted = array();
    }
    if ($form_sent == 1) {
        $usergroup->subscribe_courses_to_usergroup($id, $elements_posted);
        header('Location: usergroups.php');
        exit;
    }
}
// Filters
$filters = array(array('type' => 'text', 'name' => 'code', 'label' => get_lang('CourseCode')), array('type' => 'text', 'name' => 'title', 'label' => get_lang('Title')));
$searchForm = new FormValidator('search', 'get', api_get_self() . '?id=' . $id);
$searchForm->add_header(get_lang('AdvancedSearch'));
$renderer =& $searchForm->defaultRenderer();
$searchForm->addElement('hidden', 'id', $id);
foreach ($filters as $param) {
    $searchForm->addElement($param['type'], $param['name'], $param['label']);
}
$searchForm->addElement('button', 'submit', get_lang('Search'));
$filterData = array();
if ($searchForm->validate()) {
    $filterData = $searchForm->getSubmitValues();
}
$conditions = array();
if (!empty($filters) && !empty($filterData)) {
    foreach ($filters as $filter) {
        if (isset($filter['name']) && isset($filterData[$filter['name']])) {
            $value = $filterData[$filter['name']];
    api_not_allowed(true);
}
if (!isset($sessionInfo['duration']) || isset($sessionInfo['duration']) && empty($sessionInfo['duration'])) {
    api_not_allowed(true);
}
if (!SessionManager::durationPerUserIsEnabled()) {
    api_not_allowed(true);
}
if (empty($sessionId) || empty($userId)) {
    api_not_allowed(true);
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$interbreadcrumb[] = array('url' => "resume_session.php?id_session=" . $sessionId, "name" => get_lang('SessionOverview'));
$form = new FormValidator('edit', 'post', api_get_self() . '?session_id=' . $sessionId . '&user_id=' . $userId);
$form->add_header(get_lang('EditUserSessionDuration'));
$data = SessionManager::getUserSession($userId, $sessionId);
$userInfo = api_get_user_info($userId);
// Show current end date for the session for this user, if any
$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($sessionId, $userId);
if (count($userAccess) == 0) {
    // User never accessed the session. End date is still open
    $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
} else {
    // The user already accessed the session. Show a clear detail of the days count.
    $duration = $sessionInfo['duration'];
    if (!empty($data['duration'])) {
        $duration = $duration + $data['duration'];
    }
    $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
    $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
            }
        }
    }
}
if (isset($errors) && count($errors) != 0) {
    $error_message = '<ul>';
    foreach ($errors as $index => $error_course) {
        $error_message .= '<li>' . get_lang('Line') . ' ' . $error_course['line'] . ': <strong>' . $error_course['error'] . '</strong>: ';
        $error_message .= get_lang('Course') . ': ' . $error_course['Title'] . ' (' . $error_course['Code'] . ')';
        $error_message .= '</li>';
    }
    $error_message .= '</ul>';
    Display::display_error_message($error_message, false);
}
$form = new FormValidator('import', 'post', api_get_self(), null, array('enctype' => 'multipart/form-data'));
$form->add_header($tool_name);
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
$form->addElement('checkbox', 'add_me_as_teacher', null, get_lang('AddMeAsTeacherInCourses'));
$form->addElement('button', 'save', get_lang('Import'));
$form->addElement('hidden', 'formSent', 1);
//$form->setDefaults(array('add_me_as_teacher' => 0));
$form->display();
?>
<div style="clear: both;"></div>
<p><?php 
echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')';
?>
 :</p>

<blockquote>
<pre>