access_url_check_user_session.php 4.3 KB

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