3 if (!class_exists(
'report_canceled_orders')) {
 
    9     class Report_canceled_orders 
extends report_base
 
   17         protected $_sThisTemplate = 
"report_canceled_orders.tpl";
 
   24         public function drawReport()
 
   28             $oSmarty = $this->getSmarty();
 
   29             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars[
'time_from'])));
 
   30             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars[
'time_to'])));
 
   33             $sSql = 
"select 1 from `oxlogs` where oxclass = 'order' and 
   34                        oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   35             if ($oDb->getOne($sSql)) {
 
   40             $sSql = 
"select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   41             if ($oDb->getOne($sSql)) {
 
   46             $sSql = 
"select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   47             if ($oDb->getOne($sSql)) {
 
   52             $sSql = 
"select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   53             if ($oDb->getOne($sSql)) {
 
   58             $sSql = 
"select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
 
   59             if ($oDb->getOne($sSql)) {
 
   64             $sSql = 
"select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo";
 
   65             if ($oDb->getOne($sSql)) {
 
   77         protected function _collectSessions($sQ)
 
   79             $aTempOrder = array();
 
   81             if ($rs != 
false && $rs->recordCount() > 0) {
 
   83                     $aTempOrder[$rs->fields[1]] = $rs->fields[0];
 
  101         protected function _collectOrderSessions($sQ, $aTempOrder, &$aData, $blMonth = 
true)
 
  104             $aTempExecOrdersSessions = array();
 
  106             if ($rs != 
false && $rs->recordCount() > 0) {
 
  107                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  109                     if (!isset($aTempOrder[$rs->fields[1]])) {
 
  110                         $aTempExecOrdersSessions[$rs->fields[1]] = 1;
 
  111                         $sKey = strtotime($rs->fields[0]);
 
  114                         $sKey = $blMonth ? date(
"m/Y", $sKey) : $oUtilsData->getWeekNumber($iFirstWeekDay, $sKey);
 
  115                         if (isset($aData[$sKey])) {
 
  124             return $aTempExecOrdersSessions;
 
  138         protected function _collectPaymentSessions(
 
  141             $aTempExecOrdersSessions,
 
  145             $aTempPaymentSessions = array();
 
  147             if ($rs != 
false && $rs->recordCount() > 0) {
 
  148                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  150                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  151                         $aTempPaymentSessions[$rs->fields[1]] = 1;
 
  152                         $sKey = strtotime($rs->fields[0]);
 
  153                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  154                         if (isset($aDataX2[$sKey])) {
 
  162             return $aTempPaymentSessions;
 
  177         protected function _collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, &$aDataX3, $blMonth = 
true)
 
  179             $aTempUserSessions = array();
 
  181             if ($rs != 
false && $rs->recordCount() > 0) {
 
  182                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  184                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  185                         $aTempUserSessions[$rs->fields[1]] = 1;
 
  186                         $sKey = strtotime($rs->fields[0]);
 
  187                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  188                         if (isset($aDataX3[$sKey])) {
 
  196             return $aTempUserSessions;
 
  210         protected function _collectToBasketSessions($sSql, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, &$aDataX4, $blMonth = 
true)
 
  213             if ($rs != 
false && $rs->recordCount() > 0) {
 
  214                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  216                     if (!$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
 
  217                         $sKey = strtotime($rs->fields[0]);
 
  218                         $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  219                         if (isset($aDataX4[$sKey])) {
 
  235         protected function _collectOrdersMade($sSql, &$aDataX5, $blMonth = 
true)
 
  238             if ($rs != 
false && $rs->recordCount() > 0) {
 
  239                 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay');
 
  241                     $sKey = strtotime($rs->fields[0]);
 
  242                     $sKey = $blMonth ? date(
"m/Y", $sKey) : 
oxRegistry::get(
"oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
 
  243                     if (isset($aDataX5[$sKey])) {
 
  257         protected function _collectOrdersMadeForVisitorWeek($sQ, &$aDataX5)
 
  261             if ($rs != 
false && $rs->recordCount() > 0) {
 
  264                     if (isset($aDataX5[$sKey])) {
 
  275         public function visitor_month()
 
  281             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeTo));
 
  282             $dTimeFrom = mktime(23, 59, 59, date(
"m", $dTimeTo) - 12, date(
"d", $dTimeTo), date(
"Y", $dTimeTo));
 
  283             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", $dTimeFrom));
 
  285             $sSQL = 
"select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid";
 
  288             for ($i = 1; $i <= 12; $i++) {
 
  289                 $aTemp[date(
"m/Y", mktime(23, 59, 59, date(
"m", $dTimeFrom) + $i, date(
"d", $dTimeFrom), date(
"Y", $dTimeFrom)))] = 0;
 
  292             $rs = $oDb->execute($sSQL);
 
  294             if ($rs != 
false && $rs->recordCount() > 0) {
 
  296                     $aTemp[date(
"m/Y", strtotime($rs->fields[0]))]++;
 
  302             $aDataY = array_keys($aTemp);
 
  303             $aDataX2 = $aDataX3 = $aDataX4 = $aDataX5 = $aDataX6 = array_fill_keys($aDataY, 0);
 
  306             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  307             $aTempOrder = $this->_collectSessions($sQ);
 
  310             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  311             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6);
 
  314             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  315             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2);
 
  318             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  319             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2);
 
  322             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  323             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4);
 
  326             $sQ = 
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
 
  327             $this->_collectOrdersMade($sQ, $aDataX5);
 
  329             header(
"Content-type: image/png");
 
  332             $graph = $this->getGraph(800, 600);
 
  335             $graph->xaxis->setTickLabels($aDataY);
 
  338             $graph->title->set(
"Monat");
 
  341             $bplot2 = 
new BarPlot(array_values($aDataX2));
 
  342             $bplot2->setFillColor(
"#9966cc");
 
  343             $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden");
 
  346             $bplot3 = 
new BarPlot(array_values($aDataX3));
 
  347             $bplot3->setFillColor(
"#ffcc00");
 
  348             $bplot3->setLegend(
"Best.Abbr. in Benutzer");
 
  351             $bplot4 = 
new BarPlot(array_values($aDataX4));
 
  352             $bplot4->setFillColor(
"#6699ff");
 
  353             $bplot4->setLegend(
"Best.Abbr. in Warenkorb");
 
  356             $bplot6 = 
new BarPlot(array_values($aDataX6));
 
  357             $bplot6->setFillColor(
"#ff0099");
 
  358             $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung");
 
  361             $bplot5 = 
new BarPlot(array_values($aDataX5));
 
  362             $bplot5->setFillColor(
"silver");
 
  363             $bplot5->setLegend(
"Bestellungen");
 
  366             $gbplot = 
new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
 
  367             $graph->add($gbplot);
 
  376         public function visitor_week()
 
  389             $sTimeTo = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_to"))));
 
  390             $sTimeFrom = $oDb->quote(date(
"Y-m-d H:i:s", strtotime(
oxRegistry::getConfig()->getRequestParameter(
"time_from"))));
 
  392             $sSQL = 
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
 
  395             $rs = $oDb->execute($sSQL);
 
  397             if ($rs != 
false && $rs->recordCount() > 0) {
 
  399                     $aTemp[
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay'), strtotime($rs->fields[0]))]++;
 
  405             list($iFrom, $iTo) = $this->getWeekRange();
 
  406             for ($i = $iFrom; $i < $iTo; $i++) {
 
  413                 $aDataY[] = 
"KW " . $i;
 
  416             foreach ($aTemp as $key => $value) {
 
  417                 $aDataX[$key] = $value;
 
  423                 $aDataY[] = 
"KW " . $key;
 
  427             $sQ = 
"select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  428             $aTempOrder = $this->_collectSessions($sQ);
 
  431             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  432             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6, 
false);
 
  435             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  436             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2, 
false);
 
  439             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  440             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2, 
false);
 
  443             $sQ = 
"select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
 
  444             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4, 
false);
 
  447             $sQ = 
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
 
  448             $this->_collectOrdersMade($sQ, $aDataX5, 
false);
 
  450             header(
"Content-type: image/png");
 
  453             $graph = $this->getGraph(max(800, count($aDataX) * 80), 600);
 
  456             $graph->xaxis->setTickLabels($aDataY);
 
  459             $graph->title->set(
"Woche");
 
  462             $bplot2 = 
new BarPlot(array_values($aDataX2));
 
  463             $bplot2->setFillColor(
"#9966cc");
 
  464             $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden");
 
  467             $bplot3 = 
new BarPlot(array_values($aDataX3));
 
  468             $bplot3->setFillColor(
"#ffcc00");
 
  469             $bplot3->setLegend(
"Best.Abbr. in Benutzer");
 
  472             $bplot4 = 
new BarPlot(array_values($aDataX4));
 
  473             $bplot4->setFillColor(
"#6699ff");
 
  474             $bplot4->setLegend(
"Best.Abbr. in Warenkorb");
 
  477             $bplot6 = 
new BarPlot(array_values($aDataX6));
 
  478             $bplot6->setFillColor(
"#ff0099");
 
  479             $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung");
 
  482             $bplot5 = 
new BarPlot(array_values($aDataX5));
 
  483             $bplot5->setFillColor(
"silver");
 
  484             $bplot5->setLegend(
"Bestellungen");
 
  487             $gbplot = 
new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
 
  488             $graph->add($gbplot);