access_url_check_user_session.php 4.4 KB

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