add_courses_to_session.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @todo use formvalidator
  6. */
  7. // name of the language file that needs to be included
  8. $language_file='admin';
  9. // resetting the course id
  10. $cidReset = true;
  11. //require_once '../inc/global.inc.php';
  12. $id_session = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  13. SessionManager::protect_session_edit($id_session);
  14. $xajax = new xajax();
  15. $xajax -> registerFunction (array('search_courses', 'AddCourseToSession', 'search_courses'));
  16. // Setting the section (for the tabs)
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. // setting breadcrumbs
  19. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('Sessions'));
  20. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  21. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
  22. // Database Table Definitions
  23. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  24. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  25. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  26. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  27. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  28. // setting the name of the tool
  29. $tool_name= get_lang('SubscribeCoursesToSession');
  30. $add_type = 'multiple';
  31. if (isset($_GET['add_type']) && $_GET['add_type']!=''){
  32. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  33. }
  34. $page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
  35. $xajax->processRequests();
  36. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  37. $htmlHeadXtra[] = '<script>
  38. function add_course_to_session (code, content) {
  39. document.getElementById("course_to_add").value = "";
  40. document.getElementById("ajax_list_courses_single").innerHTML = "";
  41. destination = document.getElementById("destination");
  42. for (i=0;i<destination.length;i++) {
  43. if(destination.options[i].text == content) {
  44. return false;
  45. }
  46. }
  47. destination.options[destination.length] = new Option(content,code);
  48. destination.selectedIndex = -1;
  49. sortOptions(destination.options);
  50. }
  51. function remove_item(origin) {
  52. for(var i = 0 ; i<origin.options.length ; i++) {
  53. if(origin.options[i].selected) {
  54. origin.options[i]=null;
  55. i = i-1;
  56. }
  57. }
  58. }
  59. </script>';
  60. $formSent = 0;
  61. $errorMsg = $firstLetterCourse=$firstLetterSession='';
  62. $CourseList = $SessionList=array();
  63. $courses = $sessions=array();
  64. $noPHP_SELF = true;
  65. if (isset($_POST['formSent']) && $_POST['formSent']) {
  66. $formSent = $_POST['formSent'];
  67. $firstLetterCourse = $_POST['firstLetterCourse'];
  68. $firstLetterSession = $_POST['firstLetterSession'];
  69. $CourseList = $_POST['SessionCoursesList'];
  70. SessionManager::add_courses_to_session($id_session, $CourseList);
  71. if (isset($_GET['add'])) {
  72. header('Location: add_users_to_session.php?id_session='.$id_session.'&add=true');
  73. exit;
  74. } else {
  75. header('Location: resume_session.php?id_session='.$id_session);
  76. exit;
  77. }
  78. }
  79. // display the dokeos header
  80. Display::display_header($tool_name);
  81. if ($add_type == 'multiple') {
  82. $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
  83. $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').' ';
  84. } else {
  85. $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'&nbsp;&nbsp;&nbsp;';
  86. $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
  87. }
  88. // the form header
  89. $session_info = SessionManager::fetch($id_session);
  90. echo '<div class="actions">';
  91. echo $link_add_type_unique.$link_add_type_multiple;
  92. echo '</div>';
  93. /*$sql = 'SELECT COUNT(1) FROM '.$tbl_course;
  94. $rs = Database::query($sql);
  95. $count_courses = Database::result($rs, 0, 0);*/
  96. $ajax_search = $add_type == 'unique' ? true : false;
  97. $nosessionCourses = $sessionCourses = array();
  98. if ($ajax_search) {
  99. $sql="SELECT code, title, visual_code, id_session
  100. FROM $tbl_course course
  101. INNER JOIN $tbl_session_rel_course session_rel_course
  102. ON course.id = session_rel_course.c_id
  103. AND session_rel_course.id_session = ".intval($id_session)."
  104. ORDER BY ".(sizeof($courses)?"(course.code IN(".implode(',',$courses).")) DESC,":"")." title";
  105. if (api_is_multiple_url_enabled()) {
  106. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  107. $access_url_id = api_get_current_access_url_id();
  108. if ($access_url_id != -1){
  109. $sql="SELECT code, title, visual_code, id_session
  110. FROM $tbl_course course
  111. INNER JOIN $tbl_session_rel_course session_rel_course
  112. ON course.code = session_rel_course.course_code
  113. AND session_rel_course.id_session = ".intval($id_session)."
  114. INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.c_id = course.id)
  115. WHERE access_url_id = $access_url_id
  116. ORDER BY ".(sizeof($courses)?"(course.code IN(".implode(',',$courses).")) DESC,":"")." title";
  117. }
  118. }
  119. $result = Database::query($sql);
  120. $Courses = Database::store_result($result);
  121. foreach($Courses as $course) {
  122. $sessionCourses[$course['code']] = $course ;
  123. }
  124. } else {
  125. $sql="SELECT code, title, visual_code, id_session, course.id as real_id
  126. FROM $tbl_course course
  127. LEFT JOIN $tbl_session_rel_course session_rel_course
  128. ON course.id = session_rel_course.c_id
  129. AND session_rel_course.id_session = ".intval($id_session)."
  130. ORDER BY ".(sizeof($courses)?"(course.code IN(".implode(',',$courses).")) DESC,":"")." title";
  131. if (api_is_multiple_url_enabled()) {
  132. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  133. $access_url_id = api_get_current_access_url_id();
  134. if ($access_url_id != -1){
  135. $sql="SELECT code, title, visual_code, id_session, course.id as real_id
  136. FROM $tbl_course course
  137. LEFT JOIN $tbl_session_rel_course session_rel_course
  138. ON course.id = session_rel_course.c_id
  139. AND session_rel_course.id_session = ".intval($id_session)."
  140. INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.c_id = course.id)
  141. WHERE access_url_id = $access_url_id
  142. ORDER BY ".(sizeof($courses)?"(course.code IN(".implode(',',$courses).")) DESC,":"")." title";
  143. }
  144. }
  145. $result = Database::query($sql);
  146. $Courses = Database::store_result($result);
  147. foreach($Courses as $course) {
  148. if ($course['id_session'] == $id_session) {
  149. $sessionCourses[$course['real_id']] = $course ;
  150. } else {
  151. $nosessionCourses[$course['real_id']] = $course ;
  152. }
  153. }
  154. }
  155. unset($Courses);
  156. ?>
  157. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
  158. <legend><?php echo $tool_name.' ('.$session_info['name'].')'; ?></legend>
  159. <input type="hidden" name="formSent" value="1" />
  160. <?php
  161. if(!empty($errorMsg)) {
  162. Display::display_normal_message($errorMsg); //main API
  163. }
  164. ?>
  165. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  166. <tr>
  167. <td width="45%" align="center"><b><?php echo get_lang('CourseListInPlatform') ?> :</b></td>
  168. <td width="10%">&nbsp;</td>
  169. <td align="center" width="45%"><b><?php echo get_lang('CourseListInSession') ?> :</b></td>
  170. </tr>
  171. <?php if($add_type == 'multiple') { ?>
  172. <tr><td width="45%" align="center">
  173. <?php echo get_lang('FirstLetterCourse'); ?> :
  174. <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
  175. <option value="%">--</option>
  176. <?php
  177. echo Display :: get_alphabet_options();
  178. echo Display :: get_numeric_options(0,9,'');
  179. ?>
  180. </select>
  181. </td>
  182. <td>&nbsp;</td></tr>
  183. <?php } ?>
  184. <tr>
  185. <td width="45%" align="center">
  186. <?php
  187. if(!($add_type == 'multiple')){
  188. ?>
  189. <input type="text" id="course_to_add" onkeyup="xajax_search_courses(this.value,'single')" />
  190. <div id="ajax_list_courses_single"></div>
  191. <?php
  192. } else {
  193. ?>
  194. <div id="ajax_list_courses_multiple">
  195. <select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:360px;"> <?php
  196. foreach($nosessionCourses as $enreg) {
  197. ?>
  198. <option value="<?php echo $enreg['real_id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
  199. <?php } ?>
  200. </select>
  201. </div>
  202. <?php
  203. }
  204. unset($nosessionCourses);
  205. ?>
  206. </td>
  207. <td width="10%" valign="middle" align="center">
  208. <?php
  209. if ($ajax_search) {
  210. ?>
  211. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  212. <?php
  213. } else {
  214. ?>
  215. <button class="btn arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))">
  216. <i class="fa fa-arrow-right"></i>
  217. </button>
  218. <br /><br />
  219. <button class="btn arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))">
  220. <i class="fa fa-arrow-left"></i>
  221. </button>
  222. <?php
  223. }
  224. ?>
  225. <br /><br /><br /><br /><br /><br />
  226. <?php
  227. if (isset($_GET['add'])) {
  228. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('NextStep').'</button>';
  229. } else {
  230. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeCoursesToSession').'</button>';
  231. }
  232. ?>
  233. </td>
  234. <td width="45%" align="center">
  235. <select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" style="width:360px;">
  236. <?php foreach($sessionCourses as $enreg) { ?>
  237. <option value="<?php echo $enreg['real_id']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>"><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
  238. <?php }
  239. unset($sessionCourses);
  240. ?>
  241. </select>
  242. </td>
  243. </tr>
  244. </table>
  245. </form>
  246. <script>
  247. function valide(){
  248. var options = document.getElementById('destination').options;
  249. for (i = 0 ; i<options.length ; i++)
  250. options[i].selected = true;
  251. document.forms.formulaire.submit();
  252. }
  253. </script>
  254. <?php
  255. Display::display_footer();