OXID eShop CE  4.8.12
 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 {
14  protected $_sThisTemplate = "report_visitor_absolute.tpl";
15 
21  public function drawReport()
22  {
23  $oDb = oxDb::getDb();
24 
25  $oSmarty = $this->getSmarty();
26  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
27  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
28 
29  if ( $oDb->getOne( "select 1 from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
30  return true;
31  }
32 
33  // buyer
34  if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo" ) ) {
35  return true;
36  }
37 
38  // newcustomer
39  if ( $oDb->getOne( "select 1 from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo" ) ) {
40  return true;
41  }
42  }
43 
49  public function visitor_month()
50  {
51  $myConfig = $this->getConfig();
52  $oDb = oxDb::getDb();
53 
54  $aDataX = array();
55  $aDataY = array();
56 
57  $dTimeTo = strtotime( oxRegistry::getConfig()->getRequestParameter( "time_to" ) );
58  $dTimeFrom = mktime( 23, 59, 59, date( "m", $dTimeTo)-12, date( "d", $dTimeTo), date( "Y", $dTimeTo));
59 
60  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
61  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
62 
63  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
64  $aTemp = array();
65  for ( $i = 1; $i <= 12; $i++)
66  $aTemp[date( "m/Y", mktime( 23, 59, 59, date( "m", $dTimeFrom)+$i, date( "d", $dTimeFrom), date( "Y", $dTimeFrom)) )] = 0;
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  // Create the bar plot
145  $bplot = new BarPlot( $aDataFinalX);
146  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
147  $bplot->setLegend("Besucher");
148 
149  $aDataFinalX2 = array();
150  foreach ( $aDataX2 as $dData)
151  $aDataFinalX2[] = $dData;
152  // Create the bar plot
153  $bplot2 = new BarPlot( $aDataFinalX2);
154  $bplot2->setFillColor ("orange");
155  $bplot2->setLegend("Kaeufer");
156 
157  $aDataFinalX3 = array();
158  foreach ( $aDataX3 as $dData)
159  $aDataFinalX3[] = $dData;
160  // Create the bar plot
161  $bplot3 = new BarPlot( $aDataFinalX3);
162  $bplot3->setFillColor ("silver");
163  $bplot3->setLegend("Neukunden");
164 
165  // Create the grouped bar plot
166  $gbplot = new groupBarPlot (array($bplot, $bplot2, $bplot3));
167  $graph->add( $gbplot);
168 
169  // Finally output the image
170  $graph->stroke();
171 
172  }
173 
179  public function visitor_week()
180  {
181  $myConfig = $this->getConfig();
182  $oDb = oxDb::getDb();
183 
184  $aDataX = array();
185  $aDataY = array();
186 
187  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to" ) ) ) );
188  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from" ) ) ) );
189 
190  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
191  $aTemp = array();
192  $rs = $oDb->execute( $sSQL);
193  if ($rs != false && $rs->recordCount() > 0) {
194  while (!$rs->EOF) {
195  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
196  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
197  $rs->moveNext();
198  }
199  }
200 
201  // initializing
202  list( $iFrom, $iTo ) = $this->getWeekRange();
203  for ( $i = $iFrom; $i < $iTo; $i++ ) {
204  $aDataX[$i] = 0;
205  $aDataX2[$i] = 0;
206  $aDataX3[$i] = 0;
207  $aDataY[] = "KW ".$i;
208  }
209 
210  foreach ( $aTemp as $key => $value) {
211  $aDataX[$key] = $value;
212  $aDataX2[$key] = 0;
213  $aDataX3[$key] = 0;
214  $aDataY[] = "KW ".$key;
215  }
216 
217  // buyer
218  $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
219  $aTemp = array();
220  $rs = $oDb->execute( $sSQL);
221  if ($rs != false && $rs->recordCount() > 0) {
222  while (!$rs->EOF) {
223  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
224  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
225  $rs->moveNext();
226  }
227  }
228 
229  foreach ( $aTemp as $key => $value) {
230  $aDataX2[$key] = $value;
231  }
232 
233  // newcustomer
234  $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
235  $aTemp = array();
236  $rs = $oDb->execute( $sSQL);
237  if ($rs != false && $rs->recordCount() > 0) {
238  while (!$rs->EOF) {
239  //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
240  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
241  $rs->moveNext();
242  }
243  }
244 
245  foreach ( $aTemp as $key => $value) {
246  $aDataX3[$key] = $value;
247  }
248 
249  header ("Content-type: image/png" );
250 
251  // New graph with a drop shadow
252  $graph = new Graph( max( 800, count( $aDataX) * 80), 600);
253 
254  $graph->setBackgroundImage( $myConfig->getImageDir(true)."/reportbgrnd.jpg", BGIMG_FILLFRAME);
255 
256  // Use a "text" X-scale
257  $graph->setScale("textlin");
258 
259  // Label align for X-axis
260  $graph->xaxis->setLabelAlign('center', 'top', 'right');
261 
262  // Label align for Y-axis
263  $graph->yaxis->setLabelAlign('right', 'bottom');
264 
265  $graph->setShadow();
266  // Description
267  $graph->xaxis->setTickLabels( $aDataY);
268 
269 
270  // Set title and subtitle
271  $graph->title->set("Woche");
272 
273  // Use built in font
274  $graph->title->setFont(FF_FONT1, FS_BOLD);
275 
276  $aDataFinalX = array();
277  foreach ( $aDataX as $dData)
278  $aDataFinalX[] = $dData;
279  // Create the bar plot
280  $bplot = new BarPlot( $aDataFinalX);
281  $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
282  $bplot->setLegend("Besucher");
283 
284  $aDataFinalX2 = array();
285  foreach ( $aDataX2 as $dData)
286  $aDataFinalX2[] = $dData;
287  // Create the bar plot
288  $bplot2 = new BarPlot( $aDataFinalX2);
289  $bplot2->setFillColor ("orange");
290  $bplot2->setLegend("Kaeufer");
291 
292  $aDataFinalX3 = array();
293  foreach ( $aDataX3 as $dData)
294  $aDataFinalX3[] = $dData;
295  // Create the bar plot
296  $bplot3 = new BarPlot( $aDataFinalX3);
297  $bplot3->setFillColor ("silver");
298  $bplot3->setLegend("Neukunden");
299 
300  // Create the grouped bar plot
301  $gbplot = new groupBarPlot (array($bplot, $bplot2, $bplot3));
302  $graph->add( $gbplot);
303 
304  // Finally output the image
305  $graph->stroke();
306  }
307 }
308 }