<?php
    session_start();
	ob_start();

	$id_users = isset($_SESSION['id_users']) ? $_SESSION['id_users']: "";	
	$nome_user = isset($_SESSION['nome']) ? $_SESSION['nome']: "";	
	$email_users = isset($_SESSION['email']) ? $_SESSION['email']: "";	
	$pass_users = isset($_SESSION['pass']) ? $_SESSION['pass']: "";	
	$logado = isset($_SESSION['logado']) ? $_SESSION['logado']: "N";	

	if ($logado == "N" && $id_users == ""){	    
		echo  "<script type='text/javascript'>
					location.href='login.php'
				</script>";	
		exit();
	}

    require 'conexion.php';
    require_once('functions.php');
	include(HEADER_TEMPLATE); 
    
    // seleciona registros para a caixa de selecao de clientes    
    $query_clientes = "SELECT id, popular_name FROM companies WHERE type = 'C' and ativo = '1' ORDER BY popular_name";
	$resultado_clientes=$mysqli->query($query_clientes);

    $query_tecidos = "SELECT * from tecidos ORDER BY tecido";
	$resultado_tecidos=$mysqli->query($query_tecidos);	

?>

            <div class="row">
				<h3 style="text-align:center">PILOTO</h3>
			</div>

			<br>
			
			<form method="POST" action="piloto_grava.php" autocomplete="off">
			
				<input type="hidden" id="id" name="id" value="<?php echo $row['id']; ?>" />
                <input type="hidden" id="type" name="type" value="P" />			
                <input type="hidden" id="nr_company" name="nr_company" value="P"/>			
                <input type="hidden" id="ativo" name="ativo" value="1" />		
                
                <div class="row">
                                          
                    <div class="form-group col-md-2">
                        <label for="stdate">Data de Cadastro</label>
                        <input type="date" class="form-control" name="stdate" id="stdate" value="<?php echo date("Y-m-d") ?>" >
                    </div>
					
                    <div class="form-group col-md-1">
                        <label for="lacre">Lacre</label>
                        <input type="text" onkeyup="somenteNumeros(this);" class="form-control" id="lacre" name="lacre">
                    </div>  
                    
                    <div class="form-group col-md-7">
                        <label for="nr_company">Seleciona cliente</label>
                        <select class="form-control" id="nr_company" name="nr_company" required autofocus>
                            <option value="0">Lista dos cliente</option>
                            <?php
                             $resultado_clientes2=$mysqli->query($query_clientes);
                             while($row2 = $resultado_clientes2->fetch_assoc()) { ?>
                                <option value="<?php echo $row2['id']; ?>"><?php echo $row2['popular_name']; ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="reference">Referência</label>
                        <input type="text" class="form-control" id="reference" name="reference" placeholder="Referência" style='text-transform:uppercase'>
                    </div>                        

                </div>

                <div class="row">
                   
                    <div class="form-group col-md-2">
                      <label for="model">Modelo</label>
                        <input type="text" class="form-control" id="model" name="model" placeholder="Modelo" style='text-transform:uppercase'>                      
                    </div>

                    <div class="form-group col-md-2">
                      <label for="modelagem">Modelagem</label>
                        <input type="text" class="form-control" id="modelagem" name="modelagem" placeholder="Modelagem" style='text-transform:uppercase'>                      
                    </div>

                    <div class="form-group col-md-4">
                        <label for="tecido">Selecione Tecido</label>
                        <select class="form-control" id="tecido" name="tecido"  required>
                            <option value="0">Lista tecidos da tabela tecidos</option>
                            <?php
                             $resultado_tecidos=$mysqli->query($query_tecidos);
                             while($row2 = $resultado_tecidos->fetch_assoc()) { ?>
                                <option value="<?php echo $row2['id_tecido']; ?> - <?php echo $row2['tecido']; ?> - <?php echo $row2['composicao']; ?>"><?php echo $row2['id_tecido']; ?> - <?php echo $row2['tecido']; ?> - <?php echo $row2['fornecedor']; ?> - <?php echo $row2['composicao']; ?> - <?php echo $row2['cor']; ?></option>
                            <?php } ?>
                        </select>
                    </div>

                    <div class="form-group col-md-2">
                        <label for="colors">Cores</label>
                        <input type="text" class="form-control" id="colors" name="colors" placeholder="Cores" style='text-transform:uppercase'>
                    </div>

                    <div class="form-group col-md-2">
                        <label for="linha">Linha</label>
                        <input type="text" class="form-control" id="linha" name="linha" placeholder="Linha" style='text-transform:uppercase'>
                    </div>
                    
                    
                </div> 
                <div class="row">
                    <div class="form-group col-md-2">
                        <label for="values">Cintura</label>
                        <input type="number" step="1" class="form-control" id="cintura" name="cintura">
                    </div>
                    <div class="form-group col-md-2">
                        <label for="valued">Tamanho</label>
                        <input type="number" step="1" class="form-control" id="tamanhoPiloto" name="tamanhoPiloto">
                    </div>					
                    <div class="form-group col-md-2">
                      <label for="dlvdate">Data de Entrega</label>
                        <input type="date" class="form-control" id="dlvdate" name="dlvdate">                      
                    </div>
                   
                    <div class="form-group col-md-2">
                        <label for="approvedby">Aprovado por</label>
                        <input type="text" class="form-control" id="approvedby" name="approvedby" value="<?php echo $nome_user;?>" readonly="readonly">
                    </div>
                    
                    <div class="form-group col-md-2">
                      <label for="dtapproved">Data da Aprovação</label>
                        <input type="date" class="form-control" id="dtapproved" name="dtapproved" value="<?php echo date("Y-m-d") ?>">                          
                    </div>

                    <div class="form-group col-md-2">
                        <label for="value">Valor</label>
                        <input type="number" step="0.01" class="form-control" id="value" name="value">
                    </div>
                    
                </div>

                <div class="row">

                    <div class="form-group col-sm-12 control-label">
                        <label for="obs">Observações do PILOTO</label>
                        <div class="">
                            <textarea name="obs" class="form-control" rows="4" cols="70" style='text-transform:uppercase'></textarea>
                        </div>
                    </div>

                </div>
                
                <div class="row">                
                    <div class="form-group">
                        <div class="col-xs-6 col-xs-offset-3 col-sm-4 col-sm-offset-0">
                            <a href="piloto_index.php" class="btn btn-primary">Voltar</a>
                            <button type="submit" class="btn btn-primary">Gravar Registro</button>
                        </div>
                    </div>
                </div>
            </form>
		</div>
<?php include(FOOTER_TEMPLATE); ?>        
 <script>
    function somenteNumeros(num) {
        var er = /[^0-9.]/;
        er.lastIndex = 0;
        var campo = num;
        if (er.test(campo.value)) {
          campo.value = "";
        }
    }
 </script>
