session_course_list.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)");
  40. $nbr_affected_rows=Database::affected_rows();
  41. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code 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 code, title, nbr_users FROM $tbl_session_rel_course, $tbl_course WHERE course_code=code AND id_session='$id_session' ORDER BY $sort LIMIT $from,".($limit+1);
  50. $result=Database::query($sql);
  51. $Courses=Database::store_result($result);
  52. $tool_name = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
  53. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  54. $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
  55. $interbreadcrumb[]=array('url' => "resume_session.php?id_session=".Security::remove_XSS($_REQUEST['id_session']),"name" => get_lang('SessionOverview'));
  56. Display::display_header($tool_name);
  57. echo Display::page_header($tool_name);
  58. ?>
  59. <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;">
  60. <?php
  61. $tableHeader = array();
  62. $tableHeader[] = array(' ');
  63. $tableHeader[] = array(get_lang('CourseTitle'));
  64. $tableHeader[] = array(get_lang('NbUsers'));
  65. $tableHeader[] = array(get_lang('Actions'));
  66. $tableCourses = array();
  67. foreach($Courses as $key=>$enreg) {
  68. $course = array();
  69. $course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['code'].'">';
  70. $course[] = api_htmlentities($enreg['title'],ENT_QUOTES,$charset);
  71. $course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
  72. $course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  73. <a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>
  74. <a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['code'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  75. $tableCourses[] = $course;
  76. }
  77. echo '<form method="post" action="'.api_get_self().'">';
  78. Display :: display_sortable_table($tableHeader, $tableCourses, array (), array ());
  79. echo '<select name="action">
  80. <option value="delete">'.get_lang('UnsubscribeCoursesFromSession').'</option>
  81. </select>
  82. <button class="save" type="submit">'.get_lang('Ok').'</button>
  83. </form>';
  84. Display::display_footer();