session_course_edit.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 '../inc/global.inc.php';
  9. $id_session = intval($_GET['id_session']);
  10. SessionManager::protectSession($id_session);
  11. $course_code = $_GET['course_code'];
  12. $formSent = 0;
  13. $errorMsg = '';
  14. // Database Table Definitions
  15. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  16. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  17. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  18. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  19. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  20. $course_info = api_get_course_info($_REQUEST['course_code']);
  21. $courseId = $course_info['real_id'];
  22. $tool_name = $course_info['name'];
  23. $sql = "SELECT s.name, c.title
  24. FROM $tbl_session_course sc, $tbl_session s, $tbl_course c
  25. WHERE
  26. sc.session_id = s.id AND
  27. sc.c_id = c.id AND
  28. sc.session_id='$id_session' AND
  29. sc.c_id ='".$courseId."'";
  30. $result = Database::query($sql);
  31. if (!list($session_name,$course_title) = Database::fetch_row($result)) {
  32. header('Location: session_course_list.php?id_session='.$id_session);
  33. exit();
  34. }
  35. //$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  36. $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang("SessionList"));
  37. $interbreadcrumb[]=array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
  38. $interbreadcrumb[]=array('url' => "session_course_list.php?id_session=$id_session","name" =>api_htmlentities($session_name, ENT_QUOTES, $charset));
  39. $arr_infos = array();
  40. if (isset($_POST['formSent']) && $_POST['formSent']) {
  41. $formSent = 1;
  42. // get all tutor by course_code in the session
  43. $sql = "SELECT user_id
  44. FROM $tbl_session_rel_course_rel_user
  45. WHERE session_id = '$id_session' AND c_id = '".$courseId."' AND status = 2";
  46. $rs_coaches = Database::query($sql);
  47. $coaches_course_session = array();
  48. if (Database::num_rows($rs_coaches) > 0){
  49. while ($row_coaches = Database::fetch_row($rs_coaches)) {
  50. $coaches_course_session[] = $row_coaches[0];
  51. }
  52. }
  53. $id_coaches= $_POST['id_coach'];
  54. if (is_array($id_coaches) && count($id_coaches) > 0) {
  55. foreach ($id_coaches as $id_coach) {
  56. $id_coach = intval($id_coach);
  57. $rs1 = SessionManager::set_coach_to_course_session(
  58. $id_coach,
  59. $id_session,
  60. $courseId
  61. );
  62. }
  63. // set status to 0 other tutors from multiple list
  64. $array_intersect = array_diff($coaches_course_session,$id_coaches);
  65. foreach ($array_intersect as $no_coach_user_id) {
  66. $rs2 = SessionManager::set_coach_to_course_session(
  67. $no_coach_user_id,
  68. $id_session,
  69. $courseId,
  70. true
  71. );
  72. }
  73. header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
  74. exit();
  75. }
  76. } else {
  77. $sql = "SELECT user_id
  78. FROM $tbl_session_rel_course_rel_user
  79. WHERE
  80. session_id = '$id_session' AND
  81. c_id = '".$courseId."' AND
  82. status = 2 ";
  83. $rs = Database::query($sql);
  84. if (Database::num_rows($rs) > 0) {
  85. while ($infos = Database::fetch_array($rs)) {
  86. $arr_infos[] = $infos['user_id'];
  87. }
  88. }
  89. }
  90. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  91. if (api_is_multiple_url_enabled()) {
  92. $tbl_access_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  93. $access_url_id = api_get_current_access_url_id();
  94. $sql = "SELECT u.user_id,lastname,firstname,username
  95. FROM $tbl_user u
  96. LEFT JOIN $tbl_access_rel_user a
  97. ON(u.user_id= a.user_id)
  98. WHERE
  99. status='1' AND
  100. active = 1 AND
  101. access_url_id = $access_url_id ".
  102. $order_clause;
  103. } else {
  104. $sql = "SELECT user_id,lastname,firstname,username
  105. FROM $tbl_user
  106. WHERE
  107. status = '1' AND
  108. active = 1 ".
  109. $order_clause;
  110. }
  111. $result = Database::query($sql);
  112. $coaches = Database::store_result($result);
  113. if (!api_is_platform_admin() && api_is_teacher()) {
  114. $userInfo = api_get_user_info();
  115. $coaches = [$userInfo];
  116. }
  117. Display::display_header($tool_name);
  118. $tool_name = get_lang('ModifySessionCourse');
  119. api_display_tool_title($tool_name);
  120. ?>
  121. <div class="session-course-edit">
  122. <form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo Security::remove_XSS($_GET['page']) ?>" style="margin:0px;">
  123. <input type="hidden" name="formSent" value="1">
  124. <div class="row">
  125. <div class="col-md-12">
  126. <div class="title"></div>
  127. <?php
  128. if(!empty($errorMsg)) {
  129. Display::display_normal_message($errorMsg);
  130. }
  131. ?>
  132. </div>
  133. </div>
  134. <div class="row">
  135. <div class="col-md-2">
  136. <?php echo get_lang("CoachName") ?>
  137. </div>
  138. <div class="col-md-8">
  139. <select name="id_coach[]" class="form-control" multiple>
  140. <option value="0">----- <?php echo get_lang("Choose") ?> -----</option>
  141. <option value="0" <?php if(count($arr_infos) == 0) echo 'selected="selected"'; ?>>
  142. <?php echo get_lang('None') ?>
  143. </option>
  144. <?php
  145. foreach ($coaches as $enreg) {
  146. ?>
  147. <option value="<?php echo $enreg['user_id']; ?>" <?php if(((is_array($arr_infos) && in_array($enreg['user_id'], $arr_infos)))) echo 'selected="selected"'; ?>>
  148. <?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?>
  149. </option>
  150. <?php
  151. }
  152. unset($coaches);
  153. ?>
  154. </select>
  155. <div class="control">
  156. <button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('AssignCoach') ?>">
  157. <em class="fa fa-plus"></em>
  158. <?php echo get_lang('AssignCoach') ?>
  159. </button>
  160. </div>
  161. </div>
  162. <div class="col-md-2"></div>
  163. </div>
  164. </form>
  165. </div>
  166. <?php
  167. Display::display_footer();