<?php
require_once "../config/conexion.php";
if (isset($_POST)) {
    if (!empty($_POST)) {
        $nombre = $_POST['nombre'];
		$categoria = $_POST['categoria'];
		echo $nombre;
		echo $categoria;
        $query = mysqli_query($conexion, "INSERT INTO tiposervicio(nomtiposervicio, idclaseservicio) VALUES ('$nombre', '$categoria')");
        if ($query) {
            header('Location: categorias.php');
        }
    }
}
include("includes/header.php");
?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800">Tipo Publicidad</h1>
    <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" id="abrirCategoria"><i class="fas fa-plus fa-sm text-white-50"></i> Nuevo</a>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="table-responsive">
            <table class="table table-hover table-bordered" style="width: 100%;">
                <thead class="thead-dark">
                    <tr>
                        <th>Id</th>
                        <th>Nombre</th>
						<th>Clase</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $query = mysqli_query($conexion, " SELECT t.*, (Select nomclaseservicio From claseservicio Where idclaseservicio=t.idclaseservicio) As nomclaseservicio  FROM tiposervicio t Where idclaseservicio=1 ORDER BY t.idtiposervicio DESC");
                    while ($data = mysqli_fetch_assoc($query)) { ?>
                        <tr>
                            <td><?php echo $data['idtiposervicio']; ?></td>
                            <td><?php echo $data['nomtiposervicio']; ?></td>
							<td><?php echo $data['nomclaseservicio']; ?></td>
                            <td>
                                <form method="post" action="eliminarCat.php?accion=<?php echo $data['idtiposervicio']; ?>" class="d-inline eliminar">
                                    <button class="btn btn-danger" type="submit">Eliminar</button>
                                </form>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="categorias" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="my-modal-title" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header bg-gradient-primary text-white">
                <h5 class="modal-title" id="title">Nueva Categoria</h5>
                <button class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="" method="POST" autocomplete="off">
                    <div class="form-group">
                        <label for="nombre">Nombre</label>
					    <input id="nombre" class="form-control" type="text" name="nombre" placeholder="Categoria" required>	
                    </div>
					<div class="col-md-6">
                            <div class="form-group">
                                <label for="categoria">Clase</label>
                                <select id="categoria" class="form-control" name="categoria" required>
                                    <?php
                                    $categorias = mysqli_query($conexion, "SELECT *, UCASE(nomclaseservicio) AS categoria FROM claseservicio Where idclaseservicio=1");
                                    foreach ($categorias as $cat) { ?>
                                        <option value="<?php echo $cat['idclaseservicio']; ?>"><?php echo $cat['categoria']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                     </div>
                    <button class="btn btn-primary" type="submit">Registrar</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php include("includes/footer.php"); ?>