access_url_add_usergroup_to_url.php 4.5 KB

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