<?PHP

/* ====================
Seditio - Website engine
Copyright Neocrome
http://www.neocrome.net
[BEGIN_SED]
File=admin.statistics.referers.inc.php
Version=101
Updated=2006-mar-15
Type=Core.admin
Author=Neocrome
Description=Administration panel
[END_SED]
==================== */

if ( !defined('SED_CODE') || !defined('SED_ADMIN') ) { die('Wrong URL.'); }

list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = sed_auth('admin', 'a');
sed_block($usr['auth_read']);

$adminpath[] = array ("admin.php?m=other", $L['Other']);
$adminpath[] = array ("admin.php?m=referers", $L['Referers']);
$adminhelp = $L['adm_help_referers'];

if ($a=='prune' && $usr['isadmin'])
	{ $sql = sed_sql_query("DELETE FROM $db_referers WHERE 1"); }
elseif ($a=='prunelowhits' && $usr['isadmin'])
	{ $sql = sed_sql_query("DELETE FROM $db_referers WHERE ref_count<6"); }

$sql = sed_sql_query("SELECT * FROM $db_referers ORDER BY ref_count DESC");

$adminmain .= ($usr['isadmin']) ? "<a href=\"admin.php?m=referers&amp;a=prune&amp;".sed_xg()."\">".$L['adm_purgeall']."</a><br /><a href=\"admin.php?m=referers&amp;a=prunelowhits&amp;".sed_xg()."\">".$L['adm_ref_lowhits']."</a><br />&nbsp;<br />" : '';
$adminmain .= "<table class=\"cells\"><tr><td class=\"coltop\">".$L['Referer']."</td><td class=\"coltop\">".$L['Hits']."</td></tr>";

if (sed_sql_numrows($sql)>0)
	{
	while ($row = mysql_fetch_array($sql))
		{
		preg_match_all("|//([^/]+)/|", $row['ref_url'], $a);
		$referers[$a[1][0]][$row['ref_url']] = $row['ref_count'];
		}

	foreach($referers as $referer => $url)
		{
		$adminmain .= "<tr><td colspan=\"2\"><a href=http://".$referer.">".htmlspecialchars($referer)."</a></td></tr>";
		foreach ($url as $uri=>$count)
			{
			$uri1 = sed_cutstring($uri, 48);
			$adminmain .="<tr><td>&nbsp; &nbsp; <a href=\"$uri\" title=\"$uri\">".htmlspecialchars($uri1)."</a></td><td>".$count."</td></tr>";
			}
		}
	}
else
	{ $adminmain .= "<tr><td colspan=\"2\">".$L['None']."</td></tr>"; }

$adminmain .= "</table>";

?>
