<?php

	include('public/functions.php');

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

	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;
       			
       			if(isset($row_result['icone_menu'])){
       			    unlink("upload/icone_menu/".$row_result['icone_menu']);
       			    copy ($pic2, $tpath2);
       			}else{
       			    copy ($pic2, $tpath2);
       			}
      			
      			$data = array(
                  'icone_menu'  => $icone_menu,
                  'titulo'    => $_POST['titulo'],
                  'url'    => $_POST['url'],
                  'status'    => $_POST['status'],
          		);
      		}else{
      		    $data = array(
                  'titulo'    => $_POST['titulo'],
                  'url'    => $_POST['url'],
                  'status'    => $_POST['status'],
          		);
      		}
    
      		$registro = update('tbl_menu', $data, " WHERE id = '".$_GET['idmenu']."' ");
      		
    	    $_SESSION['msg'] = "<b style='color:green'>Menu atualizado com êxito!.</b>";
              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">Editar Menu</a>
                    </li>
                  </ol>
                </div>
            </div>
          </div>
      </div>
      <!--breadcrumbs end-->

      <!--start container-->
      <div class="container">
          <div class="section">
              <div class="row">
                    <form action="" method="POST" enctype= multipart/form-data>
                        <div class="col s12 m12 l12">
                            
                            <input type="hidden" name="id" value="<?= $_GET['idevento'] ;?>">
                                    
                                    <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l12">
                                          <label >Título</label>
                                          <br>
                                          <input type="text" name="titulo"  value="<?php echo $row_result['titulo'] ;?>">
                                          
                                        </div>
                                    </div>
                                    
                                    <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l12">
                                          <label >Url</label>
                                          <br>
                                          <input type="text" name="url"  value="<?php echo $row_result['url'] ;?>">
                                          
                                        </div>
                                    </div>
                                    
                                    <div class="col s12 m12 l6">
                                        <div class="input-field col s12 l12">
                                          <label >Status</label>
                                          <br>
                                          <select name="status" class="form-control">
                                            <option value="inativo" <?=($row_result['status'] == 'inativo')?'selected':''?> >INATIVO</option>
                                            <option value="ativo" <?=($row_result['status'] == 'ativo')?'selected':''?> >ATIVO</option>
                                          </select>
                                          
                                          
                                        </div>
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col s6 m6 l6">
                                        <div class="input-field col s12 l12">
                                          <label >Icone</label>
                                          <br><br>
                                          <img style="height: 64px; width: 64px" src="./upload/icone_menu/<?= $row_result['icone_menu'] ;?>" alt="Icone">
                                        </div>
                                    </div>
                                    
                                    <div class="col s6 m6 l6">
                                        <div class="input-field col s12 l12">
                                          <label >atualizar Icone</label>
                                          <br><br>
                                          <input type="file" name="icone_menu" class="form-control" value="<?php echo $row_result['icone_menu'] ;?>">
                                        </div>
                                    </div>
                                    </div>
                                  
                                  
                                    <div class="input-field col s12"><br>
                                      <button type="submit" name="submit" class="btn cyan waves-effect waves-light">Editar</button>
                                    </div>

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

                  </div>

              </div>

</section>
