add_students_to_session.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = array('admin','registration');
  8. // resetting the course id
  9. $cidReset = true;
  10. // including some necessary files
  11. require_once '../inc/global.inc.php';
  12. require_once '../inc/lib/xajax/xajax.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  14. // setting the section (for the tabs)
  15. $this_section = SECTION_PLATFORM_ADMIN;
  16. // Access restrictions
  17. api_protect_admin_script(true);
  18. // setting breadcrumbs
  19. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  20. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  21. // Setting the name of the tool
  22. $tool_name = get_lang('SubscribeStudentsToSession');
  23. $add_type = 'multiple';
  24. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
  25. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  26. }
  27. $form_sent = 0;
  28. $errorMsg = '';
  29. $users = $sessions = array();
  30. $id = isset($_GET['id']) ? intval($_GET['id']) : null;
  31. $htmlResult = null;
  32. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  33. $form_sent = $_POST['form_sent'];
  34. if ($form_sent == 1) {
  35. $sessionSourceList = $_POST['sessions'];
  36. $sessionDestinationList = $_POST['sessions_destination'];
  37. $result = SessionManager::copyStudentsFromSession($sessionSourceList, $sessionDestinationList);
  38. foreach ($result as $message) {
  39. $htmlResult .= $message;
  40. }
  41. }
  42. }
  43. $session_list = SessionManager::get_sessions_list(array(), array('name'));
  44. $sessionList = array();
  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(); ?>" 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('Sessions') ?> :</b>
  59. </td>
  60. <td></td>
  61. <td align="center">
  62. <b><?php echo get_lang('Sessions') ?> :</b>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td align="center">
  67. <?php
  68. echo Display::select(
  69. 'sessions[]',
  70. $sessionList,
  71. '',
  72. array('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. array('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('SubscribeStudentsToSession').'</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("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
  147. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  148. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  149. nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));
  150. sessionUsers = makepost(document.getElementById('session_in_promotion'));
  151. nosessionClasses = makepost(document.getElementById('origin_classes'));
  152. sessionClasses = makepost(document.getElementById('destination_classes'));
  153. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  154. xhr_object.onreadystatechange = function() {
  155. if(xhr_object.readyState == 4) {
  156. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  157. //alert(xhr_object.responseText);
  158. }
  159. }
  160. }
  161. function makepost(select) {
  162. var options = select.options;
  163. var ret = "";
  164. for (i = 0 ; i<options.length ; i++)
  165. ret = ret + options[i].value +'::'+options[i].text+";;";
  166. return ret;
  167. }
  168. </script>
  169. <?php
  170. Display::display_footer();