<?php

	include('public/functions.php');

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

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

  		$data = array(
          'img_tema'  => $img_tema,
          'temas'    => $_POST['temas'],
          'status'    => $_POST['status'],
  		);

  		$registro = insert('tbl_themas', $data);
  		
			$_SESSION['msg'] = "Tema Editado com êxito!.";
      header( "Location:    temas.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">Temas</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Inicio</a>
                    </li>
                    <li><a class="active">Adicionar Tema</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>temas</label>
                                      <br>
                                      <input type="text" name="temas">
                                    </div>
                                    <br>
                                    <div class="col s12 m12 l12">
                                    <div class="input-field col s12 l3">
                                      <label>status</label>
                                      <br>
                                      <input type="text" name="status">
                                     </div>
                                    </div>
                                <br>
                                  <div class="col s12 m12 l8">
                                    <div class="input-field col s12 l6">
                                      <label >Layout<label >
                                      <br>
                                      <input type="file" name="img_tema" id="img_tema" value="">
                                      </label>
                                    </div>
                                  </div>

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

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

                  </div>

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

</section>