<?php 
include ("conexion.php");
session_start();
if (!isset($_SESSION['id'])) {
  header("Location: iniciar.php");
  exit();
}

$id= $_SESSION['id'];
$nombre= $_SESSION['Nombre'];

$mostrar = $conectado->prepare("SELECT * FROM cita");
$mostrar->execute();
$resul = [];
$resul = $mostrar->get_result();


if (isset($_GET["id"])) {
  $id_obtenido = $_GET["id"];
  $mostrar2 = $conectado->prepare("SELECT * FROM cita WHERE id = $id_obtenido");
  $mostrar2->execute();
  $resul2 = [];
  $resul2 = $mostrar2->get_result();
  
  foreach($resul2 as $data){
    $datee = $data["datee"];
    $hora = $data["hora"];
  }

  $crear = $conectado->prepare("INSERT INTO citas (nombre, datee, hora, id_usuario) VALUES ('$nombre', '$datee','$hora','$id')");
  $crear->execute();
  header("location: citas.php");
}
$mostrar3 = $conectado->prepare("SELECT * FROM citas WHERE id_usuario = $id");
$mostrar3->execute();
$resul3 = [];
$resul3 = $mostrar3->get_result();


if (isset($_GET["asd"])) {
  $asd = $_GET["asd"];
  $borrar = "DELETE FROM citas WHERE id=$asd";
  $eliminar = $conectado->prepare($borrar);
  $eliminar->execute();
  header("location: citas.php");

  
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
    <title>Mi Página Web</title>
    <link rel="stylesheet" type="text/css" href="Estilos/index.css">
    <script src="https://unpkg.com/feather-icons"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" 
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit-icons.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/css/uikit.min.css" />
    <link rel="stylesheet" href="Estilos/citas.css">
  </head>
<body>
  <?php include ("menu.php") ?>

<div id="citas">
  <div class="uk-container uk-magin-top">
    <h2 class="uk-text-center">Agende su cita:</h2>
    <div class="uk-grid-match uk-child-width-1-2 uk-text-center" uk-grid>
        <div>
            <div class="uk-card uk-card-default uk-card-body">
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th class="uk-text-center">dias disponibles</th>
                            <th class="uk-text-center">desde que hora:</th>
                            <th class="uk-text-center">Agendar</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach($resul as $valores) { ?>
                        <tr>
                            <td><?php echo $valores["datee"]; ?></td>
                            <td><?php echo $valores["hora"]; ?></td>
                            <td><a href="citas.php?id=<?php echo $valores["id"]; ?>" class="uk-button uk-button-primary">Agendar cita</a></td>
                        </tr>
                        <?php } ?>
                    </tbody>
                  </table>
            </div>
        </div>
        <div>
          <div class="uk-card uk-card-default uk-card-body">
            <h2>tus citas:</h2>
            <table class="uk-table uk-table-divider">
    <thead>
        <tr>
            <th class="uk-text-center">Fecha</th>
            <th class="uk-text-center">Hora</th>
            <th class="uk-text-center">Borrar</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($resul3 as $datos){ ?>
        <tr>
            <td><?php echo $datos['datee']?></td>
            <td><?php echo $datos['hora']?></td>
            <td><a href="citas.php?asd=<?php echo $datos["id"]; ?>" class="uk-button uk-button-danger">Borrar</a></td>
        </tr>
        <?php } ?>
    </tbody>
    
</table>

          </div>
        </div>
    </div>
  </div>
</div>
<div class="chat-icon">
    <?php include("boticon.php") ?>
    </div>
    <?php include 'footer.php'?>
</body>
</html>