public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/plagiarism/urkund/lib.php';
     $plagiarismsettings = \plagiarism_plugin_urkund::get_settings();
     if (!empty($plagiarismsettings)) {
         urkund_get_scores($plagiarismsettings);
     }
 }
 public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/plagiarism/urkund/lib.php';
     $plagiarismsettings = \plagiarism_plugin_urkund::get_settings();
     if (!empty($plagiarismsettings)) {
         plagiarism_urkund_update_allowed_filetypes();
         plagiarism_urkund_delete_old_records();
     }
 }
     // Check if run in last 30min.
     echo $OUTPUT->box(get_string('cronwarning', 'plagiarism_urkund'), 'generalbox admin warning');
 }
 $warning = '';
 if (!empty($a->countallevents)) {
     $warning = ' warning';
 }
 echo $OUTPUT->box(get_string('waitingevents', 'plagiarism_urkund', $a), 'generalbox admin' . $warning) . "<br/>";
 if ($resetuser == 1 && $id && confirm_sesskey()) {
     if (urkund_reset_file($id)) {
         echo $OUTPUT->notification(get_string('fileresubmitted', 'plagiarism_urkund'));
     }
 } else {
     if ($resetuser == 2 && $id && confirm_sesskey()) {
         $plagiarismfile = $DB->get_record('plagiarism_urkund_files', array('id' => $id), '*', MUST_EXIST);
         $file = urkund_get_score(plagiarism_plugin_urkund::get_settings(), $plagiarismfile, true);
         // Reset attempts as this was a manual check.
         $file->attempt = $file->attempt - 1;
         $DB->update_record('plagiarism_urkund_files', $file);
         if ($file->statuscode == URKUND_STATUSCODE_ACCEPTED) {
             echo $OUTPUT->notification(get_string('scorenotavailableyet', 'plagiarism_urkund'));
         } else {
             if ($file->statuscode == URKUND_STATUSCODE_PROCESSED) {
                 echo $OUTPUT->notification(get_string('scoreavailable', 'plagiarism_urkund'));
             } else {
                 echo $OUTPUT->notification(get_string('unknownwarning', 'plagiarism_urkund'));
                 print_object($file);
             }
         }
     }
 }
