access_url_add_usergroup_to_url.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script allows platform admins to add users to urls.
  5. * It displays a list of users and a list of courses;
  6. * you can select multiple users and courses and then click on
  7. * @package chamilo.admin
  8. * @author Julio Montoya <gugli100@gmail.com>
  9. */
  10. // name of the language file that needs to be included
  11. $language_file = 'admin';
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  16. $this_section = SECTION_PLATFORM_ADMIN;
  17. api_protect_global_admin_script();
  18. if (!api_get_multiple_access_url()) {
  19. header('Location: index.php');
  20. exit;
  21. }
  22. $userGroup = new UserGroup();
  23. $form_sent = 0;
  24. $firstLetterUserGroup = null;
  25. $courses = array();
  26. $url_list = array();
  27. $tbl_access_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  28. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  29. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  30. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  31. $tool_name = get_lang('AddUserGroupToURL');
  32. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  33. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  34. Display::display_header($tool_name);
  35. echo '<div class="actions">';
  36. echo Display::url(
  37. Display::return_icon('edit.png', get_lang('EditUserGroupToURL'), ''),
  38. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  39. );
  40. echo '</div>';
  41. api_display_tool_title($tool_name);
  42. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  43. $form_sent = $_POST['form_sent'];
  44. $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : array() ;
  45. $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  46. $firstLetterUserGroup = $_POST['first_letter_user_group'];
  47. if ($form_sent == 1) {
  48. if (count($userGroups) == 0 || count($urlList) == 0) {
  49. Display :: display_error_message(get_lang('AtLeastOneUserGroupAndOneURL'));
  50. } else {
  51. UrlManager::addUserGroupListToUrl($userGroups, $urlList);
  52. Display::display_confirmation_message(get_lang('UserGroupBelongURL'));
  53. }
  54. }
  55. }
  56. $firstLetterUser = null;
  57. if ($userGroup->getTotalCount() > 1000) {
  58. //if there are too much num_courses to gracefully handle with the HTML select list,
  59. // assign a default filter on users names
  60. $firstLetterUser = 'A';
  61. }
  62. $dbUserGroups = $userGroup->filterByFirstLetter($firstLetterUserGroup);
  63. $sql = "SELECT id, url FROM $tbl_access_url WHERE active = 1 ORDER BY url";
  64. $result = Database::query($sql);
  65. $db_urls = Database::store_result($result);
  66. ?>
  67. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  68. <input type="hidden" name="form_sent" value="1"/>
  69. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  70. <tr>
  71. <td width="40%" align="center">
  72. <b><?php echo get_lang('UserGroupList'); ?></b>
  73. <br/><br/>
  74. <?php echo get_lang('FirstLetter'); ?> :
  75. <select name="first_letter_user_group" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  76. <option value="">--</option>
  77. <?php
  78. echo Display::get_alphabet_options($firstLetterUserGroup);
  79. echo Display::get_numeric_options(0, 9, $firstLetterUserGroup);
  80. ?>
  81. </select>
  82. </td>
  83. <td width="20%">&nbsp;</td>
  84. <td width="40%" align="center">
  85. <b><?php echo get_lang('URLList'); ?> :</b>
  86. </td>
  87. </tr>
  88. <tr>
  89. <td width="40%" align="center">
  90. <select name="user_group_list[]" multiple="multiple" size="20" style="width:400px;">
  91. <?php foreach ($dbUserGroups as $item) { ?>
  92. <option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) echo 'selected="selected"'; ?>><?php echo $item['name']; ?>
  93. </option>
  94. <?php } ?>
  95. </select>
  96. </td>
  97. <td width="20%" valign="middle" align="center">
  98. <button type="submit" class="add"> <?php echo get_lang('AddUserGroupToThatURL'); ?> </button>
  99. </td>
  100. <td width="40%" align="center">
  101. <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
  102. <?php foreach ($db_urls as $url_obj) { ?>
  103. <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?>
  104. </option>
  105. <?php } ?>
  106. </select>
  107. </td>
  108. </tr>
  109. </table>
  110. </form>
  111. <?php
  112. Display :: display_footer();