access_url_add_sessions_to_url.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_global_admin_script();
  17. if (!api_get_multiple_access_url()) {
  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">';
  40. echo Display::url(Display::return_icon('edit.gif',get_lang('EditSessionToURL'),''), api_get_path(WEB_CODE_PATH).'admin/access_url_edit_sessions_to_url.php');
  41. echo '</div>';
  42. api_display_tool_title($tool_name);
  43. if ($_POST['form_sent']) {
  44. $form_sent = $_POST['form_sent'];
  45. $sessions = is_array($_POST['session_list']) ? $_POST['session_list'] : array() ;
  46. $url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
  47. $first_letter_session = $_POST['first_letter_session'];
  48. foreach($users as $key => $value) {
  49. $users[$key] = intval($value);
  50. }
  51. if ($form_sent == 1) {
  52. if ( count($sessions) == 0 || count($url_list) == 0) {
  53. Display :: display_error_message(get_lang('AtLeastOneSessionAndOneURL'));
  54. //header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL'));
  55. } else {
  56. UrlManager::add_sessions_to_urls($sessions,$url_list);
  57. Display :: display_confirmation_message(get_lang('SessionBelongURL'));
  58. //header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL'));
  59. }
  60. }
  61. }
  62. /*
  63. Display GUI
  64. */
  65. /*
  66. if(empty($first_letter_user)) {
  67. $sql = "SELECT count(*) as num_courses FROM $tbl_course";
  68. $result = Database::query($sql);
  69. $num_row = Database::fetch_array($result);
  70. if($num_row['num_courses']>1000)
  71. {//if there are too much num_courses to gracefully handle with the HTML select list,
  72. // assign a default filter on users names
  73. $first_letter_user = 'A';
  74. }
  75. unset($result);
  76. }
  77. */
  78. $first_letter_session = Database::escape_string($first_letter_session);
  79. $sql = "SELECT id, name FROM $tbl_session
  80. WHERE name LIKE '".$first_letter_session."%' OR name LIKE '".api_strtolower($first_letter_session)."%'
  81. ORDER BY name DESC ";
  82. $result = Database::query($sql);
  83. $db_sessions = Database::store_result($result);
  84. unset($result);
  85. $sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
  86. $result = Database::query($sql);
  87. $db_urls = Database::store_result($result);
  88. unset($result);
  89. ?>
  90. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  91. <input type="hidden" name="form_sent" value="1"/>
  92. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  93. <tr>
  94. <td width="40%" align="center">
  95. <b><?php echo get_lang('SessionList'); ?></b>
  96. <br/><br/>
  97. <?php echo get_lang('FirstLetterSession'); ?> :
  98. <select name="first_letter_session" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
  99. <option value="">--</option>
  100. <?php
  101. echo Display :: get_alphabet_options($first_letter_session);
  102. echo Display :: get_numeric_options(0,9,$first_letter_session);
  103. ?>
  104. </select>
  105. </td>
  106. <td width="20%">&nbsp;</td>
  107. <td width="40%" align="center">
  108. <b><?php echo get_lang('URLList'); ?> :</b>
  109. </td>
  110. </tr>
  111. <tr>
  112. <td width="40%" align="center">
  113. <select name="session_list[]" multiple="multiple" size="20" style="width:380px;">
  114. <?php
  115. foreach ($db_sessions as $session) {
  116. ?>
  117. <option value="<?php echo $session['id']; ?>"
  118. <?php if(in_array($session['id'],$sessions))
  119. echo 'selected="selected"'; ?>>
  120. <?php echo $session['name']; ?></option>
  121. <?php
  122. }
  123. ?>
  124. </select>
  125. </td>
  126. <td width="20%" valign="middle" align="center">
  127. <button type="submit" class="add"> <?php echo get_lang('AddSessionsToThatURL'); ?> </button>
  128. </td>
  129. <td width="40%" align="center">
  130. <select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
  131. <?php
  132. foreach ($db_urls as $url_obj) {
  133. ?>
  134. <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>
  135. <?php
  136. }
  137. ?>
  138. </select>
  139. </td>
  140. </tr>
  141. </table>
  142. </form>
  143. <?php
  144. /*
  145. FOOTER
  146. */
  147. Display :: display_footer();
  148. ?>