<?php
$ruta = "../";
require_once "../class/c_login.php";

// check if the session is started
$user = Login::get_user();

$ruta = "../";
require_once "../include/bd_pdo.php";

extract($_POST);

$params = [
	"hora" => $hora,
	"salon" => $salón,
	"facultad_id" => $facultad,
	"periodo" => $periodo,
	"grupo" => $grupo,
	"materia_id" => $materia,
	"dia" => $día,
	"duracion" => $duración,
	"profesores" => "{{$profesores}}",
];

header("Content-Type: application/json");
$user->print_to_log("Creación de horario", new: $params);

try {
	$db->insert("fs_horario", $params);
} catch (Exception $e) {
	die(json_encode([
		"status" => "error",
		"message" => "No se pudo crear el horario",
	]));
}
die(json_encode([
	"status" => "success",
	"message" => "Horario creado correctamente",
]));
