session_course_edit.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Implements the edition of course-session settings.
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  11. SessionManager::protectSession($id_session);
  12. $course_code = $_GET['course_code'];
  13. $course_info = api_get_course_info($_REQUEST['course_code']);
  14. if (empty($course_info)) {
  15. api_not_allowed(true);
  16. }
  17. // Database Table Definitions
  18. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  19. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  20. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  21. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  22. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  23. $courseId = $course_info['real_id'];
  24. $tool_name = $course_info['name'];
  25. $sql = "SELECT s.name, c.title
  26. FROM $tbl_session_course sc, $tbl_session s, $tbl_course c
  27. WHERE
  28. sc.session_id = s.id AND
  29. sc.c_id = c.id AND
  30. sc.session_id='$id_session' AND
  31. sc.c_id ='".$courseId."'";
  32. $result = Database::query($sql);
  33. if (!list($session_name, $course_title) = Database::fetch_row($result)) {
  34. header('Location: session_course_list.php?id_session='.$id_session);
  35. exit();
  36. }
  37. $interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang("Session list")];
  38. $interbreadcrumb[] = [
  39. 'url' => "resume_session.php?id_session=".$id_session,
  40. "name" => get_lang('Session overview'),
  41. ];
  42. $interbreadcrumb[] = [
  43. 'url' => "session_course_list.php?id_session=$id_session",
  44. "name" => api_htmlentities($session_name, ENT_QUOTES, $charset),
  45. ];
  46. $arr_infos = [];
  47. if (isset($_POST['formSent']) && $_POST['formSent']) {
  48. // get all tutor by course_code in the session
  49. $sql = "SELECT user_id
  50. FROM $tbl_session_rel_course_rel_user
  51. WHERE session_id = '$id_session' AND c_id = '".$courseId."' AND status = 2";
  52. $rs_coaches = Database::query($sql);
  53. $coaches_course_session = [];
  54. if (Database::num_rows($rs_coaches) > 0) {
  55. while ($row_coaches = Database::fetch_row($rs_coaches)) {
  56. $coaches_course_session[] = $row_coaches[0];
  57. }
  58. }
  59. $id_coaches = isset($_POST['id_coach']) ? $_POST['id_coach'] : [0];
  60. if (is_array($id_coaches) && count($id_coaches) > 0) {
  61. foreach ($id_coaches as $id_coach) {
  62. $id_coach = intval($id_coach);
  63. $rs1 = SessionManager::set_coach_to_course_session(
  64. $id_coach,
  65. $id_session,
  66. $courseId
  67. );
  68. }
  69. // set status to 0 other tutors from multiple list
  70. $array_intersect = array_diff($coaches_course_session, $id_coaches);
  71. foreach ($array_intersect as $no_coach_user_id) {
  72. $rs2 = SessionManager::set_coach_to_course_session(
  73. $no_coach_user_id,
  74. $id_session,
  75. $courseId,
  76. true
  77. );
  78. }
  79. Display::addFlash(Display::return_message(get_lang('Update successful')));
  80. header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
  81. exit();
  82. }
  83. } else {
  84. $sql = "SELECT user_id
  85. FROM $tbl_session_rel_course_rel_user
  86. WHERE
  87. session_id = '$id_session' AND
  88. c_id = '".$courseId."' AND
  89. status = 2 ";
  90. $rs = Database::query($sql);
  91. if (Database::num_rows($rs) > 0) {
  92. while ($infos = Database::fetch_array($rs)) {
  93. $arr_infos[] = $infos['user_id'];
  94. }
  95. }
  96. }
  97. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  98. if (api_is_multiple_url_enabled()) {
  99. $tbl_access_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  100. $access_url_id = api_get_current_access_url_id();
  101. $sql = "SELECT u.user_id,lastname,firstname,username
  102. FROM $tbl_user u
  103. LEFT JOIN $tbl_access_rel_user a
  104. ON(u.user_id= a.user_id)
  105. WHERE
  106. status='1' AND
  107. active = 1 AND
  108. access_url_id = $access_url_id ".
  109. $order_clause;
  110. } else {
  111. $sql = "SELECT user_id,lastname,firstname,username
  112. FROM $tbl_user
  113. WHERE
  114. status = '1' AND
  115. active = 1 ".
  116. $order_clause;
  117. }
  118. $result = Database::query($sql);
  119. $coaches = Database::store_result($result);
  120. if (!api_is_platform_admin() && api_is_teacher()) {
  121. $userInfo = api_get_user_info();
  122. $coaches = [$userInfo];
  123. }
  124. Display::display_header($tool_name);
  125. $tool_name = get_lang('Edit session course');
  126. api_display_tool_title($tool_name);
  127. $form = new FormValidator(
  128. 'form',
  129. 'post',
  130. api_get_self().'?id_session='.$id_session.'&course_code='.$course_code.'&page='.Security::remove_XSS($_GET['page'])
  131. );
  132. $options = [];
  133. $selected = [];
  134. foreach ($coaches as $enreg) {
  135. $options[$enreg['user_id']] = api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')';
  136. if (in_array($enreg['user_id'], $arr_infos)) {
  137. $selected[] = $enreg['user_id'];
  138. }
  139. }
  140. $form->addSelect('id_coach', get_lang('Coach name'), $options, ['multiple' => 'multiple']);
  141. $form->addHidden('formSent', 1);
  142. $form->addButtonSave(get_lang('Assign coach'));
  143. $form->setDefaults(['id_coach' => $selected]);
  144. $form->display();
  145. Display::display_footer();