session_course_user_list.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../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')) ? $_GET['sort'] : $default_sort;
  26. $idChecked = isset($_GET['idChecked']) && is_array($_GET['idChecked']) ? $_GET['idChecked'] : (isset($_POST['idChecked']) && is_array($_POST['idChecked']) ? $_POST['idChecked'] : null);
  27. $direction = isset($_GET['direction']) && in_array($_GET['direction'], array('desc','asc')) ? $_GET['direction'] : 'desc';
  28. if (is_array($idChecked)) {
  29. $my_temp = array();
  30. foreach ($idChecked as $id) {
  31. // forcing the intval
  32. $my_temp[]= intval($id);
  33. }
  34. $idChecked = $my_temp;
  35. }
  36. $sql = "SELECT s.name, c.title
  37. FROM $tbl_session_rel_course src
  38. INNER JOIN $tbl_session s ON s.id = src.session_id
  39. INNER JOIN $tbl_course c ON c.id = src.c_id
  40. WHERE src.session_id='$id_session' AND src.c_id='$courseId' ";
  41. $result = Database::query($sql);
  42. if (!list($session_name,$course_title) = Database::fetch_row($result)) {
  43. header('Location: session_course_list.php?id_session='.$id_session);
  44. exit();
  45. }
  46. switch ($action) {
  47. case 'delete':
  48. if (is_array($idChecked) && count($idChecked)>0) {
  49. array_map('intval', $idChecked);
  50. $idChecked = implode(',', $idChecked);
  51. }
  52. if (!empty($idChecked)) {
  53. $sql = "DELETE FROM $tbl_session_rel_course_rel_user
  54. WHERE session_id='$id_session' AND c_id='".$courseId."' AND user_id IN($idChecked)";
  55. $result = Database::query($sql);
  56. $nbr_affected_rows = Database::affected_rows($result);
  57. $sql = "UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows
  58. WHERE session_id='$id_session' AND c_id='".$courseId."'";
  59. Database::query($sql);
  60. }
  61. header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  62. exit();
  63. break;
  64. case 'add':
  65. SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
  66. header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  67. exit;
  68. break;
  69. }
  70. $limit = 20;
  71. $from = $page * $limit;
  72. $is_western_name_order = api_is_western_name_order();
  73. $sql = "SELECT DISTINCT
  74. u.user_id,".($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname').", u.username, scru.user_id as is_subscribed
  75. FROM $tbl_session_rel_user s
  76. INNER JOIN $tbl_user u ON (u.user_id=s.user_id)
  77. LEFT JOIN $tbl_session_rel_course_rel_user scru
  78. ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = '".$courseId."' )
  79. WHERE s.session_id='$id_session'
  80. ORDER BY $sort $direction
  81. LIMIT $from,".($limit+1);
  82. if ($direction == 'desc') {
  83. $direction = 'asc';
  84. } else {
  85. $direction = 'desc';
  86. }
  87. $result = Database::query($sql);
  88. $users = Database::store_result($result);
  89. $nbr_results = sizeof($users);
  90. $tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title;
  91. //$interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  92. $interbreadcrumb[] = array("url" => "session_list.php","name" => get_lang('SessionList'));
  93. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
  94. Display::display_header($tool_name);
  95. echo Display::page_header($tool_name);
  96. ?>
  97. <form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  98. <div align="right">
  99. <?php
  100. if($page) {
  101. ?>
  102. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous');?></a>
  103. <?php
  104. } else {
  105. echo get_lang('Previous');
  106. }
  107. ?>
  108. |
  109. <?php
  110. if($nbr_results > $limit) {
  111. ?>
  112. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next');?></a>
  113. <?php
  114. } else {
  115. echo get_lang('Next');
  116. }
  117. ?>
  118. </div>
  119. <br />
  120. <table class="data_table" width="100%">
  121. <tr>
  122. <th>&nbsp;</th>
  123. <?php if ($is_western_name_order) { ?>
  124. <th><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></th>
  125. <th><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></th>
  126. <?php } else { ?>
  127. <th><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></th>
  128. <th><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></th>
  129. <?php } ?>
  130. <th><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></th>
  131. <th><?php echo get_lang('Actions');?></th>
  132. </tr>
  133. <?php
  134. $i=0;
  135. foreach ($users as $key => $enreg) {
  136. if ($key == $limit) {
  137. break;
  138. }
  139. ?>
  140. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  141. <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
  142. <?php if ($is_western_name_order) { ?>
  143. <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
  144. <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
  145. <?php } else { ?>
  146. <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
  147. <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
  148. <?php } ?>
  149. <td><?php echo api_htmlentities($enreg['username'],ENT_QUOTES,$charset); ?></td>
  150. <td>
  151. <?php if ($enreg['is_subscribed']) { ?>
  152. <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']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  153. <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
  154. </a>
  155. <?php } else { ?>
  156. <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']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  157. <?php Display::display_icon('add.png', get_lang('Add'), array(), ICON_SIZE_SMALL); ?>
  158. </a>
  159. <?php } ?>
  160. </td>
  161. </tr>
  162. <?php
  163. $i=$i ? 0 : 1;
  164. }
  165. unset($users);
  166. ?>
  167. </table>
  168. <br />
  169. <div align="left">
  170. <?php
  171. if($page) {
  172. ?>
  173. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Previous'); ?></a>
  174. <?php
  175. } else {
  176. echo get_lang('Previous');
  177. }
  178. ?>
  179. |
  180. <?php
  181. if($nbr_results > $limit) {
  182. ?>
  183. <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next'); ?></a>
  184. <?php
  185. } else {
  186. echo get_lang('Next');
  187. }
  188. ?>
  189. </div>
  190. <br />
  191. <select name="action">
  192. <option value="delete"><?php echo get_lang('UnsubscribeSelectedUsersFromSession');?></option>
  193. <option value="add"><?php echo get_lang('AddUsers');?></option>
  194. </select>
  195. <button class="save" type="submit"> <?php echo get_lang('Ok'); ?></button>
  196. </form>
  197. <?php
  198. Display::display_footer();