subscribe_user2class.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. /**
  7. * Code
  8. */
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. $course = $_GET['course'];
  14. $class_id = intval($_GET['idclass']);
  15. $form_sent = 0;
  16. $error_message = '';
  17. $first_letter_left = '';
  18. $first_letter_right = '';
  19. $left_user_list = array();
  20. $right_user_list = array();
  21. // Database table definitions
  22. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  23. $tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
  24. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  25. $sql = "SELECT name FROM $tbl_class WHERE id='$class_id'";
  26. $result = Database::query($sql);
  27. if (!list ($class_name) = Database::fetch_row($result)) {
  28. header('Location: class_list.php?filtreCours=' . urlencode($course));
  29. exit();
  30. }
  31. $noPHP_SELF = true;
  32. $tool_name = get_lang('AddUsersToAClass') . ' (' . $class_name . ')';
  33. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  34. $interbreadcrumb[] = array("url" => "class_list.php?filtreCours=" . urlencode($course), "name" => get_lang('AdminClasses'));
  35. if ($_POST['formSent']) {
  36. $form_sent = $_POST['formSent'];
  37. $first_letter_left = $_POST['firstLetterLeft'];
  38. $first_letter_right = $_POST['firstLetterRight'];
  39. $left_user_list = is_array($_POST['LeftUserList']) ? $_POST['LeftUserList'] : array();
  40. $right_user_list = is_array($_POST['RightUserList']) ? $_POST['RightUserList'] : array();
  41. $add_to_class = empty($_POST['addToClass']) ? 0 : 1;
  42. $remove_from_class = empty($_POST['removeFromClass']) ? 0 : 1;
  43. if ($form_sent == 1) {
  44. if ($add_to_class) {
  45. if (count($left_user_list) == 0) {
  46. $error_message = get_lang('AtLeastOneUser');
  47. } else {
  48. foreach ($left_user_list as $user_id) {
  49. ClassManager :: add_user($user_id, $class_id);
  50. }
  51. header('Location: class_list.php?filtreCours=' . urlencode($course));
  52. exit();
  53. }
  54. } elseif ($remove_from_class) {
  55. if (count($right_user_list) == 0)
  56. $error_message = get_lang('AtLeastOneUser');
  57. else {
  58. foreach ($right_user_list as $index => $user_id) {
  59. ClassManager :: unsubscribe_user($user_id, $class_id);
  60. }
  61. header('Location: class_list.php?filtreCours=' . urlencode($course));
  62. exit();
  63. }
  64. }
  65. }
  66. }
  67. Display :: display_header($tool_name);
  68. //api_display_tool_title($tool_name);
  69. $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
  70. $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;
  71. $result = Database::query($sql);
  72. $left_users = Database::store_result($result);
  73. $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;
  74. $result = Database::query($sql);
  75. $right_users = Database::store_result($result);
  76. if (!empty($error_message)) {
  77. Display :: display_normal_message($error_message);
  78. }
  79. ?>
  80. <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;">
  81. <input type="hidden" name="formSent" value="1"/>
  82. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  83. <tr>
  84. <td width="40%" align="center">
  85. <b><?php echo get_lang('UsersOutsideClass'); ?> :</b>
  86. <br/><br/>
  87. <?php echo get_lang('FirstLetterUser'); ?> :
  88. <select name="firstLetterLeft" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  89. <option value="">--</option>
  90. <?php
  91. echo Display :: get_alphabet_options($first_letter_left);
  92. ?>
  93. </select>
  94. </td>
  95. <td width="20%">&nbsp;</td>
  96. <td width="40%" align="center">
  97. <b><?php echo get_lang('UsersInsideClass'); ?> :</b>
  98. <br/><br/>
  99. <?php echo get_lang('FirstLetterUser'); ?> :
  100. <select name="firstLetterRight" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  101. <option value="">--</option>
  102. <?php
  103. echo Display :: get_alphabet_options($first_letter_right);
  104. ?>
  105. </select>
  106. </td>
  107. </tr>
  108. <tr>
  109. <td width="40%" align="center">
  110. <select name="LeftUserList[]" multiple="multiple" size="20" style="width:230px;">
  111. <?php
  112. foreach ($left_users as $user) {
  113. ?>
  114. <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>
  115. <?php
  116. }
  117. ?>
  118. </select>
  119. </td>
  120. <td width="20%" valign="middle" align="center">
  121. <input type="submit" name="addToClass" value="<?php echo get_lang('AddToClass'); ?> &gt;&gt;"/>
  122. <br/><br/>
  123. <input type="submit" name="removeFromClass" value="&lt;&lt; <?php echo get_lang('RemoveFromClass'); ?>"/>
  124. </td>
  125. <td width="40%" align="center">
  126. <select name="RightUserList[]" multiple="multiple" size="20" style="width:230px;">
  127. <?php
  128. foreach ($right_users as $user) {
  129. ?>
  130. <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>
  131. <?php
  132. }
  133. ?>
  134. </select>
  135. </td>
  136. </tr>
  137. </table>
  138. </form>
  139. <?php
  140. Display :: display_footer();