<?php

	include('public/functions.php');
	  $qry = "select * FROM tbl_menu";
  $registro = mysqli_query($connect, $qry);

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

  		$data = array(
          'icone_menu'  => $icone_menu,
          'titulo'    => $_POST['titulo'],
          'url'    => $_POST['url'],
          'status'    => $_POST['status'],

  		);

  		$registro = insert('tbl_menu', $data);
  		
			$_SESSION['msg'] = "Menu criado com êxito!.";
      header( "Location:    menuextra.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">Menu</h5>
                  <ol class="breadcrumb">
                    <li>
                        <a href="dashboard.php">Inicio</a>
                    </li>
                    <li>
                        <a class="active">Adicionar Menu</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">
                                <?php if(isset($_SESSION['msg']))
                                echo $_SESSION['msg'];
                                unset($_SESSION['msg']);?>
                            <div class="row">
                                <form action="" method="post" enctype="multipart/form-data">
                                    <div class="col s12 m12 l12">
                                        <div class="">
                                            <div class="input-field col s12 l6">
                                                <label>Titulo</label>
                                                <input type="text" name="titulo">
                                            </div>
                                    
                                            <div class="input-field col s12 l6">
                                                <label>url</label>
                                                <input type="text" name="url">
                                            </div>
                                        </div>
                                    
                                        <div class="input-field col s12 l6">
                                            <label>Status</label>
                                            <br>
                                            <select name="status">
                                                <option value="ativo">Ativo</option>
                                                <option value="inativo">Inativo</option>
                                            </select>                                    
                                        </div>
                                        
                                        <div class="input-field col s12 l6">
                                            <label >Icone</label>
                                            <p><br></p>
                                            <input type="file" name="icone_menu" id="icone_menu" value="">
                                        </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>
      </div>

</section>