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     {
00009 
00015         protected $_sThisTemplate = "report_visitor_absolute.tpl";
00016 
00022         public function drawReport()
00023         {
00024             $oDb = oxDb::getDb();
00025 
00026             $oSmarty = $this->getSmarty();
00027             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_from'])));
00028             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_to'])));
00029 
00030             if ($oDb->getOne("select 1 from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo")) {
00031                 return true;
00032             }
00033 
00034             // buyer
00035             if ($oDb->getOne("select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo")) {
00036                 return true;
00037             }
00038 
00039             // newcustomer
00040             if ($oDb->getOne("select 1 from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo")) {
00041                 return true;
00042             }
00043         }
00044 
00048         public function visitor_month()
00049         {
00050             $myConfig = $this->getConfig();
00051             $oDb = oxDb::getDb();
00052 
00053             $aDataX = array();
00054             $aDataY = array();
00055 
00056             $dTimeTo = strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"));
00057             $dTimeFrom = mktime(23, 59, 59, date("m", $dTimeTo) - 12, date("d", $dTimeTo), date("Y", $dTimeTo));
00058 
00059             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", $dTimeTo));
00060             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", $dTimeFrom));
00061 
00062             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00063             $aTemp = array();
00064             for ($i = 1; $i <= 12; $i++) {
00065                 $aTemp[date("m/Y", mktime(23, 59, 59, date("m", $dTimeFrom) + $i, date("d", $dTimeFrom), date("Y", $dTimeFrom)))] = 0;
00066             }
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             }
00145             // Create the bar plot
00146             $bplot = new BarPlot($aDataFinalX);
00147             $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00148             $bplot->setLegend("Besucher");
00149 
00150             $aDataFinalX2 = array();
00151             foreach ($aDataX2 as $dData) {
00152                 $aDataFinalX2[] = $dData;
00153             }
00154             // Create the bar plot
00155             $bplot2 = new BarPlot($aDataFinalX2);
00156             $bplot2->setFillColor("orange");
00157             $bplot2->setLegend("Kaeufer");
00158 
00159             $aDataFinalX3 = array();
00160             foreach ($aDataX3 as $dData) {
00161                 $aDataFinalX3[] = $dData;
00162             }
00163             // Create the bar plot
00164             $bplot3 = new BarPlot($aDataFinalX3);
00165             $bplot3->setFillColor("silver");
00166             $bplot3->setLegend("Neukunden");
00167 
00168             // Create the grouped bar plot
00169             $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3));
00170             $graph->add($gbplot);
00171 
00172             // Finally output the  image
00173             $graph->stroke();
00174 
00175         }
00176 
00180         public function visitor_week()
00181         {
00182             $myConfig = $this->getConfig();
00183             $oDb = oxDb::getDb();
00184 
00185             $aDataX = array();
00186             $aDataY = array();
00187 
00188             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
00189             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
00190 
00191             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
00192             $aTemp = array();
00193             $rs = $oDb->execute($sSQL);
00194             if ($rs != false && $rs->recordCount() > 0) {
00195                 while (!$rs->EOF) {
00196                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00197                     $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
00198                     $rs->moveNext();
00199                 }
00200             }
00201 
00202             // initializing
00203             list($iFrom, $iTo) = $this->getWeekRange();
00204             for ($i = $iFrom; $i < $iTo; $i++) {
00205                 $aDataX[$i] = 0;
00206                 $aDataX2[$i] = 0;
00207                 $aDataX3[$i] = 0;
00208                 $aDataY[] = "KW " . $i;
00209             }
00210 
00211             foreach ($aTemp as $key => $value) {
00212                 $aDataX[$key] = $value;
00213                 $aDataX2[$key] = 0;
00214                 $aDataX3[$key] = 0;
00215                 $aDataY[] = "KW " . $key;
00216             }
00217 
00218             // buyer
00219             $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
00220             $aTemp = array();
00221             $rs = $oDb->execute($sSQL);
00222             if ($rs != false && $rs->recordCount() > 0) {
00223                 while (!$rs->EOF) {
00224                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00225                     $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
00226                     $rs->moveNext();
00227                 }
00228             }
00229 
00230             foreach ($aTemp as $key => $value) {
00231                 $aDataX2[$key] = $value;
00232             }
00233 
00234             // newcustomer
00235             $sSQL = "select oxcreate from oxuser where oxcreate >= $sTimeFrom and oxcreate <= $sTimeTo order by oxcreate";
00236             $aTemp = array();
00237             $rs = $oDb->execute($sSQL);
00238             if ($rs != false && $rs->recordCount() > 0) {
00239                 while (!$rs->EOF) {
00240                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00241                     $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
00242                     $rs->moveNext();
00243                 }
00244             }
00245 
00246             foreach ($aTemp as $key => $value) {
00247                 $aDataX3[$key] = $value;
00248             }
00249 
00250             header("Content-type: image/png");
00251 
00252             // New graph with a drop shadow
00253             $graph = new Graph(max(800, count($aDataX) * 80), 600);
00254 
00255             $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME);
00256 
00257             // Use a "text" X-scale
00258             $graph->setScale("textlin");
00259 
00260             // Label align for X-axis
00261             $graph->xaxis->setLabelAlign('center', 'top', 'right');
00262 
00263             // Label align for Y-axis
00264             $graph->yaxis->setLabelAlign('right', 'bottom');
00265 
00266             $graph->setShadow();
00267             // Description
00268             $graph->xaxis->setTickLabels($aDataY);
00269 
00270 
00271             // Set title and subtitle
00272             $graph->title->set("Woche");
00273 
00274             // Use built in font
00275             $graph->title->setFont(FF_FONT1, FS_BOLD);
00276 
00277             $aDataFinalX = array();
00278             foreach ($aDataX as $dData) {
00279                 $aDataFinalX[] = $dData;
00280             }
00281             // Create the bar plot
00282             $bplot = new BarPlot($aDataFinalX);
00283             $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER);
00284             $bplot->setLegend("Besucher");
00285 
00286             $aDataFinalX2 = array();
00287             foreach ($aDataX2 as $dData) {
00288                 $aDataFinalX2[] = $dData;
00289             }
00290             // Create the bar plot
00291             $bplot2 = new BarPlot($aDataFinalX2);
00292             $bplot2->setFillColor("orange");
00293             $bplot2->setLegend("Kaeufer");
00294 
00295             $aDataFinalX3 = array();
00296             foreach ($aDataX3 as $dData) {
00297                 $aDataFinalX3[] = $dData;
00298             }
00299             // Create the bar plot
00300             $bplot3 = new BarPlot($aDataFinalX3);
00301             $bplot3->setFillColor("silver");
00302             $bplot3->setLegend("Neukunden");
00303 
00304             // Create the grouped bar plot
00305             $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3));
00306             $graph->add($gbplot);
00307 
00308             // Finally output the  image
00309             $graph->stroke();
00310         }
00311     }
00312 }