session_course_user_list.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $id_session = intval($_GET['id_session']);
  13. SessionManager::protect_session_edit($id_session);
  14. if (empty($id_session)) {
  15. api_not_allowed(true);
  16. }
  17. $course_info = api_get_course_info($_GET['course_code']);
  18. if (empty($course_info)) {
  19. api_not_allowed(true);
  20. }
  21. $course_code = $course_info['code'];
  22. $courseId = $course_info['real_id'];
  23. $page = isset($_GET['page']) ? intval($_GET['page']) : null;
  24. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  25. $default_sort = api_sort_by_first_name() ? 'firstname':'lastname';
  26. $sort = isset($_GET['sort']) && in_array($_GET['sort'], array('lastname','firstname','username')) ? $_GET['sort'] : $default_sort;
  27. $idChecked = isset($_GET['idChecked']) && (is_array($_GET['idChecked']) ? $_GET['idChecked'] : (is_array($_POST['idChecked']) ? $_POST['idChecked'] : null));
  28. $direction = isset($_GET['direction']) && in_array($_GET['direction'], array('desc','asc')) ? $_GET['direction'] : 'desc';
  29. if (is_array($idChecked)) {
  30. $my_temp = array();
  31. foreach ($idChecked as $id){
  32. $my_temp[]= intval($id);// forcing the intval
  33. }
  34. $idChecked = $my_temp;
  35. }
  36. $session_info = SessionManager::fetch($id_session);
  37. $courses = SessionManager::get_course_list_by_session_id($id_session);
  38. if (!isset($courses[$course_info['real_id']])) {
  39. header('Location: session_course_list.php?id_session='.$id_session);
  40. exit();
  41. }
  42. switch ($action) {
  43. case 'delete':
  44. SessionManager::unsubscribe_user_from_course_session($id_session, $idChecked, $courseId);
  45. header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  46. exit;
  47. break;
  48. case 'add':
  49. SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $courseId);
  50. header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
  51. exit;
  52. break;
  53. }
  54. $limit = 20;
  55. $from = $page * $limit;
  56. $is_western_name_order = api_is_western_name_order();
  57. $Users = SessionManager::get_users_in_course_session($courseId, $id_session, $sort, $direction, $from, $limit);
  58. if ($direction == 'desc') {
  59. $direction = 'asc';
  60. } else {
  61. $direction = 'desc';
  62. }
  63. $nbr_results = sizeof($Users);
  64. $tool_name = get_lang('Session').': '.$session_info['name'].' - '.get_lang('Course').': '.$course_info['title'];
  65. $interbreadcrumb[] = array("url" => "index.php","name" => get_lang('Sessions'));
  66. $interbreadcrumb[] = array("url" => "session_list.php","name" => get_lang('SessionList'));
  67. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
  68. Display::display_header($tool_name);
  69. echo Display::page_header($tool_name);
  70. ?>
  71. <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;">
  72. <div align="right">
  73. <?php
  74. if($page) {
  75. ?>
  76. <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>
  77. <?php
  78. } else {
  79. echo get_lang('Previous');
  80. }
  81. ?>
  82. |
  83. <?php
  84. if ($nbr_results > $limit) {
  85. ?>
  86. <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>
  87. <?php
  88. } else {
  89. echo get_lang('Next');
  90. }
  91. ?>
  92. </div>
  93. <br />
  94. <table class="data_table" width="100%">
  95. <tr>
  96. <th>&nbsp;</th>
  97. <?php if ($is_western_name_order) { ?>
  98. <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>
  99. <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>
  100. <?php } else { ?>
  101. <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>
  102. <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>
  103. <?php } ?>
  104. <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>
  105. <th><?php echo get_lang('Actions');?></th>
  106. </tr>
  107. <?php
  108. $i=0;
  109. if (!empty($Users)) {
  110. foreach ($Users as $key=>$enreg) {
  111. if ($key == $limit) {
  112. break;
  113. }
  114. ?>
  115. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  116. <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
  117. <?php if ($is_western_name_order) { ?>
  118. <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
  119. <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
  120. <?php } else { ?>
  121. <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
  122. <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
  123. <?php } ?>
  124. <td><?php echo api_htmlentities($enreg['username'],ENT_QUOTES,$charset); ?></td>
  125. <td>
  126. <?php if ($enreg['is_subscribed']) { ?>
  127. <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;">
  128. <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
  129. </a>
  130. <?php } else { ?>
  131. <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;">
  132. <?php Display::display_icon('add.png', get_lang('Add'), array(), ICON_SIZE_SMALL); ?>
  133. </a>
  134. <?php } ?>
  135. </td>
  136. </tr>
  137. <?php
  138. $i=$i ? 0 : 1;
  139. }
  140. }
  141. unset($Users);
  142. ?>
  143. </table>
  144. <br />
  145. <div align="left">
  146. <?php
  147. if($page) {
  148. ?>
  149. <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>
  150. <?php
  151. } else {
  152. echo get_lang('Previous');
  153. }
  154. ?>
  155. |
  156. <?php
  157. if($nbr_results > $limit) {
  158. ?>
  159. <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>
  160. <?php
  161. } else {
  162. echo get_lang('Next');
  163. }
  164. ?>
  165. </div>
  166. <br />
  167. <select name="action">
  168. <option value="delete"><?php echo get_lang('UnsubscribeSelectedUsersFromSession');?></option>
  169. <option value="add"><?php echo get_lang('AddUsers');?></option>
  170. </select>
  171. <button class="save" type="submit"> <?php echo get_lang('Ok'); ?></button>
  172. </form>
  173. <?php
  174. Display::display_footer();