report_visitor_absolute.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !class_exists( "report_visitor_absolute") ) {
00007 class Report_visitor_absolute extends report_base
00008 {
00014     protected $_sThisTemplate = "report_visitor_absolute.tpl";
00015 
00021     public function drawReport()
00022     {
00023         $oDb = oxDb::getDb();
00024 
00025         $oSmarty    = $this->getSmarty();
00026         $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
00027         $sTimeTo   = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
00028 
00029         if ( $oDb->getOne( "select 1 from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
00030             return true;
00031         }
00032 
00033         // buyer
00034         if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo" ) ) {
00035             return true;
00036         }
00037 
00038         // newcustomer
00039         if ( $oDb->getOne( "select 1 from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo" ) ) {
00040             return true;
00041         }
00042     }
00043 
00049     public function visitor_month()
00050     {
00051         $myConfig = $this->getConfig();
00052         $oDb = oxDb::getDb();
00053 
00054         $aDataX = array();
00055         $aDataY = array();
00056 
00057         $dTimeTo = strtotime( oxRegistry::getConfig()->getRequestParameter( "time_to" ) );
00058         $dTimeFrom = mktime( 23, 59, 59, date( "m", $dTimeTo)-12, date( "d", $dTimeTo), date( "Y", $dTimeTo));
00059 
00060         $sTimeTo    = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00061         $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00062 
00063         $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00064         $aTemp = array();
00065         for ( $i = 1; $i <= 12; $i++)
00066             $aTemp[date( "m/Y", mktime( 23, 59, 59, date( "m", $dTimeFrom)+$i, date( "d", $dTimeFrom), date( "Y", $dTimeFrom)) )] = 0;
00067 
00068         $rs = $oDb->execute( $sSQL);
00069         if ($rs != false && $rs->recordCount() > 0) {
00070             while (!$rs->EOF) {
00071                 $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00072                 $rs->moveNext();
00073             }
00074         }
00075 
00076         foreach ( $aTemp as $key => $value) {
00077              $aDataX[$key]     = $value;
00078             $aDataX2[$key]    = 0;
00079             $aDataX3[$key]    = 0;
00080             $aDataY[]         = $key;
00081         }
00082 
00083         // buyer
00084         $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
00085         $aTemp = array();
00086         $rs = $oDb->execute( $sSQL);
00087         if ($rs != false && $rs->recordCount() > 0) {
00088             while (!$rs->EOF) {
00089                 $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00090                 $rs->moveNext();
00091             }
00092         }
00093 
00094         foreach ( $aTemp as $key => $value) {
00095              $aDataX2[$key] = $value;
00096         }
00097 
00098         // newcustomer
00099         $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
00100         $aTemp = array();
00101         $rs = $oDb->execute( $sSQL);
00102         if ($rs != false && $rs->recordCount() > 0) {
00103             while (!$rs->EOF) {
00104                 $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00105                 $rs->moveNext();
00106             }
00107         }
00108 
00109         foreach ( $aTemp as $key => $value) {
00110              $aDataX3[$key] = $value;
00111         }
00112 
00113 
00114         header ("Content-type: image/png" );
00115 
00116         // New graph with a drop shadow
00117         $graph = new Graph(800, 600);
00118 
00119         $graph->setBackgroundImage( $myConfig->getImageDir(true)."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00120 
00121         // Use a "text" X-scale
00122         $graph->setScale("textlin");
00123 
00124         // Label align for X-axis
00125         $graph->xaxis->setLabelAlign('center', 'top', 'right');
00126 
00127         // Label align for Y-axis
00128         $graph->yaxis->setLabelAlign('right', 'bottom');
00129 
00130         $graph->setShadow();
00131         // Description
00132         $graph->xaxis->setTickLabels( $aDataY);
00133 
00134 
00135         // Set title and subtitle
00136         $graph->title->set("Monat");
00137 
00138         // Use built in font
00139         $graph->title->setFont(FF_FONT1, FS_BOLD);
00140 
00141         $aDataFinalX = array();
00142         foreach ( $aDataX as $dData)
00143             $aDataFinalX[] = $dData;
00144         // Create the bar plot
00145         $bplot = new BarPlot( $aDataFinalX);
00146         $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00147         $bplot->setLegend("Besucher");
00148 
00149         $aDataFinalX2 = array();
00150         foreach ( $aDataX2 as $dData)
00151             $aDataFinalX2[] = $dData;
00152         // Create the bar plot
00153         $bplot2 = new BarPlot( $aDataFinalX2);
00154         $bplot2->setFillColor ("orange");
00155         $bplot2->setLegend("Kaeufer");
00156 
00157         $aDataFinalX3 = array();
00158         foreach ( $aDataX3 as $dData)
00159             $aDataFinalX3[] = $dData;
00160         // Create the bar plot
00161         $bplot3 = new BarPlot( $aDataFinalX3);
00162         $bplot3->setFillColor ("silver");
00163         $bplot3->setLegend("Neukunden");
00164 
00165         // Create the grouped bar plot
00166         $gbplot = new groupBarPlot (array($bplot, $bplot2, $bplot3));
00167         $graph->add( $gbplot);
00168 
00169         // Finally output the  image
00170         $graph->stroke();
00171 
00172     }
00173 
00179     public function visitor_week()
00180     {
00181         $myConfig = $this->getConfig();
00182         $oDb = oxDb::getDb();
00183 
00184         $aDataX = array();
00185         $aDataY = array();
00186 
00187         $sTimeTo   = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to" ) ) ) );
00188         $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from" ) ) ) );
00189 
00190         $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
00191         $aTemp = array();
00192         $rs = $oDb->execute( $sSQL);
00193         if ($rs != false && $rs->recordCount() > 0) {
00194             while (!$rs->EOF) {
00195                 //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00196                 $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00197                 $rs->moveNext();
00198             }
00199         }
00200 
00201         // initializing
00202         list( $iFrom, $iTo ) = $this->getWeekRange();
00203         for ( $i = $iFrom; $i < $iTo; $i++ ) {
00204             $aDataX[$i]  = 0;
00205             $aDataX2[$i] = 0;
00206             $aDataX3[$i] = 0;
00207             $aDataY[]      = "KW ".$i;
00208         }
00209 
00210         foreach ( $aTemp as $key => $value) {
00211             $aDataX[$key]  = $value;
00212             $aDataX2[$key] = 0;
00213             $aDataX3[$key] = 0;
00214             $aDataY[]      = "KW ".$key;
00215         }
00216 
00217         // buyer
00218         $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
00219         $aTemp = array();
00220         $rs = $oDb->execute( $sSQL);
00221         if ($rs != false && $rs->recordCount() > 0) {
00222             while (!$rs->EOF) {
00223                 //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00224                 $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00225                 $rs->moveNext();
00226             }
00227         }
00228 
00229         foreach ( $aTemp as $key => $value) {
00230              $aDataX2[$key] = $value;
00231         }
00232 
00233         // newcustomer
00234         $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
00235         $aTemp = array();
00236         $rs = $oDb->execute( $sSQL);
00237         if ($rs != false && $rs->recordCount() > 0) {
00238             while (!$rs->EOF) {
00239                 //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00240                 $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00241                 $rs->moveNext();
00242             }
00243         }
00244 
00245         foreach ( $aTemp as $key => $value) {
00246              $aDataX3[$key] = $value;
00247         }
00248 
00249         header ("Content-type: image/png" );
00250 
00251         // New graph with a drop shadow
00252         $graph = new Graph( max( 800, count( $aDataX) * 80), 600);
00253 
00254         $graph->setBackgroundImage( $myConfig->getImageDir(true)."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00255 
00256         // Use a "text" X-scale
00257         $graph->setScale("textlin");
00258 
00259         // Label align for X-axis
00260         $graph->xaxis->setLabelAlign('center', 'top', 'right');
00261 
00262         // Label align for Y-axis
00263         $graph->yaxis->setLabelAlign('right', 'bottom');
00264 
00265         $graph->setShadow();
00266         // Description
00267         $graph->xaxis->setTickLabels( $aDataY);
00268 
00269 
00270         // Set title and subtitle
00271         $graph->title->set("Woche");
00272 
00273         // Use built in font
00274         $graph->title->setFont(FF_FONT1, FS_BOLD);
00275 
00276         $aDataFinalX = array();
00277         foreach ( $aDataX as $dData)
00278             $aDataFinalX[] = $dData;
00279         // Create the bar plot
00280         $bplot = new BarPlot( $aDataFinalX);
00281         $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00282         $bplot->setLegend("Besucher");
00283 
00284         $aDataFinalX2 = array();
00285         foreach ( $aDataX2 as $dData)
00286             $aDataFinalX2[] = $dData;
00287         // Create the bar plot
00288         $bplot2 = new BarPlot( $aDataFinalX2);
00289         $bplot2->setFillColor ("orange");
00290         $bplot2->setLegend("Kaeufer");
00291 
00292         $aDataFinalX3 = array();
00293         foreach ( $aDataX3 as $dData)
00294             $aDataFinalX3[] = $dData;
00295         // Create the bar plot
00296         $bplot3 = new BarPlot( $aDataFinalX3);
00297         $bplot3->setFillColor ("silver");
00298         $bplot3->setLegend("Neukunden");
00299 
00300         // Create the grouped bar plot
00301         $gbplot = new groupBarPlot (array($bplot, $bplot2, $bplot3));
00302         $graph->add( $gbplot);
00303 
00304         // Finally output the  image
00305         $graph->stroke();
00306     }
00307 }
00308 }