access_url_add_courses_to_url.php 5.2 KB

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