access_url_add_courses_to_url.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com>
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * This script allows platform admins to add users to urls.
  21. * It displays a list of users and a list of courses;
  22. * you can select multiple users and courses and then click on
  23. * @package dokeos.admin
  24. ==============================================================================
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'admin';
  28. $cidReset = true;
  29. require ('../inc/global.inc.php');
  30. $this_section=SECTION_PLATFORM_ADMIN;
  31. require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
  32. api_protect_admin_script();
  33. if (!$_configuration['multiple_access_urls'])
  34. header('Location: index.php');
  35. /*
  36. -----------------------------------------------------------
  37. Global constants and variables
  38. -----------------------------------------------------------
  39. */
  40. $form_sent = 0;
  41. $first_letter_course = '';
  42. $courses = array ();
  43. $url_list = array();
  44. $users = array();
  45. $tbl_access_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  46. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  47. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  48. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  49. /*
  50. -----------------------------------------------------------
  51. Header
  52. -----------------------------------------------------------
  53. */
  54. $tool_name = get_lang('AddCoursesToURL');
  55. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  56. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  57. /*
  58. ==============================================================================
  59. MAIN CODE
  60. ==============================================================================
  61. */
  62. Display :: display_header($tool_name);
  63. echo '<div class="actions" style="height:22px;">';
  64. echo '<div style="float:right;">
  65. <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>
  66. </div><br />';
  67. echo '</div>';
  68. api_display_tool_title($tool_name);
  69. if ($_POST['form_sent']) {
  70. $form_sent = $_POST['form_sent'];
  71. $courses = is_array($_POST['course_list']) ? $_POST['course_list'] : array() ;
  72. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  73. $first_letter_course = $_POST['first_letter_course'];
  74. foreach($users as $key => $value) {
  75. $users[$key] = intval($value);
  76. }
  77. if ($form_sent == 1) {
  78. if ( count($courses) == 0 || count($url_list) == 0) {
  79. Display :: display_error_message(get_lang('AtLeastOneCourseAndOneURL'));
  80. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  81. } else {
  82. UrlManager::add_courses_to_urls($courses,$url_list);
  83. Display :: display_confirmation_message(get_lang('CourseBelongURL'));
  84. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  85. }
  86. }
  87. }
  88. /*
  89. -----------------------------------------------------------
  90. Display GUI
  91. -----------------------------------------------------------
  92. */
  93. if(empty($first_letter_user))
  94. {
  95. $sql = "SELECT count(*) as num_courses FROM $tbl_course";
  96. $result = Database::query($sql, __FILE__, __LINE__);
  97. $num_row = Database::fetch_array($result);
  98. if($num_row['num_courses']>1000)
  99. {//if there are too much num_courses to gracefully handle with the HTML select list,
  100. // assign a default filter on users names
  101. $first_letter_user = 'A';
  102. }
  103. unset($result);
  104. }
  105. $first_letter_course = Database::escape_string($first_letter_course);
  106. $sql = "SELECT code, title FROM $tbl_course
  107. WHERE title LIKE '".$first_letter_course."%' OR title LIKE '".api_strtolower($first_letter_course)."%'
  108. ORDER BY title, code DESC ";
  109. $result = Database::query($sql, __FILE__, __LINE__);
  110. $db_courses = Database::store_result($result);
  111. unset($result);
  112. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  113. $result = Database::query($sql, __FILE__, __LINE__);
  114. $db_urls = Database::store_result($result);
  115. unset($result);
  116. ?>
  117. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  118. <input type="hidden" name="form_sent" value="1"/>
  119. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  120. <tr>
  121. <td width="40%" align="center">
  122. <b><?php echo get_lang('CourseList'); ?></b>
  123. <br/><br/>
  124. <?php echo get_lang('FirstLetterCourse'); ?> :
  125. <select name="first_letter_course" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  126. <option value="">--</option>
  127. <?php
  128. echo Display :: get_alphabet_options($first_letter_course);
  129. echo Display :: get_numeric_options(0,9,$first_letter_course);
  130. ?>
  131. </select>
  132. </td>
  133. <td width="20%">&nbsp;</td>
  134. <td width="40%" align="center">
  135. <b><?php echo get_lang('URLList'); ?> :</b>
  136. </td>
  137. </tr>
  138. <tr>
  139. <td width="40%" align="center">
  140. <select name="course_list[]" multiple="multiple" size="20" style="width:230px;">
  141. <?php
  142. foreach ($db_courses as $course) {
  143. ?>
  144. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo $course['title'].' ('.$course['code'].')'; ?></option>
  145. <?php
  146. }
  147. ?>
  148. </select>
  149. </td>
  150. <td width="20%" valign="middle" align="center">
  151. <input type="submit" value="<?php echo get_lang('AddCoursesToThatURL'); ?> &gt;&gt;"/>
  152. </td>
  153. <td width="40%" align="center">
  154. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  155. <?php
  156. foreach ($db_urls as $url_obj) {
  157. ?>
  158. <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>
  159. <?php
  160. }
  161. ?>
  162. </select>
  163. </td>
  164. </tr>
  165. </table>
  166. </form>
  167. <?php
  168. /*
  169. ==============================================================================
  170. FOOTER
  171. ==============================================================================
  172. */
  173. Display :: display_footer();
  174. ?>