<?php

define('IN_COPPERMINE', true);

require('include/init.inc.php');
pageheader("Gallery Statistics");

activityGraph("FROM_UNIXTIME(ctime)", $CONFIG['TABLE_PICTURES'], "Uploads", "images/bar.gif");
activityGraph("msg_date", $CONFIG['TABLE_COMMENTS'], "Comments", "images/bar.gif");


//Activity Graph Function
function activityGraph($cellName, $tableName, $title, $barTile, $notCtime=false)
{
	global $CONFIG;
	starttable('100%', $title, 26);
	
	$query = "SELECT COUNT(*) AS number, HOUR($cellName) AS period FROM $tableName GROUP BY HOUR($cellName) ";
	$result = cpg_db_query($query);
	while ($row = mysql_fetch_assoc($result)) $rowset[$row['period']] = $row['number'];
	mysql_free_result($result);
	
	print('<tr><td align="center" colspan="26"><b>Time of Day</b></td></tr>');
	print('<tr><td align="center" colspan="26" height="2"></td></tr>');
	print('<tr><td align="center" colspan="26" height="2" bgcolor="#000000"></td></tr>');
	print('<tr><td align="center" colspan="26" height="1"></td></tr>');
	print('<tr><td height="100" width="1" valign="bottom"><img src="images/spacer.gif" width="1" height="200" /></td>');
	
	$total = array_sum($rowset);
	$max = max($rowset);
	
	foreach ($rowset as $number)
	{
			print('<td height="100" width="4%" valign="bottom" align="center" style="font-size: 80%">'.round(($number/$total)*100,1).'%<br /><img src="'.$barTile.'" border="1" alt="" width="15" height="'.round(($number/$max)*200,0).'" /></td>');
	}
	print('<td height="100" width="1" valign="bottom"><img src="images/spacer.gif" width="1" height="200" /></td></tr>');
	print('<tr><td align="center" colspan="26" height="1"></td></tr>');
	print('<tr><td align="center" colspan="26" height="2" bgcolor="#000000"></td></tr>');
	print('<tr><td align="center" colspan="26" height="1"></td></tr>');
	print('<tr><td></td>');
	for($i = '0'; $i <= '23'; $i++)
	{
		print('<td width="4%" align="center">'.$i.'</td>');
	}
	print('<td></td></tr>');
	
	endtable();
	print('<img src="images/spacer.gif" alt="" height="17 width="1" />');
}




//Start Most Commented
display_thumbnails('mostcom', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Most Commented

//Start Most Voted
display_thumbnails('mostvot', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Most Voted

//Start Most Viewed
display_thumbnails('topn', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Most Viewed

//Start User Most Commented
display_thumbnails('mostcomusr', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End User Most Commented

//Start User Most Voted
display_thumbnails('mostvotusr', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End User Most Voted

//Start User Most Viewed
display_thumbnails('mostvieusr', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End User Most Viewed

//Start User Most Commenting
display_thumbnails('topcom', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End User Most Commenting

//Start Album Most Commented
display_thumbnails('mostcomalb', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Album Most Commented

//Start Album Most Voted
display_thumbnails('mostvotalb', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Album Most Voted


//Start Album Most Viewed
display_thumbnails('mostviealb', $cat, 1, $CONFIG['thumbcols'], 1, false);
//End Album Most Viewed

//Start Upload Activity By Time	
activityGraph("ctime", $CONFIG['TABLE_PICTURES'], "Upload Activity By Time", "images/siteLayout/Contentpanel_Sidebar_05.gif");
//End Upload Activity By Time	

//Start Comment Activity By Time	
activityGraph("msg_date", $CONFIG['TABLE_COMMENTS'], "Comment Posting By Time", "images/siteLayout/Contentpanel_Sidebar_05.gif", true);
//End Comment Activity By Time	

//Start Vote Activity By Time
activityGraph("vote_time", $CONFIG['TABLE_VOTES'], "Voting Activity By Time", "images/siteLayout/Contentpanel_Sidebar_05.gif");
//End Vote Activity By Time	

//Start Viewing Activity By Time
//check to make sure hit_stats table exists
if(isset($CONFIG['TABLE_HIT_STATS']))
{
	activityGraph("sdate", $CONFIG['TABLE_HIT_STATS'], "Viewing Activity By Time", "images/siteLayout/Contentpanel_Sidebar_05.gif");
}
//End Viewing Activity By Time


pagefooter();

$signature = 'Coppermine Photo Gallery ' . COPPERMINE_VERSION . ' ('. COPPERMINE_VERSION_STATUS . ')';

?>
