access_url_add_courses_to_url.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. $form_sent = 0;
  21. $first_letter_course = '';
  22. $courses = [];
  23. $url_list = [];
  24. $users = [];
  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. /* Header */
  30. $tool_name = get_lang('AddCoursesToURL');
  31. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  32. $interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
  33. Display :: display_header($tool_name);
  34. echo '<div class="actions">';
  35. echo Display::url(
  36. Display::return_icon('edit.png', get_lang('EditCoursesToURL'), ''),
  37. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  38. );
  39. echo '</div>';
  40. api_display_tool_title($tool_name);
  41. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  42. $form_sent = $_POST['form_sent'];
  43. $courses = is_array($_POST['course_list']) ? $_POST['course_list'] : [];
  44. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
  45. $first_letter_course = $_POST['first_letter_course'];
  46. foreach ($users as $key => $value) {
  47. $users[$key] = intval($value);
  48. }
  49. if ($form_sent == 1) {
  50. if (count($courses) == 0 || count($url_list) == 0) {
  51. echo Display::return_message(get_lang('AtLeastOneCourseAndOneURL'), 'error');
  52. } else {
  53. UrlManager::add_courses_to_urls($courses, $url_list);
  54. echo Display::return_message(get_lang('CourseBelongURL'), 'confirm');
  55. }
  56. }
  57. }
  58. if (empty($first_letter_user)) {
  59. $sql = "SELECT count(*) as num_courses FROM $tbl_course";
  60. $result = Database::query($sql);
  61. $num_row = Database::fetch_array($result);
  62. if ($num_row['num_courses'] > 1000) {
  63. //if there are too much num_courses to gracefully handle with the HTML select list,
  64. // assign a default filter on users names
  65. $first_letter_user = 'A';
  66. }
  67. unset($result);
  68. }
  69. $first_letter_course_lower = Database::escape_string(api_strtolower($first_letter_course));
  70. $sql = "SELECT code, title FROM $tbl_course
  71. WHERE title LIKE '".$first_letter_course_lower."%' OR title LIKE '".$first_letter_course_lower."%'
  72. ORDER BY title, code DESC ";
  73. $result = Database::query($sql);
  74. $db_courses = Database::store_result($result);
  75. unset($result);
  76. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  77. $result = Database::query($sql);
  78. $db_urls = Database::store_result($result);
  79. unset($result);
  80. ?>
  81. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  82. <input type="hidden" name="form_sent" value="1"/>
  83. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  84. <tr>
  85. <td width="40%" align="center">
  86. <b><?php echo get_lang('CourseList'); ?></b>
  87. <br/><br/>
  88. <?php echo get_lang('FirstLetterCourse'); ?> :
  89. <select name="first_letter_course" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  90. <option value="">--</option>
  91. <?php
  92. echo Display:: get_alphabet_options($first_letter_course);
  93. echo Display:: get_numeric_options(0, 9, $first_letter_course);
  94. ?>
  95. </select>
  96. </td>
  97. <td width="20%">&nbsp;</td>
  98. <td width="40%" align="center">
  99. <b><?php echo get_lang('URLList'); ?> :</b>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td width="40%" align="center">
  104. <select name="course_list[]" multiple="multiple" size="20" style="width:400px;">
  105. <?php foreach ($db_courses as $course) {
  106. ?>
  107. <option value="<?php echo $course['code']; ?>" <?php if (in_array($course['code'], $courses)) {
  108. echo 'selected="selected"';
  109. } ?>>
  110. <?php echo $course['title'].' ('.$course['code'].')'; ?>
  111. </option>
  112. <?php
  113. } ?>
  114. </select>
  115. </td>
  116. <td width="20%" valign="middle" align="center">
  117. <button type="submit" class="add"> <?php echo get_lang('AddCoursesToThatURL'); ?> </button>
  118. </td>
  119. <td width="40%" align="center">
  120. <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
  121. <?php foreach ($db_urls as $url_obj) {
  122. ?>
  123. <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
  124. echo 'selected="selected"';
  125. } ?>>
  126. <?php echo $url_obj['url']; ?>
  127. </option>
  128. <?php
  129. } ?>
  130. </select>
  131. </td>
  132. </tr>
  133. </table>
  134. </form>
  135. <?php
  136. Display :: display_footer();