diff --git a/Repositories/statistics/htdocs/download_by_dept.php b/Repositories/statistics/htdocs/download_by_dept.php
new file mode 100755
index 0000000..457e964
--- /dev/null
+++ b/Repositories/statistics/htdocs/download_by_dept.php
@@ -0,0 +1,135 @@
+
+
+
+
+ Downloads by department
+
+
+
+
+Downloads by department
+
+setDebug($GLOBALS["config_vars"]["debug"][$GLOBALS["config_vars"]["thisrequest"]]); */
+
+$connection_archive = $sql_archive->doConnectServer
+ ( $GLOBALS["config_vars"]["connections"]["sqlserver_eprints"],
+ $GLOBALS["config_vars"]["connections"]["sqluser_eprints"],
+ $GLOBALS["config_vars"]["connections"]["sqlpass_eprints"]
+ );
+if (!$connection_archive)
+ error($GLOBALS["config_vars"]["messages"]["message_noservice"] ,ERROR_EXIT);
+
+$db_archive = $sql_archive->doConnectDb($GLOBALS["config_vars"]["connections"]["sqldatabase_eprints"]);
+if (!$db_archive)
+{
+ error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
+ exitScript();
+}
+
+$sql_stats = new sqlconn();
+
+$connection_stats = $sql_stats->doConnectServer
+ ( $GLOBALS["config_vars"]["connections"]["sqlserver"],
+ $GLOBALS["config_vars"]["connections"]["sqluser_public"],
+ $GLOBALS["config_vars"]["connections"]["sqlpass_public"]
+ );
+if (!$connection_stats)
+ error($GLOBALS["config_vars"]["messages"]["message_noservice"] ,ERROR_EXIT);
+
+$db_stats = $sql_stats->doConnectDb($GLOBALS["config_vars"]["connections"]["sqldatabase"]);
+if (!$db_stats)
+{
+ error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
+ exitScript();
+}
+
+$query =
+"SELECT TRIM(TRAILING ' ' FROM S.name) AS name, E.eprintid AS eprintid
+ FROM archive E INNER JOIN archive_affiliations A USING (eprintid)
+ INNER JOIN subject_name S ON (A.affiliations = S.subjectid)
+ WHERE S.name LIKE '% '
+ ORDER BY S.name"; /* Note use of non-breaking space (UTF8 00A0) in name column. */
+
+$current_dept = "";
+$idlist = "";
+$dept_count = 0;
+$result = mysql_query($query, $connection_archive);
+
+if (!$result)
+{
+ error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
+ print "failed departments query
";
+ exitScript();
+}
+else
+{
+ print "
+ Department |
+ eprints |
+ Abstract views |
+ Downloads | ";
+ while ($row = mysql_fetch_assoc($result))
+ {
+ if ($row["name"] != $current_dept)
+ {
+ print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
+ $current_dept = $row["name"];
+ $dept_count = 0;
+ $idlist = "";
+ }
+ $dept_count++;
+ $idlist .= $row["eprintid"] . ',';
+ }
+ print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
+ print "
";
+}
+
+function print_new_row ($conn, $dept, $count, $idlist)
+{
+ if ($dept != "")
+ {
+ print "";
+ print "" . $dept . " | ";
+ print "" . $count . " | ";
+ print_downloads($conn, rtrim($idlist, ','));
+ }
+}
+
+function print_downloads ($conn, $idlist)
+{
+ $query =
+ "SELECT COUNT(*) AS num
+ FROM view
+ WHERE view.archiveid IN ($idlist)
+ AND view.view_type = ";
+
+ $viewtypes = array('abstract', 'download');
+
+ foreach ($viewtypes as $type)
+ {
+ $result = mysql_query($query . "'" . $type . "'", $conn);
+
+ if (!$result)
+ {
+ print "failed | ";
+ }
+ else
+ {
+ $row = mysql_fetch_assoc($result);
+ print "" . $row["num"] . " | ";
+ }
+ }
+}
+
+?>
+
+
+
+