<?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';
	
	$id = $_GET['id'];
	
    // seleciona todos os registros da base com inner join cliente 
	$sql = "SELECT ordem_corte.id_oc, pilotos.*, companies.popular_name FROM `companies` INNER JOIN pilotos ON companies.id = pilotos.nr_company LEFT JOIN ordem_corte ON pilotos.id_pedido = ordem_corte.id_pedido WHERE pilotos.id = '$id'";
	$resultado = $mysqli->query($sql);
	$row = $resultado->fetch_array(MYSQLI_ASSOC);
	//print_r($row);

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

			<div class="row">
				<h3 style="text-align:center">Piloto</h3>
			</div>
			
   			<form method="POST" action="piloto_modificar.php" autocomplete="off">
				
				<input type="hidden" id="id" name="id" value="<?php echo $row['id']; ?>" />
                <input type="hidden" id="type" name="type" value="P" />			
                
                <div class="row">
                    <div class="form-group col-md-1">
                        <label for="lacre">Lacre</label>
                        <input type="text" class="form-control" id="lacre" name="lacre" value="<?php echo $row['lacre']; ?>" readonly="readonly">
                    </div>                        

                    <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 $row['stdate'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-5">
                      <label for="dlvdate">Cliente</label>
                        <input type="text" class="form-control" id="nr_company" name="nr_company" value="<?php echo $row['popular_name']; ?>" readonly="readonly">                      
                    </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="Informe a referência" value="<?php echo $row['reference']; ?>" readonly="readonly">
                    </div>                        

                    <div class="form-group col-md-2">
                      <label for="modelagem">Modelagem</label>
                        <input type="text" class="form-control" id="modelagem" name="modelagem" value="<?php echo $row['modelagem']; ?>" readonly="readonly">                      
                    </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" value="<?php echo $row['model']; ?>" readonly="readonly">                      
                    </div>
				
                    <div class="form-group col-md-4">
                        <label for="tecido">Tecido</label>
                        <input type="text" class="form-control" id="tecido" name="tecido" value="<?php echo $row['tecido']; ?>" readonly="readonly">                      
                    </div>

                    <div class="form-group col-md-3">
                        <label for="colors">Cores</label>
                        <input type="text" class="form-control" id="colors" name="colors" value="<?php echo $row['colors']; ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-3">
                        <label for="linha">Linha</label>
                        <input type="text" class="form-control" id="linha" name="linha" value="<?php echo $row['linha']; ?>" readonly="readonly">
                    </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" value="<?php echo $row['cintura']; ?>" readonly="readonly">
                    </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" value="<?php echo $row['tamanhoPiloto']; ?>" readonly="readonly">
                    </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" value="<?php echo $row['dlvdate']; ?>" readonly="readonly">                      
                    </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 $row['approvedby']; ?>" 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 $row['dtapproved']; ?>" readonly="readonly">                          
                    </div>

                    <div class="form-group col-md-2">
                        <label for="value">Valor</label>
                        <input type="text" class="form-control" id="value" name="value" value="<?php echo $row['value']; ?>" readonly="readonly">
                    </div>
                    <div class="form-group col-md-2">
                        <label for="ativo">Piloto ATIVO?</label>
                        
                        <div class="form-group">
                            
                            <label class="radio-inline  col-md-3">
                                <input type="text" id="ativo" name="ativo" value="<?php echo $row['ativo']; ?>" readonly="readonly">
                            </label>
                        </div> 
                    </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" readonly="readonly"><?php echo $row['obs']?></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>
                            <?php if ($row['id_oc'] == 0): ?>
                                 <button type="submit" class="btn btn-primary">Editar dados</button>
                            <?php endif ?>
                        </div>
                    </div>
                </div>
            </form>
		</div>
    <?php include(FOOTER_TEMPLATE); ?>        