<?php

	include('public/functions.php');

  $qry = "SELECT * FROM tbl_progamacao WHERE id = '".$_GET['idevento']."' ";
  $result = mysqli_query($connect, $qry);
  $row_result = mysqli_fetch_assoc($result);

	if(isset($_POST['submit'])) {
    if($_FILES['img_agenda']['name'] != '') {
      unlink('upload/img_agenda/'.$_POST['old_image3']);
      $img_agenda = time().'_'.$_FILES['img_agenda']['name'];
      $pic2			 = $_FILES['img_agenda']['tmp_name'];
       $tpath2			 = 'upload/img_agenda/'.$img_agenda;
      copy ($pic2, $tpath2);
    } else {
      $img_agenda = $_POST['old_image3'];
    }

  		$data = array(
          'img_agenda'  => $img_agenda,
          'dia'         => $_POST['dia'],
          'inicio'      => $_POST['inicio'],
          'fim'         => $_POST['fim'],
          'programa'    => $_POST['programa'],
          'descricao'   => $_POST['descricao']          
  		);

  		$result = Update('tbl_progamacao', $data, " WHERE id = '".$_GET['idevento']."' ");
  		
			$_SESSION['msg'] = "Progamacao alterada com êxito!.";
      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">Editar Programação</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">
                        <h5>Programação da: <?php echo $row_result['dia']; ?></h5>
                          <form method="post" enctype="multipart/form-data">
                              <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">
                                      <div class="input-field col s12 l6">
                                        <label for="img_agenda">Foto do Locutor</label>
                                            <br><p><img width="140" heigth="140" src="upload/img_agenda/<?php echo $row_result['img_agenda']; ?> "></p>
                                            <br><p>Deseja alterar a imagem?</p></br>        
                                        <input type="file" name="img_agenda" id="img_agenda" data-max-file-size="1M" data-allowed-file-extensions="jpg png gif" data-default-file="upload/img_agenda/<?php echo $row_result['img_agenda']; ?>" data-show-remove="false"/>
                                        <input type="hidden" name="old_image3" value="<?php echo $row_result['img_agenda'];?>">
                                    </div>
                                    
                                    <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l12">
                                          <label><b><h6>Nome do Locutor</h6></b></label>
                                          <input type="text" name="programa"  value="<?php echo $row_result['programa'] ;?>">
                                          
                                        </div>
                                    </div>
                                  <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l12">
                                          <label><b><h6>Nome do Programa</h6></b></label>
                                          <input type="text" name="descricao"  value="<?php echo $row_result['descricao'] ;?>">
                                          
                                        </div>
                                    </div>
                                    
                                <div class="col s12 m12 l6">
                                    <div class="input-field col s12 l12">
                                        <select name="dia">
        									<option value="Domingo" <?php if($row_result['dia'] == 'Domingo') {echo 'selected';} ?>>Domingo</option>
        									<option value="Segunda-Feira" <?php if($row_result['dia'] == 'Segunda-Feira') {echo 'selected';} ?>>Segunda-Feira</option>
        									<option value="Terça-Feira" <?php if($row_result['dia'] == 'Terça-Feira') {echo 'selected';} ?>>Terça-Feira</option>
        									<option value="Quarta-Feira" <?php if($row_result['dia'] == 'Quarta-Feira') {echo 'selected';} ?>>Quarta-Feira</option>
        									<option value="Quinta-Feira" <?php if($row_result['dia'] == 'Quinta-Feira') {echo 'selected';} ?>>Quinta-Feira</option>
        									<option value="Sexta-Feira" <?php if($row_result['dia'] == 'Sexta-Feira') {echo 'selected';} ?>>Sexta-Feira</option>
        									<option value="Sábado" <?php if($row_result['dia'] == 'Sábado') {echo 'selected';} ?>>Sábado</option>
    									</select>
                                        <label>Selecione o Dia da Programação</label>
                                    </div>
                                </div>
                                
                                <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l6">
                                        <label>Início do Programa</label>
                                        <br>
                                        <input type="time" name="inicio" value="<?php echo $row_result['inicio'];?>">
                                        </div>
                                    
                                        <div class="input-field col s12 l6">
                                        <label>Fim do Programa</label>
                                        <br>
                                        <input type="time" name="fim" value="<?php echo $row_result['fim'];?>">
                                        </div>
                                  </div>
                                  

                                  </div>
                                  <div class="input-field col s12"><br>
                                      <button type="submit" name="submit" class="btn cyan waves-effect waves-light">Alterar</button>
                                  </div>

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

                  </div>

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

</section>
