<?php include ('./inc/header.php'); ?>

	<div class="container">
	
		<!-- FORMULARIO 
		–––––––––––––––––––––––––––––––––––––––––––––––––– -->
	
		<form enctype="multipart/form-data" action="<?php echo htmlspecialchars(legacy_config('routes.success_url', '')); ?>" name = "newproduct" id = "newproduct" method = "POST">
		
		<input name="pwd" type="hidden" value="<?php echo htmlspecialchars(legacy_config('security.form_password_hash', '')); ?>">
		
			<!-- CODIGO, SEO URL 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->		
			<div class="row" style = "margin-top: 20px">
				<div class="ten columns" id = "url_div">
					<span class="slug-ouput"> <b><input type ="text" name="url" value="" placeholder="SEO URL" class="u-full-width" id="slug" tabindex="-1"  /></b></span>
				</div>
				<div class="two columns">
					<a id="ia_link" href="" class="button button-primary u-full-width" target="_blank"><i class="fa fa-lightbulb-o fa-lg" aria-hidden="true"></i></a>
				</div>
			</div>

			<!-- NOMBRE DEL PRODUCTO 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->		
			<div class="row" >
				<div class="nine columns">
					<label for="slug-source">Nombre del Artículo: </label>
					<input type ="text" name="nombre" value="" class="u-full-width text-uppercase" id="slug-source" oninput="setLink()" required />
				</div>
				<div class="three columns">
					<label for="slug-source">EAN: </label>
					<input type ="text" name="ean" value="" class="u-full-width" id="ean" />
				</div>
			</div>

			<!-- CATEGORIAS, MARCA 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->	
			<div class="row">
				<div class="six columns">
					<select name="categoria" class="u-full-width" id="categoria" required >
					<option value="" selected disabled>CATEGORÍA</option>
						<?php 
							$categorias = mysqli_query($con," SELECT * FROM `oc_category`, `oc_category_description`, `oc_category_to_store` WHERE `oc_category`.`category_id` = `oc_category_description`.`category_id` AND `oc_category_description`.`category_id`= `oc_category_to_store`.`category_id` AND `oc_category_description`.`language_id` = 4 ORDER BY `oc_category_description`.`name` ASC"); 
							while ($row = mysqli_fetch_assoc($categorias))
							{
								echo '<option value="'. $row['category_id'] .'" >' . $row['name'] . ' </option>';
							}
						?>
					</select>
				</div>
				<div class="four columns newbrand">
					<select name="marca" class="u-full-width" id="marca" onchange="validateSelect(),setLink()" required>
						<option value="" selected disabled>MARCA</option>
						<?php 
							$marcas = mysqli_query($con," SELECT `oc_manufacturer`.`manufacturer_id` , `oc_manufacturer`.`name` FROM `oc_manufacturer` ORDER BY `oc_manufacturer`.`name`"); 
								while ($row = mysqli_fetch_assoc($marcas))
								{
									echo '<option value="'. $row['manufacturer_id'] .'" >' . $row['name'] . ' </option>';
								}
						?>
					</select>
				</div>
				
				<div class="two columns">
					<!-- Abre Ventana Modal -->
					<span class="button button-primary u-full-width" id="newbrand"><i class="fa fa-pencil fa-lg" aria-hidden="true"></i></span>
				</div>
			</div>

			<!-- PVP, COSTE, IVA 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->	
			<div class="row">		
				<div class="four columns">
					<label for="pvp">PVP: </label>
					<input type ="number" name="pvp" value="" class="u-full-width" id="pvp" step="any" required />
				</div> 
				<div class="four columns">
					<label for="coste">Coste: </label>
					<input type ="number" name="coste" value="" class="u-full-width" id="coste" step="any" required />
				</div> 
				<div class="four columns">
					<label for="iva">IVA: </label>
					<select name="iva" class="u-full-width" id="iva" required >
					<?php 
						$iva = mysqli_query($con," SELECT `tax_class_id` , `title` FROM `oc_tax_class` ORDER BY `title` ASC");
							while ($row = mysqli_fetch_assoc($iva))
							{
							echo '<option value="'. $row['tax_class_id'] .'" >' . substr($row['title'], 4) . ' </option>';
							}
					?>
					</select>
				</div> 
			</div>

			<!-- CANTIDAD, CADUCIDAD, PESO 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->	
			<div class="row">
				<div class="four columns">
					<label for="cantidad">Cantidad: </label>
					<input type ="number" name="cantidad" value="" class="u-full-width" id="cantidad" required>
				</div>
				<div class="four columns">
					<label for="caducidad">Caducidad: </label>
					<input type ="date" name="caducidad" value="" min="<?php echo date('Y-m-d');?>" class="u-full-width" id="caducidad" required />
				</div> 
				<div class="four columns">
					<label for="peso">Peso: </label>
					<select name="peso" class="u-full-width" id="peso" required>
						<option value="0.100">100gr</option>
						<option value="0.250" selected>250gr</option>
						<option value="0.500">500gr</option>
						<option value="0.750">750gr</option>
						<option value="1.000">1kg</option>
						<option value="1.500">1,5kg</option>
						<option value="2.000">2kg</option>
					</select>
				</div>
			</div>
			
			<!-- FIELDSET ATRIBUTOS 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->			
			<div class="row" id="atrib_zone">
				<div class="twelve columns">
					<?php include ('inc/atributos.php'); ?>
				</div>
			</div>
						
			<!-- EDITOR JS 
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->
			<div class="row" style = "margin-top: 20px">
				<div class="twelve columns">
					<textarea name="editor" id="editor" placeholder="Descripcion del producto..." class="u-full-width"></textarea>
				</div>
			</div>
			
			<!-- CARGAR IMAGEN X URL
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->
			<div class="row" style = "margin-top: 20px">
				<div class="twelve columns">
					<input type ="text" name="image_path" id="image_path" class="u-full-width" placeholder="Pegar URL de la Imagen" onchange="document.getElementById('imgElement').src = $('#image_path').val()" />
				</div>			
			</div>
			
			<!-- UPLOAD IMAGEN LOCAL
			–––––––––––––––––––––––––––––––––––––––––––––––––– -->
			<div class="row" style = "margin-top: 20px">
				<div class="four columns" id="imgPreview">
					<img id="imgElement" alt="Imagen de Producto" src="./images/nopic.png" />
				</div>
				<div class="four columns" >
					<p class="infoText">* Formatos soportados JPG y PNG</p>
					<label for="imagen" class="uploadImg">
						<i class="fa fa-cloud-upload"> </i> Cargar Imágen
					</label>
					<input type="file" class="u-full-width" name="imagen" id="imagen" onchange="document.getElementById('imgElement').src = window.URL.createObjectURL(this.files[0])">
				</div>
				<div class="four columns" >
					<button type="submit" class="button-primary u-full-width" name="submit" id="crearProducto" >Guardar Producto</button>
				</div>
			</div>	

		</form>
		
	</div>

	<!-- VENTANA MODAL 'NUEVA MARCA'
	–––––––––––––––––––––––––––––––––––––––––––––––––– -->
	<div id="marcanueva" class="modal">
		<!-- CONTENIDO VENTANA MODAL -->
		<div class="modal-content">
			<span class="close">&times;</span>
			<form enctype="multipart/form-data" action="inc/newmarca.php" method = "POST">
				<div class="row" >
					<div class="twelve columns">
						<input type ="text" name="nombreMarca" value="" class="u-full-width text-uppercase" id="nombreMarca" onfocus="this.value=''" placeholder="Nombre de la Marca" required />
					</div>
					<div class="modalfoot" >
						<button onclick="createBrand();return false" class="button button-primary u-full-width"id="guardarMarca" >Guardar</button>
						<button class="button button-primary u-full-width" id="loading" disabled><i class="fa fa-spinner fa-spin"></i> Guardando...</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	
	
<?php
	mysqli_close($con);
	include ('./inc/footer.php'); 
?>
