<?xml version="1.0" encoding="UTF-8"?>
<modification>
	
	<code>StvAttrPreset</code>
    <name><![CDATA[Attributes Preset Values]]></name>
    <version><![CDATA[1.6]]></version>
    <author><![CDATA[stv_vl]]></author>
    <link><![CDATA[http://stvl.koku-scripts.com/demo2011/admin/]]></link>
	
	<file path="admin/view/template/catalog/product_form.twig" error="log">
		<operation error="log">
			<search><![CDATA[<table id="attribute" class="table table-striped table-bordered table-hover">]]></search>
			<add position="before" offset="1"><![CDATA[		
			{% if (module_atpresets_installed==1) %}
				<div class="form-group">
				<div class="col-sm-3">
					<select name="attemplate" id="attemplate" class="form-control" onchange="if ($(this).find(':selected').val()<0) {$('#attemmplate_button_add').prop('disabled','disabled');$('#attemmplate_button_replace').prop('disabled','disabled');} else {$('#attemmplate_button_add').removeAttr('disabled');$('#attemmplate_button_replace').removeAttr('disabled');}">
					<option value="-1"></option>								
					{% for attemplate in attemplates  %}									
						<option value="{{ attemplate.attemplate_id }}">{{ attemplate.name }}</option>
					{% endfor %}
				  </select>
					<script>

					</script>
				</div>
				<div class="col-sm-3">
					<button id="attemmplate_button_add" disabled="disabled" data-loading-text="{{ text_loading }}" type="button" onclick="update_attributes($('#attemplate').val(),1);" data-toggle="tooltip" title="{{ help_attemplate_add }}" class="btn btn-primary">{{ text_attemplate_add }}</button>
					<button id="attemmplate_button_replace" disabled="disabled" data-loading-text="{{ text_loading }}" type="button" onclick="update_attributes($('#attemplate').val(),2);" data-toggle="tooltip" title="{{ help_attemplate_replace }}" class="btn btn-primary">{{ text_attemplate_replace }}</button>
					<button id="attemmplate_button_default" data-loading-text="{{ text_loading }}" type="button" onclick="update_attributes($('#attemplate').val(),0);" data-toggle="tooltip" title="{{ help_attemplate_default }}" class="btn btn-primary">{{ text_attemplate_default }}</button>
				</div>
				<div class="col-sm-2">
					<select name="attribute_group_id" id="attgroup" class="form-control" onchange="if ($(this).find(':selected').val()>0) {update_attributes($('#attgroup').val(),3);}">
					<option value="-1">{{ text_add_group }}</option>								
					{% for attgroup in attgroups  %}									
						<option value="{{ attgroup.attribute_group_id }}">{{ attgroup.name }}</option>
					{% endfor %}
				  </select>
				</div>					
				<div class="col-sm-2" id="new_attemplate_name">
					<input type="text" name="new_attemplate_name" value="" placeholder="{{ text_new_attemplate_name }}" class="form-control"/>
				</div>
				<div class="col-sm-2">
					<button id="attemmplate_button_save" data-loading-text="{{ text_loading }}" type="button" onclick="save_attemplate();" data-toggle="tooltip" title="{{ help_save_attemplate }}" class="btn btn-primary">{{ text_save_attemplate }}</button>
				</div>					
				</div>
			{% endif %}
			]]>
			</add>
		</operation>	
		<operation error="log">
			<search><![CDATA[<td class="text-left" style="width: 40%;"><input type="text" name="product_attribute[{{ attribute_row }}][name]" value="{{ product_attribute.name }}" placeholder="{{ entry_attribute }}" class="form-control"/> <input type="hidden" name="product_attribute[{{ attribute_row }}][attribute_id]" value="{{ product_attribute.attribute_id }}"/></td>]]></search>
			<add position="replace"><![CDATA[
					<td class="text-left" style="width: 40%;"><input type="text" name="product_attribute[{{ attribute_row }}][name]" value="{{ product_attribute.name }}" placeholder="{{ entry_attribute }}" class="form-control"/> 
						<input type="hidden" name="product_attribute[{{ attribute_row }}][attribute_id]" value="{{ product_attribute.attribute_id }}" />			
						{% if (module_atpresets_installed==1)  %}
							{% if (module_atpresets_selecttype==0)  %}
								<br><div class="test"><input type="text" name="product_attribute[{{ attribute_row }}][preset]" value="{{ product_attribute.preset_esc }}" placeholder="{{ text_preset_value }}" class="form-control" />
								<input type="hidden" name="product_attribute[{{ attribute_row }}][preset_id][]" value="{% if (product_attribute.preset_id|length==1) %}{{ product_attribute.preset_id.0 }}{% endif %}" /></div>
								
							{% else %}
								<br><div>
									{% if (module_atpresets_allow_multiple==1)  %}
									
										<input type="checkbox" id="allow_multiple{{ attribute_row }}" name="product_attribute[{{ attribute_row }}][allow_multiple]"
											{% if (product_attribute['allow_multiple'])  %}checked="checked"{% endif %}
											onchange="changeSelectionMode({{ attribute_row }});"/>
										<label for="allow_multiple{{ attribute_row }}">{{ text_allow_multiple }}</label>
										
									{% endif %}
									<select {% if (product_attribute.allow_multiple)  %}multiple style="height:200px"{% endif %} alt="{{ attribute_row }}" name="product_attribute[{{ attribute_row }}][preset_id][]" id="input-preset{{ attribute_row }}" class="form-control" onchange="select_preset(this);" onfocus="check_attribute(this);">								
									<option value="-1"></option>								
									{% set current_att=0 %}
									{% for preset in all_presets %}									
										{% if (current_att != preset.attribute_id) %}{% set current_att = preset.attribute_id %}
										<option color="red" class="att{{ attribute_row }} att{{ attribute_row }}-{{ preset['attribute_id'] }}" value="0" disabled="disabled" style="color:red">{{ preset.attribute_name }}</option>
										{% endif %}									
										{% if (preset.preset_id in product_attribute.preset_id) %}
										<option alt="{{ preset.attribute_id }}" class="pre{{ attribute_row }} pre{{ attribute_row }}-{{ preset.attribute_id }}" value="{{ preset.preset_id }}" selected="selected">{{ preset.text_esc }}</option>
										{% else  %}
										<option alt="{{ preset.attribute_id }}" class="pre{{ attribute_row }} pre{{ attribute_row }}-{{ preset.attribute_id }}" value="{{ preset.preset_id }}">{{ preset.text_esc }}</option>
										{% endif %}
									{% endfor %}
								  </select>
								<script>

					
									$('.att{{ attribute_row }}').hide();
									$('.pre{{ attribute_row }}').hide();
									$('.pre{{ attribute_row }}-{{ product_attribute.attribute_id }}').show();
								</script>
								</div>
							{% endif %}							
						{% endif %}							
						</td>
					
			]]>
			</add>
		</operation>
		<operation error="log">
			<search index="0"><![CDATA[<td class="text-left">{% for language in languages %}]]></search>
			<add position="after" offset="1"><![CDATA[
				{% if (languages|length>1 and module_atpresets_installed==1) %}
				<span onclick="copy_values({{ attribute_row }},{{ language.language_id }});" class="input-group-addon" style="cursor:pointer;cursor:hand;" title="{{ text_copy_value }}">
						<i class="fa fa-ellipsis-v" style="font-size: large;"></i>
				</span>
				{% endif %}
			]]>
			</add>
		</operation>
		<operation error="log">
			<search><![CDATA[<td class="text-right"><button type="button" onclick="$('#attribute-row{{ attribute_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>]]></search>
			<add position="replace" ><![CDATA[
						<td class="text-right">
							<button type="button" onclick="$('#attribute-row{{ attribute_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button><br>
							{% if (module_atpresets_installed==1)  %}
							<button type="button" onclick="add_preset({{ attribute_row }})" data-toggle="tooltip" title="{{ text_new_preset }}" class="btn btn-primary" style="margin-top:20px;"><i class="fa fa-save"></i></button>
							{% endif %}
						</td>
			]]>
			</add>
		</operation>	
		<operation error="log">
			<search><![CDATA[attributeautocomplete(attribute_row);]]></search>
			<add position="before" ><![CDATA[
				{% if (module_atpresets_installed==1)  %}
					addPresetField(attribute_row);
				{% endif %}
			]]>
			</add>
		</operation>		
		<operation error="log">
			<search><![CDATA[html += '  <td class="text-right"><button type="button" onclick="$(\'#attribute-row' + attribute_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';]]></search>
			<add position="replace" ><![CDATA[
			{% if (module_atpresets_installed==1)  %}
				html += '  <td class="text-right"><button type="button" onclick="$(\'#attribute-row' + attribute_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button><br><button type="button" onclick="add_preset(' + attribute_row + ')" data-toggle="tooltip" title="{{ text_new_preset }}" class="btn btn-primary" style="margin-top:20px;"><i class="fa fa-save"></i></button></td>';
			{% else  %}
				html += '  <td class="text-right"><button type="button" onclick="$(\'#attribute-row' + attribute_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
			{% endif %}
			]]>
			</add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[category: item.attribute_group,]]></search>
			<add position="before" offset="2"><![CDATA[
				{% if (module_atpresets_installed==1)  %}
					{% if (module_atpresets_selecttype==0)  %}
						if (encodeURIComponent(request)=='') {
							$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val('');
							$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("blur");
							$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("focus");
							$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("keydown");					
							$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val('');
							$('input[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(0);			
							presetautocomplete(attribute_row);							
						}
					{% else %}
						if (encodeURIComponent(request)=='') {
							$('.att' + attribute_row).show();
							$('.pre' + attribute_row).show();
							$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(-1);							
						}						
					{% endif %}
				{% endif %}
			]]>
			</add>
		</operation>	
		
		<operation error="log">
			<search><![CDATA[var attribute_row = {{ attribute_row }};]]></search>
			<add position="before" offset="1"><![CDATA[
{% if (module_atpresets_installed==1)  %}
<script type="text/javascript"><!--
function addPresetField(attribute_row) {

	{% if (module_atpresets_selecttype==0)  %}
		html  = '<br><div class="test"><input type="text" name="product_attribute[' + attribute_row + '][preset]" value="" placeholder="{{ text_preset_value }}" class="form-control" />';
		html += '<input type="hidden" name="product_attribute[' + attribute_row + '][preset_id][]" value="" /></div>';
	{% else  %}
		html = '<br><div>';
		{% if (module_atpresets_allow_multiple==1)  %}
		
		html += '	<input type="checkbox" id="allow_multiple' + attribute_row + '" name="product_attribute[' + attribute_row + '][allow_multiple]"';
		html += '		onchange="changeSelectionMode('+attribute_row+')"/>';
		html += '	<label for="allow_multiple' + attribute_row + '">{{ text_allow_multiple }}</label>'; 
			
		{% endif %}	
		html += '<br><select alt="' + attribute_row + '" name="product_attribute[' + attribute_row + '][preset_id][]" id="input-preset' + attribute_row + '" class="form-control" onchange="select_preset(this);"  onfocus="check_attribute(this);">';
		html += '<option value="-1"></option>';
			{% set current_att=0 %}{% for preset in all_presets %}
				
				{% if (current_att != preset.attribute_id) %}{% set current_att = preset.attribute_id %}
				html += '<option class="att' + attribute_row + ' att' + attribute_row + '-{{ preset.attribute_id }}" value="0" disabled="disabled" style="color:red">{{ preset.attribute_name_esc }}</option>';
				{% endif %}
				html += '<option alt="{{ preset.attribute_id }}" class="pre' + attribute_row + ' pre' + attribute_row + '-{{ preset.attribute_id }}" value="{{ preset['preset_id'] }}">{{ preset.text_esc2 }}</option>';
			{% endfor %}
		html  += '  </select></div>';
								
	{% endif %}	
	$('input[name=\'product_attribute[' + attribute_row + '][name]\']').parent().append(html);

	{% if (module_atpresets_allow_multiple==1)  %}	
		addMultiSelectFunctionality(attribute_row);
	{% endif %}
	
	{% if (languages|length > 1)  %}
		{% for language in languages %}
		html  = '	<span onclick="copy_values(' + attribute_row + ',{{ language.language_id }})" class="input-group-addon" style="cursor:pointer;cursor:hand;" title="{{ text_copy_value }}">';
		html += '		<i class="fa fa-ellipsis-v" style="font-size: large;"></i>';
		html += '	</span>';
		
		$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').before(html);
		{% endfor %}
	{% endif %}
	
	{% if (module_atpresets_selecttype==0)  %}
		presetautocomplete(attribute_row);
	{% endif %}
}
//--></script>
<script type="text/javascript"><!--
function update_attributes(attemplate_id, option) {

	$.ajax({ 
		url: 'index.php?route=extension/module/attemplate/update_attributes&user_token={{ user_token }}&attemplate_id=' + attemplate_id + '&option=' + option + '&product_id=' + {{ product_id }},
		type: 'post',
		data: $('#tab-attribute select, #tab-attribute input, #tab-attribute textarea').serialize(),		
		dataType: 'json',
		beforeSend: function() {
			if (option == 1)
				$('#attemmplate_button_add').button('loading');
			else if (option == 2)
				$('#attemmplate_button_replace').button('loading');
			else if (option == 0)
				$('#attemmplate_button_default').button('loading');
			else {
				$('#attgroup option[value="-1"]').prop('selected', true);
				$('#attgroup option[value="-1"]').text('{{ text_loading }}');
			}
		},
		complete: function() {
			$('#attemmplate_button_add').button('reset');
			$('#attemmplate_button_replace').button('reset');
			$('#attemmplate_button_default').button('reset');		

		},				
		success: function(json) {
			$('tr[id^=\'attribute-row\']').remove();
			if (option == 3) {
				$('#attgroup option[value="-1"]').html('{{ text_add_group }}');
			}				
			attribute_row = 0;
			for (var key in json['product_attributes']) {
				addAttribute();
				attribute_row = attribute_row -1;
				$('input[name=\'product_attribute[' + attribute_row + '][name]\']').val(json['product_attributes'][key]['name']);
				$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(json['product_attributes'][key]['attribute_id']);
				
				{% for language in languages  %}
					if (json['product_attributes'][key]['product_attribute_description'][{{ language.language_id }}] !== undefined) {
						$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(json['product_attributes'][key]['product_attribute_description'][{{ language.language_id }}]['text']);
					}
				{% endfor %}
				
				if (json['product_attributes'][key]['allow_multiple']) {
					$('input[name=\'product_attribute[' + attribute_row + '][allow_multiple]\']').prop('checked','checked');
					changeSelectionMode(attribute_row);
				}
				if ('1' in json['product_attributes'][key]['preset_id']) {
					for (var preset_key in json['product_attributes'][key]['preset_id']) {
						if (json['product_attributes'][key]['preset_id'][preset_key] > 0)
							$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\'] option[value="'+json['product_attributes'][key]['preset_id'][preset_key]+'"]').prop('selected', true);
					}			
				} else {	
					if (json['product_attributes'][key]['preset_id'][0] >0) {
						$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\'] option[value="'+json['product_attributes'][key]['preset_id'][0]+'"]').prop('selected', true);
						$('input[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(json['product_attributes'][key]['preset_id'][0]);		
					}
				}
				$('.att' + attribute_row).hide();
				$('.pre' + attribute_row).hide();
				$('.pre' + attribute_row + '-' + json['product_attributes'][key]['attribute_id']).show();						

				{% if (module_atpresets_selecttype==0)  %}
					presetautocomplete(attribute_row);
					$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val(json['product_attributes'][key]['preset']);
				{% endif %}				
				

				attribute_row = attribute_row +1;
			}
		}						
	});	
}


function save_attemplate() {

	$.ajax({ 
		url: 'index.php?route=extension/module/attemplate/save_attemplate&user_token={{ user_token }}',
		type: 'post',
		data: $('#tab-attribute select, #tab-attribute input, #tab-attribute textarea, input[name="new_attemplate_name"]').serialize(),		
		dataType: 'json',
		beforeSend: function() {
			$('#attemmplate_button_save').button('loading');
			$('.alert').remove();
			$('#new_attemplate_name .text-danger').remove();			
		},
		complete: function() {
			$('#attemmplate_button_save').button('reset');
		},		
		success: function(json) {
			if (json['error']) {
				var html = '<div class="text-danger">' + json['error'] + '</div>';
				$('input[name="new_attemplate_name"]').after(html);
			}

			if (json['success']) {
				$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
			}
		}						
	});	
}
//--></script>
<script type="text/javascript"><!--
function copy_values(attribute_row, language_id){
	var new_value = $('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][' + language_id + '][text]\']').val();
	$('textarea[name^=\'product_attribute[' + attribute_row + '][product_attribute_description]\']').val(new_value);
}

function add_preset(attribute_row) {
	var attribute_id = $('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val();
	var texts = {
		{% for language in languages %}
		{{ language.language_id }}:$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(),
		{% endfor %}	
	};
	$.ajax({
		url: 'index.php?route=extension/module/atpresets/insert&user_token={{ user_token }}',
		type: 'post',
		data: {attribute_id,texts},
		dataType: 'json',
		success: function(json) {
			if (json['preset_id']!=0) {
				{% if (module_atpresets_selecttype==0)  %}
					$('input[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(json['preset_id']);
					$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val(json['preset_decoded']);
				{% else  %}
					if (json['new_added']==1) {
						if (!$('.att' + attribute_row + '-' + attribute_id).length)
							$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').append('<option color="red" class="att' + attribute_row + ' att' + attribute_row + '-' + attribute_id + '" value="0" disabled="disabled" style="color:red;display:none;">'+$('input[name=\'product_attribute[' + attribute_row + '][name]\']').val()+'</option>');
						
						$('.att' + attribute_row + '-' + attribute_id).after('<option alt="'+attribute_id+'" class="pre' + attribute_row + ' pre' + attribute_row + '-' + attribute_id + '" value="'+json['preset_id']+'">'+json['preset']+'</option>');
					}
					$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(json['preset_id']);
					{% if (module_atpresets_allow_multiple==1)  %}	
						addMultiSelectFunctionality(attribute_row);
					{% endif %}					
				{% endif %}
			}		
			alert(json['message']);
		},
		error: function(json) {
			alert('{{ text_new_preset_error }}');
		}
	});
}
//--></script>
<script type="text/javascript"><!--
{% if (module_atpresets_selecttype==0)  %}
function presetautocomplete(attribute_row) {

	var attribute_id = $('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val();
	$('#attribute-row'+attribute_row+' .test ul').remove();
	if (attribute_id != '') {
		$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').autocomplete({
			'source': function(request, response) {
				$.ajax({
					url: 'index.php?route=extension/module/atpresets/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request) + '&attribute_id=' + attribute_id,
					dataType: 'json',			
					success: function(json) {
						response($.map(json, function(item) {
							return {
								label: item.not_decoded_text,
								label_decoded: item.text,								
								values: item.texts,
								value: item.preset_id	
							}
						}));
					}
				});
			},
			'select': function(item) {
				$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val(item['label_decoded']);
				$('input[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(item['value']);
				var key;
				for (key in item['values']) {
					$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][' + key + '][text]\']').val(item['values'][key]); 
				}
			}
		});
	
	} else {
		$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').autocomplete({
			'source': function(request, response) {
				$.ajax({
					url: 'index.php?route=extension/module/atpresets/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request) + '&attribute_id=' + attribute_id,
					dataType: 'json',			
					success: function(json) {
						response($.map(json, function(item) {
							return {
								category: item.attribute_name,
								attribute_id: item.attribute_id,
								label: item.not_decoded_text,
								label_decoded: item.text,
								values: item.texts,
								value: item.preset_id					
							}
						}));
					}
				});
			},
			select: function(item) {
				
				$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val(item['label_decoded']);
				$('input[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(item['value']);
				$('input[name=\'product_attribute[' + attribute_row + '][name]\']').val(item['category']);
				$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(item['attribute_id']);				
				var key;
				for (key in item['values']) {
					$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][' + key + '][text]\']').val(item['values'][key]); 
				}
				presetautocomplete(attribute_row);
			}
		});	
	}
}

$('#attribute tbody tr').each(function(index, element) {
	presetautocomplete(index);
});
{% else  %}
function select_preset(select_node) {
	var att_row = $(select_node).attr('alt');
	var preset_id = $(select_node).find(":selected").val();
	var attribute_id = $(select_node).find(":selected").attr('alt');
	
	$.ajax({
		url: 'index.php?route=extension/module/atpresets/getPresetTexts&user_token={{ user_token }}&preset_id=' + preset_id,
		dataType: 'json',			
		success: function(json) {
			$('input[name=\'product_attribute[' + att_row + '][name]\']').val($('.att' + att_row + '-' + attribute_id).text());
			$('input[name=\'product_attribute[' + att_row + '][attribute_id]\']').val(attribute_id);	
				
			{% for language in languages %}
				$('textarea[name=\'product_attribute[' + att_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(json['texts'][{{ language.language_id }}]); 
			{% endfor %}
			if (preset_id != -1) {
				$('.att' + att_row).hide();
				$('.pre' + att_row).hide();
				$('.pre' + att_row + '-' + attribute_id).show();			
			} else {
				$('.att' + att_row).show();
				$('.pre' + att_row).show();			
			}
				
		}
	});	

}

function check_attribute(select_node) {
	var att_row = $(select_node).attr('alt');
	var att_text = $('input[name=\'product_attribute[' + att_row + '][name]\']').val();
	
	if (att_text=='') {
		$('.att' + att_row).show();
		$('.pre' + att_row).show();	
		$('input[name=\'product_attribute[' + att_row + '][attribute_id]\']').val('');
		$('select[name=\'product_attribute[' + att_row + '][preset_id][]\']').val(-1);
	}
}

function changeSelectionMode(attribute_row) {
	if (!$('#allow_multiple' + attribute_row ).is(':checked')) {
		$('#input-preset' + attribute_row).css('height','auto');
		$('#input-preset' + attribute_row).removeAttr('multiple');
		$('#attribute-row'+attribute_row+' textarea').attr('readonly', false);		
		
		{% for language in languages %}
			$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(''); 
			var new_value{{ language.language_id }} = ''; 
		{% endfor %}
		
		var ids = '';
		$('#input-preset' + attribute_row + ' option').each(function(index) {
			if ($(this).prop('selected')) {
				ids += '_'+$(this).val();		
			}
			if ($(this).val() == -1) {
				$(this).prop('selected', false);		
			}			
		});
		$.ajax({
			url: 'index.php?route=extension/module/atpresets/getManyPresetsTexts&user_token={{ user_token }}&preset_id=' + ids,
			dataType: 'json',			
			success: function(json) {
				if (json) {
					{% for language in languages %}

						$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(json[{{ language.language_id }}]);
					{% endfor %}	
				} else {
					{% for language in languages %}
						$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val('');
					{% endfor %}			
				}
			}
		});			
	} else  {
		$('#input-preset' + attribute_row).attr('multiple','multiple');
		$('#input-preset' + attribute_row).css('height','200px');
		$('#attribute-row'+attribute_row+' textarea').attr('readonly', true);
		$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\'] option[value="-1"]').prop('selected', false);
	}
}

function addMultiSelectFunctionality(attribute_row) {
$('#input-preset' + attribute_row + ' option').unbind( "mousedown");
$('#input-preset' + attribute_row + ' option').mousedown(function(e) {
if ($('input[name="product_attribute[' + attribute_row + '][allow_multiple]"]').is(':checked')) {
    e.preventDefault();
	if ($(this).val() != -1) {
		$(this).prop('selected', !$(this).prop('selected'));

		if ($(this).prop('selected')) {
			var attribute_id = $(this).attr('alt');
			if ($('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val() != attribute_id) {
				$('input[name=\'product_attribute[' + attribute_row + '][name]\']').val($('.att' + attribute_row + '-' + attribute_id).text());
				$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(attribute_id);	
				$('.att' + attribute_row).hide();
				$('.pre' + attribute_row).hide();
				$('.pre' + attribute_row + '-' + attribute_id).show();					
			}
		}
		{% for language in languages %}
			$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(''); 
			var new_value{{ language.language_id }} = ''; 
		{% endfor %}			
		var ids = '';
		$('#input-preset' + attribute_row + ' option').each(function(index) {
			if ($(this).prop('selected')) {
				ids += '_'+$(this).val();		
			}
		});
		$.ajax({
			url: 'index.php?route=extension/module/atpresets/getManyPresetsTexts&user_token={{ user_token }}&preset_id=' + ids,
			dataType: 'json',			
			success: function(json) {
				if (json) {
					{% for language in languages %}

						$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val(json[{{ language.language_id }}]);
					{% endfor %}	
				} else {
					{% for language in languages %}
						$('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][{{ language.language_id }}][text]\']').val('');
					{% endfor %}			
				}
			}
		});				
	} else {
		$(this).prop('selected', false);
	}
}
	return false;
});	
}

{% for i in (0..attribute_row-1) %}
addMultiSelectFunctionality({{ i }});
if ($('#allow_multiple{{ i }}').attr("checked"))
	$('#attribute-row{{ i }} textarea').attr('readonly', true);
{% endfor %}
{% endif %}
//--></script>
{% endif %}

			]]>
			</add>
		</operation>
	
		<operation error="log">
			<search><![CDATA[$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(item['value']);]]></search>
			<add position="replace"><![CDATA[			
			if (item['value'] != $('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val()) {				
				$('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(item['value']);			
				{% if (module_atpresets_installed==1)  %}
					{% if (module_atpresets_selecttype==0)  %}
						$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("blur");
						$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("focus");
						$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').unbind("keydown");					
						$('input[name=\'product_attribute[' + attribute_row + '][preset]\']').val('');
						$('input[name=\'product_attribute[' + attribute_row + '][preset_id]\']').val(0);			
						presetautocomplete(attribute_row);
					{% else %}
						$('.att' + attribute_row).hide();
						$('.pre' + attribute_row).hide();
						$('.pre' + attribute_row + '-' + item['value']).show();	
						$('select[name=\'product_attribute[' + attribute_row + '][preset_id][]\']').val(-1);						
					{% endif %}
				{% endif %}
			}
			]]>
			</add>
		</operation>		
	</file>		
	
	<file path="admin/controller/catalog/product.php" error="log">
		<operation error="log">
			<search><![CDATA[$this->load->language('catalog/product');]]></search>
			<add position="before"><![CDATA[
		$this->load->language('extension/module/atpresets');
		$this->load->language('extension/module/attemplate');
			]]></add>
		</operation>	
		<operation error="log">
			<search><![CDATA[$data['text_form'] = !isset($this->request->get['product_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');]]></search>
			<add position="after"><![CDATA[

		if (isset($this->request->get['product_id'])) 
			$data['product_id'] = $this->request->get['product_id'];
		else
			$data['product_id'] = 0;
		
		$data['module_atpresets_installed'] = $this->config->get('module_atpresets_installed');
		$data['module_atpresets_allow_multiple'] = $this->config->get('module_atpresets_allow_multiple');		
		if ($data['module_atpresets_allow_multiple']==1)
			$data['module_atpresets_selecttype'] = 1;
		else 
			$data['module_atpresets_selecttype'] = $this->config->get('module_atpresets_selecttype');

		if ($this->config->get('module_atpresets_installed')==1) {

			$this->load->model('catalog/attribute_group');
			$data['attgroups'] = $this->model_catalog_attribute_group->getAttributeGroups(array());
			
			$this->load->model('extension/atpresets/attemplate');
			$data['attemplates'] = $this->model_extension_atpresets_attemplate->getAttemplates(array('status'=>'1'));
		
			if ($data['module_atpresets_selecttype']==1) {
				$data['all_presets'] = array();
				
				$this->load->model('extension/atpresets/atpresets');

				$results = $this->model_extension_atpresets_atpresets->getPresetsAuto(array('attribute_id'=>''));

				if ($results) {
					foreach ($results as $result) {
						$data['all_presets'][] = array(
							'preset_id'		=> $result['preset_id'],
							'text'			=> (utf8_strlen($result['text'])>50)?substr($result['text'], 0, 50).'...':$result['text'],
							'text_esc'		=> htmlentities(html_entity_decode($result['text'],ENT_QUOTES, 'UTF-8'),ENT_QUOTES),
							'text_esc2'		=> htmlentities(html_entity_decode(str_replace(array("\r\n", "\n", "\r"), '', $result['text']),ENT_QUOTES, 'UTF-8'),ENT_QUOTES),
							'attribute_name'=> $result['name'],
							'attribute_name_esc' => htmlentities($result['name'],ENT_QUOTES),							
							'attribute_id'	=> $result['attribute_id']					
						);
					}
				}
			} else {
				$data['all_presets'] = null;
			}
		}		
		
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']);]]></search>
			<add position="after"><![CDATA[
				if ($this->config->get('module_atpresets_installed')==1) {
					$preset_id = array();
					if (count($product_attribute['preset_id']) == 1) {
						$this->load->model('extension/atpresets/atpresets');
						$preset_id = $product_attribute['preset_id'];
						$product_attribute['preset'] = html_entity_decode($this->model_extension_atpresets_atpresets->getPresetTitle($product_attribute['preset_id'][0]),ENT_QUOTES, 'UTF-8');
					} else if (count($product_attribute['preset_id']) > 1) {
						/*$sql = "SELECT preset_id FROM " . DB_PREFIX . "product_attribute WHERE attribute_id = '". (int)$product_attribute['attribute_id'] ."' and product_id='".(int)$this->request->get['product_id']."'";			
						$query = $this->db->query($sql);
						foreach ($query->rows as $preset_ids) {
							$preset_id[] = $preset_ids['preset_id'];
						}*/
						$preset_id = $product_attribute['preset_id'];				
						$product_attribute['preset'] = '';
					} else {
						$product_attribute['preset'] = '';
					}
				} else {
					$preset_id = array();
					$product_attribute['preset'] = '';
				}
			]]></add>
		</operation>			
		<operation error="log">
			<search><![CDATA['attribute_id'                  => $product_attribute['attribute_id'],]]></search>
			<add position="after"><![CDATA[
					'preset_id'                  => $preset_id,
					'allow_multiple'             => count($preset_id)>1 && $data['module_atpresets_allow_multiple'],
					'preset'                  	 => $product_attribute['preset'],
					'preset_esc'				 => htmlentities($product_attribute['preset'],ENT_QUOTES),
			]]></add>
		</operation>			
	</file>		
	<file path="admin/model/catalog/product.php" error="log">
		<operation error="log">
			<search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_attribute_description['text']) . "'");]]></search>
			<add position="replace"><![CDATA[
				if ($this->config->get('module_atpresets_installed')==1) {

					if ($are_same) { 
						foreach ($product_attribute['preset_id'] as $preset_id) {
							if ($preset_id>0)
								$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET preset_id = '".$preset_id."', product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($presets_text[$preset_id][$language_id]) . "'");
						}						
					} else {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_attribute_description['text']) . "'");
					}
				} else {
					$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" .  $this->db->escape($product_attribute_description['text']) . "'");					
				} 
				]]></add>
		</operation>		
		<operation error="log">
			<search><![CDATA[foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {]]></search>
			<add position="before"><![CDATA[			
					if (count($product_attribute['preset_id']) >= 1 && $this->config->get('module_atpresets_installed')==1) {
						//retreive preset in order to check it it maches the saved data
						$this->load->model('extension/atpresets/atpresets');
						$are_same = true;

						$preset = array();
						
						$presets_text = $this->model_extension_atpresets_atpresets->getManyPresetsTexts($product_attribute['preset_id']);
						foreach ($presets_text as $texts) {
							foreach ($texts as $key => $text) {
								if (!isset($preset[$key])) {
									$preset[$key] = $text;
								} else {
									$preset[$key] .= ', '.$text;
								}
							}
						}													
						
						if (!empty($preset)) {
							if (count($product_attribute['preset_id']) == 1) //only single selected presets are checked
								foreach ( $product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {									
									if (html_entity_decode($product_attribute_description['text'], ENT_QUOTES, 'UTF-8') != html_entity_decode($preset[$language_id], ENT_QUOTES, 'UTF-8'))
										$are_same = false;									
								}
						} else {
							$are_same = false;
						}

					} else {
						$preset = array();
						$are_same = false;
					}
					$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");					

				]]></add>
		</operation>		
		<operation error="log">
			<search><![CDATA[foreach ($product_attribute_description_query->rows as $product_attribute_description) {]]></search>
			<add position="before"><![CDATA[
				if ($this->config->get('module_atpresets_installed')==1) {
					$this->load->model('extension/atpresets/atpresets');

					$preset_id = array();
					$sql = "SELECT distinct(preset_id) FROM " . DB_PREFIX . "product_attribute WHERE attribute_id = '". (int)$product_attribute['attribute_id'] ."' and product_id='".(int)$product_id."'";
					$query = $this->db->query($sql);
				
					foreach ($query->rows as $preset_ids) {
						$preset_id[] = $preset_ids['preset_id'];
					}	
						$preset = array();
						
						$presets_text = $this->model_extension_atpresets_atpresets->getManyPresetsTexts($preset_id);
						foreach ($presets_text as $texts) {
							foreach ($texts as $key => $text) {
								if (!isset($preset[$key])) {
									$preset[$key] = $text;
								} else {
									$preset[$key] .= ', '.$text;
								}
							}
						}
				} else $preset_id = array();
				]]></add>
		</operation>			
		<operation error="log">
			<search><![CDATA[foreach ($product_attribute_description_query->rows as $product_attribute_description) {]]></search>
			<add position="after"><![CDATA[
				if ($this->config->get('module_atpresets_installed')==1) {
					if (isset($preset[$product_attribute_description['language_id']])) 
						$product_attribute_description['text'] = $preset[$product_attribute_description['language_id']]; 
				} 
				]]></add>
		</operation>	
		<operation error="log">
			<search><![CDATA['attribute_id'                  => $product_attribute['attribute_id'],]]></search>
			<add position="after"><![CDATA[
				'preset_id'                  => $preset_id,
				]]></add>
		</operation>	
	</file>
	<file path="admin/controller/catalog/attribute.php" error="log">
		<operation error="log">
			<search><![CDATA[$this->load->language('catalog/attribute');]]></search>
			<add position="before"><![CDATA[
		$this->load->language('extension/module/atpresets');
			]]></add>
		</operation>		
		<operation error="log">
			<search index="1"><![CDATA[if (isset($this->error['warning'])) {]]></search>
			<add position="before"><![CDATA[
			
			$data['module_atpresets_installed'] = $this->config->get('module_atpresets_installed');
			
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$this->load->model('catalog/attribute_group');]]></search>
			<add position="before"><![CDATA[
		if ($this->config->get('module_atpresets_installed')==1) {
		
			$presets = array();
			if (isset($this->request->get['attribute_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
				$this->load->model('extension/atpresets/atpresets');
				$all_presets = $this->model_extension_atpresets_atpresets->getPresets(array('attribute_id' => $this->request->get['attribute_id']));			
				
				foreach ($all_presets as $preset) {
					$presets[] = $this->model_extension_atpresets_atpresets->getPreset($preset['preset_id']);	
				}
			}
			foreach ($presets as $key=>$preset) {
				$presets[$key]['text_short'] = ((utf8_strlen($preset['text'])>50)?substr($preset['text'], 0, 50).'...':$preset['text']);
			}
			if (isset($this->request->post['presets'])) {
				$data['presets'] = $this->request->post['presets'];
			} elseif (!empty($presets)) {
				$data['presets'] = $presets;
			} else {
				$data['presets'] = array();
			}

		}
			]]></add>
		</operation>		
		<operation error="log">
			<search><![CDATA[foreach ($this->request->post['attribute_description'] as $language_id => $value) {]]></search>
			<add position="before"><![CDATA[
		if ($this->config->get('module_atpresets_installed')==1) {
			if (isset($this->request->post['presets'])) {
				foreach ($this->request->post['presets'] as $key => $preset) {
					if (isset($preset['descriptions'])) {
						$all_null = true;
						foreach ($preset['descriptions'] as $desc) {
							if ($desc != '') {
								$all_null = false;
							}
						}
					} else $all_null = false;
					if ($all_null) unset($this->request->post['presets'][$key]['text']);
				}
			}
		}
			]]></add>
		</operation>			
	</file>		
	<file path="admin/model/catalog/attribute.php" error="log">
		<operation error="log">
			<search><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "attribute WHERE attribute_id = '" . (int)$attribute_id . "'");]]></search>
			<add position="after" offset="1"><![CDATA[
		if ($this->config->get('module_atpresets_installed')==1) {
			$sql = "SELECT preset_id FROM " . DB_PREFIX . "attribute_presets WHERE attribute_id = '". (int)$attribute_id ."'";			
			$query = $this->db->query($sql);		
			
			foreach ($query->rows as $preset) {
				$this->db->query("DELETE FROM " . DB_PREFIX . "attribute_presets WHERE preset_id = '" . (int)$preset['preset_id'] . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "attribute_presets_description WHERE preset_id = '" . (int)$preset['preset_id'] . "'");				
				$this->db->query("UPDATE " . DB_PREFIX . "product_attribute SET preset_id = 0 WHERE preset_id = '" . (int)$preset['preset_id'] . "'");
			}
		}
				]]></add>
		</operation>		
		<operation error="log">
			<search><![CDATA[foreach ($data['attribute_description'] as $language_id => $value) {]]></search>
			<add position="before"><![CDATA[
			if ($this->config->get('module_atpresets_installed')==1) {
				$this->load->model('extension/atpresets/atpresets');
				if (isset($data['presets'])) {
					foreach ($data['presets'] as $preset) {
						$preset['attribute_id'] = $attribute_id;
						if ($preset['preset_id']!=0) 
							if (isset($preset['text'])) 
								$this->model_extension_atpresets_atpresets->editPreset($preset['preset_id'],$preset);	
							else
								$this->model_extension_atpresets_atpresets->deletePreset($preset['preset_id']);	
						else if (isset($preset['text'])) 
							$this->model_extension_atpresets_atpresets->addPreset($preset);
					}
				}
			}
				]]></add>
		</operation>		
	</file>		
	<file path="admin/view/template/catalog/attribute_form.twig" error="log">
		<operation error="log">
			<search><![CDATA[<input type="text" name="sort_order" value="{{ sort_order }}" placeholder="{{ entry_sort_order }}" id="input-sort-order" class="form-control" />]]></search>
			<add position="after" offset="2"><![CDATA[
		{% if (module_atpresets_installed==1)  %}			
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-sort-order">{{ text_preset_values }}</label>
            <div class="col-sm-10">
				<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
				  {% set pcount=0 %}
				  {% for preset in presets %}
					  <input type="hidden" name="presets[{{ pcount }}][preset_id]" value="{{ preset.preset_id }}" />
					  <input type="hidden" name="presets[{{ pcount }}][text]" value="{{ preset.text }}" />
					  {% if (languages|length>1)  %}
					  <div class="panel panel-default" id="preset{{ pcount }}">					  
						<a data-toggle="collapse" data-parent="#accordion" href="#stv_collapse{{ pcount }}" aria-expanded="true" aria-controls="stv_collapse{{ pcount }}">
							<div class="panel-heading " role="tab" id="heading{{ pcount }}" style="background-color: #EEE;">
							  <h4 class="panel-title" {% if (error_presets[preset.preset_id] is defined)  %}style="color:red;"{% endif %} >
								{{ preset.text_short }}
								<div class="pull-right"><i class="fa fa-trash-o" onclick="$('#preset{{ pcount }}').remove();$('input[name^=\'presets[{{ pcount }}][text]\']').remove();"></i></div>
							  </h4>							  
							</div>
						</a>
						<div id="stv_collapse{{ pcount }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{ pcount }}">
						  <div class="panel-body">	
							  {% for language in languages  %}
								  <div class="input-group" style="margin-bottom:10px"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
	
								  	<span onclick="copy_values({{ pcount }},{{ language.language_id }});" class="input-group-addon" style="cursor:pointer;cursor:hand;" title="{{ text_copy_value }}">
										<i class="fa fa-ellipsis-v" style="font-size: large;"></i>
									</span>

									<textarea name="presets[{{ pcount }}][descriptions][{{ language.language_id }}]" rows="1" placeholder="{{ entry_value }}" class="form-control">{% if preset.descriptions[language.language_id] is defined %}{{ preset.descriptions[language.language_id] }}{% else %}{{ '' }}{% endif %}</textarea>
								  </div>
							  {% endfor %}
						  </div>
						</div>
					  </div>
					  {% else %}
						<div class="panel panel-default" id="preset{{ pcount }}">
							  {% for language in languages %}
								  <div class="input-group" style="margin-bottom:10px">
								  <span class="input-group-addon" style="cursor:pointer;cursor:hand;">
									<i class="fa fa-trash-o fa-lg" onclick="$('#preset{{ pcount }}').remove();$('input[name^=\'presets[{{ pcount }}][text]\']').remove();"></i>
								  </span>										  
								  <span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
								  
								  <textarea name="presets[{{ pcount }}][descriptions][{{ language.language_id }}]" rows="1" placeholder="{{ entry_value }}" class="form-control">{% if preset.descriptions[language.language_id] is defined %}{{ preset.descriptions[language.language_id] }}{% else %}{{ '' }}{% endif %}</textarea>
								  </div>
							  {% endfor %}
						  </div>
					  {% endif %}					  
					  			
					  {% set pcount = pcount + 1 %}
				  {% endfor %}
			   </div>
			   <div class="pull-right"><a class="btn btn-primary" onclick="addPreset();">{{ text_add_preset }}</a></div>			   
			  {% if (error_presets is defined) %}
				<div class="text-danger"></div>
			  {% endif %}			   
            </div>
          </div>
		{% endif %}
				]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[{{ footer }}]]></search>
			<add position="before" offset="1"><![CDATA[
<script type="text/javascript"><!--
var pcount = {{ pcount }};

function addPreset() {
{% if (languages|length >1)  %}
	html  = '	  <input type="hidden" name="presets[' + pcount + '][preset_id]" value="0" />';
	html += '	  <input type="hidden" name="presets[' + pcount + '][text]" value="New Preset " />';
	html += '	  <div class="panel panel-default" id="preset' + pcount + '">';
	html += '		<a data-toggle="collapse" data-parent="#accordion" href="#stv_collapse' + pcount + '" aria-expanded="true" aria-controls="stv_collapse' + pcount + '">';
	html += '			<div class="panel-heading " role="tab" id="heading' + pcount + '" style="background-color: #EEE;">';
	html += '			  <h4 class="panel-title">';
	html += '				New Preset '+ pcount;
	html += '				<div class="pull-right"><i class="fa fa-trash-o" onclick="$(\'#preset' + pcount + '\').remove();$(\'input[name^=\\\'presets[' + pcount + '][text]\\\']\').remove();"></i></div>';
	html += '			  </h4>';
	html += '			</div>';
	html += '		</a>';
	html += '		<div id="stv_collapse' + pcount + '" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading' + pcount + '">';
	html += '		  <div class="panel-body">	';
	{% for language in languages %}
	html += '				  <div class="input-group" style="margin-bottom:10px"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>';

	html += '					<span onclick="copy_values(' + pcount + ',{{ language.language_id }})" class="input-group-addon" style="cursor:pointer;cursor:hand;" title="{{ text_copy_value }}">';
	html += '						<i class="fa fa-ellipsis-v" style="font-size: large;"></i>';
	html += '					</span>';

	html += '					<textarea name="presets[' + pcount + '][descriptions][{{ language.language_id }}]" rows="1" placeholder="{{ entry_value }}" class="form-control"></textarea>';
	html += '				  </div>';
	{% endfor %}
	html += '		  </div>';
	html += '		</div>';
	html += '	  </div>';

	$('[id^=\'stv_collapse\']').removeClass("in");
{% else %}
	html  = '	  <input type="hidden" name="presets[' + pcount + '][preset_id]" value="0" />';
	html += '	  <input type="hidden" name="presets[' + pcount + '][text]" value="New Preset " />';
	html += '			<div class="panel panel-default" id="preset' + pcount + '">';
				{% for language in languages %}
	html += '					  <div class="input-group" style="margin-bottom:10px">';
	html += '					  <span class="input-group-addon" style="cursor:pointer;cursor:hand;">';
	html += '						<i class="fa fa-trash-o fa-lg" onclick="$(\'#preset' + pcount + '\').remove();$(\'input[name^=\\\'presets[' + pcount + '][text]\\\']\').remove();"></i>';
	html += '					  </span>';
	html += '					  <span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>';
	html += '					  ';
	html += '					  <textarea name="presets[' + pcount + '][descriptions][{{ language.language_id }}]" rows="1" placeholder="{{ entry_value }}" class="form-control"></textarea>';
	html += '					  </div>';
				{% endfor %}
	html += '			  </div>';
	
{% endif %}		
	$('#accordion').append(html);
	$('textarea[name=\'presets[' + pcount + '][descriptions][{% set first = languages|first %}{{ first.language_id }}]\']').focus();
	
	pcount++;
}

function copy_values(preset_count, language_id){
	var new_value = $('textarea[name=\'presets[' + preset_count + '][descriptions][' + language_id + ']\']').val();
	$('textarea[name^=\'presets[' + preset_count + '][descriptions]\']').val(new_value);
}
//--></script>   
				]]></add>
		</operation>		
	</file>		
	<file path="admin/model/localisation/language.php" error="log">
		<operation error="log">
			<search ><![CDATA[// Product Attribute]]></search>
			<add position="before"><![CDATA[
		// Attribute Preset Values
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "attribute_presets_description WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'");

		foreach ($query->rows as $attribute_preset) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "attribute_presets_description SET preset_id = '" . (int)$attribute_preset['preset_id'] . "', language_id = '" . (int)language_id . "', text = '" . $this->db->escape($attribute_preset['text']) . "'");
		}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "language WHERE language_id = '" . (int)$language_id . "'");]]></search>
			<add position="after"><![CDATA[
				$this->db->query("DELETE FROM " . DB_PREFIX . "attribute_presets_description WHERE language_id = '" . (int)language_id . "'");
			]]></add>
		</operation>						
	</file>
	<file path="catalog/model/catalog/product.php" error="log">
	
		<operation error="log">
			<search ><![CDATA[public function getProductAttributes($product_id) {]]></search>
			<add position="after"><![CDATA[
			if ($this->config->get('module_atpresets_use_newline')==1) {
				$glue_character = html_entity_decode('<br>', ENT_QUOTES, 'UTF-8');
			} else {
				$glue_character = $this->config->get('module_atpresets_other_character')." ";
			}
			]]></add>
		</operation>	
		<operation error="log">
			<search ><![CDATA[$product_attribute_data[] = array(]]></search>
			<add position="replace"><![CDATA[
			if ($this->config->get('module_atpresets_installed')==1) {
				if (!isset($product_attribute_data[$product_attribute['attribute_id']])) {
					$product_attribute_data[$product_attribute['attribute_id']] = array(
						'attribute_id' => $product_attribute['attribute_id'],
						'name'         => $product_attribute['name'],
						'text'         => $product_attribute['text']
					);
				} else {
					$product_attribute_data[$product_attribute['attribute_id']] = array(
						'attribute_id' => $product_attribute['attribute_id'],
						'name'         => $product_attribute['name'],
						'text'         => $product_attribute_data[$product_attribute['attribute_id']]['text'] .= $glue_character.$product_attribute['text']
					);			
				}
			} else $product_attribute_data[$product_attribute['attribute_id']] = array(
			]]></add>
		</operation>
	</file>			
	<file path="admin/controller/common/column_left.php" error="log">
		<operation error="log">
			<search><![CDATA[$this->load->language('common/column_left');]]></search>
			<add position="before"><![CDATA[
		$this->load->language('extension/module/attemplate');
			]]></add>
		</operation>		
		<operation error="log">
			<search ><![CDATA[if ($attribute) {]]></search>
			<add position="before" ><![CDATA[
			if ($this->config->get('module_atpresets_installed')==1) {
				if ($this->user->hasPermission('access', 'extension/module/attemplate')) {
					$attribute[] = array(
						'name'	   => $this->language->get('text_attemplate'),
						'href'     => $this->url->link('extension/module/attemplate', 'user_token=' . $this->session->data['user_token'], true),
						'children' => array()		
					);
				}	
			}			
			]]>
			</add>
		</operation>		
	</file>				
</modification>