Newer
Older
Digital_Repository / Repositories / statistics / htdocs / download_by_unit.php
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <title>Downloads by organisational unit</title>
  7. <meta name="generator" content="BBEdit 8.2" />
  8. </head>
  9. <body>
  10.  
  11. <h1>Downloads by organisational unit</h1>
  12.  
  13. <?php
  14. require("inc.vars.es.php");
  15. require("inc.fns.es.php");
  16. require("inc.class.mysql.es.php");
  17.  
  18. $sql_archive = new sqlconn();
  19. /* $sql->setDebug($GLOBALS["config_vars"]["debug"][$GLOBALS["config_vars"]["thisrequest"]]); */
  20.  
  21. $connection_archive = $sql_archive->doConnectServer
  22. ( $GLOBALS["config_vars"]["connections"]["sqlserver_eprints"],
  23. $GLOBALS["config_vars"]["connections"]["sqluser_eprints"],
  24. $GLOBALS["config_vars"]["connections"]["sqlpass_eprints"]
  25. );
  26. if (!$connection_archive)
  27. error($GLOBALS["config_vars"]["messages"]["message_noservice"] ,ERROR_EXIT);
  28.  
  29. $db_archive = $sql_archive->doConnectDb($GLOBALS["config_vars"]["connections"]["sqldatabase_eprints"]);
  30. if (!$db_archive)
  31. {
  32. error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
  33. exitScript();
  34. }
  35.  
  36. $sql_stats = new sqlconn();
  37.  
  38. $connection_stats = $sql_stats->doConnectServer
  39. ( $GLOBALS["config_vars"]["connections"]["sqlserver"],
  40. $GLOBALS["config_vars"]["connections"]["sqluser_public"],
  41. $GLOBALS["config_vars"]["connections"]["sqlpass_public"]
  42. );
  43. if (!$connection_stats)
  44. error($GLOBALS["config_vars"]["messages"]["message_noservice"] ,ERROR_EXIT);
  45.  
  46. $db_stats = $sql_stats->doConnectDb($GLOBALS["config_vars"]["connections"]["sqldatabase"]);
  47. if (!$db_stats)
  48. {
  49. error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
  50. exitScript();
  51. }
  52.  
  53. $query =
  54. "SELECT TRIM(TRAILING ' ' FROM S.name) AS name, E.eprintid AS eprintid
  55. FROM archive E INNER JOIN archive_affiliations A USING (eprintid)
  56. INNER JOIN subject_name S ON (A.affiliations = S.subjectid)
  57. ORDER BY S.name";
  58.  
  59. $current_dept = "";
  60. $idlist = "";
  61. $dept_count = 0;
  62. $result = mysql_query($query, $connection_archive);
  63.  
  64. if (!$result)
  65. {
  66. error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
  67. print "<p>failed departments query</p>";
  68. exitScript();
  69. }
  70. else
  71. {
  72. print "<table border='1'><tr>
  73. <th>Organisational unit</th>
  74. <th>eprints</th>
  75. <th>Abstract views</th>
  76. <th>Downloads</th>";
  77. while ($row = mysql_fetch_assoc($result))
  78. {
  79. if ($row["name"] != $current_dept)
  80. {
  81. print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
  82. $current_dept = $row["name"];
  83. $dept_count = 0;
  84. $idlist = "";
  85. }
  86. $dept_count++;
  87. $idlist .= $row["eprintid"] . ',';
  88. }
  89. print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
  90. print "</tr></table>";
  91. }
  92.  
  93. function print_new_row ($conn, $dept, $count, $idlist)
  94. {
  95. if ($dept != "")
  96. {
  97. print "</tr><tr>";
  98. print "<td>" . $dept . "</td>";
  99. print "<td align='center'>" . $count . "</td>";
  100. print_downloads($conn, rtrim($idlist, ','));
  101. }
  102. }
  103.  
  104. function print_downloads ($conn, $idlist)
  105. {
  106. $query =
  107. "SELECT COUNT(*) AS num
  108. FROM view
  109. WHERE view.archiveid IN ($idlist)
  110. AND view.view_type = ";
  111. $viewtypes = array('abstract', 'download');
  112. foreach ($viewtypes as $type)
  113. {
  114. $result = mysql_query($query . "'" . $type . "'", $conn);
  115. if (!$result)
  116. {
  117. print "<td align='center'>failed</td>";
  118. }
  119. else
  120. {
  121. $row = mysql_fetch_assoc($result);
  122. print "<td align='center'>" . $row["num"] . "</td>";
  123. }
  124. }
  125. }
  126.  
  127. ?>
  128.  
  129.  
  130. </body>
  131. </html>