<?php
  include('includes/config.php');
	include('public/functions.php');
	
 	$qry = "SELECT * FROM ordem AS o INNER JOIN tbl_progamacao AS a ON a.dia = o.nome ORDER BY id_semana ASC";
    $result = mysqli_query($connect, $qry);

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

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

      Delete("tbl_progamacao WHERE id = '".$_GET['id']."' ");
      $_SESSION['msg'] = "<div class='card-panel teal lighten-2' id='aviso'>
      <span class='white-text text-darken-2'>Programação excluida com Sucesso!</span>
      </div>";
      header('Location: programacao.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">Programação</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="addprogramacao.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>Dias da semana</th>
                                    <th>Locutor</th>
                                    <th>Início</th>
                                    <th>Fim</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_agenda/<?php echo $data['img_agenda'] ?>" ></td>
                                    <td><?php echo $data['dia']; ?></td>
                                    <td><?php echo $data['programa'];?></td>
                                    <td><?php echo date ('H:i',strtotime($data['inicio'])); ?></td>
                                    <td><?php echo date ('H:i',strtotime($data['fim'])); ?></td>
                                    <td><?php echo substr(strip_tags($data['descricao']),0,100) ?>...</td>
                                    <td>
                                      <a href="editaprogramacao.php?idevento=<?php echo $data['id'] ?>" class="btn-floating cyan tooltipped" data-position="left" data-tooltip="Editar Programação"><i class="material-icons">mode_edit</i></a>
                                      <a href="programacao-home.php?deleteprogramacao=true&id=<?php echo $data['id'] ?>" class="btn-floating cyan tooltipped" data-position="top" data-tooltip="Deletar Programação"><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>