<?php
  include('includes/config.php');
	include('public/functions.php');
$qry = "SELECT * FROM tbl_equipe";
	$result = mysqli_query($connect, $qry);

  if(!empty($_GET['deleteequipe'])){
    if(!empty($_GET['id'])){
      $nt = mysqli_query($connect,"SELECT * FROM tbl_equipe WHERE id = '".$_GET['id']."' ");
      $delete = mysqli_fetch_assoc($nt);

      if(!empty($delete['img_equipe'])){
        unlink('upload/img_equipe/'.$img_equipe);
      }

      Delete("tbl_equipe WHERE id = '".$_GET['id']."' ");
      $_SESSION['msg'] = "<div class='card-panel teal lighten-2' id='aviso'>
      <span class='white-text text-darken-2'>Equipe excluida com Sucesso!</span>
      </div>";
      header('Location: equipe.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">"Equipe"</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Inicio</a>
                    </li>
                    <li><a class="active">Programação Semanal</a>
                    </li>
                  </ol>
                </div>
            </div>
          </div>
      </div>
      <!--breadcrumbs end-->

      <!--start container-->
      <div class="container">
          <div class="section">
              <a href="addequipe.php" class="btn cyan waves-effect waves-light right">Cadastrar Nova</a>
              <div class="row">
                  <div class="col s12 m12 l12">
                      <div class="card-panel">
                        <div class="row">
                            <div class="ol s12 m12 l12" id="aviso">
                          <?php if(isset($_SESSION['msg']))
                          echo $_SESSION['msg'];
                          unset($_SESSION['msg']); ?>
                          </div>

                          <div class="col s12 m12 l12">
                              <table>
                                <thead>
                                  <tr>
                                    <th hidden>id</th>
                                    <th>Imagem</th>
                                    <th>Nome</th>
                                    <th>Programa</th>
                                    <th>Facebook</th>
                                    <th>Instagram</th>
                                    <th>Whatsapp</th>
                                    <th>Descrição</th>
                                    <th width="10%">Ação</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <?php while($data = mysqli_fetch_array($result)){ ?>
                                  <tr>
                                    <td hidden><?php echo $data['id'];?></td>
                                    <td><img width="60" height="60" src="upload/img_equipe/<?php echo $data['img_equipe'] ?>" ></td>
                                    <td><?php echo $data['nome'];?></td>
                                    <td><?php echo $data['programa'];?></td>
                                    <td><?php echo $data['facebook'];?></td>
                                    <td><?php echo $data['instagram'];?></td>
                                    <td><?php echo $data['whatsapp'];?></td>
                                    <td><?php echo substr(strip_tags($data['descricao']),0,100) ?>...</td>
                                    <td>
                                      <a href="editequipe.php?idevento=<?php echo $data['id'] ?>" class="btn-floating cyan tooltipped" data-position="left" data-tooltip="Editar"><i class="material-icons">mode_edit</i></a>
                                      <a href="equipe-home.php?deleteequipe=true&id=<?php echo $data['id'] ?>" class="btn-floating cyan tooltipped" data-position="top" data-tooltip="Deletar"><i class="material-icons">delete_sweep</i></a>
                                    </td>
                                  </tr>
                                  <?php } ?>
                                </tbody>
                              </table>
                          </div>

                          </div>
                      </div>

                  </div>

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

</section>
<script>
  $().ready(function() {
  setTimeout(function () {
  $('#aviso').hide(); // "aviso" é o id do elemento que seja manipular.
  }, 2500); // O valor é representado em milisegundos.
  });
</script>