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