session_course_edit.php 5.8 KB

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