access_url_add_usergroup_to_url.php 4.6 KB

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