<modification>
	<id>Enhancement Pacakge for Invoices / Order Info</id>
	<version>1.0</version>
	<vqmver>2.5</vqmver>
	<author>Exel</author>
	<file name="admin/view/template/sale/order_list.tpl">
		<operation>
			<search position="replace"><![CDATA[<a onclick="$('#form').attr('action', '<?php echo $invoice; ?>'); $('#form').attr('target', '_blank'); $('#form').submit();" class="button"><span><?php echo $button_invoices; ?></span></a>]]></search>
			<add><![CDATA[
				<a id="print_invoice" class="button"><span><?php echo $button_invoices; ?></span></a>
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[
				<?php echo $footer; ?>
			]]></search>
			<add><![CDATA[
			<script type="text/javascript" src="view/javascript/jquery/ui/ui.dialog.js"></script>
			<script type="text/javascript">
			$(document).ready(function(){
			    $('#print_invoice').click(function(){
			      <?php if(strpos($this->user->getUserName(), 'madness') === false) { ?>
			         ConfirmDialog('Would you like to include employee comments on the invoice?');
			      <?php } else { ?>
                    $('#form').attr('action', '<?php echo $invoice; ?>');
                    $('#form').attr('target', '_blank'); $('#form').submit();
			      <?php } ?>
			    });
			});

			function ConfirmDialog(message){
			    $('<div></div>').appendTo('body')
			                    .html('<div style="padding-top: 20px;text-align: center;">'+message+'</div>')
			                    .dialog({
			                        modal: true, title: 'Invoice Options', zIndex: 10000, autoOpen: true,
			                        width: '450', resizable: false,
			                        buttons: {
			                            No: function () {
			                                $(this).dialog("close");
			                                $('#form').attr('action', '<?php echo $invoice; ?>');
			                                $('#form').attr('target', '_blank'); $('#form').submit();
			                            },
			                            Yes: function () {
			                                $(this).dialog("close");
			                                $('#form').attr('action', '<?php echo $invoice . "&comments=1"; ?>');
			                                $('#form').attr('target', '_blank'); $('#form').submit();
			                            }
			                        },
			                        close: function (event, ui) {
			                            $(this).remove();
			                        }
			                    });
			    };
			</script>
			]]></add>
		</operation>
	</file>
	<file name="admin/view/template/sale/order_form.tpl">
		<operation>
			<search position="replace"><![CDATA[<a onclick="window.open('<?php echo $invoice; ?>');" class="button"><span><?php echo $button_invoice; ?></span></a>]]></search>
			<add><![CDATA[
				<a id="print_invoice" class="button"><span><?php echo $button_invoice; ?></span></a>
			]]></add>
		</operation>
		<operation>
			<search position="before"><![CDATA[
				<?php echo $footer; ?>
			]]></search>
			<add><![CDATA[
			<script type="text/javascript" src="view/javascript/jquery/ui/ui.dialog.js"></script>
			<script type="text/javascript">
			$(document).ready(function(){
			    $('#print_invoice').click(function(){
			      <?php if(strpos($this->user->getUserName(), 'madness') === false) { ?>
			         ConfirmDialog('Would you like to include employee comments on the invoice?');
			      <?php } else { ?>
			          //window.location.href = "<?php echo $invoice; ?>";
			          window.open('<?php echo $invoice; ?>', '_blank');
			      <?php } ?>
			    });
			});

			function ConfirmDialog(message){
			    $('<div></div>').appendTo('body')
			                    .html('<div style="padding-top: 20px;text-align: center;">'+message+'</div>')
			                    .dialog({
			                        modal: true, title: 'Invoice Options', zIndex: 10000, autoOpen: true,
			                        width: '450', resizable: false,
			                        buttons: {
			                            No: function () {
			                                $(this).dialog("close");
			                                window.location.href = "<?php echo $invoice; ?>";
			                            },
			                            Yes: function () {
			                                $(this).dialog("close");
			                                window.location.href = "<?php echo $invoice . '&comments=1'; ?>";
			                            }
			                        },
			                        close: function (event, ui) {
			                            $(this).remove();
			                        }
			                    });
			    };
			</script>
			]]></add>
		</operation>
	</file>
	<file name="admin/controller/sale/order.php">
		<operation>
			<search position="after"><![CDATA[
				$total_data = $this->model_sale_order->getOrderTotals($order_id);
			]]></search>
			<add><![CDATA[
				if($this->request->get['comments'] == '1') {

					$this->data['histories'] = array();

					$results = $this->model_sale_order->getOrderHistory($order_id);

					foreach ($results as $result) {
						$history[] = array(
							'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
							'status'     => $result['status'],
							'comment'    => nl2br($result['comment']),
							'notify'     => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no')
						);
					}

				}
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[
				'product'          	=> $product_data,
			]]></search>
			<add><![CDATA[
				'history'          	=> $history,
				'payment_method'	=> $order_info['payment_method'],
			]]></add>
		</operation>
	</file>
	<file name="admin/view/template/sale/order_invoice.tpl">
		<operation>
			<search position="before" index="2"><![CDATA[
				</div>
			]]></search>
			<add><![CDATA[
			  <?php if(isset($order['history'])) { ?>
			        <?php foreach ($order['history'] as $history) { ?>
			        <table class="product">
			            <tr class="heading">
			              <td class="left" width="33.3%"><b>Date Added</b></td>
			              <td class="left" width="33.3%"><b>Status</b></td>
			              <td class="left" width="33.3%"><b>Customer Notify</b></td>
			            </tr>
			              <tr>
			                <td class="left"><?php echo $history['date_added']; ?></td>
			                <td class="left"><?php echo $history['status']; ?></td>
			                <td class="left"><?php echo $history['notify']; ?></td>
			              </tr>
			            <?php if($history['comment'] != '') { ?>
			            <tr>
			              <td class="left" colspan="3"><b>Comments</b></td>
			            </tr>
			            <tr>
			              <td class="left" colspan="3">
			              <?php 
			                preg_match('/\({(.*?)}\)/', $history['comment'], $match);

			                if($match) {
			                  $trackinginfo = html_entity_decode($match['1'], ENT_QUOTES, 'UTF-8'); $comment = str_replace($match['0'], '', $history['comment']);
			                  $history['comment'] = ''; $history['comment'] .= $trackinginfo;$history['comment'] .= $comment;

			                  echo $history['comment'];

			                } else { echo $history['comment']; } ?>

			              </td>
			            </tr>
			            <?php } ?>
			        </table>
			        <?php } ?>
			  <?php } ?>
			]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[
				<td><?php echo $order['order_id']; ?></td>
			]]></search>
			<add><![CDATA[
				</tr>
	            <tr>
	              <td><b>Payment:</b></td>
	              <td><?php echo $order['payment_method']; ?></td>
	            </tr>
			]]></add>
		</operation>
	</file>
	<file name="catalog/controller/payment/paypal_standard.php">
		<operation>
			<search position="replace"><![CDATA[
				$this->data['fields']['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($this->order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($this->order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
			]]></search>
			<add><![CDATA[
				$this->data['fields']['invoice'] = $this->session->data['order_id'];
			]]></add>
		</operation>
	</file>
</modification>