Location: PHPKode > scripts > KubeStats > control/index.php
<?php
require_once("../includes/config.php");
require_once("../includes/functions/func.global.php");
require_once("../includes/functions/loggincheck.php");

// Connect to database
db_connect($config);

$sites = array();
$today_day = date("j");
$today_month = date("n");
$today_year = date("Y");
$yester_time = strtotime("-1 day");
$yester_day = date("j",$yester_time);
$yester_month = date("n",$yester_time);
$yester_year = date("Y",$yester_time);

$query = "SELECT site_id,site_title,site_url FROM ".$config['db']['pre']."sites ORDER BY site_title";
$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
while ($info = @mysql_fetch_array($query_result))
{
	$visits_today = mysql_fetch_row(mysql_query("SELECT visits FROM ".$config['db']['pre']."days WHERE site_id='".$info['site_id']."' AND day='".$today_day."' AND month='".$today_month."' AND year='".$today_year."' LIMIT 1"));
	$visits_yesterday = mysql_fetch_row(mysql_query("SELECT visits FROM ".$config['db']['pre']."days WHERE site_id='".$info['site_id']."' AND day='".$yester_day."' AND month='".$yester_month."' AND year='".$yester_year."' LIMIT 1"));

	$sites[$info['site_id']] = $info;
	if(isset($visits_today[0]))
	{
		$sites[$info['site_id']]['today'] = $visits_today[0];
	}
	else
	{
		$sites[$info['site_id']]['today'] = 0;
	}
	$sites[$info['site_id']]['yesterday'] = 0;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>KubeStats</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="images/style.css">
<script language="JavaScript" type="text/JavaScript">
var http = createRequestObject();
<?
$start_stamp = strtotime("-7 day");
$end_stamp = date("U");

$start_day = date("j");
$start_month = date("n");
$start_year = date("y");

$today_day = date("j",$end_stamp);
$today_month = date("n",$end_stamp);
$today_year = date("y",$end_stamp);

$start_disp = date("j M",$start_stamp);
$end_disp = date("j M",$end_stamp);

?>
var current_tier='';
var start_day='<?=$start_day;?>';
var start_month='<?=$start_month;?>';
var start_year='<?=$start_year;?>';
var end_day='<?=$today_day;?>';
var end_month='<?=$today_month;?>';
var end_year='<?=$today_year;?>';
var current_plus = 0;

months = new Array();
months[1] = 31;
months[2] = 28;
months[3] = 31;
months[4] = 30;
months[5] = 31;
months[6] = 30;
months[7] = 31;
months[8] = 31;
months[9] = 30;
months[10] = 31;
months[11] = 30;
months[12] = 31;

month_names = new Array();
month_names[0] = 'Jan';
month_names[1] = 'Feb';
month_names[2] = 'Mar';
month_names[3] = 'Apr';
month_names[4] = 'May';
month_names[5] = 'Jun';
month_names[6] = 'Jul';
month_names[7] = 'Aug';
month_names[8] = 'Sep';
month_names[9] = 'Oct';
month_names[10] = 'Nov';
month_names[11] = 'Dec';


function createRequestObject() 
{
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function deletesite(id)
{
	var con=confirm("Are you sure you want to remove this site?\r\n\r\nAll of your statistics will be removed forever");
	
	if(con == true)
	{
		<?
		if($config['demo'])
		{
		?>
		alert('Due to this being a demo, removing sites is disabled.');
		return;
		<?
		}
		else
		{
		?>
		document.getElementById('site'+id).style.display = 'none';
		http.open('get', 'ajax.php?id='+id+'&cmd=delete');
		http.send(null);
		<?
		}
		?>
	}
}
function add_site()
{
	http.open('get', 'ajax.php?cmd=add&site_title='+escape(document.form1.site_title.value)+'&site_url='+escape(document.form1.site_url.value));
	http.onreadystatechange = addResponse;
	http.send(null);
}
function save_site()
{
	http.open('get', 'ajax.php?cmd=save&site_id='+current_site+'&site_title='+escape(document.form1.site_title.value)+'&site_url='+escape(document.form1.site_url.value));
	http.onreadystatechange = saveResponse;
	http.send(null);
}
function change_page(page)
{
	document.getElementById('tierwin').style.display = 'none';

	if(page == 'add')
	{
		document.getElementById('addlink').className = 'current';
		document.getElementById('managelink').className = '';
		document.getElementById('content').innerHTML = '<form name="form1" method="post" action=""><table width="500" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" height="30">Site Title: </td><td><input name="site_title" type="text" id="site_title"></td></tr><tr><td height="30">Site Url:</td><td><input name="site_url" type="text" id="site_url" value="http://"></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td><input type="button" name="Submit" value="Add Site" onclick="add_site();"></td></tr></table></form>';
	}
	else if(page == 'manage')
	{
		http.open('get', 'ajax.php?cmd=view');
		http.onreadystatechange = manageResponse;
		http.send(null);
	
		document.getElementById('addlink').className = '';
		document.getElementById('managelink').className = 'current';
		document.getElementById('content').innerHTML = 'Loading Sites';
	}
}
function opensite(id)
{
	document.getElementById('tierwin').style.display = '';
	current_site = id;

	change_tier('summary',true);
}
function editsite(id)
{
	document.getElementById('tierwin').style.display = '';
	current_site = id;

	change_tier('edit',false);
}
function getcode(id)
{
	document.getElementById('tierwin').style.display = '';
	current_site = id;

	change_tier('code',false);
}
function change_tier(page,change)
{
	if(change == true)
	{
		if(current_tier != '')
		{
			document.getElementById(current_tier).className = '';
		}
		document.getElementById(page).className = 'current';
		current_tier = page;
	}
	else
	{
		if(current_tier != '')
		{
			document.getElementById(current_tier).className = '';
		}
	}

	if(page == 'summary')
	{
		current_plus = 0;
	
		//document.getElementById('content').innerHTML = 'Loading Summary';
		
		document.getElementById('content').innerHTML = '<div align="center"><img src="images/legend.gif"></div><img id="graph" alt="Visitor Graph" src="graphs.php?id='+current_site+'&rand='+Math.random()+'&time=<?=time();?>&start_stamp=<?=$start_stamp;?>&end_stamp=<?=$end_stamp;?>"><br><div align="center"><table width="200" border="0" cellpadding="0" cellspacing="0"><tr><td width="40" align="left"><a href="javascript:movegraphleft();">&lt;</a></td><td align="center"><span id="startdate"><?=$start_disp;?></span> - <span id="enddate"><?=$end_disp;?></span></td><td width="40" align="right"><a href="javascript:movegraphright();">&gt;</a></td></tr></table></div>';
		
		//http.open('get', 'ajax.php?cmd=summary&id='+current_site);
		//http.onreadystatechange = siteResponse;
		//http.send(null);
	}
	else if(page == 'referrers')
	{
		document.getElementById('content').innerHTML = 'Loading Referer List';
		
		http.open('get', 'ajax.php?cmd=referers&id='+current_site);
		http.onreadystatechange = siteResponse;
		http.send(null);
	}
	else if(page == 'code')
	{
		document.getElementById('content').innerHTML = '<br><strong>Copy and paste the code below into your webpages:</strong><br><Br><textarea name="textarea" style="width:600px;" cols="60" rows="5" onClick="this.focus();this.select();"><!-- Begin Kubelabs Tracker Code --><script language="javascript" type="text/javascript"><!-- \r\nvar refer=document.referrer;var url=\'<?=$config['site_url'];?>statlog.php?id='+current_site+'&refer=\'+escape(refer);document.write(\'<img src=\'+url+\' width="1" height="1">\');\r\n// --><\/script><noscript><img src="<?=$config['site_url'];?>statlog.php?id='+current_site+'" width="1" height="1" alt="" /><\/noscript>\r\n<!-- End Kubelabs Tracker Code --></textarea>';
	}
	else if(page == 'edit')
	{
		document.getElementById('content').innerHTML = 'Loading Site Details';
		
		http.open('get', 'ajax.php?cmd=edit&id='+current_site);
		http.onreadystatechange = siteResponse;
		http.send(null);
	}
	else if(page == 'search')
	{
		document.getElementById('content').innerHTML = 'Loading Search Keywords';
		
		http.open('get', 'ajax.php?cmd=search&id='+current_site);
		http.onreadystatechange = siteResponse;
		http.send(null);
	}
	else if(page == 'visits')
	{
		document.getElementById('content').innerHTML = 'Loading Recent Visitors';
		
		http.open('get', 'ajax.php?cmd=visits&id='+current_site);
		http.onreadystatechange = siteResponse;
		http.send(null);
	}
	else if(page == 'browsers')
	{
		document.getElementById('content').innerHTML = '<div align="center"><br><br><img id="browserpie" src="graphs.php?id='+current_site+'&rand='+Math.random()+'&cmd=browsers"><br><br></div>';
	}
}
function manageResponse()
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	
		document.getElementById('content').innerHTML = response;
	}
}
function addResponse()
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	
		change_page('manage');
	}
}

