Go to the documentation of this file.00001 <?php
00002
00006 class VoucherSerie_Export extends VoucherSerie_Main
00007 {
00013 public $sClassDo = "voucherserie_export";
00014
00020 public $sExportFileType = "csv";
00021
00026 protected $_sThisTemplate = "voucherserie_export.tpl";
00027
00033 public $iExportPerTick = 1000;
00034
00040 public function __construct()
00041 {
00042 parent::__construct();
00043
00044
00045 $this->sExportFileName = $this->_getExportFileName();
00046
00047
00048 $this->_sFilePath = $this->_getExportFilePath();
00049 }
00050
00056 public function getDownloadUrl()
00057 {
00058 $myConfig = $this->getConfig();
00059
00060
00061 $sUrl = $myConfig->getConfigParam( 'sShopURL' ). $myConfig->getConfigParam( 'sAdminDir' );
00062 if ( $myConfig->getConfigParam( 'sAdminSSLURL' ) ) {
00063 $sUrl = $myConfig->getConfigParam( 'sAdminSSLURL' );
00064 }
00065
00066 $sUrl = oxUtilsUrl::getInstance()->processUrl( $sUrl.'/index.php' );
00067 return $sUrl . '&cl='.$this->sClassDo.'&fnc=download';
00068 }
00069
00075 protected function _getExportFileName()
00076 {
00077 $sSessionFileName = oxSession::getVar( "sExportFileName" );
00078 if ( !$sSessionFileName ) {
00079 $sSessionFileName = md5( $this->getSession()->getId() . oxUtilsObject::getInstance()->generateUId() );
00080 oxSession::setVar( "sExportFileName", $sSessionFileName );
00081 }
00082 return $sSessionFileName;
00083 }
00084
00090 protected function _getExportFilePath()
00091 {
00092 return $this->getConfig()->getConfigParam( 'sShopDir' ) . "/export/". $this->_getExportFileName();
00093 }
00094
00100 public function download()
00101 {
00102 $oUtils = oxUtils::getInstance();
00103 $oUtils->setHeader( "Pragma: public" );
00104 $oUtils->setHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
00105 $oUtils->setHeader( "Expires: 0" );
00106 $oUtils->setHeader( "Content-Disposition: attachment; filename=vouchers.csv");
00107 $oUtils->setHeader( "Content-Type: application/csv" );
00108 $sFile = $this->_getExportFilePath();
00109 if ( file_exists( $sFile ) && is_readable( $sFile ) ) {
00110 readfile( $sFile );
00111 }
00112 $oUtils->showMessageAndExit( "" );
00113 }
00114
00120 public function run()
00121 {
00122 $blContinue = true;
00123 $iExportedItems = 0;
00124
00125 $this->fpFile = @fopen( $this->_sFilePath, "a");
00126 if ( !isset( $this->fpFile) || !$this->fpFile) {
00127
00128 $this->stop( ERR_FILEIO);
00129 } else {
00130
00131 $iStart = oxConfig::getParameter("iStart");
00132 if (!$iStart) {
00133 ftruncate($this->fpFile, 0);
00134 }
00135
00136 if ( ( $iExportedItems = $this->exportVouchers( $iStart ) ) === false ) {
00137
00138 $this->stop( ERR_SUCCESS );
00139 $blContinue = false;
00140 }
00141
00142 if ( $blContinue ) {
00143
00144 $this->_aViewData['refresh'] = 0;
00145 $this->_aViewData['iStart'] = $iStart + $iExportedItems;
00146 $this->_aViewData['iExpItems'] = $iStart + $iExportedItems;
00147 }
00148 fclose( $this->fpFile);
00149 }
00150 }
00151
00159 public function exportVouchers( $iStart )
00160 {
00161 $iExported = false;
00162
00163 if ( $oSerie = $this->_getVoucherSerie() ) {
00164
00165 $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
00166
00167 $sSelect = "select oxvouchernr from oxvouchers where oxvoucherserieid = ".$oDb->quote( $oSerie->getId() );
00168 $rs = $oDb->selectLimit( $sSelect, $this->iExportPerTick, $iStart );
00169
00170 if ( !$rs->EOF ) {
00171 $iExported = 0;
00172
00173
00174 if ( $iStart == 0 ) {
00175 $this->write( oxLang::getInstance()->translateString("VOUCHERSERIE_MAIN_VOUCHERSTATISTICS", oxLang::getInstance()->getTplLanguage(), true ));
00176 }
00177 }
00178
00179
00180 while ( !$rs->EOF ) {
00181 $this->write( current( $rs->fields ) );
00182 $iExported++;
00183 $rs->moveNext();
00184 }
00185 }
00186
00187 return $iExported;
00188 }
00189
00197 public function write( $sLine )
00198 {
00199 if ( $sLine ) {
00200 fwrite( $this->fpFile, $sLine."\n");
00201 }
00202 }
00203 }