subscribe_user2class.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. // $Id: subscribe_user2class.php 12269 2007-05-03 14:17:37Z elixir_julian $
  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: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @package dokeos.admin
  23. ==============================================================================
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = 'admin';
  27. $cidReset = true;
  28. require ('../inc/global.inc.php');
  29. require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  30. $this_section = SECTION_PLATFORM_ADMIN;
  31. api_protect_admin_script();
  32. $course = $_GET['course'];
  33. $class_id = intval($_GET['idclass']);
  34. $form_sent = 0;
  35. $error_message = '';
  36. $first_letter_left = '';
  37. $first_letter_right = '';
  38. $left_user_list = array();
  39. $right_user_list = array ();
  40. // Database table definitions
  41. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  42. $tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
  43. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  44. $sql = "SELECT name FROM $tbl_class WHERE id='$class_id'";
  45. $result = api_sql_query($sql, __FILE__, __LINE__);
  46. if (!list ($class_name) = mysql_fetch_row($result))
  47. {
  48. header('Location: class_list.php?filtreCours='.urlencode($course));
  49. exit ();
  50. }
  51. $noPHP_SELF = true;
  52. $tool_name = get_lang('AddUsersToAClass').' ('.$class_name.')';
  53. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  54. $interbreadcrumb[] = array ("url" => "class_list.php?filtreCours=".urlencode($course), "name" => get_lang('AdminClasses'));
  55. if ($_POST['formSent'])
  56. {
  57. $form_sent = $_POST['formSent'];
  58. $first_letter_left = $_POST['firstLetterLeft'];
  59. $first_letter_right = $_POST['firstLetterRight'];
  60. $left_user_list = is_array($_POST['LeftUserList']) ? $_POST['LeftUserList'] : array();
  61. $right_user_list = is_array($_POST['RightUserList']) ? $_POST['RightUserList'] : array();
  62. $add_to_class = empty ($_POST['addToClass']) ? 0 : 1;
  63. $remove_from_class = empty ($_POST['removeFromClass']) ? 0 : 1;
  64. if ($form_sent == 1)
  65. {
  66. if ($add_to_class)
  67. {
  68. if (count($left_user_list) == 0)
  69. {
  70. $error_message = get_lang('AtLeastOneUser');
  71. }
  72. else
  73. {
  74. foreach ($left_user_list as $user_id)
  75. {
  76. ClassManager :: add_user($user_id, $class_id);
  77. }
  78. header('Location: class_list.php?filtreCours='.urlencode($course));
  79. exit ();
  80. }
  81. }
  82. elseif ($remove_from_class)
  83. {
  84. if (count($right_user_list) == 0)
  85. $error_message = get_lang('AtLeastOneUser');
  86. else
  87. {
  88. foreach ($right_user_list as $index => $user_id)
  89. {
  90. ClassManager :: unsubscribe_user($user_id, $class_id);
  91. }
  92. header('Location: class_list.php?filtreCours='.urlencode($course));
  93. exit ();
  94. }
  95. }
  96. }
  97. }
  98. Display :: display_header($tool_name);
  99. //api_display_tool_title($tool_name);
  100. $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
  101. $sql = "SELECT u.user_id,lastname,firstname,username FROM $tbl_user u LEFT JOIN $tbl_class_user cu ON u.user_id=cu.user_id AND class_id='$class_id' WHERE ".$target_name." LIKE '".$first_letter_left."%' AND class_id IS NULL ORDER BY ". (count($left_user_list) > 0 ? "(user_id IN(".implode(',', $left_user_list).")) DESC," : "")." ".$target_name;
  102. $result = api_sql_query($sql, __FILE__, __LINE__);
  103. $left_users = api_store_result($result);
  104. $sql = "SELECT u.user_id,lastname,firstname,username FROM $tbl_user u,$tbl_class_user cu WHERE cu.user_id=u.user_id AND class_id='$class_id' AND ".$target_name." LIKE '".$first_letter_right."%' ORDER BY ". (count($right_user_list) > 0 ? "(user_id IN(".implode(',', $right_user_list).")) DESC," : "")." ".$target_name;
  105. $result = api_sql_query($sql, __FILE__, __LINE__);
  106. $right_users = api_store_result($result);
  107. if (!empty ($error_message))
  108. {
  109. Display :: display_normal_message($error_message);
  110. }
  111. ?>
  112. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?course=<?php echo urlencode($course); ?>&amp;idclass=<?php echo $class_id; ?>" style="margin:0px;">
  113. <input type="hidden" name="formSent" value="1"/>
  114. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  115. <tr>
  116. <td width="40%" align="center">
  117. <b><?php echo get_lang('UsersOutsideClass'); ?> :</b>
  118. <br/><br/>
  119. <?php echo get_lang('FirstLetterUser'); ?> :
  120. <select name="firstLetterLeft" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  121. <option value="">--</option>
  122. <?php
  123. echo Display :: get_alphabet_options($first_letter_left);
  124. ?>
  125. </select>
  126. </td>
  127. <td width="20%">&nbsp;</td>
  128. <td width="40%" align="center">
  129. <b><?php echo get_lang('UsersInsideClass'); ?> :</b>
  130. <br/><br/>
  131. <?php echo get_lang('FirstLetterUser'); ?> :
  132. <select name="firstLetterRight" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  133. <option value="">--</option>
  134. <?php
  135. echo Display :: get_alphabet_options($first_letter_right);
  136. ?>
  137. </select>
  138. </td>
  139. </tr>
  140. <tr>
  141. <td width="40%" align="center">
  142. <select name="LeftUserList[]" multiple="multiple" size="20" style="width:230px;">
  143. <?php
  144. foreach ($left_users as $user)
  145. {
  146. ?>
  147. <option value="<?php echo $user['user_id']; ?>" <?php if (in_array($user['user_id'],$left_user_list)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?></option>
  148. <?php
  149. }
  150. ?>
  151. </select>
  152. </td>
  153. <td width="20%" valign="middle" align="center">
  154. <input type="submit" name="addToClass" value="<?php echo get_lang('AddToClass'); ?> &gt;&gt;"/>
  155. <br/><br/>
  156. <input type="submit" name="removeFromClass" value="&lt;&lt; <?php echo get_lang('RemoveFromClass'); ?>"/>
  157. </td>
  158. <td width="40%" align="center">
  159. <select name="RightUserList[]" multiple="multiple" size="20" style="width:230px;">
  160. <?php
  161. foreach ($right_users as $user)
  162. {
  163. ?>
  164. <option value="<?php echo $user['user_id']; ?>" <?php if (in_array($user['user_id'],$right_user_list)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?></option>
  165. <?php
  166. }
  167. ?>
  168. </select>
  169. </td>
  170. </tr>
  171. </table>
  172. </form>
  173. <?php
  174. /*
  175. ==============================================================================
  176. FOOTER
  177. ==============================================================================
  178. */
  179. Display :: display_footer();
  180. ?>