3 if (!class_exists(
'report_canceled_orders')) {
 
    7     class Report_canceled_orders 
extends report_base
 
   15         protected $_sThisTemplate = 
"report_canceled_orders.tpl";
 
   22         public function drawReport()
 
   26             $oSmarty = $this->getSmarty();
 
   27             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars[
'time_from'])));
 
   28             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars[
'time_to'])));
 
   31             $sSql = 
"select 1 from `oxlogs` where oxclass = 'order' and 
   32                        oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   33             if ($oDb->getOne($sSql)) {
 
   38             $sSql = 
"select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   39             if ($oDb->getOne($sSql)) {
 
   44             $sSql = 
"select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   45             if ($oDb->getOne($sSql)) {
 
   50             $sSql = 
"select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   51             if ($oDb->getOne($sSql)) {
 
   56             $sSql = 
"select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   57             if ($oDb->getOne($sSql)) {
 
   62             $sSql = 
"select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo";
 
   63             if ($oDb->getOne($sSql)) {
 
   75         protected function _collectSessions($sQ)
 
   77             $aTempOrder = array();
 
   79             if ($rs != 
false && $rs->recordCount() > 0) {
 
   81                     $aTempOrder[$rs->fields[1]] = $rs->fields[0];
 
   99         protected function _collectOrderSessions($sQ, $aTempOrder, &$aData, $blMonth = 
true)
 
  102             $aTempExecOrdersSessions = array();
 
  104             if ($rs != 
false && $rs->recordCount() > 0) {
 
  105                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  107                     if (!isset($aTempOrder[$rs->fields[1]])) {
 
  108                         $aTempExecOrdersSessions[$rs->fields[1]] = 1;
 
  109                         $sKey = strtotime($rs->fields[0]);
 
  112                         $sKey = $blMonth ? date(
"m/Y", $sKey) : $oUtilsData->getWeekNumber($iFirstWeekDay, $sKey);
 
  113                         if (isset($aData[$sKey])) {
 
  122             return $aTempExecOrdersSessions;
 
  136         protected function _collectPaymentSessions(
 
  139             $aTempExecOrdersSessions,
 
  143             $aTempPaymentSessions = array();
 
  145             if ($rs != 
false && $rs->recordCount() > 0) {
 
  146                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  148                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  149                         $aTempPaymentSessions[$rs->fields[1]] = 1;
 
  150                         $sKey = strtotime($rs->fields[0]);
 
  151                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  152                         if (isset($aDataX2[$sKey])) {
 
  160             return $aTempPaymentSessions;
 
  175         protected function _collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, &$aDataX3, $blMonth = 
true)
 
  177             $aTempUserSessions = array();
 
  179             if ($rs != 
false && $rs->recordCount() > 0) {
 
  180                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  182                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  183                         $aTempUserSessions[$rs->fields[1]] = 1;
 
  184                         $sKey = strtotime($rs->fields[0]);
 
  185                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  186                         if (isset($aDataX3[$sKey])) {
 
  194             return $aTempUserSessions;
 
  208         protected function _collectToBasketSessions($sSql, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, &$aDataX4, $blMonth = 
true)
 
  211             if ($rs != 
false && $rs->recordCount() > 0) {
 
  212                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  214                     if (!$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  215                         $sKey = strtotime($rs->fields[0]);
 
  216                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  217                         if (isset($aDataX4[$sKey])) {
 
  233         protected function _collectOrdersMade($sSql, &$aDataX5, $blMonth = 
true)
 
  236             if ($rs != 
false && $rs->recordCount() > 0) {
 
  237                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  239                     $sKey = strtotime($rs->fields[0]);
 
  240                     $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  241                     if (isset($aDataX5[$sKey])) {
 
  255         protected function _collectOrdersMadeForVisitorWeek($sQ, &$aDataX5)
 
  259             if ($rs != 
false && $rs->recordCount() > 0) {
 
  262                     if (isset($aDataX5[$sKey])) {
 
  273         public function visitor_month()
 
  279             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeTo));
 
  280             $dTimeFrom = mktime(23, 59, 59, date(
"m", $dTimeTo) - 12, date(
"d", $dTimeTo), date(
"Y", $dTimeTo));
 
  281             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeFrom));
 
  283             $sSQL = 
"select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid";
 
  286             for ($i = 1; $i <= 12; $i++) {
 
  287                 $aTemp[date(
"m/Y", mktime(23, 59, 59, date(
"m", $dTimeFrom) + $i, date(
"d", $dTimeFrom), date(
"Y", $dTimeFrom)))] = 0;
 
  290             $rs = $oDb->execute($sSQL);
 
  292             if ($rs != 
false && $rs->recordCount() > 0) {
 
  294                     $aTemp[date(
"m/Y", strtotime($rs->fields[0]))]++;
 
  300             $aDataY = array_keys($aTemp);
 
  301             $aDataX2 = $aDataX3 = $aDataX4 = $aDataX5 = $aDataX6 = array_fill_keys($aDataY, 0);
 
  304             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  305             $aTempOrder = $this->_collectSessions($sQ);
 
  308             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  309             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6);
 
  312             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  313             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2);
 
  316             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  317             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2);
 
  320             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  321             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4);
 
  324             $sQ = 
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
 
  325             $this->_collectOrdersMade($sQ, $aDataX5);
 
  327             header(
"Content-type: image/png");
 
  330             $graph = $this->getGraph(800, 600);
 
  333             $graph->xaxis->setTickLabels($aDataY);
 
  336             $graph->title->set(
"Monat");
 
  339             $bplot2 = 
new BarPlot(array_values($aDataX2));
 
  340             $bplot2->setFillColor(
"#9966cc");
 
  341             $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden");
 
  344             $bplot3 = 
new BarPlot(array_values($aDataX3));
 
  345             $bplot3->setFillColor(
"#ffcc00");
 
  346             $bplot3->setLegend(
"Best.Abbr. in Benutzer");
 
  349             $bplot4 = 
new BarPlot(array_values($aDataX4));
 
  350             $bplot4->setFillColor(
"#6699ff");
 
  351             $bplot4->setLegend(
"Best.Abbr. in Warenkorb");
 
  354             $bplot6 = 
new BarPlot(array_values($aDataX6));
 
  355             $bplot6->setFillColor(
"#ff0099");
 
  356             $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung");
 
  359             $bplot5 = 
new BarPlot(array_values($aDataX5));
 
  360             $bplot5->setFillColor(
"silver");
 
  361             $bplot5->setLegend(
"Bestellungen");
 
  364             $gbplot = 
new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
 
  365             $graph->add($gbplot);
 
  374         public function visitor_week()
 
  387             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_to"))));
 
  388             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_from"))));
 
  390             $sSQL = 
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
 
  393             $rs = $oDb->execute($sSQL);
 
  395             if ($rs != 
false && $rs->recordCount() > 0) {
 
  397                     $aTemp[
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay'), strtotime($rs->fields[0]))]++;
 
  403             list($iFrom, $iTo) = $this->getWeekRange();
 
  404             for ($i = $iFrom; $i < $iTo; $i++) {
 
  411                 $aDataY[] = 
"KW " . $i;
 
  414             foreach ($aTemp as $key => $value) {
 
  415                 $aDataX[$key] = $value;
 
  421                 $aDataY[] = 
"KW " . $key;
 
  425             $sQ = 
"select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  426             $aTempOrder = $this->_collectSessions($sQ);
 
  429             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  430             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6, 
false);
 
  433             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  434             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2, 
false);
 
  437             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  438             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2, 
false);
 
  441             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  442             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4, 
false);
 
  445             $sQ = 
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
 
  446             $this->_collectOrdersMade($sQ, $aDataX5, 
false);
 
  448             header(
"Content-type: image/png");
 
  451             $graph = $this->getGraph(max(800, count($aDataX) * 80), 600);
 
  454             $graph->xaxis->setTickLabels($aDataY);
 
  457             $graph->title->set(
"Woche");
 
  460             $bplot2 = 
new BarPlot(array_values($aDataX2));
 
  461             $bplot2->setFillColor(
"#9966cc");
 
  462             $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden");
 
  465             $bplot3 = 
new BarPlot(array_values($aDataX3));
 
  466             $bplot3->setFillColor(
"#ffcc00");
 
  467             $bplot3->setLegend(
"Best.Abbr. in Benutzer");
 
  470             $bplot4 = 
new BarPlot(array_values($aDataX4));
 
  471             $bplot4->setFillColor(
"#6699ff");
 
  472             $bplot4->setLegend(
"Best.Abbr. in Warenkorb");
 
  475             $bplot6 = 
new BarPlot(array_values($aDataX6));
 
  476             $bplot6->setFillColor(
"#ff0099");
 
  477             $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung");
 
  480             $bplot5 = 
new BarPlot(array_values($aDataX5));
 
  481             $bplot5->setFillColor(
"silver");
 
  482             $bplot5->setLegend(
"Bestellungen");
 
  485             $gbplot = 
new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
 
  486             $graph->add($gbplot);