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