<?php

	include('public/functions.php');

  $qry = "SELECT * FROM tbl_mensagem";
  $result = mysqli_query($connect, $qry);

  if(!empty($_GET['excluir'])){
    Delete('tbl_mensagem',"WHERE id = '".$_GET['excluir']."' ");
    $_SESSION['msg'] = "Mensagem excluida com êxito!";
    header('Location:mensagens.php');
    exit;
  }

?>

<!-- START CONTENT -->
<section id="content">

      <!--breadcrumbs start-->
      <div id="breadcrumbs-wrapper" class=" grey lighten-3">
          <div class="container">
            <div class="row">
                <div class="col s12 m12 l12">
                  <h5 class="breadcrumbs-title">Mensagens</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Dashboard</a>
                    </li>
                    <li><a class="active">Lista de mensagens</a>
                    </li>
                  </ol>
                </div>
            </div>
          </div>
      </div>
      <!--breadcrumbs end-->

     <!--start container-->
      <div class="container">
          <div class="section">
              <div class="row">
                  <div class="col s12 m12 l12">
                      <div class="card-panel">
                        <div class="row">
                          <?php if(isset($_SESSION['msg'])) { ?>
                          <div class='card-panel teal lighten-2'>
                              <span class='white-text text-darken-2'><?php echo $_SESSION['msg'] ?></span>
                          </div>

                          <?php unset($_SESSION['msg']); }?>

                          <div class="col s12 m12 l12">
                              <table>
                                <thead>
                                  <tr>
                                    <th>ID</th>
                                    <th>Nome</th>
                                    <th>Mensagem</th>
                                    <th width="10%">Ação</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <?php while($data = mysqli_fetch_assoc($result)){ ?>
                                  <tr>
                                    <td><?php echo $data['id']; ?></td>
                                    <td><?php echo $data['nome'] ?></td>
                                    <td><?php echo $data['mensagem'] ?></td>
                                    <td><a href="mensagens.php?excluir=<?php echo $data['id'] ?>" class="btn cyan waves-effect waves-light">Excluir</a></td>
                                  </tr>
                                  <?php } ?>
                                </tbody>
                              </table>
                          </div>

                          </div>
                      </div>

                  </div>

              </div>
          </div>
      </div>

</section>
