session_course_user_list.php 10 KB

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