session_course_user_list.php 9.6 KB

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