session_course_list.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = 'admin';
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section=SECTION_PLATFORM_ADMIN;
  12. $id_session = intval($_GET['id_session']);
  13. SessionManager::protect_session_edit($id_session);
  14. // Database Table Definitions
  15. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  16. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  17. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  18. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  19. if (empty($id_session)) {
  20. api_not_allowed();
  21. }
  22. $page = intval($_GET['page']);
  23. $action = $_REQUEST['action'];
  24. $sort = in_array($_GET['sort'],array('title','nbr_users'))?$_GET['sort']:'title';
  25. $result = Database::query("SELECT name FROM $tbl_session WHERE id='$id_session'");
  26. if (!list($session_name)=Database::fetch_row($result)) {
  27. header('Location: session_list.php');
  28. exit;
  29. }
  30. if ($action == 'delete') {
  31. $idChecked = $_REQUEST['idChecked'];
  32. if (is_array($idChecked) && count($idChecked)>0) {
  33. $my_temp = array();
  34. foreach ($idChecked as $id){
  35. $my_temp[]= Database::escape_string($id);// forcing the escape_string
  36. }
  37. $idChecked = $my_temp;
  38. $idChecked="'".implode("','", $idChecked)."'";
  39. $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND c_id IN($idChecked)");
  40. $nbr_affected_rows = Database::affected_rows($result);
  41. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND c_id IN($idChecked)");
  42. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  43. }
  44. header('Location: '.api_get_self().'?id_session='.$id_session.'&sort='.$sort);
  45. exit();
  46. }
  47. $limit = 20;
  48. $from = $page * $limit;
  49. $sql = "SELECT c_id, title, nbr_users FROM $tbl_session_rel_course, $tbl_course c
  50. WHERE c_id = c.id AND id_session='$id_session'
  51. ORDER BY $sort 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['c_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['c_id'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
  74. $course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['c_id'].'/index.php?id_session='.$id_session.'">'.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['c_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>
  76. <a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['c_id'].'" onclick="javascript:if(!confirm(\''.addslashes(get_lang("ConfirmYourChoice")).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  77. $tableCourses[] = $course;
  78. }
  79. echo '<form method="post" action="'.api_get_self().'">';
  80. Display :: display_sortable_table($tableHeader, $tableCourses, array (), array ());
  81. echo '<select name="action">
  82. <option value="delete">'.get_lang('UnsubscribeCoursesFromSession').'</option>
  83. </select>
  84. <button class="save" type="submit">'.get_lang('Ok').'</button>
  85. </form>';
  86. Display::display_footer();