<?php echo $this->render('admin/header.phtml'); ?>


<script type="text/javascript" language="javascript">

	$(document).ready(function () {

		<?php if( isset( $this->addSuccess ) ){ ?>
			alertify.success("<i class='fa fa-check'></i> <?php echo @Lib_Lang::translate(admin_element_add_success); ?>");
		<?php } ?>

		$('#formAdd').validate({
			errorClass: "formError",
			errorElement: "div",
			rules: {
				product_name: {
					required: true
				},
				product_price: {
					required: true
				}
			},
			messages: {
				product_name: {
					required: "<?php echo @Lib_Lang::translate(admin_required); ?>"
				},
				product_price: {
					required: "<?php echo @Lib_Lang::translate(admin_required); ?>"
				}
			}
		});	

		
	});

</script>

<div class="container">		

<?php echo $this->render('admin/menu.phtml'); ?>
<?php echo $this->render('admin/productmenu.phtml'); ?>

	
	<div class="row">
		<div class="col-xs-3 col-sm-3 col-md-3">
			<h3><?php echo @Lib_Lang::translate(admin_product_edit_top); ?><br /><small><?php echo$this->ProductInfo['product_name']; ?></small></h3>
			
		</div>
		<div class="col-xs-9 col-sm-9 col-md-9 text-right">
		</div>
	</div>

	<?php echo $this->render('admin/producteditmenu.phtml'); ?>

	

	
	<div class="row">
		<div class="col-xs-3 col-sm-3 col-md-3">
			<h3><?php echo @Lib_Lang::translate(admin_producteditbody_top_edit); ?></h3>
		</div>
		<div class="col-xs-9 col-sm-9 col-md-9 text-right">
			<a href="<?php echo @$this->url(array('controller' => 'admin', 'action' => 'producteditbody', 'id' => $this->ProductInfo['product_id']), 'default', true); ?>" class="btn btn-default btn-sm"><i class='fa fa-edit'></i> <?php echo @Lib_Lang::translate(admin_producteditelement_menu_list); ?></a>
			<a href="<?php echo @$this->url(array('controller' => 'admin', 'action' => 'producteditbodyadd', 'id' => $this->ProductInfo['product_id']), 'default', true); ?>" class="btn btn-default btn-sm"><i class='fa fa-plus'></i> <?php echo @Lib_Lang::translate(admin_producteditelement_menu_add); ?></a>
		</div>
	</div>	
	
	
	
	
	
	
	

		
	<form id="formAdd" method="post" class="form-horizontal">
	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_name); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input maxlength="100" name="product_name" class="form-control" value="<?php echo$this->rowElement['product_body_name']; ?>" /></div>
	</div>

	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_code); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input maxlength="100" name="product_code" class="form-control" value="<?php echo$this->rowElement['product_body_code']; ?>" /></div>
	</div>

	
	
	
	
	
	
	

<script type="text/javascript" language="javascript">

	$(document).ready(function () {
	
		<?php if( $this->rowElement['product_body_typebody'] == 1 ){ ?>
			$('#typebody').hide();
		<?php }else{ ?>
			$('#typebody').show();		
		<?php } ?>
	
		$('[name="product_typebody"]').change(function(){
			if( $(this).val() == 1 ) $('#typebody').hide();
			else $('#typebody').show();		
		});
	
	});

</script>
	
	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_typebody); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8">
			
			<select name="product_typebody" class="form-control">
				<option value="0" <?php if( $this->rowElement['product_body_typebody'] == 0 )echo'selected'; ?>><?php echo @Lib_Lang::translate(option_body_typebody_0); ?></option>
				<option value="1" <?php if( $this->rowElement['product_body_typebody'] == 1 )echo'selected'; ?>><?php echo @Lib_Lang::translate(option_body_typebody_1); ?></option>
			</select>
		
		</div>
	</div>

	
	
	
	<div id="typebody">
	
	
	

<script type="text/javascript" language="javascript">

$(document).ready(function () {
});

</script>	
	
		<div class="row">
			<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_type); ?></div>
			<div class="col-xs-12 col-sm-8 col-md-8">
				
				<select name="product_type" class="form-control">
				
				<?php foreach ($this->dataTableMapFiltrBody as $key => $val): ?>
					<option value="<?php echo$val['map_filtr_body_index']; ?>" filtrlist="<?php echo Lib_Product::mapbody($val); ?>" <?php if( $this->rowElement['product_body_type'] == $val['map_filtr_body_index'] )echo'selected'; ?>><?php echo @Lib_Lang::translate(option_body_type_.$val['map_filtr_body_index']); ?></option>
				<?php endforeach; ?>
					
				</select>
			
			</div>
		</div>
	
	
	
	
		<div class="row">
			<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"></div>
			<div class="col-xs-12 col-sm-8 col-md-8">				
				
				<?php for( $i=1; $i<=8; $i++ ){ ?>

				<div id="filtrE<?php echo$i; ?>" class="filtrE">
				<div class="col-xs-3 col-sm-3 col-md-3 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_option.$i); ?></div>
				<div class="col-xs-3 col-sm-3 col-md-3">
				<select name="product_option<?php echo$i; ?>" class="optionFiltr form-control">
					<option value="0" <?php if( $this->rowElement['product_body_option'.$i] == 0 )echo'selected'; ?>><?php echo @Lib_Lang::translate(option_body_option_0); ?></option>
					<option value="1" <?php if( $this->rowElement['product_body_option'.$i] == 1 )echo'selected'; ?>><?php echo @Lib_Lang::translate(option_body_option_1); ?></option>
				</select>
				</div>
				</div>
				
				
				<?php } ?>
			
			</div>
		</div>
		
		
