access_url_add_sessions_to_url.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_session = '';
  42. $sessions = array ();
  43. $url_list = array();
  44. $users = array();
  45. $tbl_access_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  46. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  47. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  48. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  49. /*
  50. -----------------------------------------------------------
  51. Header
  52. -----------------------------------------------------------
  53. */
  54. $tool_name = get_lang('AddSessionToURL');
  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_sessions_to_url.php">'.Display::return_icon('course_del.gif',get_lang('EditSessionToURL'),'').get_lang('EditSessionToURL').'</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. $sessions = is_array($_POST['session_list']) ? $_POST['session_list'] : array() ;
  72. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  73. $first_letter_session = $_POST['first_letter_session'];
  74. foreach($users as $key => $value) {
  75. $users[$key] = intval($value);
  76. }
  77. if ($form_sent == 1) {
  78. if ( count($sessions) == 0 || count($url_list) == 0) {
  79. Display :: display_error_message(get_lang('AtLeastOneSessionAndOneURL'));
  80. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  81. } else {
  82. UrlManager::add_sessions_to_urls($sessions,$url_list);
  83. Display :: display_confirmation_message(get_lang('SessionBelongURL'));
  84. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  85. }
  86. }
  87. }
  88. /*
  89. -----------------------------------------------------------
  90. Display GUI
  91. -----------------------------------------------------------
  92. */
  93. /*
  94. if(empty($first_letter_user)) {
  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. */
  106. $first_letter_session = Database::escape_string($first_letter_session);
  107. $sql = "SELECT id, name FROM $tbl_session
  108. WHERE name LIKE '".$first_letter_session."%' OR name LIKE '".api_strtolower($first_letter_session)."%'
  109. ORDER BY name DESC ";
  110. $result = Database::query($sql, __FILE__, __LINE__);
  111. $db_sessions = Database::store_result($result);
  112. unset($result);
  113. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  114. $result = Database::query($sql, __FILE__, __LINE__);
  115. $db_urls = Database::store_result($result);
  116. unset($result);
  117. ?>
  118. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  119. <input type="hidden" name="form_sent" value="1"/>
  120. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  121. <tr>
  122. <td width="40%" align="center">
  123. <b><?php echo get_lang('SessionList'); ?></b>
  124. <br/><br/>
  125. <?php echo get_lang('FirstLetterSession'); ?> :
  126. <select name="first_letter_session" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  127. <option value="">--</option>
  128. <?php
  129. echo Display :: get_alphabet_options($first_letter_session);
  130. echo Display :: get_numeric_options(0,9,$first_letter_session);
  131. ?>
  132. </select>
  133. </td>
  134. <td width="20%">&nbsp;</td>
  135. <td width="40%" align="center">
  136. <b><?php echo get_lang('URLList'); ?> :</b>
  137. </td>
  138. </tr>
  139. <tr>
  140. <td width="40%" align="center">
  141. <select name="session_list[]" multiple="multiple" size="20" style="width:230px;">
  142. <?php
  143. foreach ($db_sessions as $session) {
  144. ?>
  145. <option value="<?php echo $session['id']; ?>"
  146. <?php if(in_array($session['id'],$sessions))
  147. echo 'selected="selected"'; ?>>
  148. <?php echo $session['name']; ?></option>
  149. <?php
  150. }
  151. ?>
  152. </select>
  153. </td>
  154. <td width="20%" valign="middle" align="center">
  155. <input type="submit" value="<?php echo get_lang('AddSessionsToThatURL'); ?> &gt;&gt;"/>
  156. </td>
  157. <td width="40%" align="center">
  158. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  159. <?php
  160. foreach ($db_urls as $url_obj) {
  161. ?>
  162. <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>
  163. <?php
  164. }
  165. ?>
  166. </select>
  167. </td>
  168. </tr>
  169. </table>
  170. </form>
  171. <?php
  172. /*
  173. ==============================================================================
  174. FOOTER
  175. ==============================================================================
  176. */
  177. Display :: display_footer();
  178. ?>