<?php
	require_once( $GLOBALS["site_root"]."/includes/pages/BackendPage.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Coupon.inc.php" );

	class AdminCouponCampaignsExport extends BackendPage {

		protected function sendExcel( $export ) {
			header( "Content-Type: application/vnd.ms-excel\n" );
			header( "Content-Disposition: attachment; filename=\"kuponok.csv\"" );
			FNTH_direct_echo( $export );
			exit();
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;

			$cm = new CouponModel();
			$codes = $cm->getCouponCodesForCampaign( $this->aG["coupon_campaign_id"] );
			$export = "";
			foreach ($codes as $code) {
				$export.=sprintf( "%s;\r\n", $code );
			}

			$this->sendExcel( $export );
			return parent::render();
		}
	}

?>
