<?php
  $Position   = '../';
  require_once($Position.'config/config.php');
  require_once($Position.'config/conexion.php');
  require_once($Position.'config/user.php');
  require_once($Position.'funciones/acces.php');
  require_once($Position.'funciones/logout.php');
  require_once($Position.'funciones/funciones.php');

  if( $_POST[Id] ){

    //Restaurante
    $Query = "
      SELECT
        res.Id, res.Fk_Menu
      FROM Restaurantes res
      WHERE res.Id = '$_POST[Id]'
  	";
  	$Result = mysqli_query($mysqli, $Query );
  	$Res = mysqli_fetch_assoc($Result);

  }

?>

<form
  method="post"
  enctype="multipart/form-data"
  id="Form-Menu"
>

  <input type="hidden" name="Save" value="Ok" />
  <input
    type="hidden"
    name="Action"
    value="<?php if( $Res[Id] ){ echo '2'; }else{ echo '1'; } ?>"
  />
  <?php if($Res[Id]){ ?>
    <input type="hidden" name="Id" value="<?php echo $Res[Id]; ?>" />
  <?php } ?>

  <div class="row">

    <!-- Información -->
    <div class="col-sm-12">
      <div class="card">
        <div class="card-body">
          <div class="row">

            <!-- Titulo -->
            <div class="col-sm-12">
              <h4>Menú</h4>
              <hr>
            </div>
            <!-- End Titulo -->

            <!-- Menu -->
            <div class="col-sm-6 form-group">
              <label>Menú seleccionado</label>
              <select
                name="Menu"
                class="form-control chosen-select"
                data-required="true"
              >
                <option></option>
                <?php
                  //Menus
                  $Query = "
                    SELECT
                      men.Id, men.Nombre
                    FROM Menus men
                    WHERE men.Fk_Cuenta = '$Cuenta[Id]'
                    ORDER BY men.Nombre ASC
                  ";
                  $Menus = $mysqli->query($Query);
                  mysqli_data_seek($Menus, 0);
                  while($Men = mysqli_fetch_array($Menus)) {
                ?>
                  <option
                    value="<?php echo $Men['Id']; ?>"
                    <?php
                      if( ($Res['Fk_Menu'] == $Men['Id']) ){
                        echo "selected";
                      }
                    ?>
                  >
                    <?php echo $Men[Nombre]; ?>
                  </option>
                <?php } ?>
              </select>
            </div>
            <!-- End Menu -->

          </div>
        </div>
      </div>
    </div>
    <!-- end Información -->

  </div>
</form>
