<modification>
	<id>Gift Vouchers</id>
	<version>1.1b</version>
	<vqmver>1.0.2</vqmver>
	<author>doug@kulakconsulting.net</author>
	<file name="admin/language/english/common/header.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[$_['text_gift_voucher'] = 'Gift Vouchers';]]></add>
		</operation>
	</file>
	<file name="admin/language/english/sale/order.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[
			$_['entry_gift_voucher_purchased'] = 'Gift Vouchers Purchased:';
			$_['entry_gift_voucher_used'] = 'Gift Vouchers Used:';
			]]></add>
		</operation>
	</file>
	<file name="admin/view/template/common/header.tpl"><!-- 1 matches -->
		<operation>
			<search position="after"><![CDATA[<li><a href="<?php echo $coupon; ?>"><?php echo $text_coupon; ?></a></li>]]></search>
			<add><![CDATA[<li><a href="<?php echo $gift_voucher; ?>"><?php echo $text_gift_voucher; ?></a></li>]]></add>
		</operation>
	</file>
	<file name="admin/view/template/sale/order_form.tpl"><!-- 1 matches -->
		<operation>
			<search position="after" offset="1"><![CDATA[<td><?php echo $payment_method; ?></td>]]></search>
			<add><![CDATA[
			<?php if ($has_gift_vouchers_purchased) { ?>    
			<tr>
			<td><?php echo $entry_gift_voucher_purchased; ?></td>
			<td id="gift_voucher">
			  <?php if (count($gift_vouchers_purchased) > 0) { ?>
				<table class="list">
				<thead>
				<tr>
					<td class="left">Gift Voucher ID</td>
					<td class="left">Code</td>
					<td class="right">Balance</td>
					<td class="left">Action</td>
				</tr>
				</thead>
				<tbody>
				<?php foreach ($gift_vouchers_purchased as $gift_voucher) { ?>
					<tr>
						<td class="left"><?php echo $gift_voucher['gift_voucher_id']; ?></td>
						<td class="left"><?php echo $gift_voucher['code']?></td>
						<td class="right"><?php echo $gift_voucher['balance']?></td>
						<td class="left"><a href="<?php echo $gift_voucher['href']; ?>">View</a></td>
					</tr>
				<?php } ?>
				</tbody>
				</table>
			  <?php } else { ?>
			  <a id="generate_gift_voucher_button" class="button"><span><?php echo $button_generate; ?></span></a>
			  <?php } ?></td>
			</tr>          
			<?php } ?>
			
			<?php if ($has_gift_vouchers_used) { ?>    
			<tr>
			<td><?php echo $entry_gift_voucher_used; ?></td>
			<td id="gift_voucher">
			  <?php if (count($gift_vouchers_used) > 0) { ?>
				<table class="list">
				<thead>
				<tr>
					<td class="left">Gift Voucher ID</td>
					<td class="left">Code</td>
					<td class="left">Amount Used</td>
					<td class="right">Current Balance</td>
					<td class="left">Action</td>
				</tr>
				</thead>
				<tbody>
				<?php foreach ($gift_vouchers_used as $gift_voucher) { ?>
					<tr>
						<td class="left"><?php echo $gift_voucher['gift_voucher_id']; ?></td>
						<td class="left"><?php echo $gift_voucher['code']?></td>
						<td class="left"><?php echo $gift_voucher['amount']?></td>
						<td class="right"><?php echo $gift_voucher['balance']?></td>
						<td class="left"><a href="<?php echo $gift_voucher['href']; ?>">View</a></td>
					</tr>
				<?php } ?>
				</tbody>
				</table>
			  <?php } ?>
			  </td>
			</tr>          
			<?php } ?>
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[$('#generate_button').click(function() {]]></search>
			<add><![CDATA[
			$('#generate_gift_voucher_button').click(function() {
				$.ajax({
					url: 'index.php?route=sale/gift_voucher/generate_gift_vouchers&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
					dataType: 'json',
					beforeSend: function() {
						$('#generate_gift_voucher_button').attr('disabled', 'disabled');
					},
					complete: function() {
						$('#generate_gift_voucher_button').attr('disabled', '');
					},
					success: function(data) {
						if (data.response) {
							$('#generate_gift_voucher_button').fadeOut('slow', function() {
								$('#gift_voucher').html(data.response);
							});
						}
					}
				});
			});
			]]></add>
		</operation>
	</file>
	<file name="admin/controller/common/header.php"><!-- 1 matches -->
		<operation>
			<search position="after"><![CDATA[$this->data['text_front'] = $this->language->get('text_front');]]></search>
			<add><![CDATA[$this->data['text_gift_voucher'] = $this->language->get('text_gift_voucher');]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['feed'] = HTTPS_SERVER . 'index.php?route=extension/feed&token=' . $this->session->data['token'];]]></search>
			<add><![CDATA[$this->data['gift_voucher'] = HTTPS_SERVER . 'index.php?route=sale/gift_voucher&token=' . $this->session->data['token'];]]></add>
		</operation>
	</file>
	<file name="admin/controller/sale/order.php"><!-- 1 matches -->
		<operation>
			<search position="after"><![CDATA[$this->data['entry_payment_method'] = $this->language->get('entry_payment_method');]]></search>
			<add><![CDATA[
			$this->data['entry_gift_voucher_purchased'] = $this->language->get('entry_gift_voucher_purchased');
			$this->data['entry_gift_voucher_used'] = $this->language->get('entry_gift_voucher_used');
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['payment_method'] = $order_info['payment_method'];]]></search>
			<add><![CDATA[
			$this->load->model('sale/gift_voucher');

			$this->data['gift_vouchers_purchased'] = array();
			
			$gift_voucher_products = explode(",", $this->config->get('gift_voucher_product'));
			
			$order_products = $this->model_sale_order->getOrderProducts($order_id);
			
			$has_eligible_products = false;
			
			foreach ($order_products as $order_product) {
				if (in_array($order_product['product_id'], $gift_voucher_products)) { 
					$has_eligible_products = true; 
				}
			}
			
			$this->data['has_gift_vouchers_purchased'] = $has_eligible_products;
				
			$results = $this->model_sale_gift_voucher->getIssuedGiftVouchersForOrder($order_id);
						
			if (is_array($results) && count($results) > 0) {
				
				$gift_vouchers = array();
				
				foreach ($results as $result) {
					
					$gift_voucher = array(
						'gift_voucher_id'	=> $result['gift_voucher_id'],
						'code'				=> $result['code'],
						'balance'			=> $this->currency->format($result['balance']),
						'href'				=> HTTPS_SERVER . 'index.php?route=sale/gift_voucher/update&token=' . $this->session->data['token'] . '&gift_voucher_id=' . $result['gift_voucher_id']
					);
					
					$gift_vouchers[] = $gift_voucher;
				}
				$this->data['gift_vouchers_purchased'] = $gift_vouchers;				 
			} 
			
			$this->data['has_gift_vouchers_used'] = false;
				
			$results = $this->model_sale_gift_voucher->getUsedGiftVouchersForOrder($order_id);
						
			if (is_array($results) && count($results) > 0) {
				
				$gift_vouchers = array();
				
				$this->data['has_gift_vouchers_used'] = true;
				
				foreach ($results as $result) {					
					$gift_voucher = array(
						'gift_voucher_id'	=> $result['gift_voucher_id'],
						'code'				=> $result['code'],
						'amount'			=> $this->currency->format($result['amount']),
						'balance'			=> $this->currency->format($result['balance']),
						'href'				=> HTTPS_SERVER . 'index.php?route=sale/gift_voucher/update&token=' . $this->session->data['token'] . '&gift_voucher_id=' . $result['gift_voucher_id']
					);
					
					$gift_vouchers[] = $gift_voucher;
				}
				$this->data['gift_vouchers_used'] = $gift_vouchers;				 
			}	
			]]></add>
		</operation>
	</file>
	<file name="catalog/language/english/checkout/payment.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[
			$_['text_gift_voucher']         = 'Enter your code and click "Apply Gift Voucher" to redeem your gift voucher balance towards your order.';
			$_['text_success_gift_voucher'] = 'Success: Gift voucher applied! Any unused balance will remain available for future use.';
			$_['entry_gift_voucher']        = 'Gift Voucher:';
			$_['error_gift_voucher']        = 'Error: Gift Voucher is either invalid, expired or has a zero balance!';
			]]></add>
		</operation>
	</file>
	<file name="catalog/language/english/checkout/confirm.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[
			$_['text_gift_voucher']         = 'Enter your code and click "Apply Gift Voucher" to redeem your gift voucher balance towards your order.';
			$_['text_success_gift_voucher'] = 'Success: Gift voucher applied! Any unused balance will remain available for future use.';
			$_['entry_gift_voucher']        = 'Gift Voucher:';
			$_['error_gift_voucher']        = 'Error: Gift Voucher is either invalid, expired or has a zero balance!';
			]]></add>
		</operation>
	</file>
	<file name="catalog/language/english/checkout/guest_step_2.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[
			$_['text_gift_voucher']         = 'Enter your code and click "Apply Gift Voucher" to redeem your gift voucher balance towards your order.';
			$_['text_success_gift_voucher'] = 'Success: Gift voucher applied! Any unused balance will remain available for future use.';
			$_['entry_gift_voucher']        = 'Gift Voucher:';
			$_['error_gift_voucher']        = 'Error: Gift Voucher is either invalid, expired or has a zero balance!';
			]]></add>
		</operation>
	</file>
	<file name="catalog/language/english/english.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[?>]]></search>
			<add><![CDATA[$_['button_gift_voucher'] = 'Apply Gift Voucher';]]></add>
		</operation>
	</file>
	<file name="catalog/view/theme/default/template/checkout/payment.tpl"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[<?php if ($coupon_status) { ?>]]></search>
			<add><![CDATA[
			<?php if ($gift_voucher_status) { ?>
			<div class="content">
			  <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="gift_voucher">
				<p><?php echo $text_gift_voucher; ?></p>
				<div style="text-align: right;"><?php echo $entry_gift_voucher; ?>&nbsp;
				<input type="text" name="gift_voucher" value="<?php echo $gift_voucher; ?>" />
				&nbsp;<a onclick="$('#gift_voucher').submit();" class="button"><span><?php echo $button_gift_voucher; ?></span></a></div>
			  </form>
			</div>
			<?php } ?>
			]]></add>
		</operation>
	</file>
	<file name="catalog/view/theme/default/template/checkout/confirm.tpl"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[<?php if ($coupon_status) { ?>]]></search>
			<add><![CDATA[
			<?php if ($gift_voucher_status) { ?>
			<div class="content">
			  <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="gift_voucher">
				<p><?php echo $text_gift_voucher; ?></p>
				<div style="text-align: right;"><?php echo $entry_gift_voucher; ?>&nbsp;
				<input type="text" name="gift_voucher" value="<?php echo $gift_voucher; ?>" />
				&nbsp;<a onclick="$('#gift_voucher').submit();" class="button"><span><?php echo $button_gift_voucher; ?></span></a></div>
			  </form>
			</div>
			<?php } ?>
			]]></add>
		</operation>
	</file>
	<file name="catalog/view/theme/default/template/checkout/guest_step_2.tpl"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[<?php if ($coupon_status) { ?>]]></search>
			<add><![CDATA[
			<?php if ($gift_voucher_status) { ?>
			<div class="content">
			  <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="gift_voucher">
				<p><?php echo $text_gift_voucher; ?></p>
				<div style="text-align: right;"><?php echo $entry_gift_voucher; ?>&nbsp;
				<input type="text" name="gift_voucher" value="<?php echo $gift_voucher; ?>" />
				&nbsp;<a onclick="$('#gift_voucher').submit();" class="button"><span><?php echo $button_gift_voucher; ?></span></a></div>
			  </form>
			</div>
			<?php } ?>
			]]></add>
		</operation>
	</file>
	<file name="catalog/controller/checkout/payment.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['coupon']) && $this->validateCoupon()) {]]></search>
			<add><![CDATA[
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['gift_voucher']) && $this->validateGiftVoucher()) {
				if (!isset($this->session->data['gift_voucher'])) { $this->session->data['gift_voucher'] = array(); }
				$this->session->data['gift_voucher'][] = $this->request->post['gift_voucher'];
				
				$this->session->data['success'] = $this->language->get('text_success_gift_voucher');
				
				$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/payment');
			}
			]]></add>
		</operation>
		<operation>
			<search position="replace"><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($this->request->post['coupon']) && $this->validate()) {]]></search>
			<add><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($this->request->post['coupon']) && !isset($this->request->post['gift_voucher']) && $this->validate()) {]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['entry_coupon'] = $this->language->get('entry_coupon');]]></search>
			<add><![CDATA[
			$this->data['text_gift_voucher'] = $this->language->get('text_gift_voucher');
			$this->data['button_gift_voucher'] = $this->language->get('button_gift_voucher');
			$this->data['entry_gift_voucher'] = $this->language->get('entry_gift_voucher');
			$this->data['gift_voucher_status'] = $this->config->get('gift_voucher_status');
			
			if (isset($this->request->post['gift_voucher'])) {
				$this->data['gift_voucher'] = $this->request->post['gift_voucher'];
			} else {
				$this->data['gift_voucher'] = '';
			}
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[private function validateCoupon() {]]></search>
			<add><![CDATA[
			private function validateGiftVoucher() {

				$this->load->model('checkout/gift_voucher');
				
				$this->language->load('checkout/payment');
				
				$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($this->request->post['gift_voucher']);
					
				if (!$gift_voucher) {
					$this->error['warning'] = $this->language->get('error_gift_voucher');
				}
				
				if (!$this->error) {
					return TRUE;
				} else {
					return FALSE;
				}
			}
			]]></add>
		</operation>
	</file>
	<file name="catalog/controller/checkout/confirm.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['coupon']) && $this->validateCoupon()) {]]></search>
			<add><![CDATA[
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['gift_voucher']) && $this->validateGiftVoucher()) {
				if (!isset($this->session->data['gift_voucher'])) { $this->session->data['gift_voucher'] = array(); }
				$this->session->data['gift_voucher'][] = $this->request->post['gift_voucher'];
			
				$this->session->data['success'] = $this->language->get('text_success_gift_voucher');
			
				$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/confirm');
			}
			]]></add>
		</operation>
		<operation>
			<search position="before" index="1"><![CDATA[if (isset($this->session->data['coupon'])) {]]></search>
			<add><![CDATA[
			if (isset($this->session->data['gift_voucher'])) {
				$this->load->model('checkout/gift_voucher');
			
				$data['gift_voucher_ids'] = array();
				$data['gift_voucher_amount'] = 0;
				
				foreach ($this->session->data['gift_voucher'] as $gift_voucher_code) {				
					$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($gift_voucher_code);
					
					if ($gift_voucher && !in_array($gift_voucher['gift_voucher_id'], $data['gift_voucher_ids'])) {
						$data['gift_voucher_ids'][] = $gift_voucher['gift_voucher_id'];
						$data['gift_voucher_amount'] = $this->session->data['gift_voucher_amount']; 
					}
				}
			} else {
				$data['gift_voucher_ids'] = array();
				$data['gift_voucher_amount'] = 0;
			}
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['entry_coupon'] = $this->language->get('entry_coupon');]]></search>
			<add><![CDATA[
			$this->data['text_gift_voucher'] = $this->language->get('text_gift_voucher');
			$this->data['button_gift_voucher'] = $this->language->get('button_gift_voucher');
			$this->data['entry_gift_voucher'] = $this->language->get('entry_gift_voucher');
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['coupon_status'] = $this->config->get('coupon_status');]]></search>
			<add><![CDATA[
			$this->data['gift_voucher_status'] = $this->config->get('gift_voucher_status');

			if (isset($this->request->post['gift_voucher'])) {
				$this->data['gift_voucher'] = $this->request->post['gift_voucher'];
			} else {
				$this->data['gift_voucher'] = '';
			}
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[private function validateCoupon() {]]></search>
			<add><![CDATA[
			private function validateGiftVoucher() {

				$this->load->model('checkout/gift_voucher');
			
				$this->language->load('checkout/confirm');
			
				$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($this->request->post['gift_voucher']);
			
				if (!$gift_voucher) {
					$this->error['warning'] = $this->language->get('error_gift_voucher');
				}
			
				if (!$this->error) {
					return TRUE;
				} else {
					return FALSE;
				}
			}
			]]></add>
		</operation>
	</file>	
	<file name="catalog/controller/checkout/guest_step_2.php"><!-- 1 matches -->
		<operation>
			<search position="replace"><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($this->request->post['coupon']) && $this->validate()) {]]></search>
			<add><![CDATA[
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['gift_voucher']) && $this->validateGiftVoucher()) {
				if (!isset($this->session->data['gift_voucher'])) { $this->session->data['gift_voucher'] = array(); }
				$this->session->data['gift_voucher'][] = $this->request->post['gift_voucher'];
				
				$this->session->data['success'] = $this->language->get('text_success_gift_voucher');
				
				$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/guest_step_2');
			}
			
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($this->request->post['coupon']) && !isset($this->request->post['gift_voucher']) && $this->validate()) {
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['entry_coupon'] = $this->language->get('entry_coupon');]]></search>
			<add><![CDATA[
			$this->data['text_gift_voucher'] = $this->language->get('text_gift_voucher');
			$this->data['button_gift_voucher'] = $this->language->get('button_gift_voucher');
			$this->data['entry_gift_voucher'] = $this->language->get('entry_gift_voucher');
			$this->data['gift_voucher_status'] = $this->config->get('gift_voucher_status');
			
			if (isset($this->request->post['gift_voucher'])) {
				$this->data['gift_voucher'] = $this->request->post['gift_voucher'];
			} else {
				$this->data['gift_voucher'] = '';
			}
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[private function validateCoupon() {]]></search>
			<add><![CDATA[
			private function validateGiftVoucher() {
			
				$this->load->model('checkout/gift_voucher');
				
				$this->language->load('checkout/payment');
				
				$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($this->request->post['gift_voucher']);
					
				if (!$gift_voucher) {
					$this->error['warning'] = $this->language->get('error_gift_voucher');
				}
				
				if (!$this->error) {
					return TRUE;
				} else {
					return FALSE;
				}
			}
			]]></add>
		</operation>
	</file>
	<file name="catalog/controller/checkout/guest_step_3.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['coupon']) && $this->validateCoupon()) {]]></search>
			<add><![CDATA[
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['gift_voucher']) && $this->validateGiftVoucher()) {
				if (!isset($this->session->data['gift_voucher'])) { $this->session->data['gift_voucher'] = array(); }
				$this->session->data['gift_voucher'][] = $this->request->post['gift_voucher'];
			
				$this->session->data['success'] = $this->language->get('text_success_gift_voucher');
			
				$this->redirect(HTTPS_SERVER . 'index.php?route=checkout/guest_step_3');
			}
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$data['value'] = $this->currency->getValue($this->currency->getCode());]]></search>
			<add><![CDATA[
			if (isset($this->session->data['gift_voucher'])) {
				$this->load->model('checkout/gift_voucher');
			
				$data['gift_voucher_ids'] = array();
				$data['gift_voucher_amount'] = 0;
				
				foreach ($this->session->data['gift_voucher'] as $gift_voucher_code) {				
					$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($gift_voucher_code);
					
					if ($gift_voucher && !in_array($gift_voucher['gift_voucher_id'], $data['gift_voucher_ids'])) {
						$data['gift_voucher_ids'][] = $gift_voucher['gift_voucher_id'];
						$data['gift_voucher_amount'] = $this->session->data['gift_voucher_amount']; 
					}
				}
			} else {
				$data['gift_voucher_ids'] = array();
				$data['gift_voucher_amount'] = 0;
			}
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['entry_coupon'] = $this->language->get('entry_coupon');]]></search>
			<add><![CDATA[
			$this->data['text_gift_voucher'] = $this->language->get('text_gift_voucher');
			$this->data['button_gift_voucher'] = $this->language->get('button_gift_voucher');
			$this->data['entry_gift_voucher'] = $this->language->get('entry_gift_voucher');
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->data['coupon_status'] = $this->config->get('coupon_status');]]></search>
			<add><![CDATA[
			$this->data['gift_voucher_status'] = $this->config->get('gift_voucher_status');

			if (isset($this->request->post['gift_voucher'])) {
				$this->data['gift_voucher'] = $this->request->post['gift_voucher'];
			} else {
				$this->data['gift_voucher'] = '';
			}
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[private function validateCoupon() {]]></search>
			<add><![CDATA[
			private function validateGiftVoucher() {

				$this->load->model('checkout/gift_voucher');
			
				$this->language->load('checkout/confirm');
			
				$gift_voucher = $this->model_checkout_gift_voucher->getGiftVoucher($this->request->post['gift_voucher']);
			
				if (!$gift_voucher) {
					$this->error['warning'] = $this->language->get('error_gift_voucher');
				}
			
				if (!$this->error) {
					return TRUE;
				} else {
					return FALSE;
				}
			}
			]]></add>
		</operation>
	</file>
	<file name="catalog/controller/checkout/success.php"><!-- 1 matches -->
		<operation>
			<search position="after"><![CDATA[unset($this->session->data['coupon']);]]></search>
			<add><![CDATA[
			unset($this->session->data['gift_voucher']);
			unset($this->session->data['gift_voucher_amount']);
			]]></add>
		</operation>
	</file>
	<file name="catalog/model/checkout/order.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[return $order_id;]]></search>
			<add><![CDATA[
			if (count($data['gift_voucher_ids']) > 0) {
				foreach ($data['gift_voucher_ids'] as $gift_voucher_id) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "gift_voucher_history SET gift_voucher_id = '" . (int)$gift_voucher_id . "', order_id = '" . (int)$order_id . "', amount = '" . (float)$data['gift_voucher_amount'][$gift_voucher_id] . "', status = '0', date_added = NOW()"); 
				}
			}
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '1', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");]]></search>
			<add><![CDATA[
			$gift_vouchers_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "gift_voucher gv LEFT JOIN " . DB_PREFIX . "gift_voucher_history gvh ON (gv.gift_voucher_id = gvh.gift_voucher_id) WHERE gvh.order_id = '" . (int)$order_id . "' AND gvh.status = '0'");
		
			$this->load->model('checkout/gift_voucher');
			
	      	foreach ($gift_vouchers_query->rows as $result) {
	      		$this->db->query("UPDATE `" . DB_PREFIX . "gift_voucher_history` SET status = '1' WHERE gift_voucher_history_id = '" . (int)$result['gift_voucher_history_id'] . "'");
				
				$this->model_checkout_gift_voucher->reduceGiftVoucherBalance($result['gift_voucher_id'], $result['amount']);
	      	}
			]]></add>
		</operation>
	</file>
	<file name="system/library/mail.php"><!-- 1 matches -->
		<operation>
			<search position="before"><![CDATA[if (substr(PHP_OS, 0, 3) != 'WIN') {]]></search>
			<add><![CDATA[$reply = '';]]></add>
		</operation>
	</file>	
</modification>

<!--
<modification>  - This is the highest point of the file and there can only be one
<id>            - This is the name of the mod. Format: Free form text
<version>       - This is the version of the mod. Format: Number and Decimal (1.0.0)
<author>        - This is the author of the mod. Format: Free form text
<file>          - This is the name of the file to modify. Requires attribute "name" as relative filename (catalog/controller/product/product.php). There can be multiple
<operation>		- This is the wrapper of the actual operation occuring. There can be multiple operations to the same file. Uses an optional "error" attribute set to skip|abort (abort is default). skip means all other operations will be applied even if one cannot. abort means to revert to the original source.
<search>        - This is the first required step of the operation. Uses an optional attribute "position" set to before|after|replace. replace is default. One per operation. Use CDATA tags to wrap code.
<add>           - This is the second required step of the operation. Uses an optional attribute "trim" set to true|false. false is default. One per operation. Location of added data depends on the position of the <search> command. Use CDATA tags to wrap code.
-->