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 = $this->_aViewData["oxid"] = $this->getEditObjectId();
00025 $aReports = array();
00026 if ( $soxId != "-1" && isset( $soxId)) {
00027
00028 $oStat = oxNew( "oxstatistic" );
00029 $oStat->load( $soxId);
00030
00031 $aReports = $oStat->getReports();
00032 $this->_aViewData["edit"] = $oStat;
00033 }
00034
00035
00036 $sPath = getShopBasePath().$myConfig->getConfigParam( 'sAdminDir' ) . "/reports";
00037 $iLanguage = (int) oxConfig::getParameter("editlanguage");
00038 $aAllreports = array();
00039
00040 $aReportFiles = glob( $sPath."/*.php" );
00041 foreach ( $aReportFiles as $sFile ) {
00042 if ( is_file( $sFile ) && !is_dir( $sFile ) ) {
00043
00044 $sConst = strtoupper( str_replace( '.php', '', basename( $sFile ) ) );
00045
00046
00047 if ( $sConst == 'REPORT_BASE') {
00048 continue;
00049 }
00050
00051 include $sFile;
00052
00053 $oItem = new oxStdClass();
00054 $oItem->filename = basename( $sFile );
00055 $oItem->name = $oLang->translateString( $sConst, $iLanguage );
00056 $aAllreports[] = $oItem;
00057 }
00058 }
00059
00060
00061 oxSession::setVar( "allstat_reports", $aAllreports);
00062 oxSession::setVar( "stat_reports_$soxId", $aReports);
00063
00064
00065 $this->_aViewData['ireports'] = count($aReports);
00066
00067 if ( oxConfig::getParameter("aoc") ) {
00068 $aColumns = array();
00069 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00070 $this->_aViewData['oxajax'] = $aColumns;
00071
00072 return "popups/statistic_main.tpl";
00073 }
00074
00075 return "statistic_main.tpl";
00076 }
00077
00083 public function save()
00084 {
00085 $soxId = $this->getEditObjectId();
00086 $aParams = oxConfig::getParameter( "editval");
00087
00088
00089 $sShopID = oxSession::getVar( "actshop");
00090
00091 $oStat = oxNew( "oxstatistic" );
00092 if ( $soxId != "-1")
00093 $oStat->load( $soxId);
00094 else
00095 $aParams['oxstatistics__oxid'] = null;
00096
00097 $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00098
00099 $aParams['oxstatistics__oxshopid'] = $sShopID;
00100 $oStat->setReports($aAllreports);
00101 $oStat->assign($aParams);
00102 $oStat->save();
00103
00104
00105 $this->setEditObjectId( $oStat->getId() );
00106 }
00107
00113 public function generate()
00114 {
00115 $myConfig = $this->getConfig();
00116
00117 $soxId = $this->getEditObjectId();
00118
00119
00120 $oStat = oxNew( "oxstatistic" );
00121 $oStat->load( $soxId );
00122
00123 $aAllreports = $oStat->getReports();
00124
00125 $oShop = oxNew( "oxshop" );
00126 $oShop->load( $myConfig->getShopId());
00127 $oShop = $this->addGlobalParams( $oShop );
00128
00129 $sTimeFrom = oxConfig::getParameter( "time_from" );
00130 $sTimeTo = oxConfig::getParameter( "time_to" );
00131 if ( $sTimeFrom && $sTimeTo ) {
00132 $sTimeFrom = oxUtilsDate::getInstance()->formatDBDate( $sTimeFrom, true );
00133 $sTimeFrom = date( "Y-m-d", strtotime( $sTimeFrom ) );
00134 $sTimeTo = oxUtilsDate::getInstance()->formatDBDate( $sTimeTo, true );
00135 $sTimeTo = date( "Y-m-d", strtotime( $sTimeTo ) );
00136 } else {
00137 $dDays = oxConfig::getParameter( "timeframe" );
00138 $dNow = time();
00139 $sTimeFrom = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow ), date( "d", $dNow ) - $dDays, date( "Y", $dNow ) ) );
00140 $sTimeTo = date( "Y-m-d", time() );
00141 }
00142
00143 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00144 $oSmarty->assign( "time_from", $sTimeFrom." 23:59:59" );
00145 $oSmarty->assign( "time_to", $sTimeTo." 23:59:59" );
00146 $oSmarty->assign( "shop", $oShop );
00147
00148 echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00149 foreach ( $aAllreports as $file ) {
00150 if ( ( $file = trim( $file ) ) ) {
00151 $sClassName = str_replace( ".php", "", strtolower( $file ) );
00152
00153 $oReport = oxNew( $sClassName );
00154 $oReport->setSmarty( $oSmarty );
00155
00156 $oSmarty->assign( "oView", $oReport );
00157 echo( $oSmarty->fetch( $oReport->render() ) );
00158 }
00159 }
00160
00161 oxUtils::getInstance()->showMessageAndExit( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00162 }
00163 }