session_user_edit.php 3.5 KB

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