diff --git a/Repositories/statistics/includes/inc.class.mysql.es.php b/Repositories/statistics/includes/inc.class.mysql.es.php index f5853f2..02974b0 100755 --- a/Repositories/statistics/includes/inc.class.mysql.es.php +++ b/Repositories/statistics/includes/inc.class.mysql.es.php @@ -146,9 +146,9 @@ //Build up the query // NJS 2006-01-18: Added count of country_code. $query = " - select count(*) as count,count(distinct country_code) as countries,month(request_date) as monthnum,date_format(request_date,'%b') as month,year(request_date) as year from view + SELECT COUNT(*) AS count, COUNT(DISTINCT country_code) AS countries, MONTH(request_date) AS monthnum, DATE_FORMAT(request_date, '%b') AS month, YEAR(request_date) AS year FROM view $limit - group by year(request_date),month(request_date) order by request_date desc + GROUP BY YEAR(request_date), MONTH(request_date) ORDER BY request_date DESC "; // Make the query $result = mysql_query($query); @@ -186,9 +186,11 @@ // Create a result array $records = array(); //Build up the query - $query = 'select count(*) as count,country_name,country_code from view ' . +// NJS 2006-05-02: Fixed typo in ORDER BY and added ascending order of country +// name for countries with the same number of accesses. + $query = 'SELECT COUNT(*) AS count, country_name, country_code FROM view ' . $limit2 . - 'group by country_name order by count desc'; + 'GROUP BY country_name ORDER BY count DESC, country_name ASC'; $result = mysql_query($query); if (!$result) { sqlconn::_setError(mysql_errno(),mysql_error()); @@ -212,9 +214,9 @@ $date_range = ''; if($year>=2002 and $year<2100) { if($month>0 and $month<=12) { - $date_range = "WHERE year(request_date) = $year and month(request_date) = $month"; + $date_range = "WHERE YEAR(request_date) = $year AND MONTH(request_date) = $month"; } else { - $date_range = "WHERE year(request_date) = $year"; + $date_range = "WHERE YEAR(request_date) = $year"; } } if($range=='4w') { @@ -228,10 +230,13 @@ } // End of addition -------------------------------------------------- // NJS 2006-01-18: Added count of country_code. + // NJS 2003-05-02: Added descending order of number of countries and + // ascending order of title for eprints with the same number of + // downloads. $query = " - select count(*) as count,count(distinct country_code) as countries,archiveid,eprint_name from view + SELECT COUNT(*) AS count, COUNT(DISTINCT country_code) AS countries, archiveid, eprint_name FROM view $date_range - group by archiveid order by count desc + GROUP BY archiveid ORDER BY count DESC, countries DESC, eprint_name ASC "; $result = mysql_query($query); if (!$result) { @@ -254,11 +259,13 @@ { $records = array(); // Create a country based limit. Also constrain to downloads only. - $restriction = "WHERE country_code = '$ccode' and view_type = 'download'"; + $restriction = "WHERE country_code = '$ccode' AND view_type = 'download'"; + // NJS 2003-05-02: Added ascending order of title for eprints with + // the same number of downloads. $query = " - select count(*) as count, archiveid, eprint_name, country_name from view + SELECT COUNT(*) AS count, archiveid, eprint_name, country_name FROM view $restriction - group by archiveid order by count desc + GROUP BY archiveid ORDER BY count DESC, eprint_name ASC "; $result = mysql_query($query); if (!$result) { @@ -301,12 +308,14 @@ $date_range = " AND request_date >= date_sub(curdate(),INTERVAL 1 MONTH)"; } +// NJS 2006-05-02: Added ascending order of country +// name for countries with the same number of accesses. $query = - 'select count(*) as count,country_name,country_code from view WHERE archiveid = ' . + 'SELECT COUNT(*) AS count, country_name, country_code FROM view WHERE archiveid = ' . $id . $limit2 . $date_range . - ' GROUP BY country_name ORDER BY count DESC'; + ' GROUP BY country_name ORDER BY count DESC, country_name ASC'; $result = mysql_query($query); if (!$result) { sqlconn::_setError(mysql_errno(),mysql_error()); @@ -341,20 +350,21 @@ // NJS 2006-01-18: Fixed upper year bound (was 2005). if($year>=2002 and $year<2100) { if($month>0 and $month<=12) { - $date_range = "AND year(request_date) = $year and month(request_date) = $month"; + $date_range = "AND YEAR(request_date) = $year AND MONTH(request_date) = $month"; } else { - $date_range = "AND year(request_date) = $year"; + $date_range = "AND YEAR(request_date) = $year"; } } if($range=='4w') { - $date_range = "AND request_date >= date_sub(curdate(),INTERVAL 1 MONTH)"; + $date_range = "AND request_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)"; } // NJS 2006-01-18: Added count of country_code. + // NJS 2006-05-02: Added ascending order of country code. $query = " - select count(*) as count,count(distinct country_code) as countries,view_type from view + SELECT COUNT(*) AS count, COUNT(DISTINCT country_code) AS countries, view_type from view WHERE archiveid = $id $date_range - group by view_type order by count desc + GROUP BY view_type ORDER BY count DESC, country_code ASC "; $result = mysql_query($query); if (!$result) { @@ -372,7 +382,7 @@ function getLastProc() { // Get the time that the stats were last processed. - $query = "SELECT timeinsert FROM lastproc ORDER BY timeinsert DESC LIMIT 1;"; + $query = "SELECT timeinsert FROM lastproc ORDER BY id DESC LIMIT 1;"; $result = mysql_query($query); if (!$result) { sqlconn::_setError(mysql_errno(),mysql_error()); @@ -383,6 +393,37 @@ } } + + /* + NJS 2006-02-09 (moved here from inc.fns.show_detail_eprint.es.php) + + Grab the title of an eprint from the repository. Only needed if + the title isn't already in the stats database, which should only + occur when an eprint hasn't been downloaded yet. + */ + function getEPrintTitle($eprint_id) + { + $eprint_title = ''; + $conn_eprints = mysql_connect( + $GLOBALS["config_vars"]["connections"]["sqlserver_eprints"], + $GLOBALS["config_vars"]["connections"]["sqluser_eprints"], + $GLOBALS["config_vars"]["connections"]["sqlpass_eprints"] + ); + $db_eprints = mysql_select_db( + $GLOBALS["config_vars"]["connections"]["sqldatabase_eprints"], + $conn_eprints + ); + if (!$db_eprints) return $eprint_title; + $query_eprints = "select title from archive where eprintid = $eprint_id"; + $result_eprints = mysql_query($query_eprints,$conn_eprints); + $row_eprints = mysql_fetch_assoc($result_eprints); + $eprint_title = trim($row_eprints["title"]); + $eprint_title = preg_replace("/\s+/"," ",$eprint_title); + mysql_close($conn_eprints); + return $eprint_title; + } + + } ?>