00001 <?php
00002
00003 if ( !class_exists( "report_conversion_rate")) {
00007 class Report_conversion_rate extends report_base
00008 {
00014 protected $_sThisTemplate = "report_conversion_rate.tpl";
00015
00021 public function drawReport()
00022 {
00023 $oDb = oxDb::getDb();
00024
00025 $oSmarty = $this->getSmarty();
00026 $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
00027 $sTime_to = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
00028
00029
00030 if ( $oDb->getOne( "select * from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00031 return true;
00032 }
00033
00034
00035 if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to" ) ) {
00036 return true;
00037 }
00038 }
00039
00045 public function visitor_month()
00046 {
00047 $myConfig = $this->getConfig();
00048 $oDb = oxDb::getDb();
00049
00050 $aDataX = array();
00051 $aDataY = array();
00052
00053 $dTimeTo = strtotime( oxConfig::getParameter( "time_to"));
00054 $sTime_to = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00055 $dTimeFrom = mktime( 23, 59, 59, date( "m", $dTimeTo)-12, date( "d", $dTimeTo), date( "Y", $dTimeTo));
00056 $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00057
00058
00059 $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00060 $aTemp = array();
00061 for ( $i = 1; $i <= 12; $i++)
00062 $aTemp[date( "m/Y", mktime( 23, 59, 59, date( "m", $dTimeFrom)+$i, date( "d", $dTimeFrom), date( "Y", $dTimeFrom)) )] = 0;
00063
00064 $rs = $oDb->execute( $sSQL);
00065 if ($rs != false && $rs->recordCount() > 0) {
00066 while (!$rs->EOF) {
00067 $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00068 $rs->moveNext();
00069 }
00070 }
00071
00072 $aDataX2 = array();
00073 $aDataX3 = array();
00074
00075 foreach ( $aTemp as $key => $value) {
00076 $aDataX[$key] = $value;
00077 $aDataX2[$key] = 0;
00078 $aDataX3[$key] = 0;
00079 $aDataY[] = $key;
00080 }
00081
00082
00083 $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00084 $aTemp = array();
00085 $rs = $oDb->execute( $sSQL);
00086 if ($rs != false && $rs->recordCount() > 0) {
00087 while (!$rs->EOF) {
00088 $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00089 $rs->moveNext();
00090 }
00091 }
00092
00093 foreach ( $aTemp as $key => $value) {
00094 if (isset($aDataX2[$key]))
00095 $aDataX2[$key] = $value;
00096 }
00097
00098 header ("Content-type: image/png" );
00099
00100
00101 $graph = new Graph(800, 600, "auto");
00102
00103 $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00104
00105
00106 $graph->setScale("textlin");
00107 $graph->setY2Scale("lin");
00108 $graph->y2axis->setColor("red");
00109
00110
00111 $graph->xaxis->setLabelAlign('center', 'top', 'right');
00112
00113
00114 $graph->yaxis->setLabelAlign('right', 'bottom');
00115
00116 $graph->setShadow();
00117
00118 $graph->xaxis->setTickLabels( $aDataY);
00119
00120
00121
00122 $graph->title->set("Monat");
00123
00124
00125 $graph->title->setFont(FF_FONT1, FS_BOLD);
00126
00127 $aDataFinalX = array();
00128 foreach ( $aDataX as $dData)
00129 $aDataFinalX[] = $dData;
00130
00131
00132 $l2plot=new LinePlot($aDataFinalX);
00133 $l2plot->setColor("navy");
00134 $l2plot->setWeight(2);
00135 $l2plot->setLegend("Besucher");
00136
00137 $l2plot->value->setColor("navy");
00138 $l2plot->value->setFormat('% d');
00139 $l2plot->value->hideZero();
00140 $l2plot->value->show();
00141
00142 $aDataFinalX2 = array();
00143 foreach ( $aDataX2 as $dData)
00144 $aDataFinalX2[] = $dData;
00145
00146
00147 $l3plot=new LinePlot($aDataFinalX2);
00148 $l3plot->setColor("orange");
00149 $l3plot->setWeight(2);
00150 $l3plot->setLegend("Bestellungen");
00151
00152 $l3plot->value->setColor('orange');
00153 $l3plot->value->setFormat('% d');
00154 $l3plot->value->hideZero();
00155 $l3plot->value->show();
00156
00157
00158 $l1datay = array();
00159 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
00160 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
00161 $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
00162 } else
00163 $l1datay[] = 0;
00164 }
00165
00166 $l1plot=new LinePlot($l1datay);
00167 $l1plot->setColor("red");
00168 $l1plot->setWeight(2);
00169 $l1plot->setLegend("Conversion rate (%)");
00170 $l1plot->value->setColor('red');
00171 $l1plot->value->setFormat('% 0.2f%%');
00172 $l1plot->value->hideZero();
00173 $l1plot->value->show();
00174
00175
00176 $graph->addY2( $l1plot );
00177 $graph->add( $l2plot );
00178 $graph->add( $l3plot );
00179
00180
00181 $graph->stroke();
00182
00183 }
00184
00190 public function visitor_week()
00191 {
00192 $myConfig = $this->getConfig();
00193 $oDb = oxDb::getDb();
00194
00195 $aDataX = array();
00196 $aDataX2 = array();
00197 $aDataX3 = array();
00198 $aDataY = array();
00199
00200 $dTimeTo = strtotime( oxConfig::getParameter( "time_to"));
00201 $sTime_to = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00202 $dTimeFrom = strtotime( oxConfig::getParameter( "time_from"));
00203 $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00204
00205 $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid order by oxtime";
00206 $aTemp = array();
00207 $rs = $oDb->execute( $sSQL);
00208 if ($rs != false && $rs->recordCount() > 0) {
00209 while (!$rs->EOF) {
00210
00211 $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00212 $rs->moveNext();
00213 }
00214 }
00215
00216
00217
00218 list( $iFrom, $iTo ) = $this->getWeekRange();
00219 for ( $i = $iFrom; $i < $iTo; $i++ ) {
00220 $aDataX[$i] = 0;
00221 $aDataX2[$i] = 0;
00222 $aDataX3[$i] = 0;
00223 $aDataY[] = "KW ".$i;
00224 }
00225
00226 foreach ( $aTemp as $key => $value) {
00227 $aDataX[$key] = $value;
00228 $aDataX2[$key] = 0;
00229 $aDataX3[$key] = 0;
00230 $aDataY[] = "KW ".$key;
00231 }
00232
00233
00234 $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00235 $aTemp = array();
00236 $rs = $oDb->execute( $sSQL);
00237 if ($rs != false && $rs->recordCount() > 0) {
00238 while (!$rs->EOF) {
00239
00240 $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00241 $rs->moveNext();
00242 }
00243 }
00244
00245 foreach ( $aTemp as $key => $value) {
00246 if (isset($aDataX2[$key]))
00247 $aDataX2[$key] = $value;
00248 }
00249
00250
00251 $sSQL = "select oxtime, oxsessid from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid order by oxtime";
00252 $aTemp = array();
00253 $rs = $oDb->execute( $sSQL);
00254 if ($rs != false && $rs->recordCount() > 0) {
00255 while (!$rs->EOF) {
00256
00257 $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00258 $rs->moveNext();
00259 }
00260 }
00261
00262 foreach ( $aTemp as $key => $value) {
00263 if (isset($aDataX3[$key]))
00264 $aDataX3[$key] = $value;
00265 }
00266
00267 header ("Content-type: image/png" );
00268
00269
00270 $graph = new Graph( max( 800, count( $aDataX) * 80), 600);
00271
00272 $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00273
00274
00275 $graph->setScale("textlin");
00276 $graph->setY2Scale("lin");
00277 $graph->y2axis->setColor("red");
00278
00279
00280 $graph->xaxis->setLabelAlign('center', 'top', 'right');
00281
00282
00283 $graph->yaxis->setLabelAlign('right', 'bottom');
00284
00285 $graph->setShadow();
00286
00287 $graph->xaxis->setTickLabels( $aDataY);
00288
00289
00290
00291 $graph->title->set("Woche");
00292
00293
00294 $graph->title->setFont(FF_FONT1, FS_BOLD);
00295
00296 $aDataFinalX = array();
00297 foreach ( $aDataX as $dData)
00298 $aDataFinalX[] = $dData;
00299
00300
00301 $l2plot=new LinePlot($aDataFinalX);
00302 $l2plot->setColor("navy");
00303 $l2plot->setWeight(2);
00304 $l2plot->setLegend("Besucher");
00305 $l2plot->value->setColor("navy");
00306 $l2plot->value->setFormat('% d');
00307 $l2plot->value->hideZero();
00308 $l2plot->value->show();
00309
00310 $aDataFinalX2 = array();
00311 foreach ( $aDataX2 as $dData)
00312 $aDataFinalX2[] = $dData;
00313
00314
00315 $l3plot=new LinePlot($aDataFinalX2);
00316 $l3plot->setColor("orange");
00317 $l3plot->setWeight(2);
00318 $l3plot->setLegend("Bestellungen");
00319
00320 $l3plot->value->setColor("orange");
00321 $l3plot->value->setFormat('% d');
00322 $l3plot->value->hideZero();
00323 $l3plot->value->show();
00324
00325
00326 $l1datay = array();
00327 for ($iCtr = 0; $iCtr < count($aDataFinalX); $iCtr++) {
00328 if ($aDataFinalX[$iCtr] != 0 && $aDataFinalX2[$iCtr] != 0) {
00329 $l1datay[] = 100/($aDataFinalX[$iCtr]/$aDataFinalX2[$iCtr]);
00330 } else
00331 $l1datay[] = 0;
00332 }
00333 $l1plot=new LinePlot($l1datay);
00334 $l1plot->setColor("red");
00335 $l1plot->setWeight(2);
00336 $l1plot->setLegend("Conversion rate (%)");
00337 $l1plot->value->setColor('red');
00338 $l1plot->value->setFormat('% 0.4f%%');
00339 $l1plot->value->hideZero();
00340 $l1plot->value->show();
00341
00342
00343 $graph->addY2($l1plot);
00344 $graph->add($l2plot);
00345 $graph->add($l3plot);
00346
00347
00348 $graph->stroke();
00349 }
00350 }
00351 }