session_course_list.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = intval($_GET['id_session']);
  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 = intval($_GET['page']);
  21. $action = $_REQUEST['action'];
  22. $sort = in_array($_GET['sort'], array('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 = array();
  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[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  56. $interbreadcrumb[] = array('url' => "session_list.php", "name" => get_lang('SessionList'));
  57. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".Security::remove_XSS($_REQUEST['id_session']), "name" => get_lang('SessionOverview'));
  58. Display::display_header($tool_name);
  59. echo Display::page_header($tool_name);
  60. ?>
  61. <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;">
  62. <?php
  63. $tableHeader = array();
  64. $tableHeader[] = array(' ');
  65. $tableHeader[] = array(get_lang('CourseTitle'));
  66. $tableHeader[] = array(get_lang('NbUsers'));
  67. $tableHeader[] = array(get_lang('Actions'));
  68. $tableCourses = array();
  69. foreach ($Courses as $key=>$enreg) {
  70. $course = array();
  71. $course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['id'].'">';
  72. $course[] = api_htmlentities($enreg['title'], ENT_QUOTES, $charset);
  73. $course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
  74. $course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.
  75. Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  76. <a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.
  77. Display::return_icon('edit.png', get_lang('Edit')).'</a>
  78. <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;">'.
  79. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  80. $tableCourses[] = $course;
  81. }
  82. echo '<form method="post" action="'.api_get_self().'">';
  83. Display :: display_sortable_table($tableHeader, $tableCourses, array(), array());
  84. echo '<select name="action">
  85. <option value="delete">'.get_lang('UnsubscribeCoursesFromSession').'</option>
  86. </select>
  87. <button class="save" type="submit">'.get_lang('Ok').'</button>
  88. </form>';
  89. Display::display_footer();