add_students_to_session.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // resetting the course id
  7. $cidReset = true;
  8. // including some necessary files
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. // setting breadcrumbs
  13. $interbreadcrumb[] = [
  14. 'url' => 'session_list.php',
  15. 'name' => get_lang('Session list'),
  16. ];
  17. // Setting the name of the tool
  18. $tool_name = get_lang('Subscribe students to session(s)');
  19. $add_type = 'multiple';
  20. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
  21. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  22. }
  23. $form_sent = 0;
  24. $errorMsg = '';
  25. $users = $sessions = [];
  26. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  27. SessionManager::protectSession($id);
  28. $htmlResult = '';
  29. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  30. $form_sent = $_POST['form_sent'];
  31. if ($form_sent == 1) {
  32. $sessionSourceList = $_POST['sessions'];
  33. $sessionDestinationList = $_POST['sessions_destination'];
  34. $result = SessionManager::copyStudentsFromSession(
  35. $sessionSourceList,
  36. $sessionDestinationList
  37. );
  38. foreach ($result as $message) {
  39. $htmlResult .= $message;
  40. }
  41. }
  42. }
  43. $session_list = SessionManager::get_sessions_list([], ['name']);
  44. $sessionList = [];
  45. foreach ($session_list as $session) {
  46. $sessionList[$session['id']] = $session['name'];
  47. }
  48. Display::display_header($tool_name);
  49. ?>
  50. <form name="formulaire" method="post" action="<?php echo api_get_self().'?id='.$id; ?>" style="margin:0px;" >
  51. <?php echo '<legend>'.$tool_name.' </legend>';
  52. echo $htmlResult;
  53. echo Display::input('hidden', 'form_sent', '1');
  54. ?>
  55. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  56. <tr>
  57. <td align="center">
  58. <b><?php echo get_lang('Course sessions'); ?> :</b>
  59. </td>
  60. <td></td>
  61. <td align="center">
  62. <b><?php echo get_lang('Course sessions'); ?> :</b>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td align="center">
  67. <?php
  68. echo Display::select(
  69. 'sessions[]',
  70. $sessionList,
  71. '',
  72. ['style' => 'width:100%', 'multiple' => 'multiple', 'id' => 'sessions', 'size' => '15px'],
  73. false
  74. );
  75. ?>
  76. </td>
  77. <td align="center">
  78. </td>
  79. <td align="center">
  80. <?php
  81. echo Display::select(
  82. 'sessions_destination[]',
  83. $sessionList,
  84. '',
  85. ['style' => 'width:100%', 'id' => 'courses', 'size' => '15px'],
  86. false
  87. );
  88. ?>
  89. </td>
  90. </tr>
  91. <tr>
  92. <td colspan="3" align="center">
  93. <br />
  94. <?php
  95. echo '<button class="save" type="submit"" >'.
  96. get_lang('Subscribe students to session(s)').'</button>';
  97. ?>
  98. </td>
  99. </tr>
  100. </table>
  101. </form>
  102. <script>
  103. function moveItem(origin , destination) {
  104. for(var i = 0 ; i<origin.options.length ; i++) {
  105. if(origin.options[i].selected) {
  106. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  107. origin.options[i]=null;
  108. i = i-1;
  109. }
  110. }
  111. destination.selectedIndex = -1;
  112. sortOptions(destination.options);
  113. }
  114. function sortOptions(options) {
  115. newOptions = new Array();
  116. for (i = 0 ; i<options.length ; i++)
  117. newOptions[i] = options[i];
  118. newOptions = newOptions.sort(mysort);
  119. options.length = 0;
  120. for(i = 0 ; i < newOptions.length ; i++)
  121. options[i] = newOptions[i];
  122. }
  123. function mysort(a, b){
  124. if (a.text.toLowerCase() > b.text.toLowerCase()){
  125. return 1;
  126. }
  127. if (a.text.toLowerCase() < b.text.toLowerCase()){
  128. return -1;
  129. }
  130. return 0;
  131. }
  132. function valide(){
  133. var options = document.getElementById('session_in_promotion').options;
  134. for (i = 0 ; i<options.length ; i++)
  135. options[i].selected = true;
  136. document.forms.formulaire.submit();
  137. }
  138. function loadUsersInSelect(select) {
  139. var xhr_object = null;
  140. if(window.XMLHttpRequest) // Firefox
  141. xhr_object = new XMLHttpRequest();
  142. else if(window.ActiveXObject) // Internet Explorer
  143. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  144. else // XMLHttpRequest non supporté par le navigateur
  145. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  146. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  147. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  148. nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));
  149. sessionUsers = makepost(document.getElementById('session_in_promotion'));
  150. nosessionClasses = makepost(document.getElementById('origin_classes'));
  151. sessionClasses = makepost(document.getElementById('destination_classes'));
  152. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  153. xhr_object.onreadystatechange = function() {
  154. if(xhr_object.readyState == 4) {
  155. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  156. //alert(xhr_object.responseText);
  157. }
  158. }
  159. }
  160. function makepost(select) {
  161. var options = select.options;
  162. var ret = "";
  163. for (i = 0 ; i<options.length ; i++)
  164. ret = ret + options[i].value +'::'+options[i].text+";;";
  165. return ret;
  166. }
  167. </script>
  168. <?php
  169. Display::display_footer();