Ahoj, vyskúšaj snippet usersOnline - využíva priamo štatistiky Etomite (v administrácií musia byť potom zapnuté), čiže nie je potrebné vytvárať ďalšie SQL tabuľky. Napíš, či to vyhovuje. Defaultne je nastavený tak, že zobrazuje aktivitu používateľov behom 15 min. a zobrazuje nie len aktivitu online používateľov, ale aj používateľov prihlásených cez administrátorské rozhranie.
Kód: Vybrať všetko
/*usersOnline V1.0
Snippet: usersOnline
Author: Cris D.
Date: 2008-11-24
Etomite: V1.0, 1.1
Use: Displays all back-end users, front-end user and site visitors activity
for a duration that you set.
Example:
21 users active in the past 15 minutes.
18 visitors, 3 members
Admin, Billy, Steven
Note: this only shows users logged into the back
and and hittting the front-end.
Due to the limitations of standard etomite tables,
it does not show users logged into the front end as members,
they count as visitors.
*/
/********* Configure snippet settings ****************/
$track_time = isset($track_time) ? $track_time:900;//seconds to return results for (900=15 mins).
$adminStyle="style='color:red;'";
$visitorStyle="style='color:blue;'";
/********* Process time variables ********************/
$time_past=round($track_time/60);//time in minutes
//get server offset time
$server_offset_time=$etomite->config['server_offset_time'];
if(!$server_offset_time) $server_offset_time = 0;
$now=(time()+$server_offset_time);
$track_period= $now - $track_time;
/********* Get Site Stats **************************/
$where="lasthit > {$track_period}";
//Get all back-end user activity
$tempBackend=$etomite->getIntTableRows('*', 'active_users',$where);
//Get all front-end unique visitors
$where="timestamp > {$track_period}";
$sql="SELECT DISTINCT(visitor) as visitor FROM ".$etomite->db."log_access WHERE {$where} ";
$rs= $etomite->dbQuery($sql);
$tempFrontend= $etomite->recordCount($rs);
//process back-end users
$limit = count($tempBackend);
$members='';
for($i=0; $i<$limit; $i++) {
$user = $tempBackend[$i]['username'];
$intKey = $tempBackend[$i]['internalKey'];
$temp=$etomite->getIntTableRows('internalKey,role','user_attributes', 'internalKey = '.$intKey);
//allocate the selected styles according to user role
$class='';
if($temp[0]['role']==1){
$style = $adminStyle;
}else{
$style = $visitorStyle;
}
$members .='<font '.$style.'> '.$user. '</font>,';
}
/********* Markup and display ******************/
$chunk=
<<<END
<div id="userOnline">
<div id="userHeader">
<p><strong>{users}</strong> user(s) in the last <strong>{time}</strong> minutes.</p>
<p>{membersCount} member(s) and {visitors} visitor(s).</p>
</div>
<div id="userBody">
{members}
</div>
</div>
END;
/********* Process user Stats ******************/
//Get some totals
$users= ($limit+$tempFrontend);
//Collect the data to parse
$data=array('users'=>$users,
'time'=>$time_past,
'membersCount'=>$limit,
'members'=>$members,
'visitors'=>$tempFrontend);
$out=$etomite->mergeCodeVariables(
$chunk, $data,
$prefix="{",$suffix="}",
$oddStyle="", $evenStyle="", $tag="");
return $out;