<?php

include "valida.php";
define('AT_INCLUDE_PATH', 'include/');
include_once AT_INCLUDE_PATH . 'funciones_bd.php';
if (!isset($_POST['id_record_change']) || !isset($_POST['num_pregs']) || !isset($_POST['num_aprobar'])) {
    header("location: consultar_quantities.php?error=1");
    exit;
} elseif ($_POST["id_record_change"] == "" || $_POST["num_pregs"] == "" || $_POST["num_aprobar"] == "") {
    header("location: consultar_quantities.php?error=1");
    exit;
} else {
    $id = $_POST['id_record_change'];
    $num_pregs = $_POST['num_pregs'];
    $num_aprob = $_POST['num_aprobar'];
    //validando si el numero de preguntas para aprobar el mayor que el numero de preguntas disponible
    if ($num_aprob > $num_pregs) {
        header("location: edit_quantities.php?error=1&id=" . $id);
    } else {
        $data_update = new funciones_BD();
        if ($data_update->updateQuantitiesByID($id, $num_pregs, $num_aprob)) {
            header("location: consultar_quantities.php?conf=1");
            exit;
        } else {
            header("location: consultar_quantities.php?error=3");
            exit;
        }
    }
}