access_url_check_user_session.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* INIT SECTION */
  8. $cidReset = true;
  9. require_once '../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[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  15. $interbreadcrumb[]=array('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(get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
  29. }
  30. break;
  31. }
  32. Display::display_header($tool_name);
  33. if (!empty($message)) {
  34. echo $message;
  35. }
  36. $multiple_url_is_on = api_get_multiple_access_url();
  37. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  38. $session_list = SessionManager::get_sessions_list();
  39. $html = '';
  40. $show_users_with_problems = isset($_REQUEST['show_users_with_problems']) && $_REQUEST['show_users_with_problems'] == 1 ? true : false;
  41. if ($show_users_with_problems) {
  42. $html .= '<a href="'.api_get_self().'?show_users_with_problems=0">'.get_lang('ShowAllUsers').'</a>';
  43. } else {
  44. $html .= '<a href="'.api_get_self().'?show_users_with_problems=1">'.get_lang('ShowUsersNotAddedInTheURL').'</a>';
  45. }
  46. foreach($session_list as $session_item) {
  47. $session_id = $session_item['id'];
  48. $html .= '<h3>'.$session_item['name'].'</h3>';
  49. $access_where = "(access_url_id = $url_id OR access_url_id is null )";
  50. if ($show_users_with_problems) {
  51. $access_where = "(access_url_id is null)";
  52. }
  53. $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
  54. FROM $tbl_user u
  55. INNER JOIN $tbl_session_rel_user su
  56. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  57. LEFT OUTER JOIN $table_access_url_user uu
  58. ON (uu.user_id = u.user_id)
  59. WHERE su.session_id = $session_id AND $access_where
  60. $order_clause";
  61. $result = Database::query($sql);
  62. $users = Database::store_result($result);
  63. if (!empty($users)) {
  64. $html .= '<table class="data_table"><tr><th>'.get_lang('User').'<th>'.get_lang('Actions').'</th></tr>';
  65. foreach ($users as $user) {
  66. $user_link = '';
  67. if (!empty($user['user_id'])) {
  68. $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>';
  69. }
  70. $link_to_add_user_in_url = '';
  71. if ($multiple_url_is_on) {
  72. if ($user['access_url_id'] != $url_id) {
  73. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_MEDIUM);
  74. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_MEDIUM);
  75. $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>';
  76. }
  77. }
  78. $html .= '<tr>
  79. <td>
  80. <b>'.$user_link.'</b>
  81. </td>
  82. <td>
  83. '.$link_to_add_user_in_url.'
  84. </td>
  85. </tr>';
  86. }
  87. $html .= '</table>';
  88. } else {
  89. }
  90. }
  91. echo $html;
  92. // footer
  93. Display :: display_footer();