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

Source for file graphDailyPageviews.php

Documentation is available at graphDailyPageviews.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 =date('F Y');
  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.  
  39.  buildWhere('phpusertrack_data.timestamp >= "' date('Y-m-01 00:00:00''"');
  40.  
  41. $sql 'select count(phpusertrack_data.id) as count, DATE_FORMAT(phpusertrack_data.timestamp, \'%e\') 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, \'%d\') order by DATE_FORMAT(phpusertrack_data.timestamp, \'%d\') asc';
  42. $pageviews $db->_query($sql);
  43. $data array();
  44. $data array_pad($datadate('t')null);
  45. $data2 array();
  46. $data2 array_pad($data2date('t')null);
  47. $xdata array();
  48. $movingaverage array();
  49.  
  50. foreach ($pageviews as $page{
  51.     $data[$page['date'1$page['count'];
  52.     $data2[$page['date'1$page['visits'];
  53. }
  54.  
  55. for ($i 0$i date('t')$i++{
  56.     array_push($xdata($i+1));
  57. }
  58.  
  59. // Create the graph. These two calls are always required
  60. $width count($xdata50;
  61. if ($width 500{
  62.     $width 500;
  63. else if ($width 1000{
  64.     $width 1000;
  65. }
  66. $graph new Graph($width,233);   
  67. $graph->img->SetAntiAliasing()
  68. $graph->SetScale("textlin");
  69. $graph->yaxis->scale->SetAutoMin(0);
  70.  
  71. // Adjust the margin a bit to make more room for titles
  72. $graph->img->SetMargin(40,10,10,30);
  73.  
  74. // Create a bar pot
  75. //$graph->xaxis->HideTicks(true,false);
  76. //$graph->xaxis->SetTextLabelInterval(5);
  77. $lplot new BarPlot($data);
  78. $lplot->SetLegend("Pageviews");
  79. $lplot2 new BarPlot($data2);
  80. $lplot2->SetFillColor("blue");
  81. $lplot2->SetLegend("Unique Visitors");
  82. $gbplot new GroupBarPlot(array($lplot,$lplot2));
  83. $graph->Add($gbplot);
  84. $lplot->SetFillColor"#BBCCFF");
  85. $lplot->SetWidth(0.6);
  86. $lplot->value->Show();
  87. $lplot->value->SetFormat('%01d');
  88. $lplot->value->SetFont(FF_VERA,FS_NORMAL6);
  89. $lplot2->value->Show();
  90. $lplot2->value->SetFormat('%01d');
  91. $lplot2->value->SetFont(FF_VERA,FS_NORMAL6);
  92. $graph->xaxis->SetTickLabels($xdata);
  93.  
  94. // Setup the titles
  95. //$graph->yaxis->title->Set("Monthly Pageviews");
  96.  
  97. $graph->title->SetFont(FF_VERA,FS_BOLD9);
  98. $graph->subtitle->SetFont(FF_VERA,FS_NORMAL8);
  99.  
  100. $graph->title->SetFont(FF_VERA,FS_BOLD);
  101. $graph->yaxis->title->SetFont(FF_VERA,FS_BOLD7);
  102. //$graph->xaxis->scale->SetDateFormat('M');
  103. $graph->xaxis->SetTickSide(SIDE_BOTTOM)
  104. $graph->yaxis->HideZeroLabel();
  105. //$graph->xaxis->SetPos('min');
  106. //$graph->xaxis->scale->ticks->Set (60*60*24*14, 60*60*24); 
  107. //$graph->xaxis->scale->SetDateAlign(MONTHADJ_1); 
  108. $graph->yaxis->scale->SetGrace(10);
  109.  
  110. //$graph->SetTickDensity (TICKD_DENSE); 
  111. $graph->xaxis->SetFont(FF_VERA,FS_NORMAL6);
  112. $graph->yaxis->SetFont(FF_VERA,FS_NORMAL6);
  113. $graph->xgrid->Show(true ,true);
  114.  
  115. $graph->legend->SetLayout(LEGEND_HOR);
  116. $graph->legend->Pos(0.05,0.02"left","top");
  117. $graph->legend->SetFillColor("#FFFFFF@0.5");
  118. $graph->legend->SetFont(FF_VERA,FS_NORMAL7.5);
  119. $graph->legend->SetMarkAbsSize(6);
  120.  
  121. $graph->title->Set($text);
  122. $graph->subtitle->Set($subtitle);
  123.  
  124. #list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($xdata);
  125.  
  126. $graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
  127. $graph->SetMarginColor("#ffffff");
  128. $graph->SetFrame(false);
  129.  
  130. $graph->xgrid->Show(truefalse);
  131.  
  132. // Display the graph
  133. $graph->Stroke();
  134. /*echo $sql;
  135. print_r($pageviews);
  136. print_r($xdata);
  137. print_r($data);
  138. print_r($data2);*/
  139.  
  140. ?>

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