session_user_edit.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. // including the global Chamilo file
  5. require_once __DIR__.'/../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. ) {
  16. api_not_allowed(true);
  17. }
  18. if (empty($sessionId) || empty($userId)) {
  19. api_not_allowed(true);
  20. }
  21. $interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
  22. $interbreadcrumb[] = array(
  23. 'url' => "resume_session.php?id_session=".$sessionId,
  24. "name" => get_lang('SessionOverview')
  25. );
  26. $form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId);
  27. $form->addHeader(get_lang('EditUserSessionDuration'));
  28. $userInfo = api_get_user_info($userId);
  29. // Show current end date for the session for this user, if any
  30. $userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
  31. $sessionId,
  32. $userId
  33. );
  34. if (count($userAccess) == 0) {
  35. // User never accessed the session. End date is still open
  36. $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
  37. } else {
  38. // The user already accessed the session. Show a clear detail of the days count.
  39. $days = SessionManager::getDayLeftInSession($sessionInfo, $userId);
  40. $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
  41. $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
  42. if ($days > 0) {
  43. $userSubscription = SessionManager::getUserSession($userId, $sessionId);
  44. $duration = $sessionInfo['duration'];
  45. if (!empty($userSubscription['duration'])) {
  46. $duration = $duration + $userSubscription['duration'];
  47. }
  48. $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
  49. } else {
  50. $endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
  51. $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
  52. $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
  53. }
  54. }
  55. $form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name']));
  56. $form->addElement('html', '<br>');
  57. $form->addElement('html', $msg);
  58. $form->addElement('text', 'duration', array(get_lang('ExtraDurationForUser'), null, get_lang('Days')));
  59. $form->addButtonSave(get_lang('Save'));
  60. $form->setDefaults(['duration' => 0]);
  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();