Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.fns.cumulative_usage_country.es.php
  1. <?php
  2. /*
  3. Usage by countries
  4. */
  5. /* -----------------------merge_countries----------------------- */
  6. // NJS 2006-06-14: Added archive name as argument.
  7. $country_downloads = $sql->getCumulativeUsageCountryType($GLOBALS["config_vars"]["archivename"],"download");
  8. $country_abstracts = $sql->getCumulativeUsageCountryType($GLOBALS["config_vars"]["archivename"],"abstract");
  9. $GLOBALS["db_values"] = merge_countries($country_abstracts,$country_downloads);
  10. // $debug->setDebug($GLOBALS["db_values"],__LINE__,__FILE__,'','','');
  11.  
  12.  
  13. /* NJS 2007-01-31
  14. Calculate the length of the largest bar for the country
  15. downloads histogram.
  16. This was refactored from inc.html.cumulative_usage_country.php.
  17. Arguments: $mode either 'country' (count only real countries)
  18. or 'bot' (count only bots/crawlers)
  19. Returns: integer
  20. */
  21. function getMaxCount ( $mode )
  22. {
  23. $max = 0;
  24. for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ )
  25. {
  26. /* If we're in country mode, skip all bot entries (country
  27. code starts with 'X@'). If we're in bot mode, skip
  28. all country entries (country code *doesn't* start with
  29. 'X@').
  30. */
  31. $cc = substr( $GLOBALS["db_values"][$rs]["country_code"], 0, 2 );
  32. if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue;
  33. if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue;
  34. // Check abstracts...
  35. $abs = $GLOBALS["db_values"][$rs]["country_abstracts"];
  36. if ( $abs > $max )
  37. {
  38. $max = $abs;
  39. }
  40.  
  41. // ...then downloads.
  42. $dl = $GLOBALS["db_values"][$rs]["country_downloads"];
  43. if ( $dl > $max )
  44. {
  45. $max = $dl;
  46. }
  47. }
  48. return $max;
  49. }
  50. /* NJS 2007-01-31
  51. Output a "country" downloads histogram. This function only
  52. generates rows (<tr>) of the table; the enclosing <table> element
  53. must be output by the caller.
  54. This was refactored from inc.html.cumulative_usage_country.php.
  55. Arguments: $mode either 'country' (display only real countries)
  56. or 'bot' (display only bots/crawlers)
  57. $max_count length (number of hits) of longest bar
  58. $max_width maximum width in pixels of a bar
  59. Returns: void
  60. */
  61. function generateCountryTable ( $mode, $max_count, $max_width )
  62. {
  63. // NJS 2006-01-18: Accumulate total number of downloads and views.
  64. $total_downloads = 0;
  65. $total_abstracts = 0;
  66. $abstract_countries = array();
  67. $download_countries = array();
  68. /* NJS 2007-02-07
  69. Keep an independent count of the row number so that we can
  70. highlight them properly. We can't just use the loop counter
  71. $rs below because we skip certain rows according to which
  72. mode we're in, so $rs will appear to skip unpredictably.
  73. */
  74. $row = 0;
  75. for ( $rs = 0; $rs < count( $GLOBALS["db_values"] ); $rs++ )
  76. {
  77. /* If we're in country mode, skip all bot entries (country
  78. code starts with 'X@'). If we're in bot mode, skip
  79. all country entries (country code *doesn't* start with
  80. 'X@').
  81. */
  82. $ccode = $GLOBALS["db_values"][$rs]["country_code"];
  83. $cc = substr( $ccode, 0, 2 );
  84. if ( ( $mode == 'country' ) && ( $cc == 'X@' ) ) continue;
  85. if ( ( $mode == 'bot' ) && ( $cc != 'X@' ) ) continue;
  86. // NJS 2006-01-18: Accumulate total number of downloads and views.
  87. // NJS 2007-01-31: Record countries in a bitmap so we can easily count them later.
  88. $abs = $GLOBALS["db_values"][$rs]["country_abstracts"];
  89. $dl = $GLOBALS["db_values"][$rs]["country_downloads"];
  90. $total_abstracts += $abs;
  91. $total_downloads += $dl;
  92. if ( $abs > 0 )
  93. {
  94. $abstract_countries[$ccode] = 1;
  95. }
  96. if ( $dl > 0 )
  97. {
  98. $download_countries[$ccode] = 1;
  99. }
  100. if ($GLOBALS["db_values"][$rs]["country_name"]=='') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  101. if ($GLOBALS["db_values"][$rs]["country_name"]=='N/A') { $GLOBALS["db_values"][$rs]["country_name"]='unknown'; }
  102. // NJS 2005-12-15: subtly highlight every alternate row
  103. print '<tr';
  104. if ($row++ % 2) print ' style="background-color:#EDF3FE;"';
  105. print '><td>';
  106. // select a flag
  107. // NJS 2005-12-15 make flags and country names links to detail page
  108. $ccode = strtolower($ccode);
  109. $c_flag = 'flags18x14/' . $ccode . '.png';
  110. // NJS 2006-06-14: Only generate a link if there are actually
  111. // some downloads.
  112. if ( $dl > 0 )
  113. print '<a href="' . $_SERVER['PHP_SELF'] .
  114. '?action=show_detail_country;code=' . $ccode . '">';
  115. if (file_exists($c_flag)) {
  116. print '<img border="0" src="'. $c_flag . '" width="18" height="14" alt="'. $ccode . '" />';
  117. } else {
  118. print '<img border="0" src="flags18x14/unknown.png" width="18" height="14" alt="' . $ccode . '" />';
  119. };
  120. if ( $dl > 0 )
  121. print '</a>';
  122. print '</td><td style="font-size:small;border-right:1px solid #dddddd;">';
  123. // NJS 2006-06-14: Only generate a link if there are actually
  124. // some downloads.
  125. if ( $dl > 0 )
  126. print '<a href="' . $_SERVER['PHP_SELF'] .
  127. '?action=show_detail_country;code=' . $ccode . '">';
  128. print $GLOBALS["db_values"][$rs]["country_name"];
  129. if ( $dl > 0 )
  130. print '</a>';
  131. print '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">'.
  132. ( ( $abs > 0 ) ? $abs : '' ).
  133. '</td><td align="right" style="font-size:small;border-right:1px solid #dddddd;">' .
  134. ( ( $dl > 0 ) ? $dl : '' ).
  135. '</td>';
  136. $cur_count = $abs;
  137. $col_width = (int) ($cur_count/$max_count * $max_width);
  138. if ( $abs > 0 ) $col_width = max($col_width,1);
  139. print '<td align="left"><img src="bars/hh.png" alt="views" height="9" width="'.
  140. $col_width .
  141. '" /><br />';
  142. $cur_count = $dl;
  143. $col_width = (int) ($cur_count/$max_count * $max_width);
  144. if ($dl > 0) $col_width = max($col_width,1);
  145. print '<img src="bars/hp.png" alt="views" height="9" width="'.
  146. $col_width .
  147. '" /></td></tr>';
  148. }
  149. // NJS 2006-01-18: Display grand totals.
  150. print '<tr><th rowspan="2" colspan="2" style="background-color:#cccccc;">Grand Totals:</th>
  151. <th align="right" style="background-color:#66ddee;">'.
  152. $total_abstracts.
  153. '</th>
  154. <th colspan="2" align="left" style="background-color:#cccccc;"> abstract';
  155. if ( $mode == 'country' )
  156. {
  157. print ' views originating from '.
  158. count($abstract_countries).
  159. ' distinct countries</th></tr>';
  160. }
  161. else
  162. {
  163. print 's indexed</th></tr>';
  164. }
  165. print '<tr><th align="right" style="background-color:#cccccc;">&nbsp;</th>
  166. <th align="right" style="background-color:#4477dd;color:#ffffff;">'.
  167. $total_downloads.
  168. '</th><th align="left" style="background-color:#cccccc;"> full text ';
  169. if ($mode == 'country' )
  170. {
  171. print 'downloads originating from '.
  172. count($download_countries).
  173. ' distinct countries</th></tr>';
  174. }
  175. else
  176. {
  177. print 'documents indexed</th></tr>';
  178. }
  179. }
  180.  
  181. ?>