session_course_edit.php 5.4 KB

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