exit; } } if (!is_null($param_submitted) and $param_do == 'intro') { $notice = turnitintool_update_partnames($cm, $turnitintool, $post); } if (!is_null($param_delpart) and $param_do == 'intro') { $notice = turnitintool_delete_part($cm, $turnitintool, $param_delpart); } if (!is_null($param_submitted) and $param_do == 'notes') { $notice = turnitintool_process_notes($cm, $turnitintool, $param_s, $post); } if (!is_null($param_submitted) and $param_do == 'options') { $notice = turnitintool_process_options($cm, $turnitintool, $post); } turnitintool_add_to_log($course->id, "view turnitintool", "view.php?id={$cm->id}", "User viewed assignment '{$turnitintool->name}'", "{$cm->id}"); // Enable activity completion on page view. if (property_exists($CFG, 'branch') && $CFG->branch >= 20) { $completion = new completion_info($course); $completion->set_module_viewed($cm); } /// Print the page header $strturnitintools = get_string("modulenameplural", "turnitintool"); $strturnitintool = get_string("modulename", "turnitintool"); if (is_object($PAGE) && @is_callable(array($PAGE->navbar, 'add'))) { $navigation = ''; } elseif (!is_callable('build_navigation')) { $navigation = array(array('title' => $course->shortname, 'url' => $CFG->wwwroot . "/course/view.php?id={$course->id}", 'type' => 'course'), array('title' => $strturnitintools, 'url' => $CFG->wwwroot . "/mod/turnitintool/index.php?id={$course->id}", 'type' => 'activity'), array('title' => format_string($turnitintool->name), 'url' => '', 'type' => 'activityinstance')); } else { $navigation = build_navigation('', $cm); }
/** * Takes the submission file and uploads it to Turnitin * * @global object * @param object $cm The moodle course module object for this instance * @param object $turnitintool The turnitintool object for this activity * @param object $submission The submission object for this submission */ function turnitintool_upload_submission($cm, $turnitintool, $submission) { global $CFG, $USER; if (!($course = turnitintool_get_record('course', 'id', $turnitintool->course))) { turnitintool_print_error('coursegeterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } if (!($part = turnitintool_get_record('turnitintool_parts', 'id', $submission->submission_part))) { turnitintool_print_error('partgeterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } $user = turnitintool_get_moodleuser($submission->userid, NULL, __FILE__, __LINE__); $owner = turnitintool_get_owner($turnitintool->course); $post = new stdClass(); $post->oid = !is_null($submission->submission_objectid) ? $submission->submission_objectid : ''; $is_resubmission = 0; if (!empty($submission->submission_objectid)) { $is_resubmission = 1; } $loaderbar = new turnitintool_loaderbarclass(4); // (2xStart/End Session and Submit Paper total 3 $tii = new turnitintool_commclass(turnitintool_getUID($user), $user->firstname, $user->lastname, $user->email, 1, $loaderbar); $tii->startSession(); // Set this user up with a Turnitin Account or check to see if an account has already been set up // Either return the stored ID OR store the New Turnitin User ID then return it // Use UTP student (1) as this is a submission [[[[ $turnitinuser = turnitintool_usersetup($user, get_string('userprocess', 'turnitintool'), $tii, $loaderbar); if ($tii->getRerror()) { if ($tii->getAPIunavailable()) { turnitintool_print_error('apiunavailable', 'turnitintool', NULL, NULL, __FILE__, __LINE__); } else { turnitintool_print_error($tii->getRmessage(), NULL, NULL, NULL, __FILE__, __LINE__); } exit; } $turnitinuser_id = $turnitinuser->turnitin_uid; // ]]]] $post->cid = turnitintool_getCID($course->id); // Get the Turnitin Class ID for Course $post->assignid = turnitintool_getAID($part->id); // Get the Assignment ID for this Assignment / Turnitintool instance $post->ctl = turnitintool_getCTL($course->id); $post->assignname = $turnitintool->name . ' - ' . $part->partname . ' (Moodle ' . $post->assignid . ')'; $post->tem = turnitintool_get_tutor_email($owner->id); $post->papertitle = $submission->submission_title; if (is_callable("get_file_storage")) { $fs = get_file_storage(); if ($CFG->branch >= 29 && $submission->submission_type != 2) { $context = context_module::instance($cm->id); $files = $fs->get_area_files($context->id, 'mod_turnitintool', 'submissions', $submission->id, "timecreated", false); //There will only be one file so get it. $file = reset($files); } else { $file = $fs->get_file($cm->id, 'mod_turnitintool', 'submission', $submission->id, '/', $submission->submission_filename); } if (!is_object($file)) { turnitintool_activitylog("SUBID: " . $submission->id . " File not found on disk in Moodle, this submission will be deleted", "SUB_DELETED"); turnitintool_delete_records('turnitintool_submissions', 'id', $submission->id); turnitintool_print_error('filenotfound', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } if ($CFG->branch >= 29 && $submission->submission_type != 2) { $filename = array($submission->submission_title, $cm->id); $tempname = turnitintool_tempfile($file->get_filename()); } else { $tempname = turnitintool_tempfile('_' . $submission->submission_filename); } $tempfile = fopen($tempname, "w"); fwrite($tempfile, $file->get_content()); fclose($tempfile); $filepath = $tempname; turnitintool_activitylog("SUBID: " . $submission->id . " - Using 2.0 File API", "UPLOAD"); turnitintool_activitylog("FILE PATH: " . $filepath, "UPLOAD"); } else { $tempname = null; $filepath = $CFG->dataroot . '/' . turnitintool_file_path($cm, $turnitintool, $submission->userid) . '/' . $submission->submission_filename; turnitintool_activitylog("SUBID: " . $submission->id . " - Using pre 2.0 File API", "UPLOAD"); turnitintool_activitylog("FILE PATH: " . $filepath, "UPLOAD"); } // Give join class 3 tries, fix for 220 errors, fail over and log failure in activity logs for ($i = 0; $i < 3; $i++) { $tii->joinClass($post, get_string('joiningclass', 'turnitintool', '')); if (!$tii->getRerror()) { break; } else { $loaderbar->total = $loaderbar->total + 1; turnitintool_activitylog("Failed: " . $tii->getRcode(), "JOINCLASS FAILED"); } } if ($tii->getRerror()) { $reason = $tii->getAPIunavailable() ? get_string('apiunavailable', 'turnitintool') : $tii->getRmessage(); turnitintool_print_error($reason . " CODE: " . $tii->getRcode(), NULL, NULL, NULL, __FILE__, __LINE__); exit; } // Upload the file to Turnitin $tii->submitPaper($post, $filepath, get_string('uploadingtoturnitin', 'turnitintool')); if (!is_null($tempname)) { unlink($tempname); // If we made a temp file earlier for the Moodle 2 file API delete it here } $update = new stdClass(); if ($tii->getRerror()) { if ($tii->getAPIunavailable()) { $status = get_string('apiunavailable', 'turnitintool'); $queued = 1; } else { $status = $tii->getRmessage(); $queued = 0; } if (!$queued) { $update->submission_score = null; $update->submission_status = $status; $update->submission_queued = $queued; $update->submission_modified = time(); $update->id = $submission->id; if (!turnitintool_update_record('turnitintool_submissions', $update)) { turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } turnitintool_print_error($tii->getRmessage() . " CODE: " . $tii->getRcode(), NULL, NULL, NULL, __FILE__, __LINE__); exit; } } else { $status = get_string('submissionuploadsuccess', 'turnitintool'); $update->submission_objectid = $tii->getObjectid(); $queued = 0; } $update->submission_status = $status; $update->submission_queued = $queued; $update->submission_attempts = 0; $update->submission_modified = time(); $update->id = $submission->id; if (!turnitintool_update_record('turnitintool_submissions', $update)) { turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } // At this point the submission has been made - lock the assignment setting for anon marking $turnitintool->submitted = 1; if (!turnitintool_update_record('turnitintool', $turnitintool)) { turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } if ($is_resubmission) { turnitintool_add_to_log($turnitintool->course, "add submission", "view.php?id={$cm->id}", "User submitted '{$submission->submission_title}' (resubmission)", "{$cm->id}", $user->id); } else { turnitintool_add_to_log($turnitintool->course, "add submission", "view.php?id={$cm->id}", "User submitted '{$submission->submission_title}'", "{$cm->id}", $user->id); } $tii->endSession(); if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) { turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions'); exit; } else { turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=submissions'); exit; } unset($tii); exit; }
if (isset($PAGE) and is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old? $jsurl = new moodle_url($CFG->wwwroot . '/mod/turnitintool/scripts/turnitintool.js'); $PAGE->requires->js($jsurl, true); $cssurl = new moodle_url($CFG->wwwroot . '/mod/turnitintool/styles.css'); $PAGE->requires->css($cssurl); } else { require_js($CFG->wwwroot . '/mod/turnitintool/scripts/turnitintool.js'); } $id = required_param('id', PARAM_INT); // course if (!($course = turnitintool_get_record("course", "id", $id))) { turnitintool_print_error('courseiderror', 'turnitintool'); } require_login($course->id); turnitintool_add_to_log($course->id, "list turnitintool", "index.php?id={$course->id}", "User viewed the Turnitin assignment list for course {$course->id}", 0); /// Get all required stringsnewmodule $strturnitintools = get_string("modulenameplural", "turnitintool"); $strturnitintool = get_string("modulename", "turnitintool"); if (is_object($PAGE) && @is_callable(array($PAGE->navbar, 'add'))) { $navigation = ''; } elseif (!is_callable('build_navigation')) { $navigation = array(array('title' => $course->shortname, 'url' => $CFG->wwwroot . "/course/view.php?id={$course->id}", 'type' => 'course'), array('title' => $strturnitintools, 'url' => '', 'type' => 'activity')); } else { $navigation = array(array('name' => $strturnitintools, 'url' => '', 'type' => 'activity')); $navigation = build_navigation($navigation, ""); } /// Print the header turnitintool_header(NULL, $course, $_SERVER["REQUEST_URI"], $strturnitintools, $SITE->fullname, $navigation, '', '', true, '', ''); //print_header_simple($strturnitintools, '', $navigation, "", "", true, "", navmenu($course)); echo '<div id="turnitintool_style">';