subscribe_user2course.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. // $Id: subscribe_user2course.php 12487 2007-05-27 06:00:33Z yannoo $
  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. // name of the language file that needs to be included
  37. $language_file = 'admin';
  38. $cidReset = true;
  39. require ('../inc/global.inc.php');
  40. $this_section=SECTION_PLATFORM_ADMIN;
  41. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  42. api_protect_admin_script();
  43. /*
  44. -----------------------------------------------------------
  45. Global constants and variables
  46. -----------------------------------------------------------
  47. */
  48. $users = $_GET['users'];
  49. $form_sent = 0;
  50. $first_letter_user = '';
  51. $first_letter_course = '';
  52. $courses = array ();
  53. $users = array();
  54. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  55. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  56. /*
  57. -----------------------------------------------------------
  58. Header
  59. -----------------------------------------------------------
  60. */
  61. $tool_name = get_lang('AddUsersToACourse');
  62. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  63. Display :: display_header($tool_name);
  64. //api_display_tool_title($tool_name);
  65. /*
  66. ==============================================================================
  67. MAIN CODE
  68. ==============================================================================
  69. */
  70. /*
  71. -----------------------------------------------------------
  72. React on POSTed request
  73. -----------------------------------------------------------
  74. */
  75. if ($_POST['formSent'])
  76. {
  77. $form_sent = $_POST['formSent'];
  78. $users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
  79. $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
  80. $first_letter_user = $_POST['firstLetterUser'];
  81. $first_letter_course = $_POST['firstLetterCourse'];
  82. foreach($users as $key => $value)
  83. {
  84. $users[$key] = intval($value);
  85. }
  86. if ($form_sent == 1)
  87. {
  88. if ( count($users) == 0 || count($courses) == 0)
  89. {
  90. Display :: display_error_message(get_lang('AtLeastOneUserAndOneCourse'));
  91. }
  92. else
  93. {
  94. foreach ($courses as $course_code)
  95. {
  96. foreach ($users as $user_id)
  97. {
  98. CourseManager::subscribe_user($user_id,$course_code);
  99. }
  100. }
  101. Display :: display_normal_message(get_lang('UsersAreSubscibedToCourse'));
  102. }
  103. }
  104. }
  105. /*
  106. -----------------------------------------------------------
  107. Display GUI
  108. -----------------------------------------------------------
  109. */
  110. if(empty($first_letter_user))
  111. {
  112. $sql = "SELECT count(*) as nb_users FROM $tbl_user";
  113. $result = api_sql_query($sql, __FILE__, __LINE__);
  114. $num_row = Database::fetch_array($result);
  115. if($num_row['nb_users']>1000)
  116. {//if there are too much users to gracefully handle with the HTML select list,
  117. // assign a default filter on users names
  118. $first_letter_user = 'A';
  119. }
  120. unset($result);
  121. }
  122. $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";
  123. $result = api_sql_query($sql, __FILE__, __LINE__);
  124. $db_users = api_store_result($result);
  125. unset($result);
  126. $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";
  127. $result = api_sql_query($sql, __FILE__, __LINE__);
  128. $db_courses = api_store_result($result);
  129. unset($result);
  130. ?>
  131. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  132. <input type="hidden" name="formSent" value="1"/>
  133. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  134. <tr>
  135. <td width="40%" align="center">
  136. <b><?php echo get_lang('UserList'); ?></b>
  137. <br/><br/>
  138. <?php echo get_lang('FirstLetterUser'); ?> :
  139. <select name="firstLetterUser" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  140. <option value="">--</option>
  141. <?php
  142. echo Display :: get_alphabet_options($first_letter_user);
  143. ?>
  144. </select>
  145. </td>
  146. <td width="20%">&nbsp;</td>
  147. <td width="40%" align="center">
  148. <b><?php echo get_lang('CourseList'); ?> :</b>
  149. <br/><br/>
  150. <?php echo get_lang('FirstLetterCourse'); ?> :
  151. <select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  152. <option value="">--</option>
  153. <?php
  154. echo Display :: get_alphabet_options($first_letter_course);
  155. ?>
  156. </select>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td width="40%" align="center">
  161. <select name="UserList[]" multiple="multiple" size="20" style="width:230px;">
  162. <?php
  163. foreach ($db_users as $user)
  164. {
  165. ?>
  166. <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>
  167. <?php
  168. }
  169. ?>
  170. </select>
  171. </td>
  172. <td width="20%" valign="middle" align="center">
  173. <input type="submit" value="<?php echo get_lang('AddToThatCourse'); ?> &gt;&gt;"/>
  174. </td>
  175. <td width="40%" align="center">
  176. <select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
  177. <?php
  178. foreach ($db_courses as $course)
  179. {
  180. ?>
  181. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
  182. <?php
  183. }
  184. ?>
  185. </select>
  186. </td>
  187. </tr>
  188. </table>
  189. </form>
  190. <?php
  191. /*
  192. ==============================================================================
  193. FOOTER
  194. ==============================================================================
  195. */
  196. Display :: display_footer();
  197. ?>