|
43 | 43 | $userId |
44 | 44 | ); |
45 | 45 |
|
| 46 | +$extension = 0; |
| 47 | + |
46 | 48 | if (count($userAccess) == 0) { |
47 | 49 | // User never accessed the session. End date is still open |
48 | 50 | $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']); |
49 | 51 | } else { |
50 | 52 | // The user already accessed the session. Show a clear detail of the days count. |
| 53 | + $duration = $sessionInfo['duration']; |
51 | 54 | $days = SessionManager::getDayLeftInSession($sessionInfo, $userId); |
| 55 | + $userSubscription = SessionManager::getUserSession($userId, $sessionId); |
| 56 | + $extension = $userSubscription['duration']; |
52 | 57 | $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC'); |
53 | 58 | $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC'); |
54 | 59 | if ($days > 0) { |
|
61 | 66 |
|
62 | 67 | $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days); |
63 | 68 | } else { |
| 69 | + if (!empty($subscription['duration'])) { |
| 70 | + $duration = $duration + $subscription['duration']; |
| 71 | + } |
64 | 72 | $endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60; |
65 | 73 | $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT); |
66 | 74 | $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last); |
67 | 75 | } |
68 | 76 | } |
69 | | -$form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name'])); |
70 | | -$form->addElement('html', '<br>'); |
71 | | -$form->addElement('html', $msg); |
72 | 77 |
|
73 | | -$form->addElement('text', 'duration', [get_lang('ExtraDurationForUser'), null, get_lang('Days')]); |
| 78 | +$header = '<div class="row">'; |
| 79 | +$header .= '<div class="col-sm-5">'; |
| 80 | +$header .= '<div class="thumbnail">'; |
| 81 | +$header .= Display::img($userInfo['avatar'], $userInfo['complete_name']); |
| 82 | +$header .= '</div>'; |
| 83 | +$header .= '</div>'; |
| 84 | + |
| 85 | +$header .= '<div class="col-sm-7">'; |
| 86 | + |
| 87 | +$userData = $userInfo['complete_name'] |
| 88 | + .PHP_EOL |
| 89 | + .$user_info['mail'] |
| 90 | + .PHP_EOL |
| 91 | + .$user_info['official_code']; |
| 92 | + |
| 93 | +$header .= '<h3>Usuario: ' . Display::url( |
| 94 | + $userData, |
| 95 | + api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_info['user_id'] |
| 96 | +) .'</h3>'; |
| 97 | + |
| 98 | +$header .= '<p><h3>Sesión: ' . $sessionInfo['name'] . '<h3></p>'; |
| 99 | + |
| 100 | +$header .= '</div>'; |
| 101 | +$header .='</div>'; |
| 102 | + |
| 103 | +$header .= '<div class="row">'; |
| 104 | +$header .= '<div class="col-sm-12">'; |
| 105 | + |
| 106 | +$header .= $msg; |
| 107 | +$header .= '<p>'.'</p>'; |
| 108 | + |
| 109 | +$header .= '</div>'; |
| 110 | +$header .= '</div>'; |
| 111 | + |
| 112 | +$form->addElement('html', $header); |
| 113 | + |
| 114 | +$formData = '<div class="row">'; |
| 115 | +$formData .= '<div class="col-sm-12">'; |
| 116 | + |
| 117 | +$form->addElement('html', $formData); |
| 118 | +$form->addElement('number', 'duration', [get_lang('ExtraDurationForUser'), null, get_lang('Days')]); |
74 | 119 | $form->addButtonSave(get_lang('Save')); |
75 | 120 |
|
76 | | -$form->setDefaults(['duration' => 0]); |
| 121 | +$formData = '</div>'; |
| 122 | +$formData .= '</div>'; |
| 123 | + |
| 124 | +$form->addElement('html', $formData); |
| 125 | + |
| 126 | +$form->setDefaults(['duration' => $extension]); |
77 | 127 | $message = null; |
78 | 128 | if ($form->validate()) { |
79 | 129 | $duration = $form->getSubmitValue('duration'); |
80 | | - // Only update if the duration is different from the default duration |
81 | | - if ($duration != 0) { |
82 | | - SessionManager::editUserSessionDuration($duration, $userId, $sessionId); |
83 | | - $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation'); |
84 | | - } else { |
85 | | - $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning'); |
86 | | - } |
| 130 | + |
| 131 | + SessionManager::editUserSessionDuration($duration, $userId, $sessionId); |
| 132 | + $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation'); |
| 133 | + |
| 134 | + $url = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; |
| 135 | + header("Location: " . $url); |
| 136 | + exit(); |
87 | 137 | } |
88 | 138 |
|
89 | 139 | // display the header |
|
0 commit comments