access_url_add_sessions_to_url.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_session = '';
  26. $sessions = array ();
  27. $url_list = array();
  28. $users = array();
  29. $tbl_access_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  30. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  31. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  32. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  33. /* Header */
  34. $tool_name = get_lang('AddSessionToURL');
  35. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  36. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  37. /* MAIN CODE */
  38. Display :: display_header($tool_name);
  39. echo '<div class="actions" style="height:22px;">';
  40. echo '<div style="float:right;">
  41. <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>
  42. </div><br />';
  43. echo '</div>';
  44. api_display_tool_title($tool_name);
  45. if ($_POST['form_sent']) {
  46. $form_sent = $_POST['form_sent'];
  47. $sessions = is_array($_POST['session_list']) ? $_POST['session_list'] : array() ;
  48. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  49. $first_letter_session = $_POST['first_letter_session'];
  50. foreach($users as $key => $value) {
  51. $users[$key] = intval($value);
  52. }
  53. if ($form_sent == 1) {
  54. if ( count($sessions) == 0 || count($url_list) == 0) {
  55. Display :: display_error_message(get_lang('AtLeastOneSessionAndOneURL'));
  56. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  57. } else {
  58. UrlManager::add_sessions_to_urls($sessions,$url_list);
  59. Display :: display_confirmation_message(get_lang('SessionBelongURL'));
  60. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  61. }
  62. }
  63. }
  64. /*
  65. Display GUI
  66. */
  67. /*
  68. if(empty($first_letter_user)) {
  69. $sql = "SELECT count(*) as num_courses FROM $tbl_course";
  70. $result = Database::query($sql);
  71. $num_row = Database::fetch_array($result);
  72. if($num_row['num_courses']>1000)
  73. {//if there are too much num_courses to gracefully handle with the HTML select list,
  74. // assign a default filter on users names
  75. $first_letter_user = 'A';
  76. }
  77. unset($result);
  78. }
  79. */
  80. $first_letter_session = Database::escape_string($first_letter_session);
  81. $sql = "SELECT id, name FROM $tbl_session
  82. WHERE name LIKE '".$first_letter_session."%' OR name LIKE '".api_strtolower($first_letter_session)."%'
  83. ORDER BY name DESC ";
  84. $result = Database::query($sql);
  85. $db_sessions = 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('SessionList'); ?></b>
  98. <br/><br/>
  99. <?php echo get_lang('FirstLetterSession'); ?> :
  100. <select name="first_letter_session" 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_session);
  104. echo Display :: get_numeric_options(0,9,$first_letter_session);
  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="session_list[]" multiple="multiple" size="20" style="width:230px;">
  116. <?php
  117. foreach ($db_sessions as $session) {
  118. ?>
  119. <option value="<?php echo $session['id']; ?>"
  120. <?php if(in_array($session['id'],$sessions))
  121. echo 'selected="selected"'; ?>>
  122. <?php echo $session['name']; ?></option>
  123. <?php
  124. }
  125. ?>
  126. </select>
  127. </td>
  128. <td width="20%" valign="middle" align="center">
  129. <input type="submit" value="<?php echo get_lang('AddSessionsToThatURL'); ?> &gt;&gt;"/>
  130. </td>
  131. <td width="40%" align="center">
  132. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  133. <?php
  134. foreach ($db_urls as $url_obj) {
  135. ?>
  136. <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>
  137. <?php
  138. }
  139. ?>
  140. </select>
  141. </td>
  142. </tr>
  143. </table>
  144. </form>
  145. <?php
  146. /*
  147. FOOTER
  148. */
  149. Display :: display_footer();
  150. ?>