session_course_list.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // setting the section (for the tabs)
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. $id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  11. SessionManager::protectSession($id_session);
  12. // Database Table Definitions
  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_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  17. if (empty($id_session)) {
  18. api_not_allowed();
  19. }
  20. $page = isset($_GET['page']) ? intval($_GET['page']) : 0;
  21. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  22. $sort = isset($_GET['sort']) && in_array($_GET['sort'], ['title', 'nbr_users']) ? $_GET['sort'] : 'title';
  23. $result = Database::query("SELECT name FROM $tbl_session WHERE id='$id_session'");
  24. if (!list($session_name) = Database::fetch_row($result)) {
  25. header('Location: session_list.php');
  26. exit;
  27. }
  28. if ($action == 'delete') {
  29. $idChecked = $_REQUEST['idChecked'];
  30. if (is_array($idChecked) && count($idChecked) > 0) {
  31. $my_temp = [];
  32. foreach ($idChecked as $id) {
  33. $my_temp[] = Database::escape_string($id); // forcing the escape_string
  34. }
  35. $idChecked = $my_temp;
  36. $idChecked = "'".implode("','", $idChecked)."'";
  37. $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
  38. $nbr_affected_rows = Database::affected_rows($result);
  39. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
  40. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  41. }
  42. header('Location: '.api_get_self().'?id_session='.$id_session.'&sort='.$sort);
  43. exit();
  44. }
  45. $limit = 20;
  46. $from = $page * $limit;
  47. $sql = "SELECT c.id, c.code, c.title, nbr_users
  48. FROM $tbl_session_rel_course, $tbl_course c
  49. WHERE c_id = c.id AND session_id='$id_session'
  50. ORDER BY $sort
  51. LIMIT $from,".($limit + 1);
  52. $result = Database::query($sql);
  53. $Courses = Database::store_result($result);
  54. $tool_name = api_htmlentities($session_name, ENT_QUOTES, $charset).' : '.get_lang('CourseListInSession');
  55. $interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang('SessionList')];
  56. $interbreadcrumb[] = ['url' => "resume_session.php?id_session=".Security::remove_XSS($_REQUEST['id_session']), "name" => get_lang('SessionOverview')];
  57. Display::display_header($tool_name);
  58. echo Display::page_header($tool_name);
  59. ?>
  60. <form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  61. <?php
  62. $tableHeader = [];
  63. $tableHeader[] = [' '];
  64. $tableHeader[] = [get_lang('CourseTitle')];
  65. $tableHeader[] = [get_lang('NbUsers')];
  66. $tableHeader[] = [get_lang('Actions')];
  67. $tableCourses = [];
  68. foreach ($Courses as $key => $enreg) {
  69. $course = [];
  70. $course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['id'].'">';
  71. $course[] = api_htmlentities($enreg['title'], ENT_QUOTES, $charset);
  72. $course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
  73. $course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.
  74. Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  75. <a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.
  76. Display::return_icon('edit.png', get_lang('Edit')).'</a>
  77. <a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;">'.
  78. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  79. $tableCourses[] = $course;
  80. }
  81. echo '<form method="post" action="'.api_get_self().'">';
  82. Display :: display_sortable_table($tableHeader, $tableCourses, [], []);
  83. echo '<select name="action">
  84. <option value="delete">'.get_lang('UnsubscribeCoursesFromSession').'</option>
  85. </select>
  86. <button class="save" type="submit">'.get_lang('Ok').'</button>
  87. </form>';
  88. Display::display_footer();