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 $oStatisticMainAjax = oxNew( 'statistic_main_ajax' );
00069 $this->_aViewData['oxajax'] = $oStatisticMainAjax->getColumns();
00070
00071 return "popups/statistic_main.tpl";
00072 }
00073
00074 return "statistic_main.tpl";
00075 }
00076
00082 public function save()
00083 {
00084 $soxId = $this->getEditObjectId();
00085 $aParams = oxConfig::getParameter( "editval");
00086
00087
00088 $sShopID = oxSession::getVar( "actshop");
00089
00090 $oStat = oxNew( "oxstatistic" );
00091 if ( $soxId != "-1")
00092 $oStat->load( $soxId);
00093 else
00094 $aParams['oxstatistics__oxid'] = null;
00095
00096 $aParams['oxstatistics__oxshopid'] = $sShopID;
00097 $oStat->assign($aParams);
00098 $oStat->save();
00099
00100
00101 $this->setEditObjectId( $oStat->getId() );
00102 }
00103
00109 public function generate()
00110 {
00111 $myConfig = $this->getConfig();
00112
00113 $soxId = $this->getEditObjectId();
00114
00115
00116 $oStat = oxNew( "oxstatistic" );
00117 $oStat->load( $soxId );
00118
00119 $aAllreports = $oStat->getReports();
00120
00121 $oShop = oxNew( "oxshop" );
00122 $oShop->load( $myConfig->getShopId());
00123 $oShop = $this->addGlobalParams( $oShop );
00124
00125 $sTimeFrom = oxConfig::getParameter( "time_from" );
00126 $sTimeTo = oxConfig::getParameter( "time_to" );
00127 if ( $sTimeFrom && $sTimeTo ) {
00128 $sTimeFrom = oxUtilsDate::getInstance()->formatDBDate( $sTimeFrom, true );
00129 $sTimeFrom = date( "Y-m-d", strtotime( $sTimeFrom ) );
00130 $sTimeTo = oxUtilsDate::getInstance()->formatDBDate( $sTimeTo, true );
00131 $sTimeTo = date( "Y-m-d", strtotime( $sTimeTo ) );
00132 } else {
00133 $dDays = oxConfig::getParameter( "timeframe" );
00134 $dNow = time();
00135 $sTimeFrom = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow ), date( "d", $dNow ) - $dDays, date( "Y", $dNow ) ) );
00136 $sTimeTo = date( "Y-m-d", time() );
00137 }
00138
00139 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00140 $oSmarty->assign( "time_from", $sTimeFrom." 23:59:59" );
00141 $oSmarty->assign( "time_to", $sTimeTo." 23:59:59" );
00142 $oSmarty->assign( "oViewConf", $this->_aViewData["oViewConf"]);
00143
00144 echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00145 foreach ( $aAllreports as $file ) {
00146 if ( ( $file = trim( $file ) ) ) {
00147 $sClassName = str_replace( ".php", "", strtolower( $file ) );
00148
00149 $oReport = oxNew( $sClassName );
00150 $oReport->setSmarty( $oSmarty );
00151
00152 $oSmarty->assign( "oView", $oReport );
00153 echo( $oSmarty->fetch( $oReport->render() ) );
00154 }
00155 }
00156
00157 oxUtils::getInstance()->showMessageAndExit( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00158 }
00159 }