access_url_add_courses_to_url.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * This script allows platform admins to add users to urls.
  6. * It displays a list of users and a list of courses;
  7. * you can select multiple users and courses and then click on
  8. * @package chamilo.admin
  9. * @author Julio Montoya <gugli100@gmail.com>
  10. */
  11. $cidReset = true;
  12. //require_once '../inc/global.inc.php';
  13. $this_section=SECTION_PLATFORM_ADMIN;
  14. api_protect_global_admin_script();
  15. if (!api_get_multiple_access_url()) {
  16. header('Location: index.php');
  17. exit;
  18. }
  19. $form_sent = 0;
  20. $first_letter_course = '';
  21. $courses = array ();
  22. $url_list = array();
  23. $users = array();
  24. $tbl_access_url_rel_course = Database:: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  25. $tbl_access_url = Database:: get_main_table(TABLE_MAIN_ACCESS_URL);
  26. $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
  27. $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  28. /* Header */
  29. $tool_name = get_lang('AddCoursesToURL');
  30. $interbreadcrumb[] = array ('url' => Container::getRouter()->generate('administration'), 'name' => get_lang('PlatformAdmin'));
  31. $interbreadcrumb[] = array ('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('EditCoursesToURL'), ''),
  36. api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_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. $courses = is_array($_POST['course_list']) ? $_POST['course_list'] : array() ;
  43. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  44. $first_letter_course = $_POST['first_letter_course'];
  45. foreach ($users as $key => $value) {
  46. $users[$key] = intval($value);
  47. }
  48. if ($form_sent == 1) {
  49. if (count($courses) == 0 || count($url_list) == 0) {
  50. Display :: display_error_message(get_lang('AtLeastOneCourseAndOneURL'));
  51. } else {
  52. UrlManager::add_courses_to_urls($courses, $url_list);
  53. Display :: display_confirmation_message(get_lang('CourseBelongURL'));
  54. }
  55. }
  56. }
  57. if (empty($first_letter_user)) {
  58. $sql = "SELECT count(*) as num_courses FROM $tbl_course";
  59. $result = Database::query($sql);
  60. $num_row = Database::fetch_array($result);
  61. if ($num_row['num_courses']>1000) {
  62. //if there are too much num_courses to gracefully handle with the HTML select list,
  63. // assign a default filter on users names
  64. $first_letter_user = 'A';
  65. }
  66. unset($result);
  67. }
  68. $first_letter_course_lower = Database::escape_string(api_strtolower($first_letter_course));
  69. $sql = "SELECT code, title FROM $tbl_course
  70. WHERE title LIKE '".$first_letter_course_lower."%' OR title LIKE '".$first_letter_course_lower."%'
  71. ORDER BY title, code DESC ";
  72. $result = Database::query($sql);
  73. $db_courses = Database::store_result($result);
  74. unset($result);
  75. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  76. $result = Database::query($sql);
  77. $db_urls = Database::store_result($result);
  78. unset($result);
  79. ?>
  80. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  81. <input type="hidden" name="form_sent" value="1"/>
  82. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  83. <tr>
  84. <td width="40%" align="center">
  85. <b><?php echo get_lang('CourseList'); ?></b>
  86. <br/><br/>
  87. <?php echo get_lang('FirstLetterCourse'); ?> :
  88. <select name="first_letter_course" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  89. <option value="">--</option>
  90. <?php
  91. echo Display :: get_alphabet_options($first_letter_course);
  92. echo Display :: get_numeric_options(0,9,$first_letter_course);
  93. ?>
  94. </select>
  95. </td>
  96. <td width="20%">&nbsp;</td>
  97. <td width="40%" align="center">
  98. <b><?php echo get_lang('URLList'); ?> :</b>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td width="40%" align="center">
  103. <select name="course_list[]" multiple="multiple" size="20" style="width:400px;">
  104. <?php foreach ($db_courses as $course) { ?>
  105. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo $course['title'].' ('.$course['code'].')'; ?>
  106. </option>
  107. <?php } ?>
  108. </select>
  109. </td>
  110. <td width="20%" valign="middle" align="center">
  111. <button type="submit" class="add"> <?php echo get_lang('AddCoursesToThatURL'); ?> </button>
  112. </td>
  113. <td width="40%" align="center">
  114. <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
  115. <?php foreach ($db_urls as $url_obj) { ?>
  116. <option value="<?php echo $url_obj['id']; ?>" <?php if(in_array($url_obj['id'],$url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?>
  117. </option>
  118. <?php } ?>
  119. </select>
  120. </td>
  121. </tr>
  122. </table>
  123. </form>
  124. <?php
  125. Display :: display_footer();