    <?php
    session_start();
    require_once 'gerador/MysqlConsulta.php';
    require_once 'script_php/conexao.php';

    if(isset($_GET['importarAvaria'])){
    $importarAvaria = $_GET['importarAvaria'];
    }

    $MysqlConsulta = new MysqlConsulta();

    ?>

    <!DOCTYPE html>
    <html>
    <head>

    <?php include_once 'head.html' ?>

    <title></title>
    </head>

    <body>

    <?php include_once 'headerSEMLOAD.php'; ?>


    <h4>
    <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-clouds" viewBox="0 0 16 16">
  <path d="M16 7.5a2.5 2.5 0 0 1-1.456 2.272 3.5 3.5 0 0 0-.65-.824 1.5 1.5 0 0 0-.789-2.896.5.5 0 0 1-.627-.421 3 3 0 0 0-5.22-1.625 5.6 5.6 0 0 0-1.276.088 4.002 4.002 0 0 1 7.392.91A2.5 2.5 0 0 1 16 7.5"/>
  <path d="M7 5a4.5 4.5 0 0 1 4.473 4h.027a2.5 2.5 0 0 1 0 5H3a3 3 0 0 1-.247-5.99A4.5 4.5 0 0 1 7 5m3.5 4.5a3.5 3.5 0 0 0-6.89-.873.5.5 0 0 1-.51.375A2 2 0 1 0 3 13h8.5a1.5 1.5 0 1 0-.376-2.953.5.5 0 0 1-.624-.492z"/>
</svg>    
    
    ÁREA DE ARQUIVOS </h4>

    <div class='upload tabelaindex'>

 
    <p></p>
    
    <h5 class="margem-enviar"> Faça upload  de arquivo preenchendo o formulário a seguir </h5>
    

    <form action="script_php/upload.php" method="POST" enctype="multipart/form-data">

    <input type="text" class="form-control" name="descricao" placeholder="NOME DO ARQUIVO" autofocus="" required><p>
        
        <p></p>

        <span class="margem-enviar"> Tipo de visibilidade </span>

           <?php if(!isset($importarAvaria)){ ?>

        <select name="visao" id="" class="form-control">
            <option value="privado">PRIVADO</option>
            <option value="publico">PUBLICO</option>
        </select>
<?php }else{?>

    <input type="hidden" name="visao" value="publico" >
    <input type="hidden" name="avaria" value="<?=$importarAvaria?>">
    <?php }?>

               <input type="file" name="file" id="file" class="form-control " required>
        
         <input type="submit" value='ENVIAR ARQUIVO' class="form-control margem-enviar btn btn-warning">
    </form>

    </div>



<?php if(!isset($importarAvaria)){ ?>

    <h5 > Lista de arquivos </h5>
    <p></p>

    <table border="1" class="table float table-striped">
            <tr class="pedidoscbc table-dark " >
                <td>ID</td>
                <td>DATA CRIAÇÃO</td>
                <td>NOME</td>
                <td align='center'>VISIBILIDADE</td>

                <td>PROPRIETÁRIO</td>
                <td>ARQUIVO</td>
                <td>BAIXAR</td>
                <td>EXCLUIR</td>
<tr>
<?php

$dados = $MysqlConsulta->listaDeArquivos($conexao);

$usuario = $_SESSION['usuario'];

foreach($dados as $dado){

    if(($usuario == $dado['usuario']) OR ($dado['visibilidade'] == 'publico')){

        $data_formatada = date('d/m/Y H:i:s', strtotime($dado['datacriacao']));
?>
            <tr>
                <td><?php echo $dado['id'] ?></td>
                <td><?php echo $data_formatada; ?></td>              
                <td><?php echo $dado['descricao'] ?></td>

                <td align='center'>
  
                
                    <?php if ($dado['visibilidade']  == 'publico'){ ?>
      
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-people-fill text-danger" viewBox="0 0 16 16">
                        <path d="M7 14s-1 0-1-1 1-4 5-4 5 3 5 4-1 1-1 1zm4-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6m-5.784 6A2.24 2.24 0 0 1 5 13c0-1.355.68-2.75 1.936-3.72A6.3 6.3 0 0 0 5 9c-4 0-5 3-5 4s1 1 1 1zM4.5 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5"/>
                        </svg>

                    <?php }else{ ?>
                        
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
                         <path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/>
                        </svg>

                    <?php } ?>

                </td>
                
            
<td><?php echo $dado['usuario'] ?></td>
<td ><?php echo $dado['nomearquivo'] ?></td>

<td>
    <a href="..\..\uploads\<?=$dado['nomearquivo']?>" target="black">
    <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="text-info bi bi-cloud-arrow-down-fill" viewBox="0 0 16 16">
        <path d="M8 2a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 6.095 0 7.555 0 9.318 0 11.366 1.708 13 3.781 13h8.906C14.502 13 16 11.57 16 9.773c0-1.636-1.242-2.969-2.834-3.194C12.923 3.999 10.69 2 8 2m2.354 6.854-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 9.293V5.5a.5.5 0 0 1 1 0v3.793l1.146-1.147a.5.5 0 0 1 .708.708"/>
    </svg>
    </a>
</td>

<td>

<?php  if($usuario == $dado['usuario']){ ?>

<a href="script_php/exluirArquivo.php?nomearquivo=<?=$dado['nomearquivo']?>&id=<?=$dado['id']?>" onclick="return confirm('Excluir arquivo? Será excluído definitavemente')">
                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="text-danger bi bi-cloud-slash" viewBox="0 0 16 16">
  <path fill-rule="evenodd" d="M3.112 5.112a3 3 0 0 0-.17.613C1.266 6.095 0 7.555 0 9.318 0 11.366 1.708 13 3.781 13H11l-1-1H3.781C2.231 12 1 10.785 1 9.318c0-1.365 1.064-2.513 2.46-2.666l.446-.05v-.447q0-.113.018-.231zm2.55-1.45-.725-.725A5.5 5.5 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773a3.2 3.2 0 0 1-1.516 2.711l-.733-.733C14.498 11.378 15 10.626 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3c-.875 0-1.678.26-2.339.661z"/>
  <path d="m13.646 14.354-12-12 .708-.708 12 12z"/>
</svg>
    </a>

<?php }else{ ?>

    SEM PREMISSAO

<?php } ?>


                </td>

            </tr>
        
<?php } } ?>

    </table>


<?php } ?>

    <?php include_once 'footer.php' ?>