<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// where are they now report
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_info.gif" width="21" height="20"> '.$MsgText[0][58];
	$BrowserTitle = $MsgText[0][58];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL.'/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][58];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[11] == 'y') {
		
				$Link1 = 'user-asc';
				$Link2 = 'previous-asc';
				$Link3 = 'current-asc';
				$Link4 = 'arrived-desc';
				$Link5 = 'userorguest-asc';
		
				if ($Arguments3 == 'user-asc') { $SortBy = 'User'; $SortOrder = 'ASC'; $Link1 = 'user-desc'; }
				else if ($Arguments3 == 'user-desc') { $SortBy = 'User'; $SortOrder = 'DESC'; }
				else if ($Arguments3 == 'previous-asc') { $SortBy = 'PreviousLocation'; $SortOrder = 'ASC'; $Link2 = 'previous-desc'; }
				else if ($Arguments3 == 'previous-desc') { $SortBy = 'PreviousLocation'; $SortOrder = 'DESC'; }
				else if ($Arguments3 == 'current-asc') { $SortBy = 'LastLocation'; $SortOrder = 'ASC'; $Link3 = 'current-desc';  }
				else if ($Arguments3 == 'current-desc') { $SortBy = 'LastLocation'; $SortOrder = 'DESC'; }
				else if ($Arguments3 == 'arrived-asc') { $SortBy = 'LastAction'; $SortOrder = 'asc'; }
				else if ($Arguments3 == 'arrived-desc') { $SortBy = 'LastAction'; $SortOrder = 'desc'; $Link4 = 'arrived-asc'; }
				else if ($Arguments3 == 'userorguest-asc') { $SortBy = 'UserOrGuest'; $SortOrder = 'asc'; $Link5 = 'userorguest-desc'; }
				else if ($Arguments3 == 'userorguest-desc') { $SortBy = 'UserOrGuest'; $SortOrder = 'desc'; }
				else { $SortBy = 'LastAction'; $SortOrder = 'DESC'; $Link4 = 'arrived-asc'; }
	
			
				$query69 = "select User,Name,LastAction,LastLocation,PreviousLocation,SessionLength,UserOrGuest from `".$Settings['DBPrefix']."core-RecentActivity` where LastAction>='".(GetTimestamp()-1800)."' and SessionLength>0 and User!='".$CookieUsername."' ORDER BY ".$SortBy." ".$SortOrder;
				$result69 = mysql_query($query69) or die (mysql_error());
													
				while ($row = mysql_fetch_array($result69)) {
					$Usernames[] = $row['User'];
					$DisplayNames[] = $row['Name'];
					$LastActions[] = $row['LastAction'];
					$LastLocations[] = $row['LastLocation'];
					$PreviousLocations[] = $row['PreviousLocation'];
					$SessionLengths[] = $row['SessionLength'];
					$UserOrGuest[] = $row['UserOrGuest'];
				}
				
							
				for ($i = 0; $i < count($Usernames); $i++) {
					if ($SessionLengths[$i] > 0) {
					
						if ($LastActions[$i]+($SessionLengths[$i]*60) >= GetTimestamp()) {
						
							if ($DisplayNames[$i] == '') { 
								if ($UserOrGuest[$i] == 'u') {
									$DisplayNames[$i] = $Usernames[$i];
								}
								else {
									$DisplayNames[$i] = 'n/a';
								}
							}
							
							if (substr($PreviousLocations[$i],0,4) == '.php') {
								$PreviousLocations[$i] = substr($PreviousLocations[$i],4);
							}
							if (substr($LastLocations[$i],0,4) == '.php') {
								$LastLocations[$i] = substr($LastLocations[$i],4);
							}
							
							
							$TimeDiff = (GetTimestamp() - $LastActions[$i]);
							$Arrival = '';
							
							if ($TimeDiff < 60) {
								$Arrival = number_format($TimeDiff,0);
								if ($Arrival == 1) { $Arrival .= ' '.$MsgText[0][382]; }
								else { $Arrival .= ' '.$MsgText[0][383]; }
							}
							else if ($TimeDiff < 3600) {
								$Arrival = number_format($TimeDiff/60,0);
								if ($Arrival == 1) { $Arrival .= ' '.$MsgText[0][384]; }
								else { $Arrival .= ' '.$MsgText[0][385]; }
							}
							else {
								$Arrival = number_format($TimeDiff/3600,1);
								if ($Arrival == 1) { $Arrival .= ' '.$MsgText[0][386]; }
								else { $Arrival .= ' '.$MsgText[0][387]; }
							}
							
							/*if ($row['Username'] == $CookieUsername) {
								// if this is the user viewing the page
								$Arrival = '--';
							}*/
							
							if ($UserOrGuest[$i] == 'u') {
								$PrintRows .= '<tr>
								<td><font face="'.$FontFace.'" size="'.$FontSize.'">User</td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$BaseURL.'/'.$Settings['ScriptName'].'/profile/'.$Usernames[$i].'.html" target="_blank">'.$DisplayNames[$i].' ('.$Usernames[$i].')</a></td>
		<td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$BaseURL.'/'.$Settings['ScriptName'].$PreviousLocations[$i].'.html" target="_blank">'.$PreviousLocations[$i].'</a></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$BaseURL.'/'.$Settings['ScriptName'].$LastLocations[$i].'.html" target="_blank">'.$LastLocations[$i].'</a></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$Arrival.'</td>
    </tr>';
							}
							else {
								$PrintRows .= '<tr>
								<td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$MsgText[0][388].'</td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$Usernames[$i].' ('.$DisplayNames[$i].')</td>
		<td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.$PreviousLocations[$i].'.html" target="_blank">'.$PreviousLocations[$i].'</a></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.$LastLocations[$i].'.html" target="_blank">'.$LastLocations[$i].'</a></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$Arrival.'</td>
    </tr>';							
							}
						
						}
								
					}
						
				}
				
				if ($PrintRows == '') {
					$PrintRows = '<tr><td colspan="3"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$MsgText[0][389].'</td></tr>';
				}
			
			
			$PageContents = $MsgText[0][390].'<br><br><br><table width="100%" border="0" cellpadding="3" cellspacing="0">
    <tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/admin/where/'.$Link5.'.html">'.$MsgText[0][391].'</a></b></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/admin/where/'.$Link1.'.html">'.$MsgText[0][392].'</a></b></td>
	  <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/admin/where/'.$Link2.'.html">'.$MsgText[0][393].'</a></b></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/admin/where/'.$Link3.'.html">'.$MsgText[0][394].'</a></b></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/admin/where/'.$Link4.'.html">'.$MsgText[0][395].'</a></b></td>
    </tr>'.$PrintRows.'</table>';
			

		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

	// ========================================================================================




?>
