OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
report_visitor_absolute.php
Go to the documentation of this file.
1 <?php
2 
3 if (!class_exists("report_visitor_absolute")) {
7  class Report_visitor_absolute extends report_base
8  {
9 
15  protected $_sThisTemplate = "report_visitor_absolute.tpl";
16 
22  public function drawReport()
23  {
24  $oDb = oxDb::getDb();
25 
26  $oSmarty = $this->getSmarty();
27  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_from'])));
28  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_to'])));
29 
30  if ($oDb->getOne("select 1 from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo")) {
31  return true;
32  }
33 
34  // buyer
35  if ($oDb->getOne("select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo")) {
36  return true;
37  }
38 
39  // newcustomer
40  if ($oDb->getOne("select 1 from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo")) {
41  return true;
42  }
43  }
44 
48  public function visitor_month()
49  {
50  $myConfig = $this->getConfig();
51  $oDb = oxDb::getDb();
52 
53  $aDataX = array();
54  $aDataY = array();
55 
56  $dTimeTo = strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"));
57  $dTimeFrom = mktime(23, 59, 59, date("m", $dTimeTo) - 12, date("d", $dTimeTo), date("Y", $dTimeTo));
58 
59  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", $dTimeTo));
60  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", $dTimeFrom));
61 
62  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
63  $aTemp = array();
64  for ($i = 1; $i <= 12; $i++) {
65  $aTemp[date("m/Y", mktime(23, 59, 59, date("m", $dTimeFrom) + $i, date("d", $dTimeFrom), date("Y", $dTimeFrom)))] = 0;
66  }
67 
68  $rs = $oDb->execute($sSQL);
69  if ($rs != false && $rs->recordCount() > 0) {
70  while (!$rs->EOF) {
71  $aTemp[date("m/Y", strtotime($rs->fields[0]))]++;
72  $rs->moveNext();
73  }
74  }
75 
76  foreach ($aTemp as $key => $value) {
77  $aDataX[$key] = $value;
78  $aDataX2[$key] = 0;
79  $aDataX3[$key] = 0;
80  $aDataY[] = $key;
81  }
82 
83  // buyer
84  $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
85  $aTemp = array();
86  $rs = $oDb->execute($sSQL);
87  if ($rs != false && $rs->recordCount() > 0) {
88  while (!$rs->EOF) {
89  $aTemp[date("m/Y", strtotime($rs->fields[0]))]++;
90  $rs->moveNext();
91  }
92  }
93 
94  foreach ($aTemp as $key => $value) {
95  $aDataX2[$key] = $value;
96  }
97 
98  // newcustomer
99  $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
100  $aTemp = array();
101  $rs = $oDb->execute($sSQL);
102  if ($rs != false && $rs->recordCount() > 0) {
103  while (!$rs->EOF) {
104  $aTemp[date("m/Y", strtotime($rs->fields[0]))]++;
105  $rs->moveNext();
106  }
107  }
108 
109  foreach ($aTemp as $key => $value) {
110  $aDataX3[$key] = $value;
111  }
112 
113 
114  header("Content-type: image/png");
115 
116  // New graph with a drop shadow
117  $graph = new Graph(800, 600);
118 
119  $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
120 
121  // Use a "text" X-scale
122  $graph->setScale("textlin");
123 
124  // Label align for X-axis
125  $graph->xaxis->setLabelAlign('center', 'top', 'right');
126 
127  // Label align for Y-axis
128  $graph->yaxis->setLabelAlign('right', 'bottom');
129 
130  $graph->setShadow();
131  // Description
132  $graph->xaxis->setTickLabels($aDataY);
133 
134 
135  // Set title and subtitle
136  $graph->title->set("Monat");
137 
138  // Use built in font
139  $graph->title->setFont(FF_FONT1, FS_BOLD);
140 
141  $aDataFinalX = array();
142  foreach ($aDataX as $dData) {
143  $aDataFinalX[] = $dData;
144  }
145  // Create the bar plot
146  $bplot = new BarPlot($aDataFinalX);
147  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
148  $bplot->setLegend("Besucher");
149 
150  $aDataFinalX2 = array();
151  foreach ($aDataX2 as $dData) {
152  $aDataFinalX2[] = $dData;
153  }
154  // Create the bar plot
155  $bplot2 = new BarPlot($aDataFinalX2);
156  $bplot2->setFillColor("orange");
157  $bplot2->setLegend("Kaeufer");
158 
159  $aDataFinalX3 = array();
160  foreach ($aDataX3 as $dData) {
161  $aDataFinalX3[] = $dData;
162  }
163  // Create the bar plot
164  $bplot3 = new BarPlot($aDataFinalX3);
165  $bplot3->setFillColor("silver");
166  $bplot3->setLegend("Neukunden");
167 
168  // Create the grouped bar plot
169  $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3));
170  $graph->add($gbplot);
171 
172  // Finally output the image
173  $graph->stroke();
174 
175  }
176 
180  public function visitor_week()
181  {
182  $myConfig = $this->getConfig();
183  $oDb = oxDb::getDb();
184 
185  $aDataX = array();
186  $aDataY = array();
187 
188  $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
189  $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
190 
191  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
192  $aTemp = array();
193  $rs = $oDb->execute($sSQL);
194  if ($rs != false && $rs->recordCount() > 0) {
195  while (!$rs->EOF) {
196  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
197  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
198  $rs->moveNext();
199  }
200  }
201 
202  // initializing
203  list($iFrom, $iTo) = $this->getWeekRange();
204  for ($i = $iFrom; $i < $iTo; $i++) {
205  $aDataX[$i] = 0;
206  $aDataX2[$i] = 0;
207  $aDataX3[$i] = 0;
208  $aDataY[] = "KW " . $i;
209  }
210 
211  foreach ($aTemp as $key => $value) {
212  $aDataX[$key] = $value;
213  $aDataX2[$key] = 0;
214  $aDataX3[$key] = 0;
215  $aDataY[] = "KW " . $key;
216  }
217 
218  // buyer
219  $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
220  $aTemp = array();
221  $rs = $oDb->execute($sSQL);
222  if ($rs != false && $rs->recordCount() > 0) {
223  while (!$rs->EOF) {
224  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
225  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
226  $rs->moveNext();
227  }
228  }
229 
230  foreach ($aTemp as $key => $value) {
231  $aDataX2[$key] = $value;
232  }
233 
234  // newcustomer
235  $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
236  $aTemp = array();
237  $rs = $oDb->execute($sSQL);
238  if ($rs != false && $rs->recordCount() > 0) {
239  while (!$rs->EOF) {
240  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
241  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
242  $rs->moveNext();
243  }
244  }
245 
246  foreach ($aTemp as $key => $value) {
247  $aDataX3[$key] = $value;
248  }
249 
250  header("Content-type: image/png");
251 
252  // New graph with a drop shadow
253  $graph = new Graph(max(800, count($aDataX) * 80), 600);
254 
255  $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
256 
257  // Use a "text" X-scale
258  $graph->setScale("textlin");
259 
260  // Label align for X-axis
261  $graph->xaxis->setLabelAlign('center', 'top', 'right');
262 
263  // Label align for Y-axis
264  $graph->yaxis->setLabelAlign('right', 'bottom');
265 
266  $graph->setShadow();
267  // Description
268  $graph->xaxis->setTickLabels($aDataY);
269 
270 
271  // Set title and subtitle
272  $graph->title->set("Woche");
273 
274  // Use built in font
275  $graph->title->setFont(FF_FONT1, FS_BOLD);
276 
277  $aDataFinalX = array();
278  foreach ($aDataX as $dData) {
279  $aDataFinalX[] = $dData;
280  }
281  // Create the bar plot
282  $bplot = new BarPlot($aDataFinalX);
283  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
284  $bplot->setLegend("Besucher");
285 
286  $aDataFinalX2 = array();
287  foreach ($aDataX2 as $dData) {
288  $aDataFinalX2[] = $dData;
289  }
290  // Create the bar plot
291  $bplot2 = new BarPlot($aDataFinalX2);
292  $bplot2->setFillColor("orange");
293  $bplot2->setLegend("Kaeufer");
294 
295  $aDataFinalX3 = array();
296  foreach ($aDataX3 as $dData) {
297  $aDataFinalX3[] = $dData;
298  }
299  // Create the bar plot
300  $bplot3 = new BarPlot($aDataFinalX3);
301  $bplot3->setFillColor("silver");
302  $bplot3->setLegend("Neukunden");
303 
304  // Create the grouped bar plot
305  $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3));
306  $graph->add($gbplot);
307 
308  // Finally output the image
309  $graph->stroke();
310  }
311  }
312 }