예제 #4
0
function plagiarism_urkund_send_files()
{
    global $DB, $CFG;
    $plagiarismsettings = plagiarism_plugin_urkund::get_settings();
    if (!empty($plagiarismsettings)) {
        // Get all files in a pending state.
        $plagiarismfiles = $DB->get_records("plagiarism_urkund_files", array("statuscode" => "pending"));
        foreach ($plagiarismfiles as $pf) {
            // Check to make sure cm exists. - delete record if cm has been deleted.
            $sql = "SELECT m.name\n                      FROM {modules} m\n                      JOIN {course_modules} cm ON cm.module = m.id\n                     WHERE cm.id = ?";
            $modulename = $DB->get_field_sql($sql, array($pf->cm));
            if (empty($modulename)) {
                // The coursemodule related to this file has been deleted, delete the urkund entry.
                mtrace("URKUND fileid:{$pf->id} Course module id:" . $pf->cm . " does not exist, deleting record");
                $DB->delete_records('plagiarism_urkund_files', array('id' => $pf->id));
                continue;
            }
            mtrace("URKUND fileid:" . $pf->id . ' sending for processing');
            $file = plagiarism_urkund_get_file_object($pf);
            if (empty($file)) {
                continue;
            }
            if ($module = "assign") {
                // Check for group assignment and adjust userid if required.
                // This prevents subsequent group submissions from flagging a previous submission as a match.
                $pf = plagiarism_urkund_check_group($pf);
            }
            if (!empty($file)) {
                urkund_send_file_to_urkund($pf, $plagiarismsettings, $file);
            } else {
                $DB->delete_records('plagiarism_urkund_files', array('id' => $pf->id));
                mtrace("URKUND fileid:{$pf->id} File not found, this may have been replaced by a newer file - deleting record");
            }
        }
    }
}
예제 #5
0
function urkund_reset_file($id)
{
    global $DB, $CFG;
    $plagiarismfile = $DB->get_record('plagiarism_urkund_files', array('id' => $id), '*', MUST_EXIST);
    if ($plagiarismfile->statuscode == 'Analyzed' || $plagiarismfile->statuscode == URKUND_STATUSCODE_ACCEPTED) {
        // Sanity Check.
        return true;
    }
    // Set some new values.
    $plagiarismfile->statuscode = 'pending';
    $plagiarismfile->attempt = 0;
    $plagiarismfile->timesubmitted = time();
    $cm = get_coursemodule_from_id('', $plagiarismfile->cm);
    $modulecontext = context_module::instance($plagiarismfile->cm);
    $fs = get_file_storage();
    if ($cm->modname == 'assignment') {
        $submission = $DB->get_record('assignment_submissions', array('assignment' => $cm->instance, 'userid' => $plagiarismfile->userid));
        $files = $fs->get_area_files($modulecontext->id, 'mod_assignment', 'submission', $submission->id);
        foreach ($files as $file) {
            if ($file->get_contenthash() == $plagiarismfile->identifier) {
                $DB->update_record('plagiarism_urkund_files', $plagiarismfile);
                // Update before trying to send again.
                return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
            }
        }
    } else {
        if ($cm->modname == 'assign') {
            require_once $CFG->dirroot . '/mod/assign/locallib.php';
            $assign = new assign($modulecontext, null, null);
            $submissionplugins = $assign->get_submission_plugins();
            $dbparams = array('assignment' => $assign->get_instance()->id, 'userid' => $plagiarismfile->userid);
            $submissions = $DB->get_records('assign_submission', $dbparams);
            foreach ($submissions as $submission) {
                foreach ($submissionplugins as $submissionplugin) {
                    $component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
                    $fileareas = $submissionplugin->get_file_areas();
                    foreach ($fileareas as $filearea => $name) {
                        $files = $fs->get_area_files($assign->get_context()->id, $component, $filearea, $submission->id, "timemodified", false);
                        foreach ($files as $file) {
                            if ($file->get_contenthash() == $plagiarismfile->identifier) {
                                $DB->update_record('plagiarism_urkund_files', $plagiarismfile);
                                // Update before trying to send again.
                                return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
                            }
                        }
                    }
                }
            }
        } else {
            if ($cm->modname == 'workshop') {
                require_once $CFG->dirroot . '/mod/workshop/locallib.php';
                $cm = get_coursemodule_from_id('workshop', $plagiarismfile->cm, 0, false, MUST_EXIST);
                $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
                $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
                $workshop = new workshop($workshop, $cm, $course);
                $submissions = $workshop->get_submissions($plagiarismfile->userid);
                foreach ($submissions as $submission) {
                    $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
                    foreach ($files as $file) {
                        if ($file->get_contenthash() == $plagiarismfile->identifier) {
                            $DB->update_record('plagiarism_urkund_files', $plagiarismfile);
                            // Update before trying to send again.
                            return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
                        }
                    }
                }
            } else {
                if ($cm->modname == 'forum') {
                    require_once $CFG->dirroot . '/mod/forum/lib.php';
                    $cm = get_coursemodule_from_id('forum', $plagiarismfile->cm, 0, false, MUST_EXIST);
                    $posts = forum_get_user_posts($cm->instance, $plagiarismfile->userid);
                    foreach ($posts as $post) {
                        $files = $fs->get_area_files($modulecontext->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
                        foreach ($files as $file) {
                            if ($file->get_contenthash() == $plagiarismfile->identifier) {
                                $DB->update_record('plagiarism_urkund_files', $plagiarismfile);
                                // Update before trying to send again.
                                return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
                            }
                        }
                    }
                }
            }
        }
    }
}