<?php
    session_start();
	ob_start();
	//resgata os valores das session em variaveis
	$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";	
	//varificamos e a var logado contém o valos (S) OU (N), se conter N quer dizer que a pessoa não fez o login corretamente
	//que no caso satisfará nossa condição no if e a pessoa sera redirecionada para a tela de login novamente
	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);
	$id = $_GET['id'];
	
	$sql = "SELECT * FROM companies WHERE id = '$id'";
	$resultado = $mysqli->query($sql);
	$row = $resultado->fetch_array(MYSQLI_ASSOC);
    
    $query_artigos = "SELECT materiais.material FROM materiais";
	$resultado_artigos=$mysqli->query($query_artigos);

    $cidades = "SELECT nome FROM tb_cidades order by nome";
    $estados = "SELECT uf FROM tb_estados";

?>
        <form method="POST" action="companies_modificar.php" autocomplete="off">
            <div class="container">  
                <div class="row">
                    <div class="form-group col-md-5">
                        <label for="tp"></label>
                        <div class="form-group">
                            <label class="radio-inline  col-md-2">
                                <input type="radio" id="type" name="type" value="C" <?php if($row['type']=='C') echo 'checked'; ?> disabled> CLIENTE
                            </label>
                            
                            <label class="radio-inline">
                                <input type="radio" id="type" name="type" value="F" <?php if($row['type']=='F') echo 'checked'; ?> disabled> FORNECEDOR
                            </label>
                        </div>                
                    </div>        
                </div>
                <div class="row">

                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="company" name="company" placeholder="Informe o nome da empresa" style='text-transform:uppercase' disabled autofocus value="<?php echo $row['company']; ?>" >
                    </div>
                        
                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="popular_name" name="popular_name" placeholder="Informe Nome Fantasia" style='text-transform:uppercase' disabled value="<?php echo $row['popular_name']; ?>" >
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="cpf_cnpj" name="cpf_cnpj" placeholder="CNPJ" disabled value="<?php echo $row['cpf_cnpj']; ?>" >
                        <script>
                            jQuery(function($){
                            $("#cpf_cnpj").mask("99.999.999/9999-99");
                            });
                        </script>
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="ie" name="ie" placeholder="Inscrição Estadual" maxlength="20" value="<?php echo $row['ie']; ?>" disabled>
                    </div>
                        
                </div>

                <div class="row">
                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="address" name="address" placeholder="Endereço principal da empresa" style='text-transform:uppercase' value="<?php echo $row['address']; ?>"required disabled>
                    </div>

                    <div class="form-group col-md-3">
                        <input type="text" class="form-control" id="city" name="city" placeholder="Cidade" style='text-transform:uppercase' value="<?php echo $row['city']; ?>"required disabled>
                    </div>

                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="hood" name="hood" placeholder="Bairro" value="<?php echo $row['hood']; ?>" disabled style='text-transform:uppercase'>
                    </div>
                    
                    <div class="form-group col-md-2">
                        <input type="text" class="form-control" id="zip_code" name="zip_code" placeholder="CEP" required disabled value="<?php echo $row['zip_code']; ?> ">
                        <script>
                            jQuery(function($){
                                $("#zip_code").mask("99999-999");
                            });
                        </script>

                        </div>
                   
                    <div class="form-group col-md-1">
                        <input type="text" class="form-control" id="state" name="state" placeholder="UF" style='text-transform:uppercase' value="<?php echo $row['state']; ?>"required disabled>
                    </div>
                </div>
                <div class="row">                

                    <div class="form-group col-md-4">
                        <input type="text" class="form-control" id="contact1" name="contact1" placeholder="Nome contato" value="<?php echo $row['contact1']; ?>" disabled style='text-transform:uppercase' disabled required>
                    </div>
                    
                    <div class="form-group col-md-4">
                        <input type="email" class="form-control" id="email1" name="email1" placeholder="Email" value="<?php echo $row['email1']; ?>" disabled style='text-transform:uppercase' >
                    </div>
                    
                    <div class="form-group col-md-2">
                        <input type="tel" class="form-control" id="phone1" name="phone1" placeholder="Fone" value="<?php echo $row['phone1']; ?>" disabled style='text-transform:uppercase' required> 
                        <script>
                            jQuery(function($){
                                $("#phone1").mask("(99)9999-9999");
                            });
                        </script>
                    </div>
                    <div class="form-group col-md-2">
                        <input type="tel" class="form-control" id="cell1" name="cell1" placeholder="celular" value="<?php echo $row['cell1']; ?>" disabled style='text-transform:uppercase'>
                        <script>
                            jQuery(function($){
                                $("#cell1").mask("(99)99999-9999");
                            });
                        </script>
                    </div>
                </div>                

                <div class="row">                
                    <div class="container">                     
                        <a href="#demo" data-toggle="collapse">contato adicional</a>                        
                    </div>
                    <div id="demo" class="collapse">
                        <div class="form-group col-md-4">
                            <input type="text" class="form-control" id="contact2" name="contact2" placeholder="Contato (opcional)" value="<?php echo $row['contact2']; ?>" disabled style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-4">
                            <input type="email" class="form-control" id="email2" name="email2" placeholder="email (opcional)" value="<?php echo $row['email2']; ?>" disabled style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="phone2" name="phone2" placeholder="telefone (opcional)" value="<?php echo $row['phone2']; ?>" disabled style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#phone2").mask("(99)9999-9999");
                                });
                            </script>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="cell2" name="cell2" placeholder="celular (opcional)" value="<?php echo $row['cell2']; ?>" disabled style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#cell2").mask("(99)99999-9999");
                                });
                            </script>

                        </div>
                        
                        <div class="container">                     
                            <a href="#demo2" data-toggle="collapse">contato adicional</a>                        
                        </div>

                    </div>
                    <div id="demo2" class="collapse">
                    
                        <div class="form-group col-md-4">
                            <input type="text" class="form-control" id="contact3" name="contact3" placeholder="Contato (opcional)" value="<?php echo $row['contact3']; ?>" disabled style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-4">
                            <input type="email" class="form-control" id="email3" name="email3" placeholder="email opcional" value="<?php echo $row['email3']; ?>" disabled style='text-transform:uppercase'>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="phone3" name="phone3" placeholder="telefone opcional" value="<?php echo $row['phone3']; ?>" disabled style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#phone3").mask("(99)9999-9999");
                                });
                            </script>
                        </div>
                        
                        <div class="form-group col-md-2">
                            <input type="tel" class="form-control" id="cell3" name="cell3" placeholder="celular opcional" value="<?php echo $row['cell3']; ?>" disabled style='text-transform:uppercase'>
                            <script>
                                jQuery(function($){
                                    $("#cell3").mask("(99)99999-9999");
                                });
                            </script>
                        </div>
                    </div>
                </div>
                <hr>
                <div class="row">                

    
                    <div class="form-group col-md-2">
                        <label for="material">Artigo</label>
                            <?php
                             $resultado2=$mysqli->query($sql);
                             while($row2 = $resultado2->fetch_assoc()) { ?>
                                <option value="<?php echo $row2['material']; ?>"><?php echo $row2['material']; ?></option>
                            <?php } ?>
                    </div>

                    <div class="form-group col-md-8">
                        <label for="obs">Observação</label>
                        <input type="text" class="form-control" id="obs" name="obs" placeholder="Observações" value="<?php echo $row['obs']; ?>" disabled style='text-transform:uppercase'>
                    </div>

                    <div class="form-group col-md-2">
                        <label for="ativo">Cliente ATIVO?</label>                        
                        <div class="form-group">                            
                            <label class="radio-inline  col-md-3">
                                <input type="radio" id="ativo" name="ativo" value="1" <?php if($row['ativo']=='1') echo 'checked'; ?> disabled> SIM
                            </label>
                            
                            <label class="radio-inline">
                                <input type="radio" id="ativo" name="ativo" value="0" <?php if($row['ativo']=='0') echo 'checked'; ?> disabled> NÃO
                        </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="companies_index.php" class="btn btn-primary">Voltar</a>
                            <a href="companies_modificar.php?id=<?php echo($id); ?>" class="btn btn-primary">Editar Dados</a>                            
                        </div>
                    </div>
                </div>
            </div>
        </form>
<?php include(FOOTER_TEMPLATE); ?>        
