add_students_to_session.php 6.0 KB

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