<modification>
	<id>Additional Product Tabs</id>
	<version>1.0.3</version>
	<vqmver>2.2.1</vqmver>
	<author>Godfrey Livinstone</author>
	<decription><![CDATA[]]></decription>

	<file name="admin/view/template/common/menu.tpl" error="log">
		<operation error="log">
			<search position="after"><![CDATA[
				<li><a href="<?php echo $information; ?>"><?php echo $text_information; ?></a></li>
				]]>
			</search>
			<add trim="true"><![CDATA[
				<li><a href="<?php echo $product_tab; ?>"><?php echo $text_product_tab; ?></a></li>
				]]>
			</add>
		</operation>
	</file>

	<file name="admin/controller/common/menu.php" error="log">
		<operation error="log">
			<search position="after"><![CDATA[
				$data['text_information'] = $this->language->get('text_information');
				]]>
			</search>
			<add trim="true"><![CDATA[
				$this->load->language('catalog/tab');
				$data['text_product_tab'] = $this->language->get('text_product_tab');
				$data['product_tab'] = $this->url->link('catalog/tab', 'token=' . $this->session->data['token'], 'SSL');
				]]>
			</add>
		</operation>
	</file>

	

	
		
	<file name="admin/model/localisation/language.php" error="log">

		<!-- Add Extra Tabs to addLanguage function -->
		<operation error="log">
			<search position="after" offset="2"><![CDATA[
				$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_attribute['product_id'] . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute['text']) . "'");
				]]>
			</search>
			<add trim="true"><![CDATA[
				// Product Tabs
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tab WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'");

				foreach ($query->rows as $product_tab) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "product_tab SET product_id = '" . (int)$product_tab['product_id'] . "', tab_id = '" . (int)$product_tab['tab_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_tab['text']) . "'");
				}
				]]>
			</add>
		</operation>
		<operation error="log">
			<search position="before" offset="1"><![CDATA[
				// Voucher Theme
				]]>
			</search>
			<add trim="true"><![CDATA[
				// Tabs
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tab_description WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'");

				foreach ($query->rows as $tab) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "tab_description SET tab_id = '" . (int)$tab['tab_id'] . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($tab['name']) . "'");
				}
				]]>
			</add>
		</operation>

		<!-- Add Extra Tabs to deleteLanguage function -->
		<operation error="log">
			<search position="after"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE language_id = '" . (int)$language_id . "'");
				]]>
			</search>
			<add trim="true"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_tab WHERE language_id = '" . (int)$language_id . "'");
				]]>
			</add>
		</operation>
		<operation error="log">
			<search position="before" offset="1"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "voucher_theme_description WHERE language_id = '" . (int)$language_id . "'");
				]]>
			</search>
			<add trim="true"><![CDATA[

				$this->db->query("DELETE FROM " . DB_PREFIX . "tab_description WHERE language_id = '" . (int)$language_id . "'");
				]]>
			</add>
		</operation>

	</file>

	<file name="admin/controller/catalog/product.php" error="log">

		<operation error="log">
			<search position="after"><![CDATA[
				$data['tab_attribute'] = $this->language->get('tab_attribute');
				]]>
			</search>
			<add trim="true"><![CDATA[
				$this->load->language('catalog/tab');
				$data['entry_tab_name'] = $this->language->get('entry_tab_name');
				$data['entry_tab_text'] = $this->language->get('entry_tab_text');
				$data['button_add_tab'] = $this->language->get('button_add_tab');
				$data['tab_product_tab'] = $this->language->get('tab_product_tab');
				
				]]>
			</add>
		</operation>


		<!-- Add Extra Tabs to getForm function -->
		<operation error="log">
			<search position="before" offset="1"><![CDATA[
				$this->load->model('catalog/option');
				]]>
			</search>
			<add><![CDATA[
				if (isset($this->request->post['product_tab'])) {
					$data['product_tabs'] = $this->request->post['product_tab'];
				} elseif (isset($this->request->get['product_id'])) {
					$data['product_tabs'] = $this->model_catalog_product->getProductTabs($this->request->get['product_id']);
				} else {
					$data['product_tabs'] = array();
				}
				
				]]>
			</add>
		</operation>

	</file>

	<file name="admin/model/catalog/product.php" error="log">

		<!-- Add Extra Tabs to addProduct function -->
		<operation error="log">
			<search position="before" index="1"><![CDATA[
				if (isset($data['product_option'])) {
				]]>
			</search>
			<add trim="true"><![CDATA[
				if (isset($data['product_tab'])) {
					foreach ($data['product_tab'] as $product_tab) {
						if ($product_tab['tab_id']) {
							$this->db->query("DELETE FROM " . DB_PREFIX . "product_tab WHERE product_id = '" . (int)$product_id . "' AND tab_id = '" . (int)$product_tab['tab_id'] . "'");

							foreach ($product_tab['product_tab_description'] as $language_id => $product_tab_description) {
								$this->db->query("INSERT INTO " . DB_PREFIX . "product_tab SET product_id = '" . (int)$product_id . "', tab_id = '" . (int)$product_tab['tab_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_tab_description['text']) . "'");
							}
						}
					}
				}
				]]>
			</add>
		</operation>

		<!-- Add Extra Tabs to editProduct function -->
    <operation error="log">
			<search position="before" index="1"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
				]]>
			</search>
			<add trim="true"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_tab WHERE product_id = '" . (int)$product_id . "'");

				if (!empty($data['product_tab'])) {
					foreach ($data['product_tab'] as $product_tab) {
						if ($product_tab['tab_id']) {
							$this->db->query("DELETE FROM " . DB_PREFIX . "product_tab WHERE product_id = '" . (int)$product_id . "' AND tab_id = '" . (int)$product_tab['tab_id'] . "'");

							foreach ($product_tab['product_tab_description'] as $language_id => $product_tab_description) {
								$this->db->query("INSERT INTO " . DB_PREFIX . "product_tab SET product_id = '" . (int)$product_id . "', tab_id = '" . (int)$product_tab['tab_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_tab_description['text']) . "'");
							}
						}
					}
				}
				]]>
			</add>
		</operation>

		<!-- Add Extra Tabs to copyProduct Function -->
    <operation error="log">
			<search position="after"><![CDATA[
				$data = array_merge($data, array('product_attribute' => $this->getProductAttributes($product_id)));
				]]>
			</search>
			<add trim="true"><![CDATA[
				$data = array_merge($data, array('product_tab' => $this->getProductTabs($product_id)));
				]]>
			</add>
		</operation>

		<!-- Add Delete Extra Tab Data to deleteProduct function -->
    <operation error="log">
			<search position="after" offset="1"><![CDATA[
				public function deleteProduct($product_id) {
				]]>
			</search>
			<add trim="true"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_tab WHERE product_id = '" . (int)$product_id . "'");
				]]>
			</add>
		</operation>

		<!-- Add Function getProductTabs to get Tab Data -->
		<operation error="log">
			<search position="before"><![CDATA[
				public function getTotalProductsByLayoutId($layout_id) {
				]]>
			</search>
			<add trim="true"><![CDATA[

				public function getProductTabs($product_id) {

					$product_tab_data = array();

					$product_tab_query = $this->db->query("SELECT t.tab_id, td.name FROM " . DB_PREFIX . "product_tab pt LEFT JOIN " . DB_PREFIX . "tab t ON (pt.tab_id = t.tab_id) LEFT JOIN " . DB_PREFIX . "tab_description td ON (t.tab_id = td.tab_id) WHERE pt.product_id = '" . (int)$product_id . "' AND td.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY pt.tab_id");

					foreach ($product_tab_query->rows as $product_tab) {

						$product_tab_description_data = array();

						$product_tab_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tab WHERE product_id = '" . (int)$product_id . "' AND tab_id = '" . (int)$product_tab['tab_id'] . "'");

						foreach ($product_tab_description_query->rows as $product_tab_description) {
							$product_tab_description_data[$product_tab_description['language_id']] = array('text' => $product_tab_description['text']);
						}

						$product_tab_data[] = array(
							'tab_id' 									=> $product_tab['tab_id'],
							'name'         						=> $product_tab['name'],
							'product_tab_description' => $product_tab_description_data
						);

					}
					return $product_tab_data;
				}

        ]]>
			</add>
    </operation>

		<!-- Add Function getTotalProductsByExtraTabId -->
		<operation error="log">
			<search position="before"><![CDATA[
				public function getTotalProductsByOptionId($option_id) {
				]]>
			</search>
			<add trim="true"><![CDATA[
				public function getTotalProductsByTabId($tab_id) {
					$query = $this->db->query("SELECT COUNT(DISTINCT product_id) AS total FROM " . DB_PREFIX . "product_tab WHERE tab_id = '" . (int)$tab_id . "'");

					return $query->row['total'];
				}
				]]>
			</add>
		</operation>

	</file>

	<file name="admin/view/template/catalog/product_form.tpl" error="log">

		

		<operation error="log">
			<search position="after"><![CDATA[
				<li><a href="#tab-design" data-toggle="tab"><?php echo $tab_design; ?></a></li>
				]]>
			</search>
			<add trim="true"><![CDATA[
				<li><a href="#tab-product_tab" data-toggle="tab"><?php echo $tab_product_tab; ?></a></li>
				]]>
			</add>
		</operation>

		<operation error="log">
			<search position="before"><![CDATA[
				<div class="tab-pane" id="tab-reward">
				]]>
			</search>
      <add trim="true"><![CDATA[
		
		
		
		<div class="tab-pane" id="tab-product_tab">
              <div class="table-responsive">
                
				<table id="tab" class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      <td class="text-left"><?php echo $entry_tab_name; ?></td>
                      <td class="text-left"><?php echo $entry_tab_text; ?></td>
                      <td></td>
                    </tr>
                  </thead>
                  <tbody>
                    <?php $product_tab_row = 0; ?>
                    <?php foreach ($product_tabs as $product_tab) { ?>
                    <tr id="tab-product_tab-<?php echo $product_tab_row; ?>">
                      <td class="text-left" style="width: 20%;"><input type="text" name="product_tab[<?php echo $product_tab_row; ?>][name]" value="<?php echo $product_tab['name']; ?>" placeholder="<?php echo $entry_tab_name; ?>" class="form-control" />
                        <input type="hidden" name="product_tab[<?php echo $product_tab_row; ?>][tab_id]" value="<?php echo $product_tab['tab_id']; ?>" /></td>                      <td class="text-left">
					  <?php foreach ($languages as $language) { ?>
                        <div class="input-group" style="background:#ffffff"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span>
						  <textarea name="product_tab[<?php echo $product_tab_row; ?>][product_tab_description][<?php echo $language['language_id']; ?>][text]" class="form-control tab_block" rows="5"><?php echo isset($product_tab['product_tab_description'][$language['language_id']]) ? $product_tab['product_tab_description'][$language['language_id']]['text'] : ''; ?></textarea>
                        </div>
                        <?php } ?>
						</td>
                      <td class="text-left"><button type="button" onclick="$('#tab-product_tab-<?php echo $product_tab_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
                    </tr>
					
                    <?php $product_tab_row++; ?>
                    <?php } ?>
                  </tbody>
                  <tfoot>
                    <tr>
                      <td colspan="2"></td>
                      <td class="text-left"><button type="button" onclick="addtab();" data-toggle="tooltip" title="<?php echo $button_add_tab; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                    </tr>
                  </tfoot>
                </table>
              </div>
            </div>
				]]>
			</add>
		</operation>

		<operation error="log">
			<search position="before"><![CDATA[
				<?php echo $footer; ?>
				]]>
			</search>
<add trim="true"><![CDATA[

				<script type="text/javascript"><!--

var product_tab_row = <?php echo $product_tab_row; ?>;

function addtab() {
    html  = '<tr id="tab-product_tab-' + product_tab_row + '">';
	html += '  <td class="text-left" style="width: 20%;"><input type="text" name="product_tab[' + product_tab_row + '][name]" value="" placeholder="<?php echo $entry_tab_name; ?>" class="form-control" /><input type="hidden" name="product_tab[' + product_tab_row + '][tab_id]" value="" /></td>';
	html += '  <td class="text-left">';
	<?php foreach ($languages as $language) { ?>
	html += '<div class="input-group" style="background:#ffffff"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span><textarea name="product_tab[' + product_tab_row + '][product_tab_description][<?php echo $language['language_id']; ?>][text]" rows="5" class="form-control tab_block"></textarea></div>';
    <?php } ?>
	html += '  </td>';
	html += '  <td class="text-left"><button type="button" onclick="$(\'#tab-product_tab-' + product_tab_row + '\').remove();" data-toggle="tooltip" title="re" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
    html += '</tr>';
	
	$('#tab-product_tab tbody').append(html)
	
	$('.tab_block').focus(function( ){
$(this).summernote({ height: 200 });
});

	product_tabautocomplete(product_tab_row);
	
	product_tab_row++;
}

$('.tab_block').focus(function( ){
$(this).summernote({ height: 200 });
});

function product_tabautocomplete(product_tab_row) {
	$('input[name=\'product_tab[' + product_tab_row + '][name]\']').autocomplete({
		'source': function(request, response) {
			$.ajax({
				url: 'index.php?route=catalog/tab/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request),
				dataType: 'json',			
				success: function(json) {
					response($.map(json, function(item) {
						return {
							label: item.name,
							value: item.tab_id
						}
					}));
				}
			});
		},
		'select': function(item) {
			$('input[name=\'product_tab[' + product_tab_row + '][name]\']').val(item['label']);
			$('input[name=\'product_tab[' + product_tab_row + '][tab_id]\']').val(item['value']);

		}
	});
}
	
$('#product_tab tbody tr').each(function(index, element) {
	product_tabautocomplete(index);
});

//--></script>
				]]>
			</add>
		</operation>
	</file>
</modification>