session_course_edit.php 5.7 KB

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