Newer
Older
Digital_Repository / Repositories / statistics / htdocs / download_by_dept.php
nstanger on 16 Apr 2007 3 KB - Updated to work with new config.
  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 department</title>
  7. <meta name="generator" content="BBEdit 8.2" />
  8. </head>
  9. <body>
  10.  
  11. <h1>Downloads by department</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"]["eprints_archives"]["otago_eprints"]["sqlserver_eprints"],
  23. $GLOBALS["config_vars"]["connections"]["eprints_archives"]["otago_eprints"]["sqluser_eprints"],
  24. $GLOBALS["config_vars"]["connections"]["eprints_archives"]["otago_eprints"]["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"]["eprints_archives"]["otago_eprints"]["sqluser_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. WHERE S.name LIKE '% '
  58. ORDER BY S.name"; /* Note use of non-breaking space (UTF8 00A0) in name column. */
  59.  
  60. $current_dept = "";
  61. $idlist = "";
  62. $dept_count = 0;
  63. $result = mysql_query($query, $connection_archive);
  64.  
  65. if (!$result)
  66. {
  67. error($GLOBALS["config_vars"]["messages"]["message_noservice"],ERROR_EXIT);
  68. print "<p>failed departments query</p>";
  69. exitScript();
  70. }
  71. else
  72. {
  73. print "<table border='1'><tr>
  74. <th>Department</th>
  75. <th>eprints</th>
  76. <th>Abstract views</th>
  77. <th>Downloads</th>";
  78. while ($row = mysql_fetch_assoc($result))
  79. {
  80. if ($row["name"] != $current_dept)
  81. {
  82. print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
  83. $current_dept = $row["name"];
  84. $dept_count = 0;
  85. $idlist = "";
  86. }
  87. $dept_count++;
  88. $idlist .= $row["eprintid"] . ',';
  89. }
  90. print_new_row($connection_stats, $current_dept, $dept_count, $idlist);
  91. print "</tr></table>";
  92. }
  93.  
  94. function print_new_row ($conn, $dept, $count, $idlist)
  95. {
  96. if ($dept != "")
  97. {
  98. print "</tr><tr>";
  99. print "<td>" . $dept . "</td>";
  100. print "<td align='center'>" . $count . "</td>";
  101. print_downloads($conn, rtrim($idlist, ','));
  102. }
  103. }
  104.  
  105. function print_downloads ($conn, $idlist)
  106. {
  107. $query =
  108. "SELECT COUNT(*) AS num
  109. FROM view
  110. WHERE view.archiveid IN ($idlist)
  111. AND view.view_type = ";
  112. $viewtypes = array('abstract', 'download');
  113. foreach ($viewtypes as $type)
  114. {
  115. $result = mysql_query($query . "'" . $type . "'", $conn);
  116. if (!$result)
  117. {
  118. print "<td align='center'>failed</td>";
  119. }
  120. else
  121. {
  122. $row = mysql_fetch_assoc($result);
  123. print "<td align='center'>" . $row["num"] . "</td>";
  124. }
  125. }
  126. }
  127.  
  128. ?>
  129.  
  130.  
  131. </body>
  132. </html>