<?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 * FROM pedidos WHERE pedidos.id = '$id'";

	$resultado = $mysqli->query($sql);
	$row = $resultado->fetch_array(MYSQLI_ASSOC);
    //print_r ($row);
    $idx = $row['nr_company'];
    // 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);
    
	$sql3 = "SELECT companies.popular_name from companies WHERE companies.id = '$idx'";
	$resultado3 = $mysqli->query($sql3);
	$row3 = $resultado3->fetch_array(MYSQLI_ASSOC);
    
    require_once('functions.php');
	include(HEADER_TEMPLATE);
?>

			<div class="row">
				<h3 style="text-align:center">Editando largura do tecido</h3>
			</div>
			
   			<form method="POST" action="pedido_update_tamanho_tecido.php" autocomplete="off">
				
				<input type="hidden" id="id" name="id" value="<?php echo $row['id']; ?>" />
                <input type="hidden" id="type" name="type" value="O" />
                <input type="hidden" id="ativo" name="ativo" value="1" />
                <input type="hidden" id="nr_company" name="nr_company" value="<?php echo $row['nr_company']; ?>" />
                
                <div class="row">

                    <div class="form-group col-md-2">
                        <label for="dtcadastro">Data de Cadastro</label>
                        <input type="date" class="form-control" name="dtcadastro" id="dtcadastro" value="<?php echo $row['dtcadastro'] ?>" readonly="readonly">
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="id_piloto">LACRE</label>
                        <input type="number" class="form-control" id="id_piloto" name="id_piloto" value="<?php echo $row['id_piloto'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-2">
                        <label for="nr_pedido">Nr Pedido</label>
                        <input type="number" class="form-control" id="nr_pedido" name="nr_pedido" value="<?php echo $row['nr_pedido'] ?>" readonly="readonly" >
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="revista">Revista</label>
                        <input type="text" class="form-control" id="revista" name="revista" value="<?php echo $row['revista'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-2">
                            <label for="pop_name">Cliente</label>
                            <input type="text" class="form-control" name="popular_name" id="popular_name" value="<?php echo $row3['popular_name']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Cliente selecionado no Piloto">
                    </div>
                    
                </div>

                <div class="row">
                   
                    <div class="form-group col-md-2">
                        <label for="referencia">Referência</label>
                        <input type="text" class="form-control" id="referencia" name="referencia" value="<?php echo $row['referencia'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-2">
                      <label for="model">Modelo</label>
                      
                      <?php if ($row['id_piloto'] == 0) : ?>   
                        <input type="text" class="form-control" id="model" name="model" placeholder="Model" value="<?php echo $row['modelo']; ?>" readonly="readonly">                      
                      <?php else : ?>  
                        <input type="text" class="form-control" id="model" name="model" placeholder="Model" value="<?php echo $row['modelo']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Modelo informado no Piloto">                      
                      <?php endif ?> 
                      
                    </div>

                    <div class="form-group col-md-2">
                      <label for="modelagem">Modelagem</label>
                      
                      <?php if ($row['id_piloto'] == 0) : ?>   
                        <input type="text" class="form-control" id="modelagem" name="modelagem" placeholder="Modelagem" value="<?php echo $row['modelagem']; ?>" readonly="readonly">                      
                      <?php else : ?>  
                        <input type="text" class="form-control" id="modelagem" name="modelagem" placeholder="Modelagem" value="<?php echo $row['modelagem']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Modelagem informada no Piloto">                      
                      <?php endif ?>
                      
                    </div>

                    <div class="form-group col-md-2">
                        <label for="tecido">Tecido</label>
                        <input type="text" class="form-control" id="tecido" name="tecido" placeholder="tecido" value="<?php echo $row['tecido'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-2">
                        <label for="tamanho">Largura</label>
                        <input type="number"  step="0.01" class="form-control" id="tamanho" name="tamanho" placeholder="999,99" value="<?php echo $row['tamanho'] ?>" style='text-transform:uppercase' required autofocus>
                    </div>

                    </div>

                <div class="row">
                    <div class="form-group col-md-2">
                        <label for="data_pre">Data Pré</label>
                        <input type="date" class="form-control" id="data_pre" name="data_pre" value="<?php echo $row['data_pre'] ?>" readonly="readonly">
                    </div>                        
                
                    <div class="form-group col-md-2">
                      <label for="dtpedido">Data do Pedido</label>
                        <input type="date" class="form-control" id="data_pedido" name="data_pedido" value="<?php echo $row['data_pedido'] ?>" readonly="readonly">                          
                    </div>
                    
                    <div class="form-group col-md-2">
                      <label for="dtentrega">Data da Entrega</label>
                        <input type="date" class="form-control" id="data_entrega" name="data_entrega" value="<?php echo $row['data_entrega'] ?>" readonly="readonly">                          
                    </div>
                                   
                </div>
                
                <div class="row">
                
                    <div class="form-group col-sm-12 control-label">
                        <label for="obs">Observações do PEDIDO</label>
                        <div class="">
                            <textarea name="obs" class="form-control" rows="4" 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="javascript:window.history.go(-1)" class="btn btn-primary">Voltar</a>
                            <button type="submit" class="btn btn-primary">Registra tamanho do tecido</button>
                        </div>
                    </div>
                </div>
            </form>
		</div>
    <?php include(FOOTER_TEMPLATE); ?>        
