1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | /** |
||
6 | * @author Bart Mollet, Julio Montoya lot of fixes |
||
7 | */ |
||
8 | |||
9 | use Chamilo\CoreBundle\Component\Utils\NameConvention; |
||
10 | use Chamilo\CoreBundle\Entity\Session; |
||
11 | use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; |
||
12 | use Chamilo\CoreBundle\Framework\Container; |
||
13 | |||
14 | $cidReset = true; |
||
15 | require_once __DIR__.'/../inc/global.inc.php'; |
||
16 | |||
17 | // setting the section (for the tabs) |
||
18 | $this_section = SECTION_PLATFORM_ADMIN; |
||
19 | $id_session = (int) $_GET['id_session']; |
||
20 | SessionManager::protect_teacher_session_edit($id_session); |
||
21 | $url = null; |
||
22 | $tool_name = get_lang('Session overview'); |
||
23 | |||
24 | $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session'); |
||
25 | if ('true' === $allowTutors) { |
||
26 | // Database Table Definitions |
||
27 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
28 | $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS); |
||
29 | $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
||
30 | $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); |
||
31 | $tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||
32 | $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
||
33 | $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
||
34 | $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); |
||
35 | $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
36 | |||
37 | $nameConvention = Container::$container->get(NameConvention::class); |
||
38 | |||
39 | $session = api_get_session_entity($id_session); |
||
40 | |||
41 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
||
42 | |||
43 | $url_id = api_get_current_access_url_id(); |
||
44 | |||
45 | switch ($action) { |
||
46 | case 'add_user_to_url': |
||
47 | $user_id = $_REQUEST['user_id']; |
||
48 | $result = UrlManager::add_user_to_url($user_id, $url_id); |
||
49 | $user_info = api_get_user_info($user_id); |
||
50 | if ($result) { |
||
51 | Display::addFlash( |
||
52 | Display::return_message( |
||
53 | get_lang('The user has been added').' '.api_get_person_name( |
||
54 | $user_info['firstname'], |
||
55 | $user_info['lastname'] |
||
56 | ), |
||
57 | 'confirm' |
||
58 | ) |
||
59 | ); |
||
60 | } |
||
61 | break; |
||
62 | case 'delete': |
||
63 | $idChecked = $_GET['idChecked']; |
||
64 | if (is_array($idChecked)) { |
||
65 | $my_temp = []; |
||
66 | foreach ($idChecked as $id) { |
||
67 | $courseInfo = api_get_course_info($id); |
||
68 | $my_temp[] = $courseInfo['real_id']; // forcing the escape_string |
||
69 | } |
||
70 | $idChecked = $my_temp; |
||
71 | $idChecked = "'".implode("','", $idChecked)."'"; |
||
72 | |||
73 | $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)"); |
||
74 | $nbr_affected_rows = Database::affected_rows($result); |
||
75 | |||
76 | Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)"); |
||
77 | Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'"); |
||
78 | } |
||
79 | |||
80 | if (!empty($_GET['class'])) { |
||
81 | $result = Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".intval($_GET['class'])); |
||
82 | $nbr_affected_rows = Database::affected_rows($result); |
||
83 | Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'"); |
||
84 | } |
||
85 | |||
86 | if (!empty($_GET['user'])) { |
||
87 | $result = Database::query("DELETE FROM $tbl_session_rel_user WHERE relation_type = ".Session::STUDENT." AND session_id ='$id_session' AND user_id=".intval($_GET['user'])); |
||
88 | $nbr_affected_rows = Database::affected_rows($result); |
||
89 | Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'"); |
||
90 | |||
91 | $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id ='$id_session' AND user_id=".intval($_GET['user'])); |
||
92 | $nbr_affected_rows = Database::affected_rows($result); |
||
93 | |||
94 | Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE session_id ='$id_session'"); |
||
95 | } |
||
96 | break; |
||
97 | } |
||
98 | Display::display_header($tool_name); |
||
99 | |||
100 | echo Display::page_header( |
||
101 | Display::return_icon( |
||
102 | 'session.png', |
||
103 | get_lang('Session') |
||
104 | ).' '.$session->getName() |
||
105 | ); |
||
106 | echo Display::page_subheader(get_lang('General properties').$url); ?> |
||
107 | <!-- General properties --> |
||
108 | <table class="table table-hover table-striped data_table"> |
||
109 | <tr> |
||
110 | <td><?php echo get_lang('General coaches'); ?> :</td> |
||
111 | <td> |
||
112 | <?php |
||
113 | foreach ($session->getGeneralCoaches() as $generalCoach) { |
||
114 | echo $nameConvention->getPersonName($generalCoach).'<br>'; |
||
115 | } |
||
116 | ?> |
||
117 | </td> |
||
118 | </tr> |
||
119 | <?php if ($session->getCategory()) { ?> |
||
120 | <tr> |
||
121 | <td><?php echo get_lang('Sessions categories'); ?></td> |
||
122 | <td><?php echo $session->getCategory()->getName(); ?></td> |
||
123 | </tr> |
||
124 | <?php } ?> |
||
125 | |||
126 | <?php if ($session->getDuration()) { ?> |
||
127 | <tr> |
||
128 | <td><?php echo get_lang('Duration'); ?></td> |
||
129 | <td><?php echo $session->getDuration().' '.get_lang('Days'); ?></td> |
||
130 | </tr> |
||
131 | <?php } else { ?> |
||
132 | <?php $sessionDates = SessionManager::parseSessionDates($session, true); ?> |
||
133 | <tr> |
||
134 | <td><?php echo get_lang('Access dates for students'); ?></td> |
||
135 | <td><?php echo $sessionDates['access'] ?></td> |
||
136 | </tr> |
||
137 | <tr> |
||
138 | <td><?php echo get_lang('Access dates for coaches'); ?></td> |
||
139 | <td><?php echo $sessionDates['coach'] ?></td> |
||
140 | </tr> |
||
141 | <?php } ?> |
||
142 | <tr> |
||
143 | <td> |
||
144 | <?php echo api_ucfirst(get_lang('Visibility after end date')); ?> : |
||
145 | </td> |
||
146 | <td> |
||
147 | <?php echo SessionManager::getSessionVisibility($session); ?> |
||
148 | </td> |
||
149 | </tr> |
||
150 | <?php |
||
151 | |||
152 | $multiple_url_is_on = api_get_multiple_access_url(); |
||
153 | if ($multiple_url_is_on) { |
||
154 | echo '<tr><td>'; |
||
155 | echo 'URL'; |
||
156 | echo '</td>'; |
||
157 | echo '<td>'; |
||
158 | $url_list = UrlManager::get_access_url_from_session($id_session); |
||
159 | foreach ($url_list as $url_data) { |
||
160 | echo $url_data['url'].'<br />'; |
||
161 | } |
||
162 | echo '</td></tr>'; |
||
163 | } ?> |
||
164 | </table> |
||
165 | <br /> |
||
166 | <?php |
||
167 | echo Display::page_subheader(get_lang('Course list').$url); ?> |
||
168 | <!--List of courses --> |
||
169 | <table class="table table-hover table-striped data_table"> |
||
170 | <tr> |
||
171 | <th width="35%"><?php echo get_lang('Course title'); ?></th> |
||
172 | <th width="30%"><?php echo get_lang('Course coach'); ?></th> |
||
173 | <th width="20%"><?php echo get_lang('Users number'); ?></th> |
||
174 | </tr> |
||
175 | <?php |
||
176 | if (0 == $session->getNbrCourses()) { |
||
177 | echo '<tr> |
||
178 | <td colspan="3">'.get_lang('No course for this session').'</td> |
||
179 | </tr>'; |
||
180 | } else { |
||
181 | // select the courses |
||
182 | foreach ($session->getCourses() as $sessionRelCourse) { |
||
183 | $course = $sessionRelCourse->getCourse(); |
||
184 | |||
185 | $coachSubscriptionList = $session->getSessionRelCourseRelUsersByStatus($course, Session::COURSE_COACH) |
||
186 | ->map( |
||
187 | fn(SessionRelCourseRelUser $sessionCourseUser) => $nameConvention->getPersonName($sessionCourseUser->getUser()) |
||
188 | ); |
||
189 | |||
190 | $courseLink = Display::url( |
||
191 | $course->getTitle().' ('.$course->getVisualCode().')', |
||
192 | api_get_course_url($course->getId(), $session->getId()) |
||
193 | ); |
||
194 | $coaches = $coachSubscriptionList ? implode('<br>', $coachSubscriptionList->getValues()) : get_lang('None'); |
||
195 | $nbrUsers = $sessionRelCourse->getNbrUsers(); |
||
196 | |||
197 | echo ' |
||
198 | <tr> |
||
199 | <td>'.$courseLink.'</td> |
||
200 | <td>'.$coaches.'</td> |
||
201 | <td>'.$nbrUsers.'</td> |
||
202 | </tr>'; |
||
203 | } |
||
204 | } ?> |
||
205 | </table> |
||
206 | <br /> |
||
207 | <?php |
||
208 | echo Display::page_subheader(get_lang('User list').$url); ?> |
||
209 | <!--List of users --> |
||
210 | <table class="table table-hover table-striped data_table"> |
||
211 | <tr> |
||
212 | <th> |
||
213 | <?php echo get_lang('User'); ?> |
||
214 | </th> |
||
215 | <th> |
||
216 | <?php echo get_lang('Detail'); ?> |
||
217 | </th> |
||
218 | </tr> |
||
219 | <?php |
||
220 | |||
221 | if (0 == $session->getNbrUsers()) { |
||
222 | echo '<tr> |
||
223 | <td colspan="2">'.get_lang('No Users for this session').'</td> |
||
224 | </tr>'; |
||
225 | } else { |
||
226 | $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname'; |
||
227 | |||
228 | if ($multiple_url_is_on) { |
||
229 | $sql = "SELECT u.id as user_id, lastname, firstname, username, access_url_id |
||
230 | FROM $tbl_user u |
||
231 | INNER JOIN $tbl_session_rel_user su |
||
232 | ON u.id = su.user_id AND su.relation_type = ".Session::STUDENT." |
||
233 | LEFT OUTER JOIN $table_access_url_user uu ON (uu.user_id = u.id) |
||
234 | WHERE su.session_id = $id_session AND (access_url_id = $url_id OR access_url_id is null ) |
||
235 | $order_clause"; |
||
236 | } else { |
||
237 | $sql = "SELECT u.id as user_id, lastname, firstname, username |
||
238 | FROM $tbl_user u |
||
239 | INNER JOIN $tbl_session_rel_user su |
||
240 | ON u.id = su.user_id AND su.relation_type = ".Session::STUDENT." |
||
241 | AND su.session_id = ".$id_session.$order_clause; |
||
242 | } |
||
243 | |||
244 | $result = Database::query($sql); |
||
245 | $users = Database::store_result($result); |
||
246 | // change breadcrumb in destination page |
||
247 | $orig_param = '&origin=resume_session&id_session='.$id_session; |
||
248 | foreach ($users as $user) { |
||
249 | $user_link = ''; |
||
250 | if (!empty($user['user_id'])) { |
||
251 | $user_link = '<a |
||
252 | href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'. |
||
253 | api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']), ENT_QUOTES, $charset).' ('.$user['username'].')</a>'; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
254 | } |
||
255 | |||
256 | $link_to_add_user_in_url = ''; |
||
257 | |||
258 | if ($multiple_url_is_on) { |
||
259 | if ($user['access_url_id'] != $url_id) { |
||
260 | $user_link .= ' '.Display::return_icon('warning.png', get_lang('Users not added to the URL'), [], ICON_SIZE_SMALL); |
||
261 | $add = Display::return_icon('add.png', get_lang('Add users to an URL'), [], ICON_SIZE_SMALL); |
||
262 | $link_to_add_user_in_url = '<a href="resume_session.php?action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>'; |
||
263 | } |
||
264 | } |
||
265 | |||
266 | echo '<tr> |
||
267 | <td width="90%"> |
||
268 | '.$user_link.' |
||
269 | </td> |
||
270 | <td> |
||
271 | <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'. |
||
272 | Display::return_icon('statistics.gif', get_lang('Reporting')).'</a> |
||
273 | <a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'. |
||
274 | Display::return_icon('course.png', get_lang('Block user from courses in this session')).'</a> |
||
275 | <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('Please confirm your choice').'\')) return false;">'. |
||
276 | Display::return_icon('delete.png', get_lang('Delete')).'</a> |
||
277 | '.$link_to_add_user_in_url.' |
||
278 | </td> |
||
279 | </tr>'; |
||
280 | } |
||
281 | } ?> |
||
282 | </table> |
||
283 | <?php |
||
284 | } else { |
||
285 | api_not_allowed(); |
||
286 | } |
||
287 | // footer |
||
288 | Display::display_footer(); |
||
289 |