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 '../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. $data = SessionManager::getUserSession($userId, $sessionId);
  29. $userInfo = api_get_user_info($userId);
  30. // Show current end date for the session for this user, if any
  31. $userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
  32. $sessionId,
  33. $userId
  34. );
  35. if (count($userAccess) == 0) {
  36. // User never accessed the session. End date is still open
  37. $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
  38. } else {
  39. // The user already accessed the session. Show a clear detail of the days count.
  40. $duration = $sessionInfo['duration'];
  41. if (!empty($data['duration'])) {
  42. $duration = $duration + $data['duration'];
  43. }
  44. $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
  45. $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
  46. $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
  47. if ($days > 0) {
  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. if (empty($data['duration'])) {
  61. $data['duration'] = 0;
  62. }
  63. $form->setDefaults($data);
  64. $message = null;
  65. if ($form->validate()) {
  66. $duration = $form->getSubmitValue('duration');
  67. // Only update if the duration is different from the default duration
  68. if ($duration != 0) {
  69. SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
  70. $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
  71. } else {
  72. $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning');
  73. }
  74. }
  75. // display the header
  76. Display::display_header(get_lang('Edit'));
  77. echo $message;
  78. $form->display();
  79. Display :: display_footer();