$a->countheld = $DB->count_records_select('events_queue_handlers', 'status > 0');
if (!$table->is_downloading($download, $exportfilename)) {
    echo $OUTPUT->header();
    $currenttab = 'unplagdebug';
    require_once 'unplag_tabs.php';
    $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
    if ($lastcron < time() - 3600 * 0.5) {
        // Check if run in last 30min.
        echo $OUTPUT->box(get_string('cronwarning', 'plagiarism_unplag'), 'generalbox admin warning');
    }
    $warning = '';
    if (!empty($a->countallevents)) {
        $warning = ' warning';
    }
    if ($resetuser == 1 && $id && confirm_sesskey()) {
        if (plagiarism_plugin_unplag::unplag_reset_file($id)) {
            echo $OUTPUT->notification(get_string('fileresubmitted', 'plagiarism_unplag'));
        }
    } else {
        if ($resetuser == 2 && $id && confirm_sesskey()) {
            $plagiarismfile = $DB->get_record('plagiarism_unplag_files', array('id' => $id), '*', MUST_EXIST);
            $file = plagiarism_plugin_unplag::unplag_get_score(plagiarism_plugin_unplag::get_settings(), $plagiarismfile, true);
            // Reset attempts as this was a manual check.
            $file->attempt = $file->attempt - 1;
            $DB->update_record('plagiarism_unplag_files', $file);
            if ($file->statuscode == UNPLAG_STATUSCODE_ACCEPTED) {
                echo $OUTPUT->notification(get_string('scorenotavailableyet', 'plagiarism_unplag'));
            } else {
                if ($file->statuscode == UNPLAG_STATUSCODE_PROCESSED) {
                    echo $OUTPUT->notification(get_string('scoreavailable', 'plagiarism_unplag'));
                } else {
 * @author     Dan Marsden <*****@*****.**>
 * @author Mikhail Grinenko <*****@*****.**>
 * @copyright 2014 Dan Marsden <*****@*****.**>
 * @copyright   UKU Group, LTD, https://www.unplag.com 
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(__FILE__)) . '/../config.php';
require_once $CFG->dirroot . '/plagiarism/unplag/lib.php';
$cmid = required_param('cmid', PARAM_INT);
// Course Module ID
$pf = required_param('pf', PARAM_INT);
// plagiarism file id.
require_sesskey();
$url = new moodle_url('/plagiarism/unplag/reset.php');
$cm = get_coursemodule_from_id('', $cmid, 0, false, MUST_EXIST);
$PAGE->set_url($url);
require_login($cm->course, true, $cm);
$modulecontext = context_module::instance($cmid);
require_capability('plagiarism/unplag:resetfile', $modulecontext);
plagiarism_plugin_unplag::unplag_reset_file($pf);
if ($cm->modname == 'assignment') {
    $redirect = new moodle_url('/mod/assignment/submissions.php', array('id' => $cmid));
} else {
    if ($cm->modname == 'assign') {
        $redirect = new moodle_url('/mod/assign/view.php', array('id' => $cmid, 'action' => 'grading'));
    } else {
        // TODO: add correct locations for workshop and forum.
        $redirect = $CFG->wwwroot;
    }
}
redirect($redirect, get_string('filereset', 'plagiarism_unplag'));