session_course_user_list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 = intval($_GET['id_session']);
  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'], array('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'], array('desc', 'asc'))
  33. ? $_GET['direction']
  34. : 'desc';
  35. if (is_array($idChecked)) {
  36. $my_temp = array();
  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. array_map('intval', $idChecked);
  57. $idChecked = implode(',', $idChecked);
  58. }
  59. if (!empty($idChecked)) {
  60. $sql = "DELETE FROM $tbl_session_rel_course_rel_user
  61. WHERE session_id='$id_session' AND c_id='".$courseId."' AND user_id IN($idChecked)";
  62. $result = Database::query($sql);
  63. $nbr_affected_rows = Database::affected_rows($result);
  64. $sql = "UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows
  65. WHERE session_id='$id_session' AND c_id='".$courseId."'";
  66. Database::query($sql);
  67. }
  68. header('Location: '.api_get_self()
  69. .'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  70. exit();
  71. break;
  72. case 'add':
  73. SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
  74. header('Location: '.api_get_self()
  75. .'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  76. exit;
  77. break;
  78. }
  79. $limit = 20;
  80. $from = $page * $limit;
  81. $is_western_name_order = api_is_western_name_order();
  82. $sql = "
  83. SELECT DISTINCT u.user_id,"
  84. .($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname')
  85. .", u.username, scru.user_id as is_subscribed
  86. FROM $tbl_session_rel_user s
  87. INNER JOIN $tbl_user u ON (u.user_id=s.user_id)
  88. LEFT JOIN $tbl_session_rel_course_rel_user scru
  89. ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = $courseId)
  90. WHERE s.session_id = $id_session
  91. ORDER BY $sort $direction
  92. LIMIT $from,".($limit + 1);
  93. if ($direction == 'desc') {
  94. $direction = 'asc';
  95. } else {
  96. $direction = 'desc';
  97. }
  98. $result = Database::query($sql);
  99. $users = Database::store_result($result);
  100. $nbr_results = sizeof($users);
  101. $tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title;
  102. //$interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  103. $interbreadcrumb[] = array("url" => "session_list.php", "name" => get_lang('SessionList'));
  104. $interbreadcrumb[] = array(
  105. 'url' => "resume_session.php?id_session=".$id_session,
  106. "name" => get_lang('SessionOverview')
  107. );
  108. Display::display_header($tool_name);
  109. echo Display::page_header($tool_name);
  110. ?>
  111. <form method="post"
  112. action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>"
  113. onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  114. <div align="right">
  115. <?php
  116. if ($page) {
  117. ?>
  118. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  119. - 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous'); ?></a>
  120. <?php
  121. } else {
  122. echo get_lang('Previous');
  123. }
  124. ?>
  125. |
  126. <?php
  127. if ($nbr_results > $limit) {
  128. ?>
  129. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  130. + 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next'); ?></a>
  131. <?php
  132. } else {
  133. echo get_lang('Next');
  134. }
  135. ?>
  136. </div>
  137. <br/>
  138. <table class="data_table" width="100%">
  139. <tr>
  140. <th>&nbsp;</th>
  141. <?php if ($is_western_name_order) { ?>
  142. <th>
  143. <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); ?>"><?php echo get_lang('FirstName'); ?></a>
  144. </th>
  145. <th>
  146. <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); ?>"><?php echo get_lang('LastName'); ?></a>
  147. </th>
  148. <?php } else { ?>
  149. <th>
  150. <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); ?>"><?php echo get_lang('LastName'); ?></a>
  151. </th>
  152. <th>
  153. <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); ?>"><?php echo get_lang('FirstName'); ?></a>
  154. </th>
  155. <?php } ?>
  156. <th>
  157. <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); ?>"><?php echo get_lang('Login'); ?></a>
  158. </th>
  159. <th><?php echo get_lang('Actions'); ?></th>
  160. </tr>
  161. <?php
  162. $i = 0;
  163. foreach ($users as $key => $enreg) {
  164. if ($key == $limit) {
  165. break;
  166. }
  167. ?>
  168. <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
  169. <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
  170. <?php if ($is_western_name_order) { ?>
  171. <td><?php echo api_htmlentities($enreg['firstname'], ENT_QUOTES, $charset); ?></td>
  172. <td><?php echo api_htmlentities($enreg['lastname'], ENT_QUOTES, $charset); ?></td>
  173. <?php } else { ?>
  174. <td><?php echo api_htmlentities($enreg['lastname'], ENT_QUOTES, $charset); ?></td>
  175. <td><?php echo api_htmlentities($enreg['firstname'], ENT_QUOTES, $charset); ?></td>
  176. <?php } ?>
  177. <td><?php echo api_htmlentities($enreg['username'], ENT_QUOTES, $charset); ?></td>
  178. <td>
  179. <?php if ($enreg['is_subscribed']) { ?>
  180. <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']; ?>"
  181. onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  182. <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
  183. </a>
  184. <?php } else { ?>
  185. <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']; ?>"
  186. onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  187. <?php Display::display_icon('add.png', get_lang('Add'), array(), ICON_SIZE_SMALL); ?>
  188. </a>
  189. <?php } ?>
  190. </td>
  191. </tr>
  192. <?php
  193. $i = $i ? 0 : 1;
  194. }
  195. unset($users);
  196. ?>
  197. </table>
  198. <br/>
  199. <div align="left">
  200. <?php
  201. if ($page) {
  202. ?>
  203. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  204. - 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous'); ?></a>
  205. <?php
  206. } else {
  207. echo get_lang('Previous');
  208. }
  209. ?>
  210. |
  211. <?php
  212. if ($nbr_results > $limit) {
  213. ?>
  214. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page
  215. + 1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next'); ?></a>
  216. <?php
  217. } else {
  218. echo get_lang('Next');
  219. }
  220. ?>
  221. </div>
  222. <br/>
  223. <select name="action">
  224. <option value="delete"><?php echo get_lang('UnsubscribeSelectedUsersFromSession'); ?></option>
  225. <option value="add"><?php echo get_lang('AddUsers'); ?></option>
  226. </select>
  227. <button class="save" type="submit"> <?php echo get_lang('Ok'); ?></button>
  228. </form>
  229. <?php
  230. Display::display_footer();