subscribe_user2class.php 6.9 KB

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