<?php

	include('public/functions.php');

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

	if(isset($_POST['submit'])) {

  		$data = array(
          'titulo' => $_POST['titulo'],
          'descricao' => $_POST['descricao']
  		);

  		$result = Update('tbl_agenda', $data, " WHERE id = '".$_GET['idevento']."' ");
  		
			$_SESSION['msg'] = "Agenda alterada com êxito!.";
      header( "Location:agenda.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">Dashboard</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>Título :</label>
                                          <br>
                                          <input type="text" name="titulo" id="titulo" value="<?php echo $row_result['titulo'] ?>" placeholder="Título da agenda" required />
                                      </div>
                                  </div>

                                  <div class="col s12 m12 l12">
                                    <div id="input-select " class="input-field col s12 l6">
                                      <label>Descrição</label>
                                      <br>
                                      <textarea name="descricao" id="descricao" class="form-control" cols="60" rows="15"><?php echo $row_result['descricao'] ?></textarea>
                                      <script>                             
                                          CKEDITOR.replace( 'descricao' );
                                      </script>
                                    </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>
