session_user_edit.php 3.6 KB

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