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


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

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

</script>

<div class="container">		

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


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

	$(document).ready(function () {	

		$('#formAddCategory').validate({
			errorClass: "formError",
			errorElement: "div",
			rules: {
				product_name: {
					required: true
				},
				product_code: {
					required: true
				},
				image_product: {
					required: false
				}
			},
			messages: {
				product_name: {
					required: "<?php echo @Lib_Lang::translate(admin_product_required); ?>"
				},
				product_code: {
					required: "<?php echo @Lib_Lang::translate(admin_product_required); ?>"
				}
			}
		});	
	
		$('[name="admin_addproduct"]').click(function(){
			if( $('#category_id3').val() == 0 ){
				alertify.error("<i class='fa fa-close'></i> <?php echo @Lib_Lang::translate(admin_product_category_selecterr); ?>");
				return false;
			}else{
				return true;
			}
		});
	
	
	});

</script>

	
	<div class="row">
		<div class="col-xs-3 col-sm-3 col-md-3">
			<h3><?php echo @Lib_Lang::translate(admin_product_add_top); ?></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' => 'shop'), 'default', true); ?>" class="btn btn-default btn-sm"><i class='fa fa-th'></i> <?php echo @Lib_Lang::translate(admin_product_menu_list); ?></a>
		</div>
	</div>


		
	<form id="formAddCategory" 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_product_name); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input maxlength="100" name="product_name" class="form-control" /></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_product_code); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input maxlength="100" name="product_code" class="form-control" /></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_product_image_main); ?></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 () {

	$("[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' => 'productaddphoto'), '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>


	
	
	
	
	
	
	
	
<?php
	for( $i = 1; $i <= 8; $i++ ){
?>	
	<div class="row">
		<div class="col-xs-12 col-sm-4 col-md-4 text-right formLabelMarginTop"><?php echo @Lib_Lang::translate(admin_product_image); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8"><input type="file" name="image_product_<?php echo$i; ?>" class="form-control fileInput" />
		
		<div id="message_<?php echo$i; ?>" style="padding-top:8px;padding-bottom:8px;display:none;"></div>
		<div class="row" id="finishPhoto_<?php echo$i; ?>"></div>
		</div>
	</div>
	
	

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

	$("[name='image_product_<?php echo$i; ?>']").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_<?php echo$i; ?>").html('');
			$("#message_<?php echo$i; ?>").html('<?php echo @Lib_Lang::translate(admin_product_image_upload); ?>');
			$("#message_<?php echo$i; ?>").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' => 'productaddphoto2', 'num' => $i), 'default', true); ?>", 
					type: "POST",  
					data: {'image_product_<?php echo$i; ?>':dataURL.replace(/^data:image\/(gif|png|jpg|jpeg);base64,/, "")},     
					success: function(data)  
					{
						var control = $("[name='image_product_<?php echo$i; ?>']");
						control.replaceWith( control = control.clone( true ) );
						$("input").removeAttr('disabled');
						$("#message_<?php echo$i; ?>").css({'display':'none'});
						$("#message_<?php echo$i; ?>").html('');
						$("#finishPhoto_<?php echo$i; ?>").html(data);
					}
				});
				
			};
			reader.readAsDataURL(this.files[0]);
		}
		
		
	});
	
	
	
});

</script>

<?php
	}
?>	


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

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

	$("[name='image_product_2']").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_2").html('');
			$("#message_2").html('<?php echo @Lib_Lang::translate(admin_product_image_upload); ?>');
			$("#message_2").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' => 'productaddphoto2'), 'default', true); ?>", 
					type: "POST",  
					data: {'image_product_2':dataURL.replace(/^data:image\/(gif|png|jpg|jpeg);base64,/, "")},     
					success: function(data)  
					{
						var control = $("[name='image_product_2']");
						control.replaceWith( control = control.clone( true ) );
						$("input").removeAttr('disabled');
						$("#message_2").css({'display':'none'});
						$("#message_2").html('');
						$("#finishPhoto_2").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_product_parent); ?></div>
		<div class="col-xs-12 col-sm-8 col-md-8">
	
<script type="text/javascript" language="javascript">

	$(document).ready(function () {			
	
		$( "#categoryBox0" ).load( "<?php echo $this->url(array('controller' => 'admin', 'action' => 'productaddcategory'), 'default', true); ?>", {category_id: 0, category_type: 3}, function(){} );

		
	});
	
</script>
	
			<div id="categoryBox0"></div>	
			<input type="hidden" name="category_id3" id="category_id3" value="0" />
		



		</div>
	</div>

	
	<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_addproduct" class="btn btn-info form-control" type="submit" value="<?php echo @Lib_Lang::translate(admin_product_add_button); ?>" /></div>
	</div>
	
	</form>	
		
</div>

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