Esempio n. 1
0
/**
 * Processes the tutor request to reveal an anonymous students name
 *
 * @global object
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object for this activity
 * @param array $post The POST values from the reveal student form
 */
function turnitintool_revealuser($cm, $turnitintool, $post, $loaderbar = null)
{
    global $CFG;
    $anonid = $post["anonid"];
    // For the sake of anonymity we get the userid from the object id
    $submission = turnitintool_get_record('turnitintool_submissions', 'submission_objectid', $anonid);
    $reason = $post["reason"][$anonid];
    if ($reason == get_string('revealreason', 'turnitintool') or empty($reason)) {
        turnitintool_print_error('revealerror', 'turnitintool', $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions', NULL, __FILE__, __LINE__);
        exit;
    } else {
        $owner = turnitintool_get_owner($turnitintool->course);
        $tii = new turnitintool_commclass(turnitintool_getUID($owner), $owner->firstname, $owner->lastname, $owner->email, 2, $loaderbar);
        $tiipost = new stdClass();
        $tiipost->cid = turnitintool_getCID($turnitintool->course);
        $tiipost->paperid = $submission->submission_objectid;
        $tiipost->anon_reason = (strlen($reason) > 1 and strlen($reason) < 6) ? str_pad($reason, 6, " ") : $reason;
        $input = new stdClass();
        $input->from = 1;
        $input->to = 1;
        $result = $tii->revealAnon($tiipost, get_string('updatestudent', 'turnitintool', $input));
        if ($tii->getRerror()) {
            $reason = $tii->getAPIunavailable() ? get_string('apiunavailable', 'turnitintool') : $tii->getRmessage();
            turnitintool_print_error('<strong>' . get_string('submissionupdateerror', 'turnitintool') . '</strong><br />' . $reason, NULL, NULL, NULL, __FILE__, __LINE__);
            exit;
        }
        $update = new stdClass();
        $update->id = $submission->id;
        $update->submission_unanon = 1;
        $update->submission_unanonreason = $reason;
        turnitintool_update_record('turnitintool_submissions', $update);
        unset($tii);
        unset($loaderbar);
    }
}