access_url_add_users_to_url.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $users = $_GET['users'];
  40. $form_sent = 0;
  41. $first_letter_user = '';
  42. $first_letter_course = '';
  43. $courses = array ();
  44. $url_list = array();
  45. $users = array();
  46. $tbl_access_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  47. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  48. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  49. /*
  50. -----------------------------------------------------------
  51. Header
  52. -----------------------------------------------------------
  53. */
  54. $tool_name = get_lang('AddUsersToURL');
  55. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  56. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  57. /*
  58. ==============================================================================
  59. MAIN CODE
  60. ==============================================================================
  61. */
  62. Display :: display_header($tool_name);
  63. echo '<div class="actions" style="height:22px;">';
  64. echo '<div style="float:right;">
  65. <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>
  66. </div><br />';
  67. echo '</div>';
  68. api_display_tool_title($tool_name);
  69. if ($_POST['form_sent']) {
  70. $form_sent = $_POST['form_sent'];
  71. $users = is_array($_POST['user_list']) ? $_POST['user_list'] : array() ;
  72. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  73. $first_letter_user = $_POST['first_letter_user'];
  74. foreach($users as $key => $value) {
  75. $users[$key] = intval($value);
  76. }
  77. if ($form_sent == 1)
  78. {
  79. if ( count($users) == 0 || count($url_list) == 0) {
  80. Display :: display_error_message(get_lang('AtLeastOneUserAndOneURL'));
  81. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  82. } else {
  83. UrlManager::add_users_to_urls($users,$url_list);
  84. Display :: display_confirmation_message(get_lang('UsersBelongURL'));
  85. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  86. }
  87. }
  88. }
  89. /*
  90. -----------------------------------------------------------
  91. Display GUI
  92. -----------------------------------------------------------
  93. */
  94. if(empty($first_letter_user)) {
  95. $sql = "SELECT count(*) as nb_users FROM $tbl_user";
  96. $result = api_sql_query($sql, __FILE__, __LINE__);
  97. $num_row = Database::fetch_array($result);
  98. if($num_row['nb_users']>1000) {
  99. //if there are too much users to gracefully handle with the HTML select list,
  100. // assign a default filter on users names
  101. $first_letter_user = 'A';
  102. }
  103. unset($result);
  104. }
  105. $sql = "SELECT user_id,lastname,firstname,username FROM $tbl_user
  106. WHERE lastname LIKE '".$first_letter_user."%' OR lastname LIKE '".strtolower($first_letter_user)."%'
  107. ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." lastname";
  108. $result = api_sql_query($sql, __FILE__, __LINE__);
  109. $db_users = api_store_result($result);
  110. unset($result);
  111. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  112. $result = api_sql_query($sql, __FILE__, __LINE__);
  113. $db_urls = api_store_result($result);
  114. unset($result);
  115. ?>
  116. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  117. <input type="hidden" name="form_sent" value="1"/>
  118. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  119. <tr>
  120. <td width="40%" align="center">
  121. <b><?php echo get_lang('UserList'); ?></b>
  122. <br/><br/>
  123. <?php echo get_lang('FirstLetterUser'); ?> :
  124. <select name="first_letter_user" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  125. <option value="">--</option>
  126. <?php
  127. echo Display :: get_alphabet_options($first_letter_user);
  128. ?>
  129. </select>
  130. </td>
  131. <td width="20%">&nbsp;</td>
  132. <td width="40%" align="center">
  133. <b><?php echo get_lang('URLList'); ?> :</b>
  134. </td>
  135. </tr>
  136. <tr>
  137. <td width="40%" align="center">
  138. <select name="user_list[]" multiple="multiple" size="20" style="width:250px;">
  139. <?php
  140. foreach ($db_users as $user) {
  141. ?>
  142. <option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'; ?></option>
  143. <?php
  144. }
  145. ?>
  146. </select>
  147. </td>
  148. <td width="20%" valign="middle" align="center">
  149. <input type="submit" value="<?php echo get_lang('AddToThatURL'); ?> &gt;&gt;"/>
  150. </td>
  151. <td width="40%" align="center">
  152. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  153. <?php
  154. foreach ($db_urls as $url_obj) {
  155. ?>
  156. <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>
  157. <?php
  158. }
  159. ?>
  160. </select>
  161. </td>
  162. </tr>
  163. </table>
  164. </form>
  165. <?php
  166. /*
  167. ==============================================================================
  168. FOOTER
  169. ==============================================================================
  170. */
  171. Display :: display_footer();
  172. ?>