|
@@ -38,15 +38,54 @@ $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$sessionId,
|
|
|
$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);
|
|
|
|
|
|
-$form->addElement('text', 'duration', array(get_lang('Duration'), null, get_lang('Days')));
|
|
|
+// 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');
|
|
|
+ $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
|
|
|
+ if ($days > 0) {
|
|
|
+ $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
|
|
|
+ } else {
|
|
|
+ $endDateInSeconds = $firstAccess + $duration*24*60*60;
|
|
|
+ $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
|
|
|
+ $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
|
|
|
+ }
|
|
|
+}
|
|
|
+$form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name']));
|
|
|
+$form->addElement('html', '<br>');
|
|
|
+$form->addElement('html', $msg);
|
|
|
+
|
|
|
+$form->addElement('text', 'duration', array(get_lang('ExtraDurationForUser'), null, get_lang('Days')));
|
|
|
$form->addElement('button', 'submit', get_lang('Send'));
|
|
|
+
|
|
|
+if (empty($data['duration'])) {
|
|
|
+ $data['duration'] = 0;
|
|
|
+}
|
|
|
$form->setDefaults($data);
|
|
|
$message = null;
|
|
|
if ($form->validate()) {
|
|
|
$duration = $form->getSubmitValue('duration');
|
|
|
- SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
|
|
|
- $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
|
|
|
+ // Only update if the duration is different from the default duration
|
|
|
+ if ($duration != 0) {
|
|
|
+ SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
|
|
|
+ $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
|
|
|
+ } else {
|
|
|
+ $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// display the header
|