<?php

	include('public/functions.php');

  $qry = "insert * FROM tbl_progamacao";
  $registro = mysqli_query($connect, $qry);

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

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

  		$registro = insert('tbl_progamacao', $data);
  		
			$_SESSION['msg'] = "Programação Cadastrada 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">Nova Programação</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Inicio</a>
                    </li>
                    <li><a class="active">Nova 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">
                          <form method="post" enctype="multipart/form-data">
                              <div class="row">
                                  <?php if(isset($_SESSION['msg']))
                                  echo $_SESSION['msg'];
                                  unset($_SESSION['msg']);?>

                                  <div class="col s12 m12 l12">
                                    <div class="input-field col s12 l3">
                                      <label>Nome do Locutor</label>
                                      <br>
                                      <input type="text" name="programa">
                                    </div>
                                    
                                    <div class="col s12 m12 l12">
                                    <div class="input-field col s12 l3">
                                      <label>Nome do Programa</label>
                                      <br>
                                      <input type="text" name="descricao">
                                    </div>
                                  </div>
                                    
                                    <div class="input-field col s12 l3">
                                      <label>Início do Programa</label>
                                      <br>
                                      <input type="time" name="inicio">
                                    </div>
                                    
                                    <div class="input-field col s12 l3">
                                      <label>Fim do Programa</label>
                                      <br>
                                      <input type="time" name="fim">
                                    </div>
                                    <br>
                                    <div class="input-field col s12 l3">
                                    <select name="dia">
                                        <option value="" disabled selected>Escolha o Dia?</option>
                                        <option value="Segunda-Feira">Segunda-Feira</option>
                                        <option value="Terça-Feira">Terça-Feira</option>
                                        <option value="Quarta-Feira">Quarta-Feira</option>
                                        <option value="Quinta-Feira">Quinta-Feira</option>
                                        <option value="Sexta-Feira">Sexta-Feira</option>
                                        <option value="Sábado">Sábado</option>
                                        <option value="Domingo">Domingo</option>
                                    </select>
                                <label>Selecione o Dia da Programação</label>
                                </div>
                                  </div>

                                  <div class="col s12 m12 l4">
                                    <div class="input-field col s12 l6">
                                      <p><br><label >Imagem do Progama<input type="file" name="img_agenda" id="img_agenda" value="">
                                      </label></p></br>
                                    </div>
                                  </div>


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

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

                  </div>

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

</section>