subscribe_user2course.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. // $Id: subscribe_user2course.php 9246 2006-09-25 13:24:53Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This script allows platform admins to add users to courses.
  24. * It displays a list of users and a list of courses;
  25. * you can select multiple users and courses and then click on
  26. * 'Add to this(these) course(s)'.
  27. *
  28. * @package dokeos.admin
  29. ==============================================================================
  30. */
  31. /*
  32. ==============================================================================
  33. INIT SECTION
  34. ==============================================================================
  35. */
  36. $langFile = 'admin';
  37. $cidReset = true;
  38. require ('../inc/global.inc.php');
  39. $this_section=SECTION_PLATFORM_ADMIN;
  40. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  41. api_protect_admin_script();
  42. /*
  43. -----------------------------------------------------------
  44. Global constants and variables
  45. -----------------------------------------------------------
  46. */
  47. $users = $_GET['users'];
  48. $form_sent = 0;
  49. $first_letter_user = '';
  50. $first_letter_course = '';
  51. $courses = array ();
  52. $users = array();
  53. $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  54. $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
  55. /*
  56. -----------------------------------------------------------
  57. Header
  58. -----------------------------------------------------------
  59. */
  60. $tool_name = get_lang('AddUsersToACourse');
  61. //$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  62. Display :: display_header($tool_name);
  63. //api_display_tool_title($tool_name);
  64. /*
  65. ==============================================================================
  66. MAIN CODE
  67. ==============================================================================
  68. */
  69. /*
  70. -----------------------------------------------------------
  71. React on POSTed request
  72. -----------------------------------------------------------
  73. */
  74. if ($_POST['formSent'])
  75. {
  76. $form_sent = $_POST['formSent'];
  77. $users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
  78. $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
  79. $first_letter_user = $_POST['firstLetterUser'];
  80. $first_letter_course = $_POST['firstLetterCourse'];
  81. foreach($users as $key => $value)
  82. {
  83. $users[$key] = intval($value);
  84. }
  85. if ($form_sent == 1)
  86. {
  87. if ( count($users) == 0 || count($courses) == 0)
  88. {
  89. Display :: display_error_message(get_lang('AtLeastOneUserAndOneCourse'));
  90. }
  91. else
  92. {
  93. foreach ($courses as $course_code)
  94. {
  95. foreach ($users as $user_id)
  96. {
  97. CourseManager::subscribe_user($user_id,$course_code);
  98. }
  99. }
  100. Display :: display_normal_message(get_lang('UsersAreSubscibedToCourse'));
  101. }
  102. }
  103. }
  104. /*
  105. -----------------------------------------------------------
  106. Display GUI
  107. -----------------------------------------------------------
  108. */
  109. $sql = "SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE lastname LIKE '".$first_letter_user."%' ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." lastname";
  110. $result = api_sql_query($sql, __FILE__, __LINE__);
  111. $db_users = api_store_result($result);
  112. $sql = "SELECT code,visual_code,title FROM $tbl_course WHERE visual_code LIKE '".$first_letter_course."%' ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
  113. $result = api_sql_query($sql, __FILE__, __LINE__);
  114. $db_courses = api_store_result($result);
  115. ?>
  116. <form name="formulaire" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="margin:0px;">
  117. <input type="hidden" name="formSent" value="1"/>
  118. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  119. <tr>
  120. <td width="40%" align="center">
  121. <b><?php echo get_lang('UserList'); ?></b>
  122. <br/><br/>
  123. <?php echo get_lang('FirstLetterUser'); ?> :
  124. <select name="firstLetterUser" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  125. <option value="">--</option>
  126. <?php
  127. echo Display :: get_alphabet_options($first_letter_user);
  128. ?>
  129. </select>
  130. </td>
  131. <td width="20%">&nbsp;</td>
  132. <td width="40%" align="center">
  133. <b><?php echo get_lang('CourseList'); ?> :</b>
  134. <br/><br/>
  135. <?php echo get_lang('FirstLetterCourse'); ?> :
  136. <select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  137. <option value="">--</option>
  138. <?php
  139. echo Display :: get_alphabet_options($first_letter_course);
  140. ?>
  141. </select>
  142. </td>
  143. </tr>
  144. <tr>
  145. <td width="40%" align="center">
  146. <select name="UserList[]" multiple="multiple" size="20" style="width:230px;">
  147. <?php
  148. foreach ($db_users as $user)
  149. {
  150. ?>
  151. <option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'; ?></option>
  152. <?php
  153. }
  154. ?>
  155. </select>
  156. </td>
  157. <td width="20%" valign="middle" align="center">
  158. <input type="submit" value="<?php echo get_lang('AddToThatCourse'); ?> &gt;&gt;"/>
  159. </td>
  160. <td width="40%" align="center">
  161. <select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
  162. <?php
  163. foreach ($db_courses as $course)
  164. {
  165. ?>
  166. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
  167. <?php
  168. }
  169. ?>
  170. </select>
  171. </td>
  172. </tr>
  173. </table>
  174. </form>
  175. <?php
  176. /*
  177. ==============================================================================
  178. FOOTER
  179. ==============================================================================
  180. */
  181. Display :: display_footer();
  182. ?>