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 = 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 = $oLang->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 
00133     public function generate()
00134     {
00135         $myConfig  = $this->getConfig();
00136 
00137         $soxId       = oxConfig::getParameter( "oxid");
00138         $aAllreports = oxSession::getVar( "stat_reports_$soxId");
00139 
00140         $sPath          = getShopBasePath().$myConfig->getConfigParam( 'sAdminDir' )."/reports";
00141 
00142         $oShop = oxNew( "oxshop" );
00143         $oShop->load( $myConfig->getShopId());
00144         $oShop = $this->addGlobalParams( $oShop);
00145 
00146         $myUtilsView = oxUtilsView::getInstance();
00147         $myUtilsView->getSmarty()->assign( "shop", $oShop );
00148 
00149         $sTime_from = oxConfig::getParameter( "time_from");
00150         $sTime_to   = oxConfig::getParameter( "time_to");
00151         if ( isset( $sTime_from) && $sTime_from && isset( $sTime_to) && $sTime_to) {
00152               $sTime_from = oxUtilsDate::getInstance()->formatDBDate( $sTime_from, true);
00153             $sTime_from = date( "Y-m-d", strtotime( $sTime_from));
00154             $sTime_to = oxUtilsDate::getInstance()->formatDBDate( $sTime_to, true);
00155             $sTime_to = date( "Y-m-d", strtotime( $sTime_to));
00156         } else {
00157              $dDays         = oxConfig::getParameter( "timeframe");
00158             $dNow          = time();
00159             $sTime_from  = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow), date( "d", $dNow) - $dDays, date( "Y", $dNow)));
00160             $sTime_to       = date( "Y-m-d", time());
00161         }
00162 
00163         $oSmarty = $myUtilsView->getSmarty();
00164         $oSmarty->assign( "time_from", $sTime_from." 23:59:59" );
00165         $oSmarty->assign( "time_to", $sTime_to." 23:59:59" );
00166 
00167         echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00168 
00169         foreach ( $aAllreports as $file ) {
00170             if ( !trim( $file ) ) {
00171                 continue;
00172             }
00173 
00174             $sClassName = str_replace( ".php", "", strtolower($file));
00175 
00176             $oReport = oxNew( $sClassName );
00177 
00178             echo( $oSmarty->fetch( $oReport->render() ) );
00179         }
00180         echo( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00181         exit();
00182     }
00183 }

Generated on Wed Apr 22 12:26:30 2009 for OXID eShop CE by  doxygen 1.5.5