session_course_user_list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  9. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  10. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  11. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  12. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  13. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  14. $id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  15. SessionManager::protectSession($id_session);
  16. if (empty($id_session)) {
  17. api_not_allowed();
  18. }
  19. $course_code = Database::escape_string(trim($_GET['course_code']));
  20. $courseInfo = api_get_course_info($course_code);
  21. $courseId = $courseInfo['real_id'];
  22. $page = isset($_GET['page']) ? intval($_GET['page']) : null;
  23. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  24. $default_sort = api_sort_by_first_name() ? 'firstname' : 'lastname';
  25. $sort = isset($_GET['sort']) && in_array($_GET['sort'], ['lastname', 'firstname', 'username'])
  26. ? $_GET['sort']
  27. : $default_sort;
  28. $idChecked = isset($_GET['idChecked']) && is_array($_GET['idChecked'])
  29. ? $_GET['idChecked']
  30. : (isset($_POST['idChecked'])
  31. && is_array($_POST['idChecked']) ? $_POST['idChecked'] : null);
  32. $direction = isset($_GET['direction']) && in_array($_GET['direction'], ['desc', 'asc'])
  33. ? $_GET['direction']
  34. : 'desc';
  35. if (is_array($idChecked)) {
  36. $my_temp = [];
  37. foreach ($idChecked as $id) {
  38. // forcing the intval
  39. $my_temp[] = intval($id);
  40. }
  41. $idChecked = $my_temp;
  42. }
  43. $sql = "SELECT s.name, c.title
  44. FROM $tbl_session_rel_course src
  45. INNER JOIN $tbl_session s ON s.id = src.session_id
  46. INNER JOIN $tbl_course c ON c.id = src.c_id
  47. WHERE src.session_id='$id_session' AND src.c_id='$courseId' ";
  48. $result = Database::query($sql);
  49. if (!list($session_name, $course_title) = Database::fetch_row($result)) {
  50. header('Location: session_course_list.php?id_session='.$id_session);
  51. exit();
  52. }
  53. switch ($action) {
  54. case 'delete':
  55. if (is_array($idChecked) && count($idChecked) > 0) {
  56. foreach ($idChecked as $userId) {
  57. SessionManager::unSubscribeUserFromCourseSession($userId, $courseId, $id_session);
  58. }
  59. } else {
  60. SessionManager::unSubscribeUserFromCourseSession($idChecked, $courseId, $id_session);
  61. }
  62. header('Location: '.api_get_self()
  63. .'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  64. exit();
  65. break;
  66. case 'add':
  67. SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
  68. header('Location: '.api_get_self()
  69. .'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  70. exit;
  71. break;
  72. }
  73. $limit = 20;
  74. $from = $page * $limit;
  75. $is_western_name_order = api_is_western_name_order();
  76. $sql = "
  77. SELECT DISTINCT u.user_id,"
  78. .($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname')
  79. .", u.username, scru.user_id as is_subscribed
  80. FROM $tbl_session_rel_user s
  81. INNER JOIN $tbl_user u ON (u.user_id=s.user_id)
  82. LEFT JOIN $tbl_session_rel_course_rel_user scru
  83. ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = $courseId)
  84. WHERE s.session_id = $id_session
  85. ORDER BY $sort $direction
  86. LIMIT $from,".($limit + 1);
  87. if ($direction == 'desc') {
  88. $direction = 'asc';
  89. } else {
  90. $direction = 'desc';
  91. }
  92. $result = Database::query($sql);
  93. $users = Database::store_result($result);
  94. $nbr_results = sizeof($users);
  95. $tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title;
  96. $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('Session list')];
  97. $interbreadcrumb[] = [
  98. 'url' => "resume_session.php?id_session=".$id_session,
  99. 'name' => get_lang('Session overview'),
  100. ];
  101. Display::display_header($tool_name);
  102. echo Display::page_header($tool_name);
  103. ?>
  104. <form method="post"
  105. action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>"
  106. onsubmit="javascript:if(!confirm('<?php echo get_lang('Please confirm your choice'); ?>')) return false;">
  107. <div align="right">
  108. <?php
  109. if ($page) {
  110. ?>
  111. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  112. - 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous'); ?></a>
  113. <?php
  114. } else {
  115. echo get_lang('Previous');
  116. }
  117. ?>
  118. |
  119. <?php
  120. if ($nbr_results > $limit) {
  121. ?>
  122. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  123. + 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next'); ?></a>
  124. <?php
  125. } else {
  126. echo get_lang('Next');
  127. }
  128. ?>
  129. </div>
  130. <br/>
  131. <table class="data_table" width="100%">
  132. <tr>
  133. <th>&nbsp;</th>
  134. <?php if ($is_western_name_order) {
  135. ?>
  136. <th>
  137. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=firstname&direction=<?php echo urlencode($direction); ?>">
  138. <?php echo get_lang('First name'); ?></a>
  139. </th>
  140. <th>
  141. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=lastname&direction=<?php echo urlencode($direction); ?>">
  142. <?php echo get_lang('Last name'); ?></a>
  143. </th>
  144. <?php
  145. } else {
  146. ?>
  147. <th>
  148. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=lastname&direction=<?php echo urlencode($direction); ?>">
  149. <?php echo get_lang('Last name'); ?></a>
  150. </th>
  151. <th>
  152. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=firstname&direction=<?php echo urlencode($direction); ?>">
  153. <?php echo get_lang('First name'); ?></a>
  154. </th>
  155. <?php
  156. } ?>
  157. <th>
  158. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=username&direction=<?php echo urlencode($direction); ?>">
  159. <?php echo get_lang('Login'); ?></a>
  160. </th>
  161. <th><?php echo get_lang('Detail'); ?></th>
  162. </tr>
  163. <?php
  164. $i = 0;
  165. foreach ($users as $key => $enreg) {
  166. if ($key == $limit) {
  167. break;
  168. } ?>
  169. <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
  170. <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
  171. <?php if ($is_western_name_order) {
  172. ?>
  173. <td><?php echo api_htmlentities($enreg['firstname'], ENT_QUOTES, $charset); ?></td>
  174. <td><?php echo api_htmlentities($enreg['lastname'], ENT_QUOTES, $charset); ?></td>
  175. <?php
  176. } else {
  177. ?>
  178. <td><?php echo api_htmlentities($enreg['lastname'], ENT_QUOTES, $charset); ?></td>
  179. <td><?php echo api_htmlentities($enreg['firstname'], ENT_QUOTES, $charset); ?></td>
  180. <?php
  181. } ?>
  182. <td><?php echo api_htmlentities($enreg['username'], ENT_QUOTES, $charset); ?></td>
  183. <td>
  184. <?php if ($enreg['is_subscribed']) {
  185. ?>
  186. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=delete&idChecked[]=<?php echo $enreg['user_id']; ?>"
  187. onclick="javascript:if(!confirm('<?php echo get_lang('Please confirm your choice'); ?>')) return false;">
  188. <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
  189. </a>
  190. <?php
  191. } else {
  192. ?>
  193. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=add&idChecked[]=<?php echo $enreg['user_id']; ?>"
  194. onclick="javascript:if(!confirm('<?php echo get_lang('Please confirm your choice'); ?>')) return false;">
  195. <?php Display::display_icon('add.png', get_lang('Add'), [], ICON_SIZE_SMALL); ?>
  196. </a>
  197. <?php
  198. } ?>
  199. </td>
  200. </tr>
  201. <?php
  202. $i = $i ? 0 : 1;
  203. }
  204. unset($users);
  205. ?>
  206. </table>
  207. <br/>
  208. <div align="left">
  209. <?php
  210. if ($page) {
  211. ?>
  212. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  213. - 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous'); ?></a>
  214. <?php
  215. } else {
  216. echo get_lang('Previous');
  217. }
  218. ?>
  219. |
  220. <?php
  221. if ($nbr_results > $limit) {
  222. ?>
  223. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  224. + 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next'); ?></a>
  225. <?php
  226. } else {
  227. echo get_lang('Next');
  228. }
  229. ?>
  230. </div>
  231. <br/>
  232. <select name="action">
  233. <option value="delete"><?php echo get_lang('Unsubscribe selected users from session'); ?></option>
  234. <option value="add"><?php echo get_lang('Add a user'); ?></option>
  235. </select>
  236. <button class="save" type="submit"> <?php echo get_lang('Validate'); ?></button>
  237. </form>
  238. <?php
  239. Display::display_footer();