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 
00082             $aColumns = array();
00083             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00084             $this->_aViewData['oxajax'] = $aColumns;
00085 
00086             return "popups/statistic_main.tpl";
00087         }
00088 
00089         return "statistic_main.tpl";
00090     }
00091 
00097     public function save()
00098     {
00099         $soxId   = oxConfig::getParameter( "oxid");
00100         $aParams = oxConfig::getParameter( "editval");
00101 
00102         // shopid
00103         $sShopID = oxSession::getVar( "actshop");
00104 
00105         $oStat = oxNew( "oxstatistic" );
00106         if ( $soxId != "-1")
00107             $oStat->load( $soxId);
00108         else
00109             $aParams['oxstatistics__oxid'] = null;
00110 
00111         $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00112 
00113         $aParams['oxstatistics__oxshopid'] = $sShopID;
00114         $oStat->setReports($aAllreports);
00115         $oStat->assign($aParams);
00116         $oStat->save();
00117         $this->_aViewData["updatelist"] = "1";
00118 
00119         // set oxid if inserted
00120         if ( $soxId == "-1")
00121             oxSession::setVar( "saved_oxid", $oStat->oxstatistics__oxid->value);
00122     }
00123 
00129     public function generate()
00130     {
00131         $myConfig  = $this->getConfig();
00132 
00133         $soxId = oxConfig::getParameter( "oxid" );
00134 
00135         // load object
00136         $oStat = oxNew( "oxstatistic" );
00137         $oStat->load( $soxId );
00138 
00139         $aAllreports = $oStat->getReports();
00140 
00141         $oShop = oxNew( "oxshop" );
00142         $oShop->load( $myConfig->getShopId());
00143         $oShop = $this->addGlobalParams( $oShop );
00144 
00145         $sTime_from = oxConfig::getParameter( "time_from" );
00146         $sTime_to   = oxConfig::getParameter( "time_to" );
00147         if ( $sTime_from && $sTime_to ) {
00148             $sTime_from = oxUtilsDate::getInstance()->formatDBDate( $sTime_from, true );
00149             $sTime_from = date( "Y-m-d", strtotime( $sTime_from ) );
00150             $sTime_to = oxUtilsDate::getInstance()->formatDBDate( $sTime_to, true );
00151             $sTime_to = date( "Y-m-d", strtotime( $sTime_to ) );
00152         } else {
00153             $dDays = oxConfig::getParameter( "timeframe" );
00154             $dNow  = time();
00155             $sTime_from = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow ), date( "d", $dNow ) - $dDays, date( "Y", $dNow ) ) );
00156             $sTime_to   = date( "Y-m-d", time() );
00157         }
00158 
00159         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00160         $oSmarty->assign( "time_from", $sTime_from." 23:59:59" );
00161         $oSmarty->assign( "time_to", $sTime_to." 23:59:59" );
00162         $oSmarty->assign( "shop", $oShop );
00163 
00164         echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00165         foreach ( $aAllreports as $file ) {
00166             if ( ( $file = trim( $file ) ) ) {
00167                 $sClassName = str_replace( ".php", "", strtolower( $file ) );
00168 
00169                 $oReport = oxNew( $sClassName );
00170                 $oReport->setSmarty( $oSmarty );
00171 
00172                 $oSmarty->assign( "oView", $oReport );
00173                 echo( $oSmarty->fetch( $oReport->render() ) );
00174             }
00175         }
00176 
00177         echo( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00178         exit();
00179     }
00180 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5