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