Location: PHPKode > projects > Basic Announce > Basic Announce Version 4.0/system/mod_statistics.php
<?php
################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 #
## --------------------------------------------------------------------------- #
##  ApPHP AdminPanel Pro                                                       #
##  Developed by:  ApPHP <hide@address.com>                                      #
##  License:       GNU LGPL v.3                                                #
##  Site:          http://www.apphp.com/php-adminpanel/                        #
##  Copyright:     ApPHP AdminPanel (c) 2006-2011. All rights reserved.        #
##                                                                             #
################################################################################

    // Initialize the session.
    session_start();
    
    require_once("../inc/classes/session.class.php");	
    require_once("../inc/checkAdminPagePermissions.php");

    require_once("../inc/config.inc.php");
    require_once("../inc/settings.inc.php");
	require_once("../inc/functions.inc.php");
	require_once("../inc/languages/".$SETTINGS['site_language'].".php");

	if(!module_istalled('statistics')) redirect_to("access_denied.php");
    if(!page_access_allowed($_SERVER['SCRIPT_NAME'])) redirect_to("access_denied.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
	<title><?php echo $SETTINGS['site_name']; ?> :: <?php echo lang('admin_panel'); ?></title>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">	
	<style>	
		#frmTabs{
			margin:0px;
		}
		
		IMG { border:0px; }

		/*** Dashboard **/
		.section_title_left  	{ background:url(../images/left_border.gif) no-repeat; height: 22px; width: 2px; }
		.section_title 		 	{ background:url(../images/rep.gif) 0 100% repeat-x; height: 22px; width: 100%; vertical-align: middle; }
		.section_title_right 	{ background:url(../images/right_border.gif) no-repeat; height: 22px; width: 2px; }
		.section_title_text  	{ font-family: Tahoma, Verdana; font-size: 12px; font-weight: bold; color: #666666; text-decoration: none; padding: 3px 0 0 5px; }
		
		/*** Breadcrumbs ***/                        
		.breadcrumb           { font:12px Tahoma, Verdana;  }
		.breadcrumb a         { text-decoration: none; color:#555555; }
		.breadcrumb a:link    { text-decoration: none; color:#555555; }
		.breadcrumb a:visited { text-decoration: none; color:#555555; }
		.breadcrumb a:hover   { text-decoration: underline; color:#a60000; }
		
	</style>
</head>
<body dir="<?php echo $SETTINGS['language_dir'];?>">
<?php echo page_breadcrumbs(); ?>
<br />
<?php

    define ("TABS_DIR", "../modules/tabs/");
    require_once(TABS_DIR."tabs.class.php");
	
	echo "<script type='text/javascript' src='http://www.google.com/jsapi'></script>";

	$first_tab_content 	= "";
	$second_tab_content = "";
	$third_tab_content 	= "";
	$fourth_tab_content	= "";
	$tabid 				= isset($_POST['tabid']) ? $_POST['tabid'] : "1_1";
	
	$chart_type = isset($_POST['chart_type']) ? $_POST['chart_type'] : "columnchart";
	$year 		= isset($_POST['year']) ? $_POST['year'] : date("Y");

	if($tabid == "1_1") {		
		$first_tab_content = "
			<script type='text/javascript'>
					function drawVisualization(){
					// Create and populate the data table.
					var data = new google.visualization.DataTable();
					data.addColumn('string', 'Admins');
					data.addColumn('number', 'Logins');";
					
		$sql = "SELECT username, logins_count FROM ".TABLE_ADMINS." ORDER BY logins_count DESC LIMIT 0, 10";         
		$db->Query($sql);									
			
		$first_tab_content .= "\n data.addRows(10);";
		
		$ind = "0";
		while($row = $db->FetchArray()){
			$first_tab_content .= "\n data.setValue(".$ind.", 0, '".$row['username']." (".$row['logins_count'].")');";
			$first_tab_content .= "\n data.setValue(".$ind.", 1, ".(($row['logins_count'] != "") ? $row['logins_count'] : "0").");";
			$ind++;	
		}
				 
		// Create and draw the visualization
		if($chart_type == "barchart"){
			$first_tab_content .= "new google.visualization.BarChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});"; 
		}else if($chart_type == "piechart"){
			$first_tab_content .= "new google.visualization.PieChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}else if($chart_type == "areachart"){
			$first_tab_content .= "new google.visualization.AreaChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}else{ // columnchart
			$first_tab_content .= "new google.visualization.ColumnChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}			   
				   
		$first_tab_content .= " } </script>";
		
		$first_tab_content .= "<script type='text/javascript'>";
		$first_tab_content .= "\n google.load('visualization', '1', {packages: ['".$chart_type."']});";
		$first_tab_content .= "\n google.setOnLoadCallback(drawVisualization);";
		$first_tab_content .= "\n function frmStatistics_Submit() { document.frmStatistics.submit(); }";
		$first_tab_content .= "</script>";
		
		$first_tab_content .= "<form action='mod_statistics.php' name='frmStatistics' method='post' style='margin:0px;margin-left:20px;' >
				<input type='hidden' name='tabid' value='1_1' />
				<table width='98%' align='center' border='0'>
				<tr>
					<td valign='middle' width='140px'>
					Type: <select name='chart_type' onchange='frmStatistics_Submit();'>
						<option value='barchart' ".(($chart_type == "barchart") ? " selected='selected'" : "").">Barchart</option>
						<option value='columnchart' ".(($chart_type == "columnchart") ? " selected='selected'" : "").">ColumnChart</option>
						<option value='piechart' ".(($chart_type == "piechart") ? " selected='selected'" : "").">PieChart</option>
						<option value='areachart' ".(($chart_type == "areachart") ? " selected='selected'" : "").">AreaChart</option>
					</select>
					</td>
					<td></td>
				</tr>
				</table>
				</form>";	
			
		$first_tab_content .= "<div id='div_visualization' style='margin-left:20px;width:670px;height:320px;'>
		<img src='../images/loading.gif' style='margin:100px auto;' alt='loading...'></div>";
		
	}else if($tabid == "1_2"){
		
		$second_tab_content = "
			<script type='text/javascript'>
					function drawVisualization(){
					// Create and populate the data table.
					var data = new google.visualization.DataTable();
					data.addColumn('string', 'Admins');
					data.addColumn('number', 'Logins');";
					
		$sql = "SELECT username, logins_count FROM ".TABLE_USERS." ORDER BY logins_count DESC LIMIT 0, 10";         
		$db->Query($sql);									
			
		$second_tab_content .= "\n data.addRows(10);";
		
		$ind = "0";
		while($row = $db->FetchArray()){
			$second_tab_content .= "\n data.setValue(".$ind.", 0, '".$row['username']." (".$row['logins_count'].")');";
			$second_tab_content .= "\n data.setValue(".$ind.", 1, ".(($row['logins_count'] != "") ? $row['logins_count'] : "0").");";
			$ind++;	
		}
				 
		// Create and draw the visualization
		if($chart_type == "barchart"){
			$second_tab_content .= "new google.visualization.BarChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});"; 
		}else if($chart_type == "piechart"){
			$second_tab_content .= "new google.visualization.PieChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}else if($chart_type == "areachart"){
			$second_tab_content .= "new google.visualization.AreaChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}else{ // columnchart
			$second_tab_content .= "new google.visualization.ColumnChart(document.getElementById('div_visualization')).draw(data, {is3D: true, min:0, title:'Logins'});";
		}			   
				   
		$second_tab_content .= " } </script>";
		
		$second_tab_content .= "<script type='text/javascript'>";
		$second_tab_content .= "\n google.load('visualization', '1', {packages: ['".$chart_type."']});";
		$second_tab_content .= "\n google.setOnLoadCallback(drawVisualization);";
		$second_tab_content .= "\n function frmStatistics_Submit() { document.frmStatistics.submit(); }";
		$second_tab_content .= "</script>";
		
		$second_tab_content .= "<form action='mod_statistics.php' name='frmStatistics' method='post' style='margin:0px;margin-left:20px;' >	
				<input type='hidden' name='tabid' value='1_2' />
				<table width='98%' align='center' border='0'>
				<tr>
					<td valign='middle' width='140px'>
					Type: <select name='chart_type' onchange='frmStatistics_Submit();'>
						<option value='barchart' ".(($chart_type == "barchart") ? " selected='selected'" : "").">Barchart</option>
						<option value='columnchart' ".(($chart_type == "columnchart") ? " selected='selected'" : "").">ColumnChart</option>
						<option value='piechart' ".(($chart_type == "piechart") ? " selected='selected'" : "").">PieChart</option>
						<option value='areachart' ".(($chart_type == "areachart") ? " selected='selected'" : "").">AreaChart</option>
					</select>
					</td>
					<td></td>
				</tr>
				</table>
				</form>";	
			
		$second_tab_content .= "<div id='div_visualization' style='margin-left:20px;width:670px;height:320px;'>
		<img src='../images/loading.gif' style='margin:100px auto;' alt='loading...'></div>";
		
	}else if($tabid == "1_3"){
		
		$third_tab_content .= "<table border=0 width='94%' align='center'>";
		$third_tab_content .= "<tr><th align='right' colspan='2'>".lang('today').": ".date("F d, Y")."</th></tr>";
		$third_tab_content .= "<tr>
								<th width='50%' align='left'>Logged Users</th>
								<th width='50%' align='left'>Accounts Created</th>
							</tr>";
		$third_tab_content .= "<tr>";
		$third_tab_content .= "<td>";
			$sql = "SELECT * FROM ".TABLE_USERS." WHERE last_login LIKE '".date("Y-m-d")."%'";
			$db->Query($sql);
			$ind = 0;
			while($row = $db->FetchArray()){
				$third_tab_content .= ($ind+1).". ".$row["first_name"]." ".$row["last_name"]." (".$row["username"].")<br>";
				$ind++;
			}
			if(!$ind) $third_tab_content .= "None";
		$third_tab_content .= "</td>";
		$third_tab_content .= "<td>";
			$sql = "SELECT * FROM ".TABLE_USERS." WHERE date_created LIKE '".date("Y-m-d")."%'";
			$db->Query($sql);
			$ind = 0;
			while($row = $db->FetchArray()){
				$third_tab_content .= ($ind+1).". ".$row["first_name"]." ".$row["last_name"]." (".$row["username"].")<br>";
				$ind++;
			}
			if(!$ind) $third_tab_content .= "None";
		$third_tab_content .= "</td>";
		$third_tab_content .= "</tr>";
		$third_tab_content .= "</table>";
		
	}else{
		$countries_top = "";
		$countries_total = "0";

		$sql = "SELECT
					COUNT(*) as cnt,
					".TABLE_COUNTRIES.".abbrv as country_abbrv,
					".TABLE_COUNTRIES.".name as country_name
				FROM ".TABLE_USERS."
					INNER JOIN ".TABLE_COUNTRIES." ON ".TABLE_USERS.".country = ".TABLE_COUNTRIES.".abbrv
				WHERE ".TABLE_COUNTRIES.".is_active = 1
				GROUP BY ".TABLE_COUNTRIES.".abbrv";
				
		$db->Query($sql);									
		
		$fourth_tab_content = "			
			<script type='text/javascript'>
			 google.load('visualization', '1', {'packages': ['geomap']});
			 google.setOnLoadCallback(drawMap);
			
			  function drawMap() {
				var data = new google.visualization.DataTable();
				";
				
		$ind = "0";
		if($db->RowCount() > 0){
			$fourth_tab_content .= "\n data.addRows(".$db->RowCount().");";
			$fourth_tab_content .= "\n data.addColumn('string', 'Country');";
			$fourth_tab_content .= "\n data.addColumn('number', 'Popularity');";
			$fourth_tab_content .= "\n data.addColumn('string', 'HOVER', '');";
			
			$ind = "0";	
			while($row = $db->FetchArray()){
				$fourth_tab_content .= "\n data.setValue(".$ind.", 0, '".$row['country_abbrv']."');";
				$fourth_tab_content .= "\n data.setValue(".$ind.", 1, ".$row['cnt'].");";
				$fourth_tab_content .= "\n data.setValue(".$ind.", 2, '".$row['country_name']."');";
				$ind++;
				if($ind < 20) $countries_top .= (($ind < 9) ? "&nbsp;" : "").($ind).". ".$row['country_name']." (".(int)$row['cnt'].") <br>";
				$countries_total += (int)$row['cnt'];
			}
		}else{
			$fourth_tab_content .= "\n data.addRows(1);";
			$fourth_tab_content .= "\n data.addColumn('string', 'Country');";
			$fourth_tab_content .= "\n data.addColumn('number', 'Popularity');";
			$fourth_tab_content .= "\n data.addColumn('string', 'HOVER', '');";
			$fourth_tab_content .= "\n data.setValue(0, 0, 'USA');";
			$fourth_tab_content .= "\n data.setValue(0, 1, 0)";
			$fourth_tab_content .= "\n data.setValue(0, 2, 'USA');";
		}
		
		$fourth_tab_content .= "	
				var options = {};
				options['dataMode'] = 'regions';
				options['width'] = '675px';
				options['showLegend'] = true;
			
				var container = document.getElementById('map_canvas');
				var geomap = new google.visualization.GeoMap(container);
				geomap.draw(data, options);
			};
			</script>
			
			<table border='0'>
			<tr>
				<td align='left' valign='top'>
					<div id='map_canvas' style='padding:1px 10px; 1px 10px;'></div>	
				</td>
				<td align='left' valign='top' nowrap style='padding-right:10px;'>
					<small>".$countries_top."</small>
				</td>
			</tr>
			</table>			
		";			
	}
	

	$tabs = new Tabs(1, "xp", TABS_DIR, "");   
	//$tabs->SetHttpVars(array("admin"));
 
	$tab1=$tabs->AddTab("Admins Logins", $first_tab_content);
	if(module_istalled('users')) $tab2=$tabs->AddTab("Users Logins", $second_tab_content);
	if(module_istalled('users')) $tab3=$tabs->AddTab("Today's Info (Users)", $third_tab_content);
	if(module_istalled('users')) $tab4=$tabs->AddTab("Map Overlay (Users)", $fourth_tab_content);
	
	 
	## +---------------------------------------------------------------------------+
	## | 2. Customizing:                                                           |
	## +---------------------------------------------------------------------------+
	## *** set container's width in pixels (px), inches (in) or points (pt)
	$tabs->SetWidth("850px");
 
	## *** set container's height in pixels (px), inches (in) or points (pt)
	$tabs->SetHeight("auto"); // "auto"
 
	## *** set alignment inside the container (left, center or right)
	$tabs->SetAlign("left");
 
	## *** set container's color in RGB format or using standard names
	/// $tabs->SetContainerColor("#64C864");
	## *** set border's width in pixels (px), inches (in) or points (pt)
	/// $tabs->SetBorderWidth("5px");
	## *** set border's color in RGB format or using standard names
	/// $tabs->SetBorderColor("#64C864");
	/// $tabs->SetBorderColor("blue");
	/// $tabs->SetBorderColor("#445566");
	## *** show debug info - false|true
	$tabs->Debug(false);
	## *** allow refresh selected tabs - false|true
	/// $tabs->AllowRefreshSelectedTabs(true);
	## *** set form submission type: "get" or "post"
	$tabs->SetSubmissionType("post");

	echo "<table align='center'>";	
	echo "<tr><td><div style='font-size:18px; font-weight:bold; text-align:center; padding-bottom:0;'>Statistics</div></td></tr>";
	echo "<tr><td>";
	$tabs->Display();
	echo "</td></tr>";
	echo "</table>";

?>
<br />
</body>
</html>
Return current item: Basic Announce