access_url_check_user_session.php 4.3 KB

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