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