<?php
  require "login/dbconf.php";
  header ('Content-type: text/html; charset=UTF-8');
  $conn = mysqli_connect($host,$user,$password,$db_name);

  $mysqli = new mysqli($host, $user, $password, $db_name);

  if(mysqli_connect_errno()){
      die("Conexão falhou: ".mysqli_connect_errno());
  }

  $usr = $_SESSION['username'];
  
  mysqli_set_charset($conn, 'utf8');

  //Retorna do DB os dados do autor logado
  $query = "SELECT `email`,`tel1`,`username`,`fullname` FROM members WHERE username = '$usr'";

  $data = mysqli_query($conn,$query);

  while($linhaAutor = mysqli_fetch_assoc($data)){
    $dadosAutor[] = $linhaAutor;
  }

  $nome = '';
  $cpf = '';
  $email = '';
  $tel = '';

  foreach($dadosAutor as $item){
    $nome = $item['fullname'];
    $email = $item['email'];
    $cpf = $item['username'];
    $tel = $item['tel1'];
  }

  //var_dump($nome);
  //-----------------------

  //Retorna do DB todos os artigos
  $sql = "SELECT * FROM myblob WHERE user = '$usr'";

  $result = mysqli_query($conn,$sql);

  echo '<div style="display: flex; flex-wrap: wrap; justify-content:space-between; align-items:strech; flex-direction: column;">';
  
  while($linha = mysqli_fetch_assoc($result)){
    $items[] = $linha;
  }

  $items = array_reverse($items, true);

  foreach($items as $row){

    echo "<div class='rounded' style='background-color: white; border: 2px solid #0779e4; border-radius: 35px !important; margin-bottom: 10px; padding:20px; width: 90%'>";
    $autores = "";
    if($row['user'] == $_SESSION['username']){

      echo "<h1 style='font-size: 19px'>".$row['nome_artigo']."</h1>";
      
      for($i = 1; $i <= 15; $i++){        
        
        $autores .= $row['autor'.$i].", ";        
        
      }
      $autores = rtrim($autores,", ");      
      echo "<p>Autores: ".$autores."</p>";
      echo '<div id="steps-container">
        
        <div id="steps">
          <h1 style="font-size: 17px;">Status da publicação</h1>

          <div class="step done" data-desc="Aguardando pagamento">1</div>

          <div class="step active" data-desc="Pagamento Aprovado">2</div>
          
          <div class="step" data-desc="Em conferência">3</div>

            <div class="step" data-desc="Em edição">4</div>

            <div class="step" data-desc="Publicado">5</div>
          
        </div>
      ';
      echo '
      <div id="steps">        
        <h1 style="font-size: 17px;">Status da publicação</h1>

        
        </div>
      </div>
    ';

      echo "<div style='display: flex; flex-direction: row !important;'><form style='margin-right: 5px;' action='pagseguro_combanco/checkout.php' method='POST'>
            
            <input type='hidden' name='idArt' value=".$row['id']."></input>
            <input type='hidden' name='nome' value=".$nome."></input>
            <input type='hidden' name='cpf' value=".$cpf."></input>
            <input type='hidden' name='tel' value=".$tel."></input>
            <input type='hidden' name='email' value=".$email."></input>
            <button type='submit' class='btn btn-primary'>Pagar</button>
          </form></br>
          <form action='alterarform.php' method='POST'><td style='border: 2px solid #fff; padding: 15px;	border-collapse: collapse;'>
            <input type='hidden' name='idArt' value=".$row['id']."></input>
            <button type='submit' class='btn btn-primary'>Alterar</button>
          </form></div>";
      echo "</div>";   
    } 
    
  }

  echo "</div>";

  mysqli_close($conn);
?>
