session_user_edit.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. // including the global Chamilo file
  5. require_once '../inc/global.inc.php';
  6. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
  7. $userId = isset($_GET['user_id']) ? $_GET['user_id'] : null;
  8. SessionManager::protectSession($sessionId);
  9. $sessionInfo = api_get_session_info($sessionId);
  10. if (empty($sessionInfo)) {
  11. api_not_allowed(true);
  12. }
  13. if (!isset($sessionInfo['duration']) ||
  14. isset($sessionInfo['duration']) && empty($sessionInfo['duration'])) {
  15. api_not_allowed(true);
  16. }
  17. if (empty($sessionId) || empty($userId)) {
  18. api_not_allowed(true);
  19. }
  20. //$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  21. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  22. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$sessionId, "name" => get_lang('SessionOverview'));
  23. $form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId);
  24. $form->addHeader(get_lang('EditUserSessionDuration'));
  25. $data = SessionManager::getUserSession($userId, $sessionId);
  26. $userInfo = api_get_user_info($userId);
  27. // Show current end date for the session for this user, if any
  28. $userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
  29. $sessionId,
  30. $userId
  31. );
  32. if (count($userAccess) == 0) {
  33. // User never accessed the session. End date is still open
  34. $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
  35. } else {
  36. // The user already accessed the session. Show a clear detail of the days count.
  37. $duration = $sessionInfo['duration'];
  38. if (!empty($data['duration'])) {
  39. $duration = $duration + $data['duration'];
  40. }
  41. $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
  42. $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
  43. $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
  44. if ($days > 0) {
  45. $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
  46. } else {
  47. $endDateInSeconds = $firstAccess + $duration*24*60*60;
  48. $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
  49. $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
  50. }
  51. }
  52. $form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name']));
  53. $form->addElement('html', '<br>');
  54. $form->addElement('html', $msg);
  55. $form->addElement('text', 'duration', array(get_lang('ExtraDurationForUser'), null, get_lang('Days')));
  56. $form->addButtonSave(get_lang('Save'));
  57. if (empty($data['duration'])) {
  58. $data['duration'] = 0;
  59. }
  60. $form->setDefaults($data);
  61. $message = null;
  62. if ($form->validate()) {
  63. $duration = $form->getSubmitValue('duration');
  64. // Only update if the duration is different from the default duration
  65. if ($duration != 0) {
  66. SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
  67. $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
  68. } else {
  69. $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning');
  70. }
  71. }
  72. // display the header
  73. Display::display_header(get_lang('Edit'));
  74. echo $message;
  75. $form->display();
  76. Display :: display_footer();