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

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

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

      Delete("tbl_menu WHERE id = '".$_GET['id']."' ");
      $_SESSION['msg'] = "<div class='card-panel teal lighten-2' id='aviso'><span class='white-text text-darken-2'>Menu excluido com Sucesso!</span></div>";
      header('Location: menuextra.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">"Menu Lateral"</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Inicio</a>
                    </li>
                    <li><a class="active">Novo Menu</a>
                    </li>
                  </ol>
                </div>
            </div>
          </div>
      </div>
      <!--breadcrumbs end-->

      <!--start container-->
      <div class="container">
          <div class="section">
              <a href="addmenu.php" class="btn cyan waves-effect waves-light right">Criar Menu</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>Icone</th>
                                    <th>Título</th>
                                    <th>Url</th>
                                    <th>Status</th>
                                    <th>Ação</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <?php while($data = mysqli_fetch_array($result)){ ?>
                                  <tr>
                                    <td hidden><?= $data['id'];?></td>
                                    <td><img width="60" height="60" src="upload/icone_menu/<?= $data['icone_menu'] ?>" ></td>
                                    <td><?= $data['titulo'];?></td>
                                    <td><?= $data['url'];?></td>
                                    <td><?php if($data['status'] == "ativo"){echo "<b style='color:green'>ATIVO</b>";}else{echo "<b style='color:red'>INATIVO</b>";}?></td>
                                    <td>
                                      <a href="editmenu.php?idmenu=<?= $data['id'] ?>" class="btn-floating cyan tooltipped" data-position="left" data-tooltip="Editar"><i class="material-icons">mode_edit</i></a>
                                      <a href="menu-extra.php?deletemenu=true&id=<?= $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>