3 if ( !class_exists(
"report_conversion_rate")) {
7 class Report_conversion_rate
extends report_base
14 protected $_sThisTemplate =
"report_conversion_rate.tpl";
21 public function drawReport()
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'] ) ) );
30 if ( $oDb->getOne(
"select * from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
35 if ( $oDb->getOne(
"select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo" ) ) {
45 public function visitor_month()
54 $dTimeFrom = mktime( 23, 59, 59, date(
"m", $dTimeTo)-12, date(
"d", $dTimeTo), date(
"Y", $dTimeTo));
56 $sTimeTo = $oDb->quote( date(
"Y-m-d H:i:s", $dTimeTo ) );
57 $sTimeFrom = $oDb->quote( date(
"Y-m-d H:i:s", $dTimeFrom ) );
60 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
62 for ( $i = 1; $i <= 12; $i++)
63 $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;
130 $l2plot=
new LinePlot($aDataFinalX);
131 $l2plot->setColor(
"navy");
132 $l2plot->setWeight(2);
133 $l2plot->setLegend(
"Besucher");
135 $l2plot->value->setColor(
"navy");
136 $l2plot->value->setFormat(
'% d');
137 $l2plot->value->hideZero();
138 $l2plot->value->show();
140 $aDataFinalX2 = array();
141 foreach ( $aDataX2 as $dData)
142 $aDataFinalX2[] = $dData;
145 $l3plot=
new LinePlot($aDataFinalX2);
146 $l3plot->setColor(
"orange");
147 $l3plot->setWeight(2);
148 $l3plot->setLegend(
"Bestellungen");
150 $l3plot->value->setColor(
'orange');
151 $l3plot->value->setFormat(
'% d');
152 $l3plot->value->hideZero();
153 $l3plot->value->show();
157 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
158 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
159 $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
164 $l1plot=
new LinePlot($l1datay);
165 $l1plot->setColor(
"red");
166 $l1plot->setWeight(2);
167 $l1plot->setLegend(
"Conversion rate (%)");
168 $l1plot->value->setColor(
'red');
169 $l1plot->value->setFormat(
'% 0.2f%%');
170 $l1plot->value->hideZero();
171 $l1plot->value->show();
174 $graph->addY2( $l1plot );
175 $graph->add( $l2plot );
176 $graph->add( $l3plot );
188 public function visitor_week()
201 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
203 $rs = $oDb->execute( $sSQL);
204 if ($rs !=
false && $rs->recordCount() > 0) {
207 $aTemp[
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
214 list( $iFrom, $iTo ) = $this->getWeekRange();
215 for ( $i = $iFrom; $i < $iTo; $i++ ) {
219 $aDataY[] =
"KW ".$i;
222 foreach ( $aTemp as $key => $value) {
223 $aDataX[$key] = $value;
226 $aDataY[] =
"KW ".$key;
230 $sSQL =
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
231 $rs = $oDb->execute( $sSQL);
232 if ($rs !=
false && $rs->recordCount() > 0) {
234 $sKey =
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay' ), strtotime( $rs->fields[0]));
235 if (isset($aDataX2[$sKey])) {
243 $sSQL =
"select oxtime, oxsessid from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
244 $rs = $oDb->execute( $sSQL);
245 if ($rs !=
false && $rs->recordCount() > 0) {
247 $sKey =
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay' ), strtotime( $rs->fields[0]));
248 if ( isset( $aDataX3[$sKey] ) ) {
255 header (
"Content-type: image/png" );
258 $graph =
new Graph( max( 800, count( $aDataX) * 80), 600);
260 $graph->setBackgroundImage(
$myConfig->getImageDir(
true).
"/reportbgrnd.jpg", BGIMG_FILLFRAME);
263 $graph->setScale(
"textlin");
264 $graph->setY2Scale(
"lin");
265 $graph->y2axis->setColor(
"red");
268 $graph->xaxis->setLabelAlign(
'center',
'top',
'right');
271 $graph->yaxis->setLabelAlign(
'right',
'bottom');
275 $graph->xaxis->setTickLabels( $aDataY);
279 $graph->title->set(
"Woche");
282 $graph->title->setFont(FF_FONT1, FS_BOLD);
284 $aDataFinalX = array();
285 foreach ( $aDataX as $dData)
286 $aDataFinalX[] = $dData;
289 $l2plot=
new LinePlot($aDataFinalX);
290 $l2plot->setColor(
"navy");
291 $l2plot->setWeight(2);
292 $l2plot->setLegend(
"Besucher");
293 $l2plot->value->setColor(
"navy");
294 $l2plot->value->setFormat(
'% d');
295 $l2plot->value->hideZero();
296 $l2plot->value->show();
298 $aDataFinalX2 = array();
299 foreach ( $aDataX2 as $dData)
300 $aDataFinalX2[] = $dData;
303 $l3plot=
new LinePlot($aDataFinalX2);
304 $l3plot->setColor(
"orange");
305 $l3plot->setWeight(2);
306 $l3plot->setLegend(
"Bestellungen");
308 $l3plot->value->setColor(
"orange");
309 $l3plot->value->setFormat(
'% d');
310 $l3plot->value->hideZero();
311 $l3plot->value->show();
315 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
316 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
317 $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
321 $l1plot=
new LinePlot($l1datay);
322 $l1plot->setColor(
"red");
323 $l1plot->setWeight(2);
324 $l1plot->setLegend(
"Conversion rate (%)");
325 $l1plot->value->setColor(
'red');
326 $l1plot->value->setFormat(
'% 0.4f%%');
327 $l1plot->value->hideZero();
328 $l1plot->value->show();
331 $graph->addY2($l1plot);
332 $graph->add($l2plot);
333 $graph->add($l3plot);