phpUserTrack
[ class tree: phpUserTrack ] [ index: phpUserTrack ] [ all elements ]

Source for file graphMonthlyPageviews.php

Documentation is available at graphMonthlyPageviews.php

  1. <?php
  2.  
  3. require_once './../include/version.php';
  4. require_once './../lib/core.php';
  5.  
  6. include ('jpgraph/jpgraph.php');
  7. include ('jpgraph/jpgraph_bar.php');
  8. include ('jpgraph/jpgraph_date.php');
  9.  
  10. global $plugins;
  11.  
  12. $whereSQL '';
  13.  
  14. function buildWhere($newCond{
  15.   global $whereSQL;
  16.   if (substr($whereSQL06== ' where'{
  17.     $whereSQL .= ' and ' $newCond ' ';
  18.   else {
  19.     $whereSQL ' where ' $newCond ' ';
  20.   }
  21. }
  22.  
  23. $db new phpusertrack_db();
  24. if (!$_GET['notitle']{
  25.   $text 'Monthly Pageviews';
  26. }
  27.  
  28. if (isset($_GET['site'])) {
  29.   buildWhere('phpusertrack_data.site_id="' $_GET['site''"');
  30.   $sitenameSQL "select * from phpusertrack_sites where id=" $_GET['site'];
  31.   $sitename $db->_query($sitenameSQL);
  32.   $text .= ' - ' $sitename[0]['name'];
  33. }
  34. if (isset($_GET['path'])) {
  35.   buildWhere('phpusertrack_data.path="' $_GET['path''"');
  36.   $subtitle .= 'Path: ' $_GET['path'];
  37. }
  38. if (isset($_GET['startdate'])) {
  39.   buildWhere('phpusertrack_data.timestamp >= "' $_GET['startdate''"');
  40.   $subtitle .= 'Start Date: ' $_GET['startdate'];
  41. }
  42. $sql 'select count(phpusertrack_data.id) as count, DATE_FORMAT(phpusertrack_data.timestamp, \'%b %y\') as date, count(distinct phpusertrack_ip.id) as visits from phpusertrack_ip inner join phpusertrack_data on phpusertrack_ip.id=phpusertrack_data.ip_id ' $whereSQL ' group by DATE_FORMAT(phpusertrack_data.timestamp, \'%b %Y\') order by phpusertrack_data.timestamp asc';
  43. $pageviews $db->_query($sql);
  44. $data array();
  45. $data2 array();
  46. $xdata array();
  47. $movingaverage array();
  48.  
  49. foreach ($pageviews as $view{
  50.     array_push($data(int)$view['count']);
  51.     array_push($xdata$view['date']);
  52.     array_push($data2$view['visits']);
  53. }
  54.  
  55. // Create the graph. These two calls are always required
  56. $width count($xdata50;
  57. if ($width 500{
  58.     $width 500;
  59. else if ($width 1000{
  60.     $width 1000;
  61. }
  62. $graph new Graph($width,233);   
  63. $graph->img->SetAntiAliasing()
  64. $graph->SetScale("textlin");
  65. $graph->yaxis->scale->SetAutoMin(0);
  66.  
  67. // Adjust the margin a bit to make more room for titles
  68. $graph->img->SetMargin(40,10,10,30);
  69.  
  70. // Create a bar pot
  71. //$graph->xaxis->HideTicks(true,false);
  72. //$graph->xaxis->SetTextLabelInterval(5);
  73. $lplot new BarPlot($data);
  74. $lplot->SetLegend("Pageviews");
  75. $lplot2 new BarPlot($data2);
  76. $lplot2->SetFillColor("blue");
  77. $lplot2->SetLegend("Unique Visitors");
  78. $gbplot new GroupBarPlot(array($lplot,$lplot2));
  79. $graph->Add($gbplot);
  80. $lplot->SetFillColor"#BBCCFF");
  81. $lplot->SetWidth(0.6);
  82. $lplot->value->Show();
  83. $lplot->value->SetFormat('%01d');
  84. $lplot->value->SetFont(FF_VERA,FS_NORMAL6);
  85. $lplot2->value->Show();
  86. $lplot2->value->SetFormat('%01d');
  87. $lplot2->value->SetFont(FF_VERA,FS_NORMAL6);
  88. $graph->xaxis->SetTickLabels($xdata);
  89.  
  90. // Setup the titles
  91. //$graph->yaxis->title->Set("Monthly Pageviews");
  92.  
  93. $graph->title->SetFont(FF_VERA,FS_BOLD9);
  94. $graph->subtitle->SetFont(FF_VERA,FS_NORMAL8);
  95.  
  96. $graph->title->SetFont(FF_VERA,FS_BOLD);
  97. $graph->yaxis->title->SetFont(FF_VERA,FS_BOLD7);
  98. //$graph->xaxis->scale->SetDateFormat('M');
  99. $graph->xaxis->SetTickSide(SIDE_BOTTOM)
  100. $graph->yaxis->HideZeroLabel();
  101. //$graph->xaxis->SetPos('min');
  102. //$graph->xaxis->scale->ticks->Set (60*60*24*14, 60*60*24); 
  103. //$graph->xaxis->scale->SetDateAlign(MONTHADJ_1); 
  104. $graph->yaxis->scale->SetGrace(10);
  105.  
  106. //$graph->SetTickDensity (TICKD_DENSE); 
  107. $graph->xaxis->SetFont(FF_VERA,FS_NORMAL6);
  108. $graph->yaxis->SetFont(FF_VERA,FS_NORMAL6);
  109. $graph->xgrid->Show(true ,true);
  110.  
  111. $graph->legend->SetLayout(LEGEND_HOR);
  112. $graph->legend->Pos(0.1,0.02"left","top");
  113. $graph->legend->SetFillColor("#FFFFFF@0.5");
  114. $graph->legend->SetFont(FF_VERA,FS_NORMAL7.5);
  115. $graph->legend->SetMarkAbsSize(6);
  116.  
  117. #list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($xdata);
  118.  
  119. $graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
  120. $graph->SetMarginColor("#ffffff");
  121. $graph->SetFrame(false);
  122.  
  123. $graph->xgrid->Show(truefalse);
  124.  
  125. // Display the graph
  126. $graph->Stroke();
  127. //echo $sql;
  128. //print_r($xdata);
  129. ?>

Documentation generated on Tue, 06 Nov 2007 09:21:46 -0800 by phpDocumentor 1.4.0a2