function saveResponse()
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	
		change_page('manage');
	}
}

function siteResponse()
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	
		document.getElementById('content').innerHTML = response;
	}
}

function movegraphleft()
{

}

function addDays(days,date) 
{
	return (date + (days*86400));
}

function movegraphright()
{
	current_plus = (current_plus+3);

	stamp_start = addDays(current_plus,<?=$start_stamp;?>);
	stamp_end = addDays(current_plus,<?=$end_stamp;?>);
	
	document.getElementById('startdate').innerHTML = formdate(stamp_start);
	document.getElementById('enddate').innerHTML = formdate(stamp_end);
	
	document.getElementById('graph').src = 'graphs.php?id='+current_site+'&rand='+Math.random()+'&start_stamp='+stamp_start+'&end_stamp='+stamp_end;
}

function formdate(stamp)
{
	var curdate = new Date((stamp*1000));
	var mday = curdate.getDate();
	var month = curdate.getMonth();
	
	return mday+' '+month_names[month];
}

function movegraphleft()
{
	current_plus = (current_plus-3);

	stamp_start = addDays(current_plus,<?=$start_stamp;?>);
	stamp_end = addDays(current_plus,<?=$end_stamp;?>);
	
	document.getElementById('startdate').innerHTML = formdate(stamp_start);
	document.getElementById('enddate').innerHTML = formdate(stamp_end);
	
	document.getElementById('graph').src = 'graphs.php?id='+current_site+'&rand='+Math.random()+'&start_stamp='+stamp_start+'&end_stamp='+stamp_end;
}
</script>
</head>
<body>
<br>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td><span class="statstitle">KubeStats</span><br></td>
  </tr>
  <tr>
    <td>                <div id="tabs1">
                        <ul>
