<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

/**
 * Supprime un document de stage.
 *
 * @package local_kid
 */

require(__DIR__ . '/../../../config.php');

use local_kid\local\access_helper;
use local_kid\local\stage_repository;

require_login();
$context = context_system::instance();
access_helper::require_capability_or_teacher('local/kid:evaluate_stage', $context);
require_sesskey();

$docid = required_param('docid', PARAM_INT);

global $DB;
$doc = $DB->get_record('local_kid_stage_doc', ['id' => $docid], '*', MUST_EXIST);
$entry = stage_repository::get_entry((int) $doc->entryid);

stage_repository::delete_doc($docid);

redirect(new moodle_url('/local/kid/pages/stages.php', ['stageid' => $entry->stageid, 'studentid' => $entry->studentid]));
