3 if (!class_exists(
"report_conversion_rate")) {
7 class Report_conversion_rate
extends report_base
15 protected $_sThisTemplate =
"report_conversion_rate.tpl";
22 public function drawReport()
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'])));
31 if ($oDb->getOne(
"select * from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo")) {
36 if ($oDb->getOne(
"select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo")) {
44 public function visitor_month()
53 $dTimeFrom = mktime(23, 59, 59, date(
"m", $dTimeTo) - 12, date(
"d", $dTimeTo), date(
"Y", $dTimeTo));
55 $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeTo));
56 $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeFrom));
59 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
61 for ($i = 1; $i <= 12; $i++) {
62 $aTemp[date(
"m/Y", mktime(23, 59, 59, date(
"m", $dTimeFrom) + $i, date(
"d", $dTimeFrom), date(
"Y", $dTimeFrom)))] = 0;
65 $rs = $oDb->execute($sSQL);
66 if ($rs !=
false && $rs->recordCount() > 0) {
68 $aTemp[date(
"m/Y", strtotime($rs->fields[0]))]++;
76 foreach ($aTemp as $key => $value) {
77 $aDataX[$key] = $value;
84 $sSQL =
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
85 $rs = $oDb->execute($sSQL);
86 if ($rs !=
false && $rs->recordCount() > 0) {
88 $sKey = date(
"m/Y", strtotime($rs->fields[0]));
89 if (isset($aDataX2[$sKey])) {
96 header(
"Content-type: image/png");
99 $graph =
new Graph(800, 600,
"auto");
101 $graph->setBackgroundImage(
$myConfig->getImageDir(
true) .
"/reportbgrnd.jpg", BGIMG_FILLFRAME);
104 $graph->setScale(
"textlin");
105 $graph->setY2Scale(
"lin");
106 $graph->y2axis->setColor(
"red");
109 $graph->xaxis->setLabelAlign(
'center',
'top',
'right');
112 $graph->yaxis->setLabelAlign(
'right',
'bottom');
116 $graph->xaxis->setTickLabels($aDataY);
120 $graph->title->set(
"Monat");
123 $graph->title->setFont(FF_FONT1, FS_BOLD);
125 $aDataFinalX = array();
126 foreach ($aDataX as $dData) {
127 $aDataFinalX[] = $dData;
131 $l2plot =
new LinePlot($aDataFinalX);
132 $l2plot->setColor(
"navy");
133 $l2plot->setWeight(2);
134 $l2plot->setLegend(
"Besucher");
136 $l2plot->value->setColor(
"navy");
137 $l2plot->value->setFormat(
'% d');
138 $l2plot->value->hideZero();
139 $l2plot->value->show();
141 $aDataFinalX2 = array();
142 foreach ($aDataX2 as $dData) {
143 $aDataFinalX2[] = $dData;
147 $l3plot =
new LinePlot($aDataFinalX2);
148 $l3plot->setColor(
"orange");
149 $l3plot->setWeight(2);
150 $l3plot->setLegend(
"Bestellungen");
152 $l3plot->value->setColor(
'orange');
153 $l3plot->value->setFormat(
'% d');
154 $l3plot->value->hideZero();
155 $l3plot->value->show();
159 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
160 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
161 $l1datay[] = 100 / ($aDataFinalX[$iCtr] / $aDataFinalX2[$iCtr]);
167 $l1plot =
new LinePlot($l1datay);
168 $l1plot->setColor(
"red");
169 $l1plot->setWeight(2);
170 $l1plot->setLegend(
"Conversion rate (%)");
171 $l1plot->value->setColor(
'red');
172 $l1plot->value->setFormat(
'% 0.2f%%');
173 $l1plot->value->hideZero();
174 $l1plot->value->show();
177 $graph->addY2($l1plot);
178 $graph->add($l2plot);
179 $graph->add($l3plot);
189 public function visitor_week()
199 $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_to"))));
200 $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_from"))));
202 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
204 $rs = $oDb->execute($sSQL);
205 if ($rs !=
false && $rs->recordCount() > 0) {
208 $aTemp[
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay'), strtotime($rs->fields[0]))]++;
215 list($iFrom, $iTo) = $this->getWeekRange();
216 for ($i = $iFrom; $i < $iTo; $i++) {
220 $aDataY[] =
"KW " . $i;
223 foreach ($aTemp as $key => $value) {
224 $aDataX[$key] = $value;
227 $aDataY[] =
"KW " . $key;
231 $sSQL =
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
232 $rs = $oDb->execute($sSQL);
233 if ($rs !=
false && $rs->recordCount() > 0) {
235 $sKey =
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay'), strtotime($rs->fields[0]));
236 if (isset($aDataX2[$sKey])) {
244 $sSQL =
"select oxtime, oxsessid from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
245 $rs = $oDb->execute($sSQL);
246 if ($rs !=
false && $rs->recordCount() > 0) {
248 $sKey =
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay'), strtotime($rs->fields[0]));
249 if (isset($aDataX3[$sKey])) {
256 header(
"Content-type: image/png");
259 $graph =
new Graph(max(800, count($aDataX) * 80), 600);
261 $graph->setBackgroundImage(
$myConfig->getImageDir(
true) .
"/reportbgrnd.jpg", BGIMG_FILLFRAME);
264 $graph->setScale(
"textlin");
265 $graph->setY2Scale(
"lin");
266 $graph->y2axis->setColor(
"red");
269 $graph->xaxis->setLabelAlign(
'center',
'top',
'right');
272 $graph->yaxis->setLabelAlign(
'right',
'bottom');
276 $graph->xaxis->setTickLabels($aDataY);
280 $graph->title->set(
"Woche");
283 $graph->title->setFont(FF_FONT1, FS_BOLD);
285 $aDataFinalX = array();
286 foreach ($aDataX as $dData) {
287 $aDataFinalX[] = $dData;
291 $l2plot =
new LinePlot($aDataFinalX);
292 $l2plot->setColor(
"navy");
293 $l2plot->setWeight(2);
294 $l2plot->setLegend(
"Besucher");
295 $l2plot->value->setColor(
"navy");
296 $l2plot->value->setFormat(
'% d');
297 $l2plot->value->hideZero();
298 $l2plot->value->show();
300 $aDataFinalX2 = array();
301 foreach ($aDataX2 as $dData) {
302 $aDataFinalX2[] = $dData;
306 $l3plot =
new LinePlot($aDataFinalX2);
307 $l3plot->setColor(
"orange");
308 $l3plot->setWeight(2);
309 $l3plot->setLegend(
"Bestellungen");
311 $l3plot->value->setColor(
"orange");
312 $l3plot->value->setFormat(
'% d');
313 $l3plot->value->hideZero();
314 $l3plot->value->show();
318 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
319 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
320 $l1datay[] = 100 / ($aDataFinalX[$iCtr] / $aDataFinalX2[$iCtr]);
325 $l1plot =
new LinePlot($l1datay);
326 $l1plot->setColor(
"red");
327 $l1plot->setWeight(2);
328 $l1plot->setLegend(
"Conversion rate (%)");
329 $l1plot->value->setColor(
'red');
330 $l1plot->value->setFormat(
'% 0.4f%%');
331 $l1plot->value->hideZero();
332 $l1plot->value->show();
335 $graph->addY2($l1plot);
336 $graph->add($l2plot);
337 $graph->add($l3plot);