access_url_add_courses_to_url.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $first_letter_course = '';
  21. $courses = [];
  22. $url_list = [];
  23. $tbl_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
  24. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  25. /* Header */
  26. $tool_name = get_lang('Add courses to an URL');
  27. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  28. $interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('Multiple access URL / Branding')];
  29. Display :: display_header($tool_name);
  30. echo '<div class="actions">';
  31. echo Display::url(
  32. Display::return_icon('edit.png', get_lang('Edit courses of an URL'), ''),
  33. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
  34. );
  35. echo '</div>';
  36. api_display_tool_title($tool_name);
  37. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  38. $form_sent = $_POST['form_sent'];
  39. $courses = is_array($_POST['course_list']) ? $_POST['course_list'] : [];
  40. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
  41. $first_letter_course = $_POST['first_letter_course'];
  42. if ($form_sent == 1) {
  43. if (count($courses) == 0 || count($url_list) == 0) {
  44. echo Display::return_message(get_lang('At least one course and one URL'), 'error');
  45. } else {
  46. UrlManager::add_courses_to_urls($courses, $url_list);
  47. echo Display::return_message(get_lang('Course registered to the URL'), 'confirm');
  48. }
  49. }
  50. }
  51. $first_letter_course_lower = Database::escape_string(api_strtolower($first_letter_course));
  52. $sql = "SELECT code, title FROM $tbl_course
  53. WHERE
  54. title LIKE '".$first_letter_course_lower."%' OR
  55. title LIKE '".$first_letter_course_lower."%'
  56. ORDER BY title, code DESC ";
  57. $result = Database::query($sql);
  58. $db_courses = Database::store_result($result);
  59. unset($result);
  60. $sql = "SELECT id, url FROM $tbl_access_url WHERE active = 1 ORDER BY url";
  61. $result = Database::query($sql);
  62. $db_urls = Database::store_result($result);
  63. unset($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('Course list'); ?></b>
  71. <br/><br/>
  72. <?php echo get_lang('First letter (code)'); ?> :
  73. <select name="first_letter_course" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  74. <option value="">--</option>
  75. <?php
  76. echo Display:: get_alphabet_options($first_letter_course);
  77. echo Display:: get_numeric_options(0, 9, $first_letter_course);
  78. ?>
  79. </select>
  80. </td>
  81. <td width="20%">&nbsp;</td>
  82. <td width="40%" align="center">
  83. <b><?php echo get_lang('URL list'); ?> :</b>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td width="40%" align="center">
  88. <select name="course_list[]" multiple="multiple" size="20" style="width:400px;">
  89. <?php foreach ($db_courses as $course) {
  90. ?>
  91. <option value="<?php echo $course['code']; ?>" <?php if (in_array($course['code'], $courses)) {
  92. echo 'selected="selected"';
  93. } ?>>
  94. <?php echo $course['title'].' ('.$course['code'].')'; ?>
  95. </option>
  96. <?php
  97. } ?>
  98. </select>
  99. </td>
  100. <td width="20%" valign="middle" align="center">
  101. <button type="submit" class="add"> <?php echo get_lang('Add courses to that URL'); ?> </button>
  102. </td>
  103. <td width="40%" align="center">
  104. <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
  105. <?php foreach ($db_urls as $url_obj) {
  106. ?>
  107. <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
  108. echo 'selected="selected"';
  109. } ?>>
  110. <?php echo $url_obj['url']; ?>
  111. </option>
  112. <?php
  113. } ?>
  114. </select>
  115. </td>
  116. </tr>
  117. </table>
  118. </form>
  119. <?php
  120. Display :: display_footer();