access_url_check_user_session.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Bart Mollet, Julio Montoya lot of fixes
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script(true);
  13. $tool_name = get_lang('SessionOverview');
  14. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  15. $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
  16. // Database Table Definitions
  17. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  18. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  19. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  20. $url_id = api_get_current_access_url_id();
  21. $action = $_GET['action'];
  22. switch ($action) {
  23. case 'add_user_to_url':
  24. $user_id = $_REQUEST['user_id'];
  25. $result = UrlManager::add_user_to_url($user_id, $url_id);
  26. $user_info = api_get_user_info($user_id);
  27. if ($result) {
  28. $message = Display::return_message(
  29. get_lang('UserAdded').' '.api_get_person_name(
  30. $user_info['firstname'],
  31. $user_info['lastname']
  32. ),
  33. 'confirm'
  34. );
  35. }
  36. break;
  37. }
  38. Display::display_header($tool_name);
  39. if (!empty($message)) {
  40. echo $message;
  41. }
  42. $multiple_url_is_on = api_get_multiple_access_url();
  43. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  44. $session_list = SessionManager::get_sessions_list();
  45. $html = '';
  46. $show_users_with_problems = isset($_REQUEST['show_users_with_problems']) && $_REQUEST['show_users_with_problems'] == 1 ? true : false;
  47. if ($show_users_with_problems) {
  48. $html .= '<a href="'.api_get_self().'?show_users_with_problems=0">'.get_lang('ShowAllUsers').'</a>';
  49. } else {
  50. $html .= '<a href="'.api_get_self().'?show_users_with_problems=1">'.get_lang('ShowUsersNotAddedInTheURL').'</a>';
  51. }
  52. foreach ($session_list as $session_item) {
  53. $session_id = $session_item['id'];
  54. $html .= '<h3>'.$session_item['name'].'</h3>';
  55. $access_where = "(access_url_id = $url_id OR access_url_id is null )";
  56. if ($show_users_with_problems) {
  57. $access_where = "(access_url_id is null)";
  58. }
  59. $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
  60. FROM $tbl_user u
  61. INNER JOIN $tbl_session_rel_user su
  62. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  63. LEFT OUTER JOIN $table_access_url_user uu
  64. ON (uu.user_id = u.user_id)
  65. WHERE su.session_id = $session_id AND $access_where
  66. $order_clause";
  67. $result = Database::query($sql);
  68. $users = Database::store_result($result);
  69. if (!empty($users)) {
  70. $html .= '<table class="data_table"><tr><th>'.get_lang('User').'<th>'.get_lang('Actions').'</th></tr>';
  71. foreach ($users as $user) {
  72. $user_link = '';
  73. if (!empty($user['user_id'])) {
  74. $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.Security::remove_XSS(api_get_person_name($user['firstname'], $user['lastname'])).' ('.$user['username'].')</a>';
  75. }
  76. $link_to_add_user_in_url = '';
  77. if ($multiple_url_is_on) {
  78. if ($user['access_url_id'] != $url_id) {
  79. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), [], ICON_SIZE_MEDIUM);
  80. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), [], ICON_SIZE_MEDIUM);
  81. $link_to_add_user_in_url = '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  82. }
  83. }
  84. $html .= '<tr>
  85. <td>
  86. <b>'.$user_link.'</b>
  87. </td>
  88. <td>
  89. '.$link_to_add_user_in_url.'
  90. </td>
  91. </tr>';
  92. }
  93. $html .= '</table>';
  94. }
  95. }
  96. echo $html;
  97. // footer
  98. Display :: display_footer();