<li id="addlink"><a href="javascript:change_page('add');"><span>Add Site</span></a></li>
<li id="managelink" class="current"><a href="javascript:change_page('manage');"><span>Manage Sites</span></a></li>
<li id="logoutlink"><a href="logout.php"><span>Logout</span></a></li>
                        </ul>
                </div></td>
  </tr>
  <tr id="tierwin" style="display:none;">
    <td style="border-bottom: 1px solid #BCD2E6;border-right: 1px solid #BCD2E6;"><div id="navcontainer"><ul id="navlist">
<li id="summary"><a href="javascript:change_tier('summary',true);">Summary</a></li>
<li id="referrers"><a href="javascript:change_tier('referrers',true);">Referrers</a></li>
<li id="search"><a href="javascript:change_tier('search',true);">Search Keywords</a></li>
<li id="visits"><a href="javascript:change_tier('visits',true);">Latest Visitors</a></li>
<li id="browsers"><a href="javascript:change_tier('browsers',true);">Browsers</a></li>
</ul></div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><div id="content">
<?
if(count($sites) == 0)
{
	echo 'You havn\'t added any sites yet, <a href="javascript:change_page(\'add\');">click here</a> to add one.';
}
else
{
?>	
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?
foreach ($sites as $key => $info)
{
	if($info['site_title'] == '')
	{
		$info['site_title'] = '&nbsp;';
	}
?>
      <tr id="site<?=$info['site_id'];?>">
        <td style="font-size:14px;"><a href="javascript:opensite(<?=$info['site_id'];?>);"><?=$info['site_title'];?></a></td>
		<td width="88"><a href="javascript:getcode(<?=$info['site_id'];?>);"><img src="images/code.gif" width="78" height="16" border="0"></a></td>
		<td width="88" align="left" valign="middle"><a href="javascript:opensite(<?=$info['site_id'];?>);"><img src="images/stats.gif" width="78" height="16" border="0"></a></td>
        <td width="58" height="20" align="left" valign="middle"><a href="javascript:editsite(<?=$info['site_id'];?>);"><img src="images/editfull.gif" width="48" height="16" border="0"></a></td>
        <td width="64" align="left" valign="middle"><a href="javascript:deletesite('<?=$info['site_id'];?>');"><img src="images/delete.gif" width="64" height="16" border="0"></a></td>
        </tr>
<?
}
?>
    </table>
<?
}
?>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="center"><br>
    <br>      &copy;2007 <a href="http://www.kubelabs.com/kubestats.php">KubeStats</a> <?=$config['version'];?></td>
  </tr>
</table>
</body>
</html>
Return current item: KubeStats