<?

/*
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
*/



	// ========================================================================================
	// Statistics - Page Views By Page
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_stats.gif" width="24" height="18"> '.$MsgText[4][4];
	$BrowserTitle = $MsgText[4][4];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[4][4];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[401] == 'y') {
		
		
			function GetPageName($PagePath) {
			
				Global $PageNames, $MsgText;
				
			
				$PageNames['/index'] = $MsgText[4][18];
				$PageNames['/options'] = $MsgText[0][4];
				$PageNames['/register'] = $MsgText[0][53];
				$PageNames['/profile-edit'] = $MsgText[0][78];
				$PageNames['/lost_password'] = $MsgText[0][506];
				$PageNames['/lost_password-send'] = $MsgText[0][506];
				$PageNames['/login'] = $MsgText[0][192];
				$PageNames['/logout'] = $MsgText[0][193];
				$PageNames['/notifications'] = $MsgText[0][18];
				
				
				$PageNames['/admin/blocks'] = $MsgText[0][50];
				$PageNames['/admin/blocks-edit'] = $MsgText[0][50].' - '.$MsgText[0][240];
				$PageNames['/admin/blocks-delete'] = $MsgText[0][50].' - '.$MsgText[0][235];
				$PageNames['/admin/pages'] = $MsgText[0][244];
				$PageNames['/admin/pages-edit'] = $MsgText[0][244].' - '.$MsgText[0][300];
				$PageNames['/admin/pages-delete'] = $MsgText[0][244].' - '.$MsgText[0][298];
				$PageNames['/admin/templates'] = $MsgText[0][63];
				$PageNames['/admin/settings'] = $MsgText[0][64];
				$PageNames['/admin/smilies'] = $MsgText[0][60];
				$PageNames['/admin/preferences'] = $MsgText[0][62];
				$PageNames['/admin/users'] = $MsgText[0][59];
				$PageNames['/admin/info'] = $MsgText[0][57];
				$PageNames['/admin/where'] = $MsgText[0][58];
				$PageNames['/admin/modules'] = $MsgText[0][49];
				$PageNames['/admin/levels'] = $MsgText[0][56];
				$PageNames['/admin/permissions'] = $MsgText[0][55];
				
				$PageNames['/photos'] = $MsgText[3][1];
				$PageNames['/admin/photos'] = $MsgText[3][2];
				$PageNames['/admin/photos_edit'] = $MsgText[3][1].' - '.$MsgText[3][64];
				$PageNames['/admin/photos_galleries'] = $MsgText[3][1].' - '.$MsgText[3][3];
				$PageNames['/admin/photos_prefs'] = $MsgText[3][4];
				
				$PageNames['/admin/stats'] = $MsgText[4][1].' - '.$MsgText[4][2];
				$PageNames['/admin/stats_pages'] = $MsgText[4][1].' - '.$MsgText[4][4];
				$PageNames['/admin/stats_pageviews'] = $MsgText[4][1].' - '.$MsgText[4][3];
				$PageNames['/admin/stats_referrals'] = $MsgText[4][1].' - '.$MsgText[4][5];
				$PageNames['/admin/stats_users'] = $MsgText[4][1].' - '.$MsgText[4][6];
				$PageNames['/admin/stats_systems'] = $MsgText[4][1].' - '.$MsgText[4][7];
				
				$PageNames['/guestbook'] = $MsgText[6][1];
				$PageNames['/admin/guestbook_manage'] = $MsgText[6][1].' - '.$MsgText[6][2];
				$PageNames['/admin/guestbook_edit'] = $MsgText[6][1].' - '.$MsgText[6][15];
				$PageNames['/admin/guestbook_delete'] = $MsgText[6][1].' - '.$MsgText[6][12];
				
				
				$PageNames['/calendar'] = $MsgText[1][1];
				$PageNames['/forum'] = $MsgText[2][1];
				
				
				$PageNames['/newsletter/messages'] = $MsgText[5][1].' - '.$MsgText[5][70];
				$PageNames['/newsletter/subscribe'] = $MsgText[5][1].' - '.$MsgText[5][48];
				$PageNames['/newsletter/subscribe_submit'] = $MsgText[5][1].' - '.$MsgText[5][48];
				$PageNames['/newsletter/subscribe_confirm'] = $MsgText[5][1].' - '.$MsgText[5][48];
				$PageNames['/newsletter/unsubscribe'] = $MsgText[5][1].' - '.$MsgText[5][62];
				$PageNames['/newsletter/unsubscribe_submit'] = $MsgText[5][1].' - '.$MsgText[5][62];
				$PageNames['/newsletter/unsubscribe_confirm'] = $MsgText[5][1].' - '.$MsgText[5][62];
				$PageNames['/admin/newsletter_archived'] = $MsgText[5][1].' - '.$MsgText[5][4];
				$PageNames['/admin/newsletter_compose'] = $MsgText[5][1].' - '.$MsgText[5][2];
				$PageNames['/admin/newsletter_preview'] = $MsgText[5][1].' - '.$MsgText[5][2];
				$PageNames['/admin/newsletter_send'] = $MsgText[5][1].' - '.$MsgText[5][2];
				$PageNames['/admin/newsletter_subscribers'] = $MsgText[5][1].' - '.$MsgText[5][3];
				$PageNames['/admin/newsletter_subscribers_add'] = $MsgText[5][1].' - '.$MsgText[5][32];
				$PageNames['/admin/newsletter_prefs'] = $MsgText[5][1];
				
									
				
				if ($PageNames[$PagePath] != '') {
					return $PageNames[$PagePath];
				}
				else {
					
					if (substr($PagePath,0,7) == '/pages/') {
					
						Global $AlreadyReadPages, $Settings;
						
						if ($AlreadyReadPages != 'y') {
								
							$query = "select * from `".$Settings['DBPrefix']."core-Pages`";
							$result = mysql_query($query) or die (mysql_error());
							while ($row = mysql_fetch_array($result)) {
							
								if ($row['PageTitle'] != '') {
									$PageNames['/pages/'.$row['PageLink']] = $row['PageTitle'];
								}
								else {
									$PageNames['/pages/'.$row['PageLink']] = '('.$MsgText[4][19].')';
								}
							
							}
							
							$AlreadyReadPages = 'y';
							
						}
						
						return $PageNames[$PagePath];
						
						
					} // end if a custom page
					else if (substr($PagePath,0,8) == '/photos/') {
					
						Global $AlreadyReadPhotos;
						
						if ($AlreadyReadPhotos != 'y') {
								
							$query = "select * from `".$Settings['DBPrefix']."pg-Galleries`";
							$result = mysql_query($query) or die (mysql_error());
							while ($row = mysql_fetch_array($result)) {
							
								if ($row['GalleryTitle'] != '') {
									$PageNames['/photos/'.$row['RecordNumber']] = $MsgText[3][1].' - '.$row['GalleryTitle'];
								}
								else {
									$PageNames['/photos/'.$row['RecordNumber']] = '('.$MsgText[4][20].')';
								}
							
							}
							
							$AlreadyReadPhotos = 'y';
							
						}
						
						return $PageNames[$PagePath];
					
					}
					else if (substr($PagePath,0,9) == '/profile/') {
					
						list ($Trash, $Trash, $Username) = explode('/',$PagePath,3);
					
						$PageNames[$PagePath] = $Username.'\'s '.$MsgText[4][21];
						
						
						return $PageNames[$PagePath];
					
					}
					else if (substr($PagePath,0,20) == '/newsletter/messages') {
					
						$PageNames[$PagePath] = $MsgText[5][1].' - '.$MsgText[5][70];
						
						
						return $PageNames[$PagePath];
					
					}
					else if (substr($PagePath,0,7) == '/forum/') {
					
						$ForumString = explode('/',$PagePath);
						
						if ($ForumString[3] == '') {
						// just a board
					
							Global $AlreadyReadBoards;
							
							if ($AlreadyReadBoards != 'y') {
									
								$query = "select * from `".$Settings['DBPrefix']."mb-Boards`";
								$result = mysql_query($query) or die (mysql_error());
								while ($row = mysql_fetch_array($result)) {
							
									if ($row['Title'] != '') {
										$PageNames['/forum/'.$row['RecordNumber']] = $MsgText[2][1].' - '.$row['Title'].' '.$MsgText[4][22];
									}
									else {
										$PageNames['/forum/'.$row['RecordNumber']] = $MsgText[2][1].' - '.$MsgText[4][23];
									}
								
								}
								
								$AlreadyReadBoards = 'y';
							
							}
							
						} // end if just a board
						else {
						// thread
					
							Global $AlreadyReadThreads;
							
							if ($AlreadyReadThreads != 'y') {
									
								$query = "select * from `".$Settings['DBPrefix']."mb-Threads`";
								$result = mysql_query($query) or die (mysql_error());
								while ($row = mysql_fetch_array($result)) {
							
									if ($row['Title'] != '') {
										$PageNames['/forum/'.$ForumString[2].'/'.$row['RecordNumber']] = $MsgText[2][1].' - '.$row['Title'].' '.$MsgText[4][24];
									}
									else {
										$PageNames['/forum/'.$ForumString[2].'/'.$row['RecordNumber']] = $MsgText[2][1].' - '.$MsgText[4][25];
									}
									
									for ($k = 1; $k <= 10; $k++) {
									
										if ($row['Title'] != '') {
											$PageNames['/forum/'.$ForumString[2].'/'.$row['RecordNumber'].'/'.$k] = $MsgText[2][1].' - '.$row['Title'].' '.$MsgText[4][24];
										}
										else {
											$PageNames['/forum/'.$ForumString[2].'/'.$row['RecordNumber'].'/'.$k] = $MsgText[2][1].' - '.$MsgText[4][25];
										}
									
									}
								
								}
								
								$AlreadyReadThreads = 'y';
							
							}
							
						} // end if thread
						
						return $PageNames[$PagePath];
					
					}
					else {
					
						return '';
					
					}
				
				
				} // end if not already found in above list
				
			}	// end page name function		
		
		
			function HostnameLookup($IPAddress) {
			
				Global $PastLookups;
				
				if ($PastLookups[$IPAddress] != '') {
					return $PastLookups[$IPAddress];
				}
				else {
					return @gethostbyaddr($IPAddress);
				}
			
			}
		
				
			
			$TodayStartTimestamp = mktime(0,0,0,date('n',GetTimestamp()),date('j',GetTimestamp()),date('Y',GetTimestamp()));
			
			
			
			$OthersAtOne = 0;
			
			$PagesList = '';
			$PagesList2 = '';
			$PageCounts = '';
			$PageAddedToList = '';
			
			$LargestFound = -1;
			
			$PagesList[] = '/admin/stats';
			$PageCounts['/admin/stats'] = 1;
			$PageAddedToList['/admin/stats'] = 'y';
			
			$PagesBreakdown = '';

			$query = "select * from `".$Settings['DBPrefix']."cs-Recent` where DateCode>='".$TodayStartTimestamp."'";
			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
			
			
				if (substr($row['CurrentPage'],0,18) == '/admin/blocks-edit') {
					$row['CurrentPage'] = '/admin/blocks-edit';
				}
				if (substr($row['CurrentPage'],0,20) == '/admin/blocks-delete') {
					$row['CurrentPage'] = '/admin/blocks-delete';
				}
				if (substr($row['CurrentPage'],0,17) == '/admin/pages-edit') {
					$row['CurrentPage'] = '/admin/pages-edit';
				}
				if (substr($row['CurrentPage'],0,19) == '/admin/pages-delete') {
					$row['CurrentPage'] = '/admin/pages-delete';
				}
				if (substr($row['CurrentPage'],0,18) == '/admin/photos_edit') {
					$row['CurrentPage'] = '/admin/photos_edit';
				}
				if (substr($row['CurrentPage'],0,21) == '/admin/guestbook_edit') {
					$row['CurrentPage'] = '/admin/guestbook_edit';
				}
				if (substr($row['CurrentPage'],0,23) == '/admin/guestbook_delete') {
					$row['CurrentPage'] = '/admin/guestbook_delete';
				}
				if (substr($row['CurrentPage'],0,12) == '/admin/users') {
					$row['CurrentPage'] = '/admin/users';
				}
				if (substr($row['CurrentPage'],0,6) == '/login') {
					$row['CurrentPage'] = '/login';
				}
				if (substr($row['CurrentPage'],0,29) == '/newsletter/subscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/subscribe_confirm';
				}
				if (substr($row['CurrentPage'],0,35) == '/admin/newsletter_subscriber_delete') {
					$row['CurrentPage'] = '/admin/newsletter_subscriber_delete';
				}
				if (substr($row['CurrentPage'],0,32) == '/admin/newsletter_archive_delete') {
					$row['CurrentPage'] = '/admin/newsletter_archive_delete';
				}
				if (substr($row['CurrentPage'],0,31) == '/newsletter/unsubscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/unsubscribe_confirm';
				}
				
				
			
			
				$PageCounts[$row['CurrentPage']]++;
				$TotalCount++;
				
				if ($PageAddedToList[$row['CurrentPage']] == '') {
					$PageAddedToList[$row['CurrentPage']] = 'y';
					$PagesList[] = $row['CurrentPage'];
				}
				
				if ($PageCounts[$row['CurrentPage']] > $LargestFound) {
					$LargestFound = $PageCounts[$row['CurrentPage']];
				}
			
			}
			
			
			$TopPageCounts = '';
			$TopPageNames = '';
			
			for ($k = 0; $k < count($PagesList); $k++) {
				if ($PageCounts[$PagesList[$k]] > $TopPageCounts[50]) {
					
					$ArraySlot = 50;
					while ($PageCounts[$PagesList[$k]] > $TopPageCounts[$ArraySlot-1] && $ArraySlot > 1) {
						$ArraySlot--;
					}
					
					for ($z = 50; $z > $ArraySlot; $z--) {
						$TopPageCounts[$z] = $TopPageCounts[$z-1];
						$TopPageNames[$z] = $TopPageNames[$z-1]; 
					}
					
					$TopPageCounts[$ArraySlot] = $PageCounts[$PagesList[$k]];
					$TopPageNames[$ArraySlot] = $PagesList[$k];
										
				}
			}
			
			
			$OthersViewsCount = $TotalCount;
			for ($z = 1; $z <= 50; $z++) {
				$OthersViewsCount -= $TopPageCounts[$z];
			}
			
					
			
			$PagesList2 = $TopPageNames;
			
			// sort by title
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PagesList2[$j] > $PagesList2[$j+1]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PageCounts[$PagesList2[$j]] < $PageCounts[$PagesList2[$j+1]]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$PagesBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][26].'</b>&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][27].'</b></td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][28].'</b>&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($PagesList2); $j++) {
			
				if ($PagesList2[$j] != '') {
			
					$ThisPercent = ($PageCounts[$PagesList2[$j]]/$TotalCount);
					$ThisWidth = number_format($ThisPercent * 120 * $SizeMultiplier,0);
				
				
					//$PagesBreakdown .= '<br>'.$PagesList2[$j].' ('.$PageNames[$PagesList2[$j]].'): '.$PageCounts[$PagesList2[$j]].' ('.number_format(($PageCounts[$PagesList2[$j]]/$TodayPageViews)*100,1).'%)';
				 
			
					if (strpos($PagesList2[$j],'confirm') === false && strpos($PagesList2[$j],'submit') === false && strpos($PagesList2[$j],'save') === false && strpos($PagesList2[$j],'edit') === false && strpos($PagesList2[$j],'delete') === false && strpos($PagesList2[$j],'message-post') === false && strpos($PagesList2[$j],'send') === false) {
						$PagePathPrint = '<a href="'.$MainURL.$PagesList2[$j].'.html" target="_blank">'.$PagesList2[$j].'</a>';
					}
					else {
						$PagePathPrint = $PagesList2[$j];
					}
					 
			
					$PagesBreakdown .= '<tr>
				      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .$PagePathPrint. '&nbsp;&nbsp;</td>
				      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.GetPageName($PagesList2[$j]).'</td>
					  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.$PageCounts[$PagesList2[$j]].'&nbsp;&nbsp;</td>
			    	  <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
	    			</tr>';
					
				}
			
			}
			if (count($PagesList)-51 > 0) {
				$PagesBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .number_format(count($PagesList)-51,0). ' Other Pages Representing '.number_format($OthersViewsCount,0).' Pageviews&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;</td>
    			</tr>';
			}
			
			$PagesBreakdown .= '</table></td></tr></table>';
				
				
			
			
			
			$PageContents .= '<br><b>('.$MsgText[4][30].')</b><br><br><br><b>'.$MsgText[4][31].':</b>'.$PagesBreakdown;
			
			
			
			
			
			$OthersAtOne = 0;
			
			$PagesList = '';
			$PagesList2 = '';
			$PageCounts = '';
			$PageAddedToList = '';
			
			$PagesList[] = '/admin/stats';
			$PageCounts['/admin/stats'] = 1;
			$PageAddedToList['/admin/stats'] = 'y';
			
			$PagesBreakdown = '';

			$query = "select * from `".$Settings['DBPrefix']."cs-Recent` where DateCode>='".($TodayStartTimestamp-(60*60*24))."' and DateCode<'".$TodayStartTimestamp."'";
			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
			
				if (substr($row['CurrentPage'],0,18) == '/admin/blocks-edit') {
					$row['CurrentPage'] = '/admin/blocks-edit';
				}
				if (substr($row['CurrentPage'],0,20) == '/admin/blocks-delete') {
					$row['CurrentPage'] = '/admin/blocks-delete';
				}
				if (substr($row['CurrentPage'],0,17) == '/admin/pages-edit') {
					$row['CurrentPage'] = '/admin/pages-edit';
				}
				if (substr($row['CurrentPage'],0,19) == '/admin/pages-delete') {
					$row['CurrentPage'] = '/admin/pages-delete';
				}
				if (substr($row['CurrentPage'],0,18) == '/admin/photos_edit') {
					$row['CurrentPage'] = '/admin/photos_edit';
				}
				if (substr($row['CurrentPage'],0,21) == '/admin/guestbook_edit') {
					$row['CurrentPage'] = '/admin/guestbook_edit';
				}
				if (substr($row['CurrentPage'],0,23) == '/admin/guestbook_delete') {
					$row['CurrentPage'] = '/admin/guestbook_delete';
				}
				if (substr($row['CurrentPage'],0,12) == '/admin/users') {
					$row['CurrentPage'] = '/admin/users';
				}
				if (substr($row['CurrentPage'],0,6) == '/login') {
					$row['CurrentPage'] = '/login';
				}
				if (substr($row['CurrentPage'],0,29) == '/newsletter/subscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/subscribe_confirm';
				}
				if (substr($row['CurrentPage'],0,35) == '/admin/newsletter_subscriber_delete') {
					$row['CurrentPage'] = '/admin/newsletter_subscriber_delete';
				}
				if (substr($row['CurrentPage'],0,32) == '/admin/newsletter_archive_delete') {
					$row['CurrentPage'] = '/admin/newsletter_archive_delete';
				}
				if (substr($row['CurrentPage'],0,31) == '/newsletter/unsubscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/unsubscribe_confirm';
				}
				
				
			
			
				$PageCounts[$row['CurrentPage']]++;
				$TotalCount++;
				
				if ($PageAddedToList[$row['CurrentPage']] == '') {
					$PageAddedToList[$row['CurrentPage']] = 'y';
					$PagesList[] = $row['CurrentPage'];
				}
				
				if ($PageCounts[$row['CurrentPage']] > $LargestFound) {
					$LargestFound = $PageCounts[$row['CurrentPage']];
				}
				
			}
			
			
			$TopPageCounts = '';
			$TopPageNames = '';
			
			for ($k = 0; $k < count($PagesList); $k++) {
				if ($PageCounts[$PagesList[$k]] > $TopPageCounts[50]) {
					
					$ArraySlot = 50;
					while ($PageCounts[$PagesList[$k]] > $TopPageCounts[$ArraySlot-1] && $ArraySlot > 1) {
						$ArraySlot--;
					}
					
					for ($z = 50; $z > $ArraySlot; $z--) {
						$TopPageCounts[$z] = $TopPageCounts[$z-1];
						$TopPageNames[$z] = $TopPageNames[$z-1]; 
					}
					
					$TopPageCounts[$ArraySlot] = $PageCounts[$PagesList[$k]];
					$TopPageNames[$ArraySlot] = $PagesList[$k];
										
				}
			}
			
			
			$OthersViewsCount = $TotalCount;
			for ($z = 1; $z <= 50; $z++) {
				$OthersViewsCount -= $TopPageCounts[$z];
			}
			
					
			
			$PagesList2 = $TopPageNames;
			
			
			// sort by title
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PagesList2[$j] > $PagesList2[$j+1]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PageCounts[$PagesList2[$j]] < $PageCounts[$PagesList2[$j+1]]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$PagesBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][26].'</b>&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][27].'</b></td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][28].'</b>&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($PagesList2); $j++) {
			
				if ($PagesList2[$j] != '') {
			
					$ThisPercent = ($PageCounts[$PagesList2[$j]]/$TotalCount);
					$ThisWidth = number_format($ThisPercent * 120 * $SizeMultiplier,0);
					
					
					//$PagesBreakdown .= '<br>'.$PagesList2[$j].' ('.$PageNames[$PagesList2[$j]].'): '.$PageCounts[$PagesList2[$j]].' ('.number_format(($PageCounts[$PagesList2[$j]]/$TodayPageViews)*100,1).'%)';
				 
			
					if (strpos($PagesList2[$j],'confirm') === false && strpos($PagesList2[$j],'submit') === false && strpos($PagesList2[$j],'save') === false && strpos($PagesList2[$j],'edit') === false && strpos($PagesList2[$j],'delete') === false && strpos($PagesList2[$j],'message-post') === false && strpos($PagesList2[$j],'send') === false) {
						$PagePathPrint = '<a href="'.$MainURL.$PagesList2[$j].'.html" target="_blank">'.$PagesList2[$j].'</a>';
					}
					else {
						$PagePathPrint = $PagesList2[$j];
					}
					 
				
					$PagesBreakdown .= '<tr>
			    	  <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .$PagePathPrint. '&nbsp;&nbsp;</td>
				      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.GetPageName($PagesList2[$j]).'</td>
					  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.$PageCounts[$PagesList2[$j]].'&nbsp;&nbsp;</td>
				      <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    				</tr>';
			
				}
			}
			if (count($PagesList)-51 > 0) {
				$PagesBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .number_format(count($PagesList)-51,0). ' Other Pages Representing '.number_format($OthersViewsCount,0).' Pageviews&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;</td>
    			</tr>';
			}
			
			$PagesBreakdown .= '</table></td></tr></table>';
			
			
			$PageContents .= '<br><br><br><b>'.$MsgText[4][32].':</b>'.$PagesBreakdown;
			
			
			
			
			
			$OthersAtOne = 0;
			
			$PagesList = '';
			$PagesList2 = '';
			$PageCounts = '';
			$PageAddedToList = '';
			
			$PagesList[] = '/admin/stats';
			$PageCounts['/admin/stats'] = 1;
			$PageAddedToList['/admin/stats'] = 'y';
			
			$PagesBreakdown = '';

			$query = "select * from `".$Settings['DBPrefix']."cs-Recent` where DateCode>='".($TodayStartTimestamp-(60*60*24*6))."'";
			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
			
				if (substr($row['CurrentPage'],0,18) == '/admin/blocks-edit') {
					$row['CurrentPage'] = '/admin/blocks-edit';
				}
				if (substr($row['CurrentPage'],0,20) == '/admin/blocks-delete') {
					$row['CurrentPage'] = '/admin/blocks-delete';
				}
				if (substr($row['CurrentPage'],0,17) == '/admin/pages-edit') {
					$row['CurrentPage'] = '/admin/pages-edit';
				}
				if (substr($row['CurrentPage'],0,19) == '/admin/pages-delete') {
					$row['CurrentPage'] = '/admin/pages-delete';
				}
				if (substr($row['CurrentPage'],0,18) == '/admin/photos_edit') {
					$row['CurrentPage'] = '/admin/photos_edit';
				}
				if (substr($row['CurrentPage'],0,21) == '/admin/guestbook_edit') {
					$row['CurrentPage'] = '/admin/guestbook_edit';
				}
				if (substr($row['CurrentPage'],0,23) == '/admin/guestbook_delete') {
					$row['CurrentPage'] = '/admin/guestbook_delete';
				}
				if (substr($row['CurrentPage'],0,12) == '/admin/users') {
					$row['CurrentPage'] = '/admin/users';
				}
				if (substr($row['CurrentPage'],0,6) == '/login') {
					$row['CurrentPage'] = '/login';
				}
				if (substr($row['CurrentPage'],0,29) == '/newsletter/subscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/subscribe_confirm';
				}
				if (substr($row['CurrentPage'],0,35) == '/admin/newsletter_subscriber_delete') {
					$row['CurrentPage'] = '/admin/newsletter_subscriber_delete';
				}
				if (substr($row['CurrentPage'],0,32) == '/admin/newsletter_archive_delete') {
					$row['CurrentPage'] = '/admin/newsletter_archive_delete';
				}
				if (substr($row['CurrentPage'],0,31) == '/newsletter/unsubscribe_confirm') {
					$row['CurrentPage'] = '/newsletter/unsubscribe_confirm';
				}
				
				
			
			
				$PageCounts[$row['CurrentPage']]++;
				$TotalCount++;
				
				if ($PageAddedToList[$row['CurrentPage']] == '') {
					$PageAddedToList[$row['CurrentPage']] = 'y';
					$PagesList[] = $row['CurrentPage'];
				}
				
				if ($PageCounts[$row['CurrentPage']] > $LargestFound) {
					$LargestFound = $PageCounts[$row['CurrentPage']];
				}
			
			}
			
			
			$TopPageCounts = '';
			$TopPageNames = '';
			
			for ($k = 0; $k < count($PagesList); $k++) {
				if ($PageCounts[$PagesList[$k]] > $TopPageCounts[50]) {
					
					$ArraySlot = 50;
					while ($PageCounts[$PagesList[$k]] > $TopPageCounts[$ArraySlot-1] && $ArraySlot > 1) {
						$ArraySlot--;
					}
					
					for ($z = 50; $z > $ArraySlot; $z--) {
						$TopPageCounts[$z] = $TopPageCounts[$z-1];
						$TopPageNames[$z] = $TopPageNames[$z-1]; 
					}
					
					$TopPageCounts[$ArraySlot] = $PageCounts[$PagesList[$k]];
					$TopPageNames[$ArraySlot] = $PagesList[$k];
										
				}
			}
			
			
			$OthersViewsCount = $TotalCount;
			for ($z = 1; $z <= 50; $z++) {
				$OthersViewsCount -= $TopPageCounts[$z];
			}
			
					
			
			$PagesList2 = $TopPageNames;
			
			
			// sort by title
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PagesList2[$j] > $PagesList2[$j+1]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($PagesList2); $k++) {
				for ($j = 0; $j < (count($PagesList2)-1); $j++) {
				
					if ($PageCounts[$PagesList2[$j]] < $PageCounts[$PagesList2[$j+1]]) {
					
						$Swap2 = $PagesList2[$j+1];
						
						$PagesList2[$j+1] = $PagesList2[$j];
						
						$PagesList2[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$PagesBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][26].'</b>&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][27].'</b></td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][28].'</b>&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($PagesList2); $j++) {
			
				if ($PagesList2[$j] != '') {
			
					$ThisPercent = ($PageCounts[$PagesList2[$j]]/$TotalCount);
					$ThisWidth = number_format($ThisPercent * 120 * $SizeMultiplier,0);
					
					
					//$PagesBreakdown .= '<br>'.$PagesList2[$j].' ('.$PageNames[$PagesList2[$j]].'): '.$PageCounts[$PagesList2[$j]].' ('.number_format(($PageCounts[$PagesList2[$j]]/$TodayPageViews)*100,1).'%)';
				 
				
					if (strpos($PagesList2[$j],'confirm') === false && strpos($PagesList2[$j],'submit') === false && strpos($PagesList2[$j],'save') === false && strpos($PagesList2[$j],'edit') === false && strpos($PagesList2[$j],'delete') === false && strpos($PagesList2[$j],'message-post') === false && strpos($PagesList2[$j],'send') === false) {
						$PagePathPrint = '<a href="'.$MainURL.$PagesList2[$j].'.html" target="_blank">'.$PagesList2[$j].'</a>';
					}
					else {
						$PagePathPrint = $PagesList2[$j];
					}
					 
				
					$PagesBreakdown .= '<tr>
			    	  <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .$PagePathPrint. '&nbsp;&nbsp;</td>
				      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.GetPageName($PagesList2[$j]).'</td>
					  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.$PageCounts[$PagesList2[$j]].'&nbsp;&nbsp;</td>
				      <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    				</tr>';
			
				}
			}
			if (count($PagesList)-51 > 0) {
				$PagesBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">' .number_format(count($PagesList)-51,0). ' Other Pages Representing '.number_format($OthersViewsCount,0).' Pageviews&nbsp;&nbsp;</td>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;</td>
			      <td width="130"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;</td>
    			</tr>';
			}
			
			$PagesBreakdown .= '</table></td></tr></table>';
			
			
			$PageContents .= '<br><br><br><b>'.$MsgText[4][33].':</b>'.$PagesBreakdown;
						
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
