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