subscribe_user2class.php 6.8 KB

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