access_url_add_usergroup_to_url.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $firstLetterUserGroup = null;
  22. $courses = [];
  23. $url_list = [];
  24. $tbl_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
  25. $tool_name = get_lang('Add group to URL');
  26. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  27. $interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('Multiple access URL / Branding')];
  28. Display::display_header($tool_name);
  29. echo '<div class="actions">';
  30. echo Display::url(
  31. Display::return_icon('edit.png', get_lang('Edit groups for one URL'), ''),
  32. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
  33. );
  34. echo '</div>';
  35. api_display_tool_title($tool_name);
  36. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  37. $form_sent = $_POST['form_sent'];
  38. $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : [];
  39. $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
  40. $firstLetterUserGroup = $_POST['first_letter_user_group'];
  41. if ($form_sent == 1) {
  42. if (count($userGroups) == 0 || count($urlList) == 0) {
  43. echo Display::return_message(get_lang('You need to select at least one group and one site'), 'error');
  44. } else {
  45. UrlManager::addUserGroupListToUrl($userGroups, $urlList);
  46. echo Display::return_message(get_lang('The group now belongs to the selected site'), 'confirm');
  47. }
  48. }
  49. }
  50. $firstLetterUser = null;
  51. if ($userGroup->getTotalCount() > 1000) {
  52. //if there are too much num_courses to gracefully handle with the HTML select list,
  53. // assign a default filter on users names
  54. $firstLetterUser = 'A';
  55. }
  56. $dbUserGroups = $userGroup->filterByFirstLetter($firstLetterUserGroup);
  57. $sql = "SELECT id, url FROM $tbl_access_url WHERE active = 1 ORDER BY url";
  58. $result = Database::query($sql);
  59. $db_urls = Database::store_result($result);
  60. ?>
  61. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  62. <input type="hidden" name="form_sent" value="1"/>
  63. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  64. <tr>
  65. <td width="40%" align="center">
  66. <b><?php echo get_lang('User groups list'); ?></b>
  67. <br/><br/>
  68. <?php echo get_lang('First letter'); ?> :
  69. <select name="first_letter_user_group" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  70. <option value="">--</option>
  71. <?php
  72. echo Display::get_alphabet_options($firstLetterUserGroup);
  73. echo Display::get_numeric_options(0, 9, $firstLetterUserGroup);
  74. ?>
  75. </select>
  76. </td>
  77. <td width="20%">&nbsp;</td>
  78. <td width="40%" align="center">
  79. <b><?php echo get_lang('URL list'); ?> :</b>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td width="40%" align="center">
  84. <select name="user_group_list[]" multiple="multiple" size="20" style="width:400px;">
  85. <?php foreach ($dbUserGroups as $item) {
  86. ?>
  87. <option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) {
  88. echo 'selected="selected"';
  89. } ?>><?php echo $item['name']; ?>
  90. </option>
  91. <?php
  92. } ?>
  93. </select>
  94. </td>
  95. <td width="20%" valign="middle" align="center">
  96. <button type="submit" class="add"> <?php echo get_lang('Add user group to this URL'); ?> </button>
  97. </td>
  98. <td width="40%" align="center">
  99. <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
  100. <?php foreach ($db_urls as $url_obj) {
  101. ?>
  102. <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
  103. echo 'selected="selected"';
  104. } ?>><?php echo $url_obj['url']; ?>
  105. </option>
  106. <?php
  107. } ?>
  108. </select>
  109. </td>
  110. </tr>
  111. </table>
  112. </form>
  113. <?php
  114. Display :: display_footer();