session_course_edit.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Implements the edition of course-session settings
  5. * @package chamilo.admin
  6. */
  7. $id_session = intval($_GET['id_session']);
  8. SessionManager::protect_session_edit($id_session);
  9. $course_code = Database::escape_string($_GET['course_code']);
  10. $courseInfo = api_get_course_info($course_code);
  11. $courseId = $courseInfo['real_id'];
  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. $tool_name = $course_info['name'];
  22. $sql = "SELECT s.name, c.title FROM $tbl_session_course sc,$tbl_session s,$tbl_course c
  23. WHERE sc.id_session=s.id AND
  24. sc.c_id = c.id AND
  25. sc.id_session='$id_session' AND
  26. sc.c_id='".$courseId."'";
  27. $result = Database::query($sql);
  28. if (!list($session_name,$course_title)=Database::fetch_row($result)) {
  29. header('Location: session_course_list.php?id_session='.$id_session);
  30. exit();
  31. }
  32. $interbreadcrumb[]= array('url' => 'index.php',"name" => get_lang('Sessions'));
  33. $interbreadcrumb[]= array('url' => "session_list.php","name" => get_lang("SessionList"));
  34. $interbreadcrumb[]= array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
  35. $interbreadcrumb[]= array('url' => "session_course_list.php?id_session=$id_session","name" => $session_name);
  36. $id_coach = null;
  37. $arr_infos = array();
  38. if (isset($_POST['formSent']) && $_POST['formSent']) {
  39. $formSent=1;
  40. // get all tutor by course_code in the session
  41. $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user WHERE id_session = '$id_session' AND c_id = '$courseId' AND status = 2";
  42. $rs_coachs = Database::query($sql);
  43. $coachs_course_session = array();
  44. if (Database::num_rows($rs_coachs) > 0){
  45. while ($row_coachs = Database::fetch_row($rs_coachs)) {
  46. $coachs_course_session[] = $row_coachs[0];
  47. }
  48. }
  49. $id_coachs = $_POST['id_coach'];
  50. if (is_array($id_coachs) && count($id_coachs) > 0) {
  51. foreach ($id_coachs as $id_coach) {
  52. $id_coach = intval($id_coach);
  53. $rs1 = SessionManager::set_coach_to_course_session($id_coach, $id_session, $courseId);
  54. }
  55. // set status to 0 other tutors from multiple list
  56. $array_intersect = array_diff($coachs_course_session,$id_coachs);
  57. foreach ($array_intersect as $nocoach_user_id) {
  58. $rs2 = SessionManager::set_coach_to_course_session($nocoach_user_id, $id_session, $courseId, true);
  59. }
  60. header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
  61. exit();
  62. }
  63. } else {
  64. $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user WHERE id_session = '$id_session' AND c_id = '$courseId' AND status = 2 ";
  65. $rs = Database::query($sql);
  66. if (Database::num_rows($rs) > 0) {
  67. while ($infos = Database::fetch_array($rs)) {
  68. $arr_infos[] = $infos['id_user'];
  69. }
  70. }
  71. }
  72. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  73. if (api_is_multiple_url_enabled()) {
  74. $tbl_access_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  75. $access_url_id = api_get_current_access_url_id();
  76. $sql="SELECT u.user_id,lastname,firstname,username FROM $tbl_user u LEFT JOIN $tbl_access_rel_user a ON(u.user_id= a.user_id)
  77. WHERE status='1' AND access_url_id = $access_url_id ".$order_clause;
  78. } else {
  79. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
  80. }
  81. $result = Database::query($sql);
  82. $coaches = Database::store_result($result);
  83. Display::display_header($tool_name);
  84. $tool_name = get_lang('ModifySessionCourse');
  85. echo Display::page_header($tool_name);
  86. ?>
  87. <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;">
  88. <input type="hidden" name="formSent" value="1">
  89. <table>
  90. <?php
  91. if(!empty($errorMsg)) {
  92. ?>
  93. <tr>
  94. <td colspan="2">
  95. <?php
  96. Display::display_normal_message($errorMsg);
  97. ?>
  98. </td>
  99. </tr>
  100. <?php
  101. }
  102. ?>
  103. <tr>
  104. <td width="25%" valign = "top"><?php echo get_lang("CoachName") ?>&nbsp;&nbsp;</td>
  105. <td width="70%"><select name="id_coach[]" style="width:450px;" multiple="multiple" size="7">
  106. <option value="0">----- <?php echo get_lang("Choose") ?> -----</option>
  107. <option value="0" <?php if(count($arr_infos) == 0) echo 'selected="selected"'; ?>><?php echo get_lang('None') ?></option>
  108. <?php
  109. foreach($coaches as $enreg) {
  110. ?>
  111. <option value="<?php echo $enreg['user_id']; ?>" <?php if (((is_array($arr_infos) && in_array($enreg['user_id'],$arr_infos))) || ($enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>>
  112. <?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?>
  113. </option>
  114. <?php
  115. }
  116. unset($coaches);
  117. ?>
  118. </select></td>
  119. </tr>
  120. <tr>
  121. <td>&nbsp;</td>
  122. <td><button class="save" type="submit" name="name" value="<?php echo get_lang('AssignCoach') ?>"><?php echo get_lang('AssignCoach') ?></button>
  123. </td>
  124. </tr>
  125. </table>
  126. </form>
  127. <?php