add_students_to_session.php 5.9 KB

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