statistic_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Statistic_Main extends oxAdminDetails
00010 {
00018     public function render()
00019     {
00020         $myConfig  = $this->getConfig();
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 = oxConfig::getParameter("editlanguage");
00051         if ( !isset( $iLanguage))
00052             $iLanguage = 0;
00053         $aAllreports = array();
00054 
00055         $handle = opendir( $sPath);
00056         while ( false !== ( $file = readdir( $handle ) ) ) {
00057             if ( $file != '.' && $file != '..' && !is_dir( $sPath."/".$file)) {
00058                 include $sPath."/".$file;
00059 
00060                 $sConst = strtoupper( str_replace( '.php', '', $file ) );
00061 
00062                 // skipping base report class
00063                 if ( $sConst == 'REPORT_BASE') {
00064                     continue;
00065                 }
00066 
00067                 $sName = oxLang::getInstance()->translateString( $sConst, $iLanguage );
00068 
00069                 $oItem = new stdClass();
00070                 $oItem->filename = $file.$i;
00071                 $oItem->name     = $sName.$i;
00072                 $aAllreports[]   = $oItem;
00073             }
00074         }
00075         closedir($handle);
00076 
00077         // setting reports data
00078         oxSession::setVar( "allstat_reports", $aAllreports);
00079 
00080         oxSession::setVar( "stat_reports_$soxId", $aReports);
00081 
00082         // passing assigned reports count
00083         $this->_aViewData['ireports'] = count($aReports);
00084 
00085          if ( oxConfig::getParameter("aoc") ) {
00086 
00087             $aColumns = array();
00088             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00089             $this->_aViewData['oxajax'] = $aColumns;
00090 
00091             return "popups/statistic_main.tpl";
00092         }
00093 
00094         return "statistic_main.tpl";
00095     }
00096 
00102     public function save()
00103     {
00104         $soxId   = oxConfig::getParameter( "oxid");
00105         $aParams = oxConfig::getParameter( "editval");
00106 
00107         // shopid
00108         $sShopID = oxSession::getVar( "actshop");
00109 
00110         $oStat = oxNew( "oxstatistic" );
00111         if ( $soxId != "-1")
00112             $oStat->load( $soxId);
00113         else
00114             $aParams['oxstatistics__oxid'] = null;
00115 
00116         $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00117         $aParams['oxstatistics__oxshopid'] = $sShopID;
00118         $oStat->setReports($aAllreports);
00119         $oStat->assign($aParams);
00120         $oStat->save();
00121         $this->_aViewData["updatelist"] = "1";
00122 
00123         // set oxid if inserted
00124         if ( $soxId == "-1")
00125             oxSession::setVar( "saved_oxid", $oStat->oxstatistics__oxid->value);
00126 
00127         return $this->autosave();
00128     }
00129 
00135     public function generate()
00136     {
00137         $myConfig  = $this->getConfig();
00138 
00139         $soxId       = oxConfig::getParameter( "oxid");
00140         $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00141 
00142         $sPath          = getShopBasePath().$myConfig->getConfigParam( 'sAdminDir' )."/reports";
00143 
00144         $oShop = oxNew( "oxshop" );
00145         $oShop->load( $myConfig->getShopId());
00146         $oShop = $this->addGlobalParams( $oShop);
00147 
00148         oxUtilsView::getInstance()->getSmarty()->assign( "shop", $oShop );
00149 
00150         $sTime_from = oxConfig::getParameter( "time_from");
00151         $sTime_to   = oxConfig::getParameter( "time_to");
00152         if ( isset( $sTime_from) && $sTime_from && isset( $sTime_to) && $sTime_to) {
00153               $sTime_from = oxUtilsDate::getInstance()->formatDBDate( $sTime_from, true);
00154             $sTime_from = date( "Y-m-d", strtotime( $sTime_from));
00155             $sTime_to = oxUtilsDate::getInstance()->formatDBDate( $sTime_to, true);
00156             $sTime_to = date( "Y-m-d", strtotime( $sTime_to));
00157         } else {
00158              $dDays         = oxConfig::getParameter( "timeframe");
00159             $dNow          = time();
00160             $sTime_from  = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow), date( "d", $dNow) - $dDays, date( "Y", $dNow)));
00161             $sTime_to       = date( "Y-m-d", time());
00162         }
00163 
00164         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00165         $oSmarty->assign( "time_from", $sTime_from." 23:59:59" );
00166         $oSmarty->assign( "time_to", $sTime_to." 23:59:59" );
00167 
00168         echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00169 
00170         foreach ( $aAllreports as $file ) {
00171             if ( !trim( $file ) ) {
00172                 continue;
00173             }
00174 
00175             $sClassName = str_replace( ".php", "", strtolower($file));
00176 
00177             $oReport = oxNew( $sClassName );
00178 
00179             echo( $oSmarty->fetch( $oReport->render() ) );
00180         }
00181         echo( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00182         exit();
00183     }
00184 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5