add_teachers_to_session.php 6.4 KB

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