access_url_add_users_to_url.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com>
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * This script allows platform admins to add users to urls.
  20. * It displays a list of users and a list of courses;
  21. * you can select multiple users and courses and then click on
  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. $this_section=SECTION_PLATFORM_ADMIN;
  30. require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
  31. api_protect_admin_script();
  32. if (!$_configuration['multiple_access_urls'])
  33. header('Location: index.php');
  34. /*
  35. -----------------------------------------------------------
  36. Global constants and variables
  37. -----------------------------------------------------------
  38. */
  39. $form_sent = 0;
  40. $first_letter_user = '';
  41. $first_letter_course = '';
  42. $courses = array ();
  43. $url_list = array();
  44. $users = array();
  45. $tbl_access_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  46. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  47. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  48. /*
  49. -----------------------------------------------------------
  50. Header
  51. -----------------------------------------------------------
  52. */
  53. $tool_name = get_lang('AddUsersToURL');
  54. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  55. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  56. /*
  57. ==============================================================================
  58. MAIN CODE
  59. ==============================================================================
  60. */
  61. Display :: display_header($tool_name);
  62. echo '<div class="actions" style="height:22px;">';
  63. echo '<div style="float:right;">
  64. <a href="'.api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php">'.Display::return_icon('edit.gif',get_lang('EditUsersToURL'),'').get_lang('EditUsersToURL').'</a>
  65. </div><br />';
  66. echo '</div>';
  67. api_display_tool_title($tool_name);
  68. if ($_POST['form_sent']) {
  69. $form_sent = $_POST['form_sent'];
  70. $users = is_array($_POST['user_list']) ? $_POST['user_list'] : array() ;
  71. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  72. $first_letter_user = $_POST['first_letter_user'];
  73. foreach($users as $key => $value) {
  74. $users[$key] = intval($value);
  75. }
  76. if ($form_sent == 1)
  77. {
  78. if ( count($users) == 0 || count($url_list) == 0) {
  79. Display :: display_error_message(get_lang('AtLeastOneUserAndOneURL'));
  80. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  81. } else {
  82. UrlManager::add_users_to_urls($users,$url_list);
  83. Display :: display_confirmation_message(get_lang('UsersBelongURL'));
  84. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  85. }
  86. }
  87. }
  88. /*
  89. -----------------------------------------------------------
  90. Display GUI
  91. -----------------------------------------------------------
  92. */
  93. if(empty($first_letter_user)) {
  94. $sql = "SELECT count(*) as nb_users FROM $tbl_user";
  95. $result = Database::query($sql, __FILE__, __LINE__);
  96. $num_row = Database::fetch_array($result);
  97. if($num_row['nb_users']>1000) {
  98. //if there are too much users to gracefully handle with the HTML select list,
  99. // assign a default filter on users names
  100. $first_letter_user = 'A';
  101. }
  102. unset($result);
  103. }
  104. $first_letter_user = Database::escape_string($first_letter_user);
  105. $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
  106. $sql = "SELECT user_id,lastname,firstname,username FROM $tbl_user
  107. WHERE ".$target_name." LIKE '".$first_letter_user."%' OR ".$target_name." LIKE '".api_strtolower($first_letter_user)."%'
  108. ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
  109. $result = Database::query($sql, __FILE__, __LINE__);
  110. $db_users = Database::store_result($result);
  111. unset($result);
  112. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  113. $result = Database::query($sql, __FILE__, __LINE__);
  114. $db_urls = Database::store_result($result);
  115. unset($result);
  116. ?>
  117. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  118. <input type="hidden" name="form_sent" value="1"/>
  119. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  120. <tr>
  121. <td width="40%" align="center">
  122. <b><?php echo get_lang('UserList'); ?></b>
  123. <br/><br/>
  124. <?php echo get_lang('FirstLetterUser'); ?> :
  125. <select name="first_letter_user" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  126. <option value="">--</option>
  127. <?php
  128. echo Display :: get_alphabet_options($first_letter_user);
  129. ?>
  130. </select>
  131. </td>
  132. <td width="20%">&nbsp;</td>
  133. <td width="40%" align="center">
  134. <b><?php echo get_lang('URLList'); ?> :</b>
  135. </td>
  136. </tr>
  137. <tr>
  138. <td width="40%" align="center">
  139. <select name="user_list[]" multiple="multiple" size="20" style="width:250px;">
  140. <?php
  141. foreach ($db_users as $user) {
  142. ?>
  143. <option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?></option>
  144. <?php
  145. }
  146. ?>
  147. </select>
  148. </td>
  149. <td width="20%" valign="middle" align="center">
  150. <input type="submit" value="<?php echo get_lang('AddToThatURL'); ?> &gt;&gt;"/>
  151. </td>
  152. <td width="40%" align="center">
  153. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  154. <?php
  155. foreach ($db_urls as $url_obj) {
  156. ?>
  157. <option value="<?php echo $url_obj['id']; ?>" <?php if(in_array($url_obj['id'],$url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?></option>
  158. <?php
  159. }
  160. ?>
  161. </select>
  162. </td>
  163. </tr>
  164. </table>
  165. </form>
  166. <?php
  167. /*
  168. ==============================================================================
  169. FOOTER
  170. ==============================================================================
  171. */
  172. Display :: display_footer();
  173. ?>