statistic_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Statistic_Main extends oxAdminDetails
00009 {
00017     public function render()
00018     {
00019         $myConfig  = $this->getConfig();
00020         $oLang = oxLang::getInstance();
00021 
00022         parent::render();
00023 
00024         $soxId = oxConfig::getParameter( "oxid");
00025         if (!$soxId)
00026             $soxId = "-1";
00027 
00028         // check if we right now saved a new entry
00029         $sSavedID = oxConfig::getParameter( "saved_oxid");
00030         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00031             $soxId = $sSavedID;
00032             oxSession::deleteVar( "saved_oxid");
00033             $this->_aViewData["oxid"] =  $soxId;
00034             // for reloading upper frame
00035             $this->_aViewData["updatelist"] =  "1";
00036         }
00037 
00038         $aReports = array();
00039         if ( $soxId != "-1" && isset( $soxId)) {
00040             // load object
00041             $oStat = oxNew( "oxstatistic" );
00042             $oStat->load( $soxId);
00043 
00044             $aReports = $oStat->getReports();
00045             $this->_aViewData["edit"] =  $oStat;
00046         }
00047 
00048         // setting all reports data: check for reports and load them
00049         $sPath     = getShopBasePath().$myConfig->getConfigParam( 'sAdminDir' ) . "/reports";
00050         $iLanguage = (int) oxConfig::getParameter("editlanguage");
00051         $aAllreports = array();
00052 
00053         $aReportFiles = glob( $sPath."/*.php" );
00054         foreach ( $aReportFiles as $sFile ) {
00055             if ( is_file( $sFile ) && !is_dir( $sFile ) ) {
00056 
00057                 $sConst = strtoupper( str_replace( '.php', '', basename( $sFile ) ) );
00058 
00059                 // skipping base report class
00060                 if ( $sConst == 'REPORT_BASE') {
00061                     continue;
00062                 }
00063 
00064                 include $sFile;
00065 
00066                 $oItem = new oxStdClass();
00067                 $oItem->filename = basename( $sFile );
00068                 $oItem->name     = $oLang->translateString( $sConst, $iLanguage );
00069                 $aAllreports[]   = $oItem;
00070             }
00071         }
00072 
00073         // setting reports data
00074         oxSession::setVar( "allstat_reports", $aAllreports);
00075         oxSession::setVar( "stat_reports_$soxId", $aReports);
00076 
00077         // passing assigned reports count
00078         $this->_aViewData['ireports'] = count($aReports);
00079 
00080         if ( oxConfig::getParameter("aoc") ) {
00081             $aColumns = array();
00082             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00083             $this->_aViewData['oxajax'] = $aColumns;
00084 
00085             return "popups/statistic_main.tpl";
00086         }
00087 
00088         return "statistic_main.tpl";
00089     }
00090 
00096     public function save()
00097     {
00098         $soxId   = oxConfig::getParameter( "oxid");
00099         $aParams = oxConfig::getParameter( "editval");
00100 
00101         // shopid
00102         $sShopID = oxSession::getVar( "actshop");
00103 
00104         $oStat = oxNew( "oxstatistic" );
00105         if ( $soxId != "-1")
00106             $oStat->load( $soxId);
00107         else
00108             $aParams['oxstatistics__oxid'] = null;
00109 
00110         $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00111 
00112         $aParams['oxstatistics__oxshopid'] = $sShopID;
00113         $oStat->setReports($aAllreports);
00114         $oStat->assign($aParams);
00115         $oStat->save();
00116         $this->_aViewData["updatelist"] = "1";
00117 
00118         // set oxid if inserted
00119         if ( $soxId == "-1")
00120             oxSession::setVar( "saved_oxid", $oStat->oxstatistics__oxid->value);
00121     }
00122 
00128     public function generate()
00129     {
00130         $myConfig  = $this->getConfig();
00131 
00132         $soxId = oxConfig::getParameter( "oxid" );
00133 
00134         // load object
00135         $oStat = oxNew( "oxstatistic" );
00136         $oStat->load( $soxId );
00137 
00138         $aAllreports = $oStat->getReports();
00139 
00140         $oShop = oxNew( "oxshop" );
00141         $oShop->load( $myConfig->getShopId());
00142         $oShop = $this->addGlobalParams( $oShop );
00143 
00144         $sTimeFrom = oxConfig::getParameter( "time_from" );
00145         $sTimeTo   = oxConfig::getParameter( "time_to" );
00146         if ( $sTimeFrom && $sTimeTo ) {
00147             $sTimeFrom = oxUtilsDate::getInstance()->formatDBDate( $sTimeFrom, true );
00148             $sTimeFrom = date( "Y-m-d", strtotime( $sTimeFrom ) );
00149             $sTimeTo = oxUtilsDate::getInstance()->formatDBDate( $sTimeTo, true );
00150             $sTimeTo = date( "Y-m-d", strtotime( $sTimeTo ) );
00151         } else {
00152             $dDays = oxConfig::getParameter( "timeframe" );
00153             $dNow  = time();
00154             $sTimeFrom = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow ), date( "d", $dNow ) - $dDays, date( "Y", $dNow ) ) );
00155             $sTimeTo   = date( "Y-m-d", time() );
00156         }
00157 
00158         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00159         $oSmarty->assign( "time_from", $sTimeFrom." 23:59:59" );
00160         $oSmarty->assign( "time_to", $sTimeTo." 23:59:59" );
00161         $oSmarty->assign( "shop", $oShop );
00162 
00163         echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00164         foreach ( $aAllreports as $file ) {
00165             if ( ( $file = trim( $file ) ) ) {
00166                 $sClassName = str_replace( ".php", "", strtolower( $file ) );
00167 
00168                 $oReport = oxNew( $sClassName );
00169                 $oReport->setSmarty( $oSmarty );
00170 
00171                 $oSmarty->assign( "oView", $oReport );
00172                 echo( $oSmarty->fetch( $oReport->render() ) );
00173             }
00174         }
00175 
00176         oxUtils::getInstance()->showMessageAndExit( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00177     }
00178 }