Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.fns.show_detail_eprint.es.php
<?php
/*
	Usage by dates, countries, totals.
*/
/* New */
	function getCountryEprintType($year,$month,$rnge,$type,$id) 
	{
		$year = (int) $year;
		$month = (int) $month;
		$records = array();

		// Generate type enquiry
		if ($type == 'download') {
			$limit2 = ' AND view_type = "download" ';
		} elseif ($type == 'abstract') {
			$limit2 = ' AND view_type = "abstract" ';
		} else {
			$limit2 = '';
		}

		// generate date enquiry
		$date_range = '';
		if($year>=2002 and $year<2100) {
			if($month>0 and $month<=12) {
				$date_range = " AND year(request_date) = $year AND month(request_date) = $month";
			} else {
				$date_range = " AND year(request_date) = $year";
			}
		} 
		if($rnge=='4w') {
			$date_range = " AND request_date >= date_sub(curdate(),INTERVAL 1 MONTH)";
		}
		
		$query = 
			'select count(*) as count,country_name,country_code from view WHERE archiveid = ' . 
			$id .
			$limit2 .
			$date_range .
			' GROUP BY country_name ORDER BY count DESC';
		$result = mysql_query($query);
		if (!$result) {
			sqlconn::_setError(mysql_errno(),mysql_error());
			return mysql_error();
		} else {
			while ($row = mysql_fetch_assoc($result)) {
				$records[] = $row;
			}
			return $records;
		}
		
	}

	// If no id default to front page.
	if(!isset($_REQUEST["id"])) { return "pub_default"; }

	// Get detail given year/month
	$show_date = 'all years';
	if(isset($_REQUEST["year"]) and $_REQUEST["year"]>2002) {
		if(isset($_REQUEST["month"]) and $_REQUEST["month"]>=1 and $_REQUEST["month"]<=12) { 
			$dt = strtotime($_REQUEST["month"]."/1/".$_REQUEST["year"]);
			$show_date = date("F Y",$dt);
		} else {
			$show_date = $_REQUEST["year"];	
			$_REQUEST["month"] = 0;
		}
	} else {
		$_REQUEST["year"] = 0;
		$_REQUEST["month"] = 0;
	}
	if(isset($_REQUEST["range"])) {
		// Work out current date
		if($_REQUEST["range"]=='4w') {
			$show_date = 'past 4 weeks';
		}
	} else {
		$_REQUEST["range"] = '';
	}
	// by country
	$country_abstracts = getCountryEprintType($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'abstract', $_REQUEST["id"]);
	$country_downloads = getCountryEprintType($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
	$GLOBALS["db_values"] = merge_countries($country_abstracts, $country_downloads);
	// title
	$title = $sql->getTitle($_REQUEST["id"]);
	// by type
	$type_count = $sql->getAbstractDownload($_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
	// by date
	$month_downloads = $sql->getCumulativeUsageType($_REQUEST["id"],'download');
	$month_abstracts = $sql->getCumulativeUsageType($_REQUEST["id"],'abstract');
	$month_tally = merge_dates($month_abstracts,$month_downloads);
	
?>