Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.fns.show_detail_eprint.es.php
nstanger on 7 Feb 2007 8 KB - Added by search engine display.
  1. <?php
  2. /*
  3. Usage by dates, countries, totals.
  4. */
  5. // If no id default to front page.
  6. if(!isset($_REQUEST["id"])) { return "pub_default"; }
  7.  
  8. // Get detail given year/month
  9. $show_date = 'all years';
  10. if(isset($_REQUEST["year"]) and $_REQUEST["year"]>2002) {
  11. if(isset($_REQUEST["month"]) and $_REQUEST["month"]>=1 and $_REQUEST["month"]<=12) {
  12. $dt = strtotime($_REQUEST["month"]."/1/".$_REQUEST["year"]);
  13. $show_date = date("F Y",$dt);
  14. } else {
  15. $show_date = $_REQUEST["year"];
  16. $_REQUEST["month"] = 0;
  17. }
  18. } else {
  19. $_REQUEST["year"] = 0;
  20. $_REQUEST["month"] = 0;
  21. }
  22. if(isset($_REQUEST["range"])) {
  23. // Work out current date
  24. if($_REQUEST["range"]=='4w') {
  25. $show_date = 'past 4 weeks';
  26. }
  27. } else {
  28. $_REQUEST["range"] = '';
  29. }
  30. // by country
  31. // NJS 2006-06-14: Added archive name as argument.
  32. $country_abstracts = $sql->getCountryEprintType($GLOBALS["config_vars"]["archivename"],$_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'abstract', $_REQUEST["id"]);
  33. $country_downloads = $sql->getCountryEprintType($GLOBALS["config_vars"]["archivename"],$_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
  34. // NJS 2006-01-18: Calculate total number of countries.
  35. $total_download_countries = count($country_downloads);
  36. $total_abstract_countries = count($country_abstracts);
  37. $GLOBALS["db_values"] = merge_countries($country_abstracts, $country_downloads);
  38. // title
  39. // NJS 2006-06-14: Added archive name as argument.
  40. $title = $sql->getTitle($GLOBALS["config_vars"]["archivename"],$_REQUEST["id"]);
  41. // by type
  42. $type_count = $sql->getAbstractDownload($GLOBALS["config_vars"]["archivename"],$_REQUEST["year"], $_REQUEST["month"], $_REQUEST["range"], 'download', $_REQUEST["id"]);
  43. // by date
  44. // NJS 2006-06-14: Added archive name as argument.
  45. $month_downloads = $sql->getCumulativeUsageType($GLOBALS["config_vars"]["archivename"],$_REQUEST["id"],'download');
  46. $month_abstracts = $sql->getCumulativeUsageType($GLOBALS["config_vars"]["archivename"],$_REQUEST["id"],'abstract');
  47. $month_tally = merge_dates($month_abstracts,$month_downloads);
  48.  
  49.  
  50. /* NJS 2007-01-31
  51. Calculate the length of the largest bar for the country
  52. downloads histogram.
  53. This was refactored from inc.html.show_detail_eprint.php.
  54. Arguments: $mode either 'country' (count only real countries)
  55. or 'bot' (count only bots/crawlers)
  56. Returns: integer
  57. */
  58. function getMaxCount ( $mode )
  59. {
  60. $max = 0;
  61. for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ )
  62. {
  63. /* If we're in country mode, skip all bot entries (country
  64. code starts with 'X@'). If we're in bot mode, skip
  65. all country entries (country code *doesn't* start with
  66. 'X@').
  67. */
  68. $cc = substr( $GLOBALS["db_values"][$rs]["country_code"], 0, 2 );
  69. if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue;
  70. if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue;
  71. // Check abstracts...
  72. $abs = $GLOBALS["db_values"][$rs]["country_abstracts"];
  73. if ( $abs > $max )
  74. {
  75. $max = $abs;
  76. }
  77.  
  78. // ...then downloads.
  79. $dl = $GLOBALS["db_values"][$rs]["country_downloads"];
  80. if ( $dl > $max )
  81. {
  82. $max = $dl;
  83. }
  84. }
  85. return $max;
  86. }
  87. /* NJS 2007-02-02
  88. Output a "country" downloads histogram. This function only
  89. generates rows (<tr>) of the table; the enclosing <table> element
  90. must be output by the caller.
  91. This was refactored from inc.html.show_detail_eprint.php.
  92. Note that while this is *very* similar to the equivalent
  93. function in inc.fns.cumulative_usage_country.php, it is
  94. not *quite* identical! (A good candidate for future
  95. refactoring?) In particular, the "count" columns in this
  96. table span two columns each, not one.
  97. Arguments: $mode either 'country' (display only real countries)
  98. or 'bot' (display only bots/crawlers)
  99. $max_count length (number of hits) of longest bar
  100. $max_width maximum width in pixels of a bar
  101. Returns: void
  102. */
  103. function generateCountryTable ( $mode, $max_count, $max_width )
  104. {
  105. // NJS 2006-01-18: Accumulate total number of downloads and views.
  106. $total_downloads = 0;
  107. $total_abstracts = 0;
  108. $abstract_countries = array();
  109. $download_countries = array();
  110. /* NJS 2007-02-07
  111. Keep an independent count of the row number so that we can
  112. highlight them properly. We can't just use the loop counter
  113. $rs below because we skip certain rows according to which
  114. mode we're in, so $rs will appear to skip unpredictably.
  115. */
  116. $row = 0;
  117. for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ )
  118. {
  119. /* If we're in country mode, skip all bot entries (country
  120. code starts with 'X@'). If we're in bot mode, skip
  121. all country entries (country code *doesn't* start with
  122. 'X@').
  123. */
  124. $ccode = $GLOBALS["db_values"][$rs]["country_code"];
  125. $cc = substr( $ccode, 0, 2 );
  126. if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue;
  127. if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue;
  128. // NJS 2006-01-18: Accumulate total number of downloads and views.
  129. // NJS 2007-01-31: Record countries in a bitmap so we can easily count them later.
  130. $abs = $GLOBALS["db_values"][$rs]["country_abstracts"];
  131. $dl = $GLOBALS["db_values"][$rs]["country_downloads"];
  132. $total_abstracts += $abs;
  133. $total_downloads += $dl;
  134. if ( $abs > 0 )
  135. {
  136. $abstract_countries[$ccode] = 1;
  137. }
  138. if ( $dl > 0 )
  139. {
  140. $download_countries[$ccode] = 1;
  141. }
  142. if ($GLOBALS["db_values"][$rs]["country_name"]=='') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  143. if ($GLOBALS["db_values"][$rs]["country_name"]=='N/A') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  144. // NJS 2005-12-15: subtly highlight every alternate row
  145. print '<tr';
  146. if ($row++ % 2) print ' style="background-color:#EDF3FE;"';
  147. print '><td>';
  148. // select a flag
  149. // NJS 2005-12-15 make flags and country names links to detail page
  150. $ccode = strtolower($ccode);
  151. $c_flag = 'flags18x14/' . $ccode . '.png';
  152. // NJS 2006-06-14: Only generate a link if there are actually
  153. // some downloads.
  154. if ( $dl > 0 )
  155. print '<a href="' . $_SERVER['PHP_SELF'] .
  156. '?action=show_detail_country;code=' . $ccode . '">';
  157. if (file_exists($c_flag)) {
  158. print '<img border="0" src="'. $c_flag . '" width="18" height="14" alt="'. $ccode . '" />';
  159. } else {
  160. print '<img border="0" src="flags18x14/unknown.png" width="18" height="14" alt="' . $ccode . '" />';
  161. };
  162. if ( $dl > 0 )
  163. print '</a>';
  164. print '</td><td style="font-size:small;border-right:1px solid #dddddd;">';
  165. // NJS 2006-06-14: Only generate a link if there are actually
  166. // some downloads.
  167. if ( $dl > 0 )
  168. print '<a href="' . $_SERVER['PHP_SELF'] .
  169. '?action=show_detail_country;code=' . $ccode . '">';
  170. print $GLOBALS["db_values"][$rs]["country_name"];
  171. if ( $dl > 0 )
  172. print '</a>';
  173. print '</td><td colspan="2" align="right" style="font-size:small;border-right:1px solid #dddddd;">'.
  174. ( ( $abs > 0 ) ? $abs : '' ).
  175. '</td><td colspan="2" align="right" style="font-size:small;border-right:1px solid #dddddd;">' .
  176. ( ( $dl > 0 ) ? $dl : '' ).
  177. '</td>';
  178. $cur_count = $abs;
  179. $col_width = (int) ($cur_count/$max_count * $max_width);
  180. if ( $abs > 0 ) $col_width = max($col_width,1);
  181. print '<td align="left"><img src="bars/hh.png" alt="views" height="9" width="'.
  182. $col_width .
  183. '" /><br />';
  184. $cur_count = $dl;
  185. $col_width = (int) ($cur_count/$max_count * $max_width);
  186. if ($dl > 0) $col_width = max($col_width,1);
  187. print '<img src="bars/hp.png" alt="views" height="9" width="'.
  188. $col_width .
  189. '" /></td></tr>';
  190. }
  191. // NJS 2006-01-18: Display grand totals.
  192. print '<tr><th rowspan="2" colspan="2" style="background-color:#cccccc;">Grand Totals:</th>
  193. <th colspan="2" align="right" style="background-color:#66ddee;">'.
  194. $total_abstracts.
  195. '</th>
  196. <th colspan="3" align="left" style="background-color:#cccccc;"> abstract';
  197. if ( $mode == 'country' )
  198. {
  199. print ' views originating from '.
  200. count($abstract_countries).
  201. ' distinct countries</th></tr>';
  202. }
  203. else
  204. {
  205. print 's indexed</th></tr>';
  206. }
  207. print '<tr><th colspan="2" align="right" style="background-color:#cccccc;">&nbsp;</th>
  208. <th colspan="2" align="right" style="background-color:#4477dd;color:#ffffff;">'.
  209. $total_downloads.
  210. '</th><th align="left" style="background-color:#cccccc;"> full text ';
  211. if ($mode == 'country' )
  212. {
  213. print 'downloads originating from '.
  214. count($download_countries).
  215. ' distinct countries</th></tr>';
  216. }
  217. else
  218. {
  219. print 'documents indexed</th></tr>';
  220. }
  221. }
  222. ?>