<?php
	$Seccion      = 'Cursos';
	$NameSec      = 'Cursos';
	$SecLine      = array('Cursos', 'Categorías', 'Categoría');
	$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');
	require_once($Position.'funciones/extras.php');

	if ( $_POST['Save'] == "Ok" ) {

		$Nombre    = $_POST['Nombre'];

	}

	//Guardar Datos
	if ( $_POST['Save'] == "Ok" && $_POST['New'] == "Ok" ) {

    $Query = "
			INSERT INTO CMS_CrusosCategorias
	    (Nombre)
	    VALUES
	    ('$Nombre')
		";
    mysqli_query($mysqli, $Query );
    $Id = mysqli_insert_id($mysqli);

	}

	if ( $_POST['Save'] == "Ok" && $_POST['Id'] ) {

	    $Id             = $_POST['Id'];
	    $Query = "
		    UPDATE CMS_CrusosCategorias SET
			    Nombre    = '$Nombre'
		    WHERE Id  = '$Id'
	    ";
	    mysqli_query($mysqli, $Query );
	    $Save = 'Ok';

	}

	if ( $_POST['Save'] == "Ok" && $_POST['New'] == "Ok" && $Id ) {
	    echo '<script type="text/javascript">document.location.href="index.php?Id='.$Id.'&New=Ok"</script>';
	}

	//Administrador
	$Query = "
		SELECT
			cat.Id,
			cat.Nombre
		FROM CMS_CrusosCategorias cat
		WHERE cat.Id = '$_GET[Id]'
	";
	$Result = mysqli_query($mysqli, $Query );
	$Cat = mysqli_fetch_assoc($Result);

?>

<!DOCTYPE html>
<html lang="en">

<?php require_once($Position.'head.php'); ?>

<body class="fix-sidebar fix-header card-no-border">

  <div class="preloader">
    <svg class="circular" viewBox="25 25 50 50">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
  </div>

  <div id="main-wrapper">

    <?php require_once($Position.'header.php'); ?>
    <?php require_once($Position.'menu.php'); ?>

    <div class="page-wrapper">

      <div class="container-fluid">

        <form method="post" enctype="multipart/form-data" data-validate="parsley" role="form" id="FormPer">

          <div class="row page-titles page-titles-fixed">

            <?php require_once($Position.'title.php'); ?>

            <!-- Botones -->
            <div class="col-md-7 align-self-center text-right">
              <div class="btn-group" role="group" aria-label="Basic example">
                <button type="button" class="btn btn-sm btn-secondary" onclick="window.location.href='../index.php'">Regresar<i class="fa fa-arrow-left m-l-10"></i></button>
								<?php if( $Perms[42] ){ ?>
                	<button type="button" class="btn btn-sm btn-secondary" onclick="window.location.href='edit.php'">Nuevo<i class="fa fa-plus m-l-10"></i></button>
								<?php } ?>
								<button type="submit" class="btn btn-sm btn-success">Guardar<i class="fa fa-check m-l-10"></i></button>
                <input type="hidden" name="Save" value="Ok">
                <?php if( $Cat['Id'] ){ ?>
									<input name="Id" type="hidden" id="Id" value="<?php echo $Cat['Id']; ?>">
								<?php }else{ ?>
									<input name="New" type="hidden" id="New" value="Ok">
								<?php } ?>
              </div>
            </div>
            <!-- End Botones -->

          </div>

          <div class="row inner-fixed-content">
            <div class="col-12">

							<!-- Tab Información -->
							<div class="card">
								<div class="card-body active" id="Informacion" role="tabpanel">
									<h4 class="card-title">
										Categoría
									</h4>
									<hr />
									<div class="row">

										<!-- Nombre -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Nombre<span class="text-danger">*</span></label>
											<div class="">
												<input name="Nombre" type="text" class="form-control"  value="<?php echo $Cat['Nombre'];?>" autocomplete="off" parsley-trigger="change" required>
											</div>
										</div>
										<!-- End Nombre -->

									</div>
								</div>
							</div>
							<!-- End Tab Información -->

            </div>
          </div>

        </form>
      </div>

      <?php require_once($Position.'footer.php'); ?>

    </div>

  </div>

  <?php require_once($Position.'scripts.php'); ?>
  <script>

  </script>
</body>

</html>
