diff --git a/main/inc/ajax/online.ajax.php b/main/inc/ajax/online.ajax.php new file mode 100644 index 0000000000..026e345a72 --- /dev/null +++ b/main/inc/ajax/online.ajax.php @@ -0,0 +1,32 @@ + 0) { + $user_list = who_is_online_in_this_course(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']); + } else { + $user_list = who_is_online(api_get_setting('time_limit_whosonline')); + } + if ($page == 2) { + $_SESSION['online_user_items'] = array(); + } + $max_page = round(count($user_list)/10); + if (!in_array($page, $_SESSION['online_user_items']) && $page <= $max_page) { + $_SESSION['online_user_items'][] = $page; + echo SocialManager::display_user_list($user_list); + } else { + echo 'end'; + } + break; + default: + break; +} \ No newline at end of file diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index cd29360c15..8f05cd28b6 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -235,7 +235,7 @@ class Display { global $origin; $column = 0; $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20; - $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name); + $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name); if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } diff --git a/main/inc/lib/javascript/jquery.endless-scroll.js b/main/inc/lib/javascript/jquery.endless-scroll.js new file mode 100644 index 0000000000..41a8a5f773 --- /dev/null +++ b/main/inc/lib/javascript/jquery.endless-scroll.js @@ -0,0 +1,132 @@ +/** + * Endless Scroll plugin for jQuery + * + * v1.4.8 + * + * Copyright (c) 2008 Fred Wu + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + */ + +/** + * Usage: + * + * // using default options + * $(document).endlessScroll(); + * + * // using some custom options + * $(document).endlessScroll({ + * fireOnce: false, + * fireDelay: false, + * loader: "
", + * callback: function(){ + * alert("test"); + * } + * }); + * + * Configuration options: + * + * bottomPixels integer the number of pixels from the bottom of the page that triggers the event + * fireOnce boolean only fire once until the execution of the current event is completed + * fireDelay integer delay the subsequent firing, in milliseconds, 0 or false to disable delay + * loader string the HTML to be displayed during loading + * data string|function plain HTML data, can be either a string or a function that returns a string, + * when passed as a function it accepts one argument: fire sequence (the number + * of times the event triggered during the current page session) + * insertAfter string jQuery selector syntax: where to put the loader as well as the plain HTML data + * callback function callback function, accepts one argument: fire sequence (the number of times + * the event triggered during the current page session) + * resetCounter function resets the fire sequence counter if the function returns true, this function + * could also perform hook actions since it is applied at the start of the event + * ceaseFire function stops the event (no more endless scrolling) if the function returns true + * + * Usage tips: + * + * The plugin is more useful when used with the callback function, which can then make AJAX calls to retrieve content. + * The fire sequence argument (for the callback function) is useful for 'pagination'-like features. + */ + +(function($){ + + $.fn.endlessScroll = function(options) { + + var defaults = { + bottomPixels: 50, + fireOnce: true, + fireDelay: 150, + loader: "
Loading...
", + data: "", + insertAfter: "div:last", + resetCounter: function() { return false; }, + callback: function() { return true; }, + ceaseFire: function() { return false; } + }; + + var options = $.extend({}, defaults, options); + + var firing = true; + var fired = false; + var fireSequence = 0; + + if (options.ceaseFire.apply(this) === true) { + firing = false; + } + + if (firing === true) { + $(this).scroll(function() { + if (options.ceaseFire.apply(this) === true) { + firing = false; + return; // Scroll will still get called, but nothing will happen + } + + if (this == document || this == window) { + var is_scrollable = $(document).height() - $(window).height() <= $(window).scrollTop() + options.bottomPixels; + } else { + // calculates the actual height of the scrolling container + var inner_wrap = $(".endless_scroll_inner_wrap", this); + if (inner_wrap.length == 0) { + inner_wrap = $(this).wrapInner("
").find(".endless_scroll_inner_wrap"); + } + var is_scrollable = inner_wrap.length > 0 && + (inner_wrap.height() - $(this).height() <= $(this).scrollTop() + options.bottomPixels); + } + + if (is_scrollable && (options.fireOnce == false || (options.fireOnce == true && fired != true))) { + if (options.resetCounter.apply(this) === true) fireSequence = 0; + + fired = true; + fireSequence++; + + $(options.insertAfter).after("
" + options.loader + "
"); + + data = typeof options.data == 'function' ? options.data.apply(this, [fireSequence]) : options.data; + + if (data !== false) { + $(options.insertAfter).after("
" + data + "
"); + $("div#endless_scroll_data").hide().fadeIn(); + $("div#endless_scroll_data").removeAttr("id"); + + options.callback.apply(this, [fireSequence]); + + if (options.fireDelay !== false || options.fireDelay !== 0) { + $("body").after("
"); + // slight delay for preventing event firing twice + $("div#endless_scroll_marker").fadeTo(options.fireDelay, 1, function() { + $(this).remove(); + fired = false; + }); + } + else { + fired = false; + } + } + + $("div#endless_scroll_loader").remove(); + } + }); + } + }; + +})(jQuery); diff --git a/main/inc/lib/online.inc.php b/main/inc/lib/online.inc.php index 3566da3d50..2bb4b34116 100644 --- a/main/inc/lib/online.inc.php +++ b/main/inc/lib/online.inc.php @@ -150,6 +150,7 @@ function who_is_online($valid, $friends = false) { $friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER); $query = ''; + if ($friends) { // who friends from social network is online $query = "SELECT DISTINCT login_user_id,login_date @@ -161,8 +162,7 @@ function who_is_online($valid, $friends = false) { $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." e INNER JOIN ".$table_user ." u ON (u.user_id=e.login_user_id) WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ORDER BY picture_uri DESC"; } - if (api_get_multiple_access_url()) { - $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { if ($friends) { @@ -177,11 +177,10 @@ function who_is_online($valid, $friends = false) { WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ORDER BY picture_uri DESC "; } } - } - + } //This query will show all registered users. Only for dev purposes. - //$query = "SELECT DISTINCT u.user_id as login_user_id, login_date FROM ".$track_online_table ." e , $table_user u GROUP by u.user_id ORDER BY picture_uri DESC"; + $query = "SELECT DISTINCT u.user_id as login_user_id, login_date FROM ".$track_online_table ." e , $table_user u GROUP by u.user_id ORDER BY picture_uri DESC"; $result = Database::query($query); if ($result) { diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 1de6339551..7eb65fc7f5 100644 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -775,7 +775,7 @@ class SocialManager extends UserManager { * Displays a sortable table with the list of online users. * @param array $user_list */ - public static function display_user_list($user_list) { + public static function display_user_list($user_list, $query_vars = array()) { global $charset; if ($_GET['id'] == '') { $extra_params = array(); @@ -784,7 +784,6 @@ class SocialManager extends UserManager { $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']); $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); } - foreach ($user_list as $user) { $uid = $user[0]; $user_info = api_get_user_info($uid); @@ -803,13 +802,11 @@ class SocialManager extends UserManager { // reduce image $name = $user_info['complete_name']; + $status_icon = Display::span('', array('class' => 'online_user_in_text')); if ($image_array['file'] == 'unknown.jpg' || !file_exists($image_array['dir'].$image_array['file'])) { - $friends_profile['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg'; - $status_icon = Display::span('', array('class' => 'online_user')); - //$img = $status_icon.$img; - - $table_row[] = ''.$status_icon.''; + $friends_profile['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg'; + $table_row[] = ''; } else { $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL); @@ -824,14 +821,9 @@ class SocialManager extends UserManager { if ($friends_profile['original_height'] < 50 || $friends_profile['original_height']< 50) { $clip = ''; } - //$status_icon = Display::span($status_icon, array('class' => 'online_user')); - //$img = $status_icon.$img; - - $table_row[] = Display::url(Display::div(Display::div($img, array('class'=>$clip)), array('class'=>'clip-wrapper')) , $url); - - } - $table_row[] = ''.(cut($user_info['firstName'],16)).'
'.cut($user_info['lastName'],18).'
'; - + $table_row[] = Display::url(Display::div(Display::div($img, array('class'=>$clip)), array('class'=>'clip-wrapper')) , $url); + } + $table_row[] = Display::div($status_icon).''.$name.'

Send message'; $table_data[] = $table_row; } $table_header[] = array(get_lang('UserPicture'), false, 'width="90"'); @@ -839,7 +831,13 @@ class SocialManager extends UserManager { if (api_get_setting('show_email_addresses') == 'true') { //$table_header[] = array(get_lang('Email'), true); } - echo Display::return_sortable_grid('online', $table_header, $table_data, array('per_page' => 20)); + + $params = array(); + if (!isset($params['per_page'])) { + $params['per_page'] = 10; + } + $params['hide_navigation'] = true; + echo Display::return_sortable_grid('online', $table_header, $table_data, $params, $query_vars); //Display::display_sortable_table($table_header, $table_data, array(), array('per_page' => 10), $extra_params, array(),'grid'); } } diff --git a/whoisonline.php b/whoisonline.php index e67f564bdb..5fa867b9c8 100644 --- a/whoisonline.php +++ b/whoisonline.php @@ -16,6 +16,8 @@ if (!isset($_GET['cidReq'])) { require_once './main/inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; +$htmlHeadXtra[] = api_get_js('jquery.endless-scroll.js'); + //social tab $this_section = SECTION_SOCIAL; // table definitions @@ -102,6 +104,33 @@ function hide_icon_edit(element_html) { ident="#edit_image"; $(ident).hide(); } + + +$(document).ready(function() { + $(document).endlessScroll({ + fireOnce: false, + fireDelay: false, + loader: "
Loading
", + callback: function(page) { + page = page + 1; + $.ajax({ + beforeSend: function(objeto) { + $("#display_response_id").html("Loading"); }, + type: "GET", + url: "main/inc/ajax/online.ajax.php?a=load_online_user", + data: "online_page_nr="+page, + success: function(data) { + if (data != "end") { + var last = $(".online_grid_container .online_grid_item:last"); + last.after(data); + } + } + }); + } + }); +}); + + '; @@ -124,7 +153,7 @@ if ($_GET['chatid'] != '') { if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])) { if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { - $user_list = who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']); + $user_list = who_is_online_in_this_course(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']); } else { $user_list = who_is_online(api_get_setting('time_limit_whosonline')); } @@ -179,6 +208,4 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || Display::display_header(get_lang('UsersOnLineList')); Display::display_error_message(get_lang('AccessNotAllowed')); } -$referer = empty($_GET['referer']) ? 'index.php' : api_htmlentities(strip_tags($_GET['referer']), ENT_QUOTES); - Display::display_footer(); \ No newline at end of file