<script type="text/javascript" language="javascript">
	

	$(document).ready(function () {
		
		function checkFiltrProductType(){			
			$('.filtrE').hide();		
			var f = $('[name="product_type"] option:selected').attr('filtrlist');	
		//	console.log(f);
			var res = f.split(",");
			for ( i = 0; i < res.length; i++ ) {
				$('#filtrE'+res[i]).show();
			}
		}
		
		$('[name="product_type"]').change(function(){
			checkFiltrProductType();
		});
		
		checkFiltrProductType();
		
	});

</script>
	
	
	
	</div>
	
	
	
	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_image); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input type="file" name="image_product" class="form-control fileInput" />
		
		<div id="message" style="padding-top:8px;padding-bottom:8px;display:none;"></div>
		<div class="row" id="finishPhoto"></div>
		</div>
	</div>
	
	

				
<script type="text/javascript" language="javascript">
	
$(document).ready(function () {

	<?php if( $this->rowElement['product_body_image'] ){ ?>
	$("#message").html('<?php echo @Lib_Lang::translate(admin_category_image_upload); ?>');
	$("#message").css({'display':'block'});
	$("#finishPhoto").load("<?php echo $this->url(array('controller' => 'admin', 'action' => 'producteditbodyphoto'), 'default', true); ?>",{filename: '<?php echo$this->rowElement['product_body_image']; ?>'}, function(){$("#message").css({'display':'none'});$("#message").html('');});
	<?php } ?>

	$("[name='image_product']").change(function() {
		var file = this.files[0];
		var imagefile = file.type;
		var imagename = file.name;
		var imagesize = file.size;
		
		if(imagesize > 1024*1024){
			alertify.error("<i class='fa fa-close'></i> <?php echo @Lib_Lang::translate(admin_product_image_maxsize); ?>");
		}else if( imagefile != 'image/jpeg' && imagefile != 'image/jpg' && imagefile != 'image/gif' && imagefile != 'image/png' ){
			alertify.error("<i class='fa fa-close'></i> <?php echo @Lib_Lang::translate(admin_product_image_errorfile); ?>");
		}else{
			$("#finishPhoto").html('');
			$("#message").html('<?php echo @Lib_Lang::translate(admin_product_image_upload); ?>');
			$("#message").css({'display':'block'});
			$("input").attr('disabled','disabled');
			var reader = new FileReader();
			reader.onload = function(){
			  var dataURL = reader.result;
			  
				$.ajax({
					url: "<?php echo $this->url(array('controller' => 'admin', 'action' => 'producteditbodyaddphoto'), 'default', true); ?>", 
					type: "POST",  
					data: {'image_product':dataURL.replace(/^data:image\/(gif|png|jpg|jpeg);base64,/, "")},     
					success: function(data)  
					{
						var control = $("[name='image_product']");
						control.replaceWith( control = control.clone( true ) );
						$("input").removeAttr('disabled');
						$("#message").css({'display':'none'});
						$("#message").html('');
						$("#finishPhoto").html(data);
					}
				});
				
			};
			reader.readAsDataURL(this.files[0]);
		}
		
		
	});
	
	
	
});

</script>

	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_productelement_pricem2); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input type="number" step="0.01" name="product_price" class="form-control" value="<?php echo$this->rowElement['product_body_price']; ?>" /></div>
	</div>
	
	
	
	



	
	<div class="row">
		<div class="col-xs-3 col-sm-3 col-md-3">
			<h3><?php echo @Lib_Lang::translate(admin_category_edit_top_translate); ?></h3>
		</div>
		<div class="col-xs-9 col-sm-9 col-md-9 text-right">
		</div>
	</div>	
	
	
	<?php foreach ($this->dataLang as $key => $val):?>
	<div class="row">
	
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><u><b><?php echo $val['lang_name']; ?></b></u></div>
		<div class="col-xs-12 col-sm-8 col-md-8"></div>
		
	</div>
	<div class="row">
	
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_element_name); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input maxlength="100" name="product_name_translate[<?php echo $val['lang_suffix']; ?>]" class="form-control" value="<?php echo $val['language_value']; ?>" /></div>
		
	</div>
	<div class="row">
	
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_element_description); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><textarea maxlength="500" name="product_description_translate[<?php echo $val['lang_suffix']; ?>]" class="form-control"><?php echo $val['language_value_2']; ?></textarea></div>
		
	</div>
	<div class="row"><hr /></div>
	<?php endforeach; ?>
	
	
	
	
	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right"></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input name="admin_add" class="btn btn-info form-control" type="submit" value="<?php echo @Lib_Lang::translate(admin_product_addelement_button); ?>" /></div>
	</div>
	
	</form>	
		
	
	
	
	

	
		
	<div class="row"><hr /></div>
	
</div>

<?php echo $this->render('admin/footer.phtml'); ?>