session_course_edit.php 5.5 KB

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