Esempio n. 1
0
     echo html_writer::tag("div", $turnitintooltwoview->output_dv_launch_form($do, $submissionid, $user->tii_user_id, $userrole), array("class" => "launch_form"));
     if ($do === "origreport") {
         $submission = new turnitintooltwo_submission($submissionid, 'turnitin');
         turnitintooltwo_add_to_log($turnitintooltwoassignment->turnitintooltwo->course, "view submission", 'view.php?id=' . $cm->id, get_string('viewsubmissiondesc', 'turnitintooltwo') . " '{$submission->submission_title}'", $cm->id, $submission->userid);
     }
     break;
 case "submissions":
     // Output a link for the student to accept the turnitin licence agreement.
     $noscriptula = "";
     $ula = "";
     if (!$istutor) {
         $eulaaccepted = false;
         $user = new turnitintooltwo_user($USER->id, $userrole);
         $coursedata = $turnitintooltwoassignment->get_course_data($turnitintooltwoassignment->turnitintooltwo->course);
         $user->join_user_to_class($coursedata->turnitin_cid);
         $eulaaccepted = $user->user_agreement_accepted != 1 ? $user->get_accepted_user_agreement() : $user->user_agreement_accepted;
         // Check if the submitting user has accepted the EULA
         if ($eulaaccepted != 1) {
             // Moodle strips out form and script code for forum posts so we have to do the Eula Launch differently.
             $ula_link = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/extras.php?cmid=' . $cm->id . '&cmd=useragreement&view_context=box_solid', html_writer::tag('i', '', array('class' => 'tiiicon icon-warn icon-2x turnitin_ula_warn')) . '</br></br>' . get_string('turnitinula', 'turnitintooltwo') . " " . get_string('turnitinula_btn', 'turnitintooltwo'), array("class" => "turnitin_eula_link"));
             $eulaignoredclass = $eulaaccepted == 0 ? ' turnitin_ula_ignored' : '';
             $ula = html_writer::tag('div', $ula_link, array('class' => 'turnitin_ula js_required' . $eulaignoredclass, 'data-userid' => $user->id));
             $noscriptula = html_writer::tag('noscript', turnitintooltwo_view::output_dv_launch_form("useragreement", 0, $user->tii_user_id, "Learner", get_string('turnitinula', 'turnitintooltwo'), false) . " " . get_string('noscriptula', 'turnitintooltwo'), array('class' => 'warning turnitin_ula_noscript'));
             echo $ula . $noscriptula;
         }
     }
     $listsubmissionsdesc = $istutor ? "listsubmissionsdesc" : "listsubmissionsdesc_student";
     turnitintooltwo_add_to_log($turnitintooltwoassignment->turnitintooltwo->course, "list submissions", 'view.php?id=' . $cm->id, get_string($listsubmissionsdesc, 'turnitintooltwo') . ": {$course->id}", $cm->id);
     if (!$istutor && !has_capability('mod/turnitintooltwo:submit', context_module::instance($cm->id))) {
         turnitintooltwo_print_error('permissiondeniederror', 'turnitintooltwo');
         exit;
 /**
  *
  * @global type $CFG
  * @param type $linkarray
  * @return type
  */
 public function get_links($linkarray)
 {
     global $CFG, $DB, $OUTPUT, $PAGE, $USER;
     // Don't show links for certain file types as they won't have been submitted to Turnitin.
     if (!empty($linkarray["file"])) {
         $file = $linkarray["file"];
         $filearea = $file->get_filearea();
         $nonsubmittingareas = array("feedback_files", "introattachment");
         if (in_array($filearea, $nonsubmittingareas)) {
             return;
         }
     }
     // Set static variables.
     static $cm;
     static $forum;
     if (empty($cm)) {
         $cm = get_coursemodule_from_id('', $linkarray["cmid"]);
         if ($cm->modname == 'forum') {
             if (!($forum = $DB->get_record("forum", array("id" => $cm->instance)))) {
                 print_error('invalidforumid', 'forum');
             }
         }
     }
     static $plagiarismsettings;
     if (empty($plagiarismsettings)) {
         $plagiarismsettings = $this->get_settings($linkarray["cmid"]);
     }
     // Exit if Turnitin is not being used for this module.
     if (empty($plagiarismsettings['use_turnitin'])) {
         return;
     }
     static $config;
     if (empty($config)) {
         $config = turnitintooltwo_admin_config();
     }
     static $moduletiienabled;
     if (empty($moduletiienabled)) {
         $moduletiienabled = $this->get_config_settings('mod_' . $cm->modname);
     }
     // Exit if Turnitin is not being used for this activity type.
     if (empty($moduletiienabled)) {
         return;
     }
     static $moduledata;
     if (empty($moduledata)) {
         $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance));
     }
     static $context;
     if (empty($context)) {
         $context = context_course::instance($cm->course);
     }
     static $coursedata;
     if (empty($coursedata)) {
         $coursedata = $this->get_course_data($cm->id, $cm->course);
     }
     // Create module object
     $moduleclass = "turnitin_" . $cm->modname;
     $moduleobject = new $moduleclass();
     // Work out if logged in user is a tutor on this module.
     static $istutor;
     if (empty($istutor)) {
         $istutor = $moduleobject->is_tutor($context);
     }
     // Define the timestamp for updating Peermark Assignments.
     if (empty($_SESSION["updated_pm"][$cm->id]) && $config->enablepeermark) {
         $_SESSION["updated_pm"][$cm->id] = time() - 60 * 5;
     }
     $output = "";
     // If a text submission has been made, we can only display links for current attempts so don't show links previous attempts.
     // This will need to be reworked when linkarray contains submission id.
     static $contentdisplayed;
     if ($cm->modname == 'assign' && !empty($linkarray["content"]) && $contentdisplayed == true) {
         return $output;
     }
     if ((!empty($linkarray["file"]) || !empty($linkarray["content"])) && !empty($linkarray["cmid"])) {
         $this->load_page_components();
         $identifier = '';
         $itemid = 0;
         // Get File or Content information.
         $submittinguser = $linkarray['userid'];
         if (!empty($linkarray["file"])) {
             $identifier = $file->get_pathnamehash();
             $itemid = $file->get_itemid();
             $submissiontype = 'file';
         } else {
             if (!empty($linkarray["content"])) {
                 // Get turnitin text content details.
                 $submissiontype = $cm->modname == "forum" ? 'forum_post' : 'text_content';
                 $content = $moduleobject->set_content($linkarray, $cm);
                 $identifier = sha1($content);
             }
         }
         // Group submissions where all students have to submit sets userid to 0;
         if ($linkarray['userid'] == 0 && !$istutor) {
             $linkarray['userid'] = $USER->id;
         }
         // Get correct user id that submission is for rather than who submitted, this only affects file submissions
         // post Moodle 2.7 which is problematic as teachers can submit on behalf of students.
         $author = $linkarray['userid'];
         if ($itemid != 0) {
             $author = $moduleobject->get_author($itemid);
             $linkarray['userid'] = !empty($author) ? $author : $linkarray['userid'];
         }
         $output .= $OUTPUT->box_start('tii_links_container');
         // Show the EULA for a student if necessary.
         if ($linkarray["userid"] == $USER->id && empty($plagiarismfile->externalid)) {
             $eula = "";
             static $userid;
             if (empty($userid)) {
                 $userid = 0;
             }
             // Condition added to test for Moodle 2.7 as it calls this function twice.
             if ($CFG->branch >= 27 || $userid != $linkarray["userid"]) {
                 // Show EULA if necessary and we have a connection to Turnitin.
                 static $eulashown;
                 if (empty($eulashown)) {
                     $eulashown = false;
                 }
                 $user = new turnitintooltwo_user($USER->id, "Learner");
                 $success = $user->join_user_to_class($coursedata->turnitin_cid);
                 // $success is false if there is no Turnitin connection and null if user has previously been enrolled.
                 if ((is_null($success) || $success === true) && $eulashown == false) {
                     $eulaaccepted = $user->user_agreement_accepted == 0 ? $user->get_accepted_user_agreement() : $user->user_agreement_accepted;
                     $userid = $linkarray["userid"];
                     if ($eulaaccepted != 1) {
                         $eula_link = html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"] . '&cmd=useragreement&view_context=box_solid', $OUTPUT->pix_icon('tiiIcon', '', 'plagiarism_turnitin', array('class' => 'icon_size_large')) . '<br/>' . get_string('turnitinppulapost', 'plagiarism_turnitin'), array("class" => "pp_turnitin_eula_link"));
                         $eula = html_writer::tag('div', $eula_link, array('class' => 'pp_turnitin_ula js_required', 'data-userid' => $user->id));
                     }
                     // Show EULA launcher and form placeholder.
                     if (!empty($eula)) {
                         $output .= $eula;
                         $turnitincomms = new turnitin_comms();
                         $turnitincall = $turnitincomms->initialise_api();
                         $customdata = array("disable_form_change_checker" => true, "elements" => array(array('html', $OUTPUT->box('', '', 'useragreement_inputs'))));
                         $eulaform = new turnitintooltwo_form($turnitincall->getApiBaseUrl() . TiiLTI::EULAENDPOINT, $customdata, 'POST', $target = 'eulaWindow', array('id' => 'eula_launch'));
                         $output .= $OUTPUT->box($eulaform->display(), 'tii_useragreement_form', 'useragreement_form');
                         $eulashown = true;
                     }
                 }
             }
         }
         // Check whether submission is a group submission - only applicable to assignment module.
         // If it's a group submission then other users in the group should be able to see the originality score
         // They can not open the DV though.
         $submissionusers = array($linkarray["userid"]);
         if ($cm->modname == "assign") {
             if ($moduledata->teamsubmission) {
                 $assignment = new assign($context, $cm, null);
                 if ($group = $assignment->get_submission_group($linkarray["userid"])) {
                     $users = groups_get_members($group->id);
                     $submissionusers = array_keys($users);
                 }
             }
         }
         // Group originality score for Coursework module
         // Check whether submission is a group submission
         // If it's a group submission then other users in the group should be able to see the originality score
         // They can not open the DV though.
         if ($cm->modname == "coursework") {
             if ($moduledata->use_groups) {
                 $coursework = new \mod_coursework\models\coursework($moduledata->id);
                 $user = $DB->get_record('user', array('id' => $linkarray["userid"]));
                 $user = mod_coursework\models\user::find($user);
                 if ($group = $coursework->get_student_group($user)) {
                     $users = groups_get_members($group->id);
                     $submissionusers = array_keys($users);
                 }
             }
         }
         // Proceed to displaying links for submissions.
         if ($istutor || in_array($USER->id, $submissionusers)) {
             // Prevent text content links being displayed for previous attempts as we have no way of getting the data.
             if (!empty($linkarray["content"]) && $linkarray["userid"] == $USER->id) {
                 $contentdisplayed = true;
             }
             // Get turnitin file details
             $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', array('userid' => $linkarray["userid"], 'cm' => $linkarray["cmid"], 'identifier' => $identifier), 'lastmodified DESC', '*', 0, 1);
             $plagiarismfile = current($plagiarismfiles);
             // Populate gradeitem query
             $gradeitemqueryarray = array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, 'itemnumber' => 0);
             // Get grade item and work out whether grades have been released for viewing.
             $gradesreleased = true;
             if ($gradeitem = $DB->get_record('grade_items', $gradeitemqueryarray)) {
                 switch ($gradeitem->hidden) {
                     case 1:
                         $gradesreleased = false;
                         break;
                     default:
                         $gradesreleased = $gradeitem->hidden >= time() ? false : true;
                         break;
                 }
                 // Give Marking workflow higher priority than gradebook hidden date.
                 if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) {
                     $gradesreleased = $DB->record_exists('assign_user_flags', array('userid' => $linkarray["userid"], 'assignment' => $cm->instance, 'workflowstate' => 'released'));
                 }
             }
             $currentgradequery = false;
             if ($gradeitem) {
                 $currentgradequery = $moduleobject->get_current_gradequery($linkarray["userid"], $cm->instance, $gradeitem->id);
             }
             // Display links to OR, GradeMark and show relevant errors.
             if ($plagiarismfile) {
                 if ($plagiarismfile->statuscode == 'success') {
                     if ($istutor || $linkarray["userid"] == $USER->id) {
                         $output .= html_writer::tag('div', $OUTPUT->pix_icon('tiiIcon', get_string('turnitinid', 'plagiarism_turnitin') . ': ' . $plagiarismfile->externalid, 'plagiarism_turnitin', array('class' => 'icon_size')) . get_string('turnitinid', 'plagiarism_turnitin') . ': ' . $plagiarismfile->externalid, array('class' => 'turnitin_status'));
                     }
                     // Show Originality Report score and link.
                     if (($istutor || in_array($USER->id, $submissionusers) && $plagiarismsettings["plagiarism_show_student_report"]) && ((is_null($plagiarismfile->orcapable) || $plagiarismfile->orcapable == 1) && !is_null($plagiarismfile->similarityscore))) {
                         // This class is applied so that only the user who submitted or a tutor can open the DV.
                         $useropenclass = $USER->id == $linkarray["userid"] || $istutor ? 'pp_origreport_open' : '';
                         $output .= $OUTPUT->box_start('row_score pp_origreport ' . $useropenclass . ' origreport_' . $plagiarismfile->externalid . '_' . $linkarray["cmid"], $CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"]);
                         // Show score.
                         if ($plagiarismfile->statuscode == "pending") {
                             $output .= html_writer::tag('div', '&nbsp;', array('title' => get_string('pending', 'plagiarism_turnitin'), 'class' => 'tii_tooltip origreport_score score_colour score_colour_'));
                         } else {
                             // Put EN flag if translated matching is on and that is the score used.
                             $transmatch = $plagiarismfile->transmatch == 1 ? ' EN' : '';
                             if (is_null($plagiarismfile->similarityscore)) {
                                 $score = '&nbsp;';
                                 $titlescore = get_string('pending', 'plagiarism_turnitin');
                                 $class = 'score_colour_';
                             } else {
                                 $score = $plagiarismfile->similarityscore . '%';
                                 $titlescore = $plagiarismfile->similarityscore . '% ' . get_string('similarity', 'plagiarism_turnitin');
                                 $class = 'score_colour_' . round($plagiarismfile->similarityscore, -1);
                             }
                             $output .= html_writer::tag('div', $score . $transmatch, array('title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour ' . $class));
                         }
                         // Put in div placeholder for DV launch form.
                         $output .= $OUTPUT->box('', 'launch_form origreport_form_' . $plagiarismfile->externalid);
                         // Add url for launching DV from Forum post.
                         if ($cm->modname == 'forum') {
                             $output .= $OUTPUT->box($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"], 'origreport_forum_launch origreport_forum_launch_' . $plagiarismfile->externalid);
                         }
                         $output .= $OUTPUT->box_end(true);
                     }
                     if ($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable)) {
                         // This class is applied so that only the user who submitted or a tutor can open the DV.
                         $useropenclass = $USER->id == $linkarray["userid"] || $istutor ? 'pp_origreport_open' : '';
                         $output .= $OUTPUT->box_start('row_score pp_origreport ' . $useropenclass, '');
                         $output .= html_writer::tag('div', 'x', array('title' => get_string('notorcapable', 'plagiarism_turnitin'), 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable'));
                         $output .= $OUTPUT->box_end(true);
                     }
                     //Check if blind marking is on and revealidentities is not set yet.
                     $blindon = !empty($moduledata->blindmarking) && empty($moduledata->revealidentities);
                     // Can grade and feedback be released to this student yet?
                     $released = !$blindon && ($gradesreleased && (!empty($plagiarismfile->gm_feedback) || isset($currentgradequery->grade)));
                     // Show link to open grademark.
                     if ($config->usegrademark && ($istutor || $linkarray["userid"] == $USER->id && $released) && !empty($gradeitem)) {
                         // Output grademark icon.
                         $output .= $OUTPUT->box_start('grade_icon', '');
                         $output .= html_writer::tag('div', $OUTPUT->pix_icon('icon-edit', get_string('grademark', 'plagiarism_turnitin'), 'plagiarism_turnitin'), array('title' => get_string('grademark', 'plagiarism_turnitin'), 'class' => 'pp_grademark_open tii_tooltip grademark_' . $plagiarismfile->externalid . '_' . $linkarray["cmid"], 'id' => $CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"]));
                         // Add url for launching DV from Forum post.
                         if ($cm->modname == 'forum') {
                             $output .= $OUTPUT->box($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"], 'grademark_forum_launch grademark_forum_launch_' . $plagiarismfile->externalid);
                         }
                         // Put in div placeholder for DV launch form.
                         $output .= $OUTPUT->box('', 'launch_form grademark_form_' . $plagiarismfile->externalid);
                         $output .= $OUTPUT->box_end(true);
                     }
                     // Indicate whether student has viewed the feedback.
                     if ($istutor) {
                         if (isset($plagiarismfile->externalid)) {
                             $studentread = !empty($plagiarismfile->student_read) ? $plagiarismfile->student_read : 0;
                             if ($studentread > 0) {
                                 $output .= $OUTPUT->pix_icon('icon-student-read', get_string('student_read', 'plagiarism_turnitin') . ' ' . userdate($studentread), 'plagiarism_turnitin', array("class" => "student_read_icon"));
                             } else {
                                 $output .= $OUTPUT->pix_icon('icon-dot', get_string('student_notread', 'plagiarism_turnitin'), 'plagiarism_turnitin', array("class" => "student_read_icon"));
                             }
                         } else {
                             $output .= "--";
                         }
                     }
                     // Show link to view rubric for student.
                     if (!$istutor && $config->usegrademark && !empty($plagiarismsettings["plagiarism_rubric"])) {
                         // Update assignment in case rubric is not stored in Turnitin yet.
                         $tiiassignment = $this->sync_tii_assignment($cm, $coursedata->turnitin_cid);
                         $rubricviewlink = html_writer::tag('div', html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/ajax.php?cmid=' . $cm->id . '&action=rubricview&view_context=box', '&nbsp;', array('class' => 'tii_tooltip rubric_view_pp_launch', 'id' => 'rubric_view_launch', 'title' => get_string('launchrubricview', 'plagiarism_turnitin'))) . html_writer::tag('span', '', array('class' => 'launch_form', 'id' => 'rubric_view_form')), array('class' => 'row_rubric_view'));
                         $output .= $rubricviewlink;
                     }
                     if ($config->enablepeermark) {
                         // If this module is already on Turnitin then refresh and get Peermark Assignments.
                         if (!empty($plagiarismsettings['turnitin_assignid'])) {
                             if ($_SESSION["updated_pm"][$cm->id] <= time() - 60 * 2) {
                                 $this->refresh_peermark_assignments($cm, $plagiarismsettings['turnitin_assignid']);
                                 $turnitintooltwoassignment = new turnitintooltwo_assignment($cm->instance, '', 'PP');
                                 $_SESSION["peermark_assignments"][$cm->id] = $turnitintooltwoassignment->get_peermark_assignments($plagiarismsettings['turnitin_assignid']);
                                 $_SESSION["updated_pm"][$cm->id] = time();
                             }
                             // Determine if we have any active Peermark Assignments.
                             static $peermarksactive;
                             if (!isset($peermarksactive)) {
                                 $peermarksactive = false;
                                 foreach ($_SESSION["peermark_assignments"][$cm->id] as $peermarkassignment) {
                                     if (time() > $peermarkassignment->dtstart) {
                                         $peermarksactive = true;
                                         break;
                                     }
                                 }
                             }
                             // Show Peermark Reviews link.
                             if ($istutor && count($_SESSION["peermark_assignments"][$cm->id]) > 0 || !$istutor && $peermarksactive) {
                                 $peermarkreviewslink = $OUTPUT->box_start('row_peermark_reviews', '');
                                 $peermarkreviewslink .= html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/ajax.php?cmid=' . $cm->id . '&action=peermarkreviews&view_context=box', '', array('title' => get_string('launchpeermarkreviews', 'plagiarism_turnitin'), 'class' => 'peermark_reviews_pp_launch tii_tooltip'));
                                 $peermarkreviewslink .= html_writer::tag('span', '', array('class' => 'launch_form', 'id' => 'peermark_reviews_form'));
                                 $peermarkreviewslink .= $OUTPUT->box_end(true);
                                 $output .= $peermarkreviewslink;
                             }
                         }
                     }
                 } else {
                     if ($plagiarismfile->statuscode == 'error') {
                         // Deal with legacy error issues.
                         $errorcode = isset($plagiarismfile->errorcode) ? $plagiarismfile->errorcode : 0;
                         if ($errorcode == 0 && $submissiontype == 'file') {
                             if ($file->get_filesize() > TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE) {
                                 $errorcode = 2;
                             }
                         }
                         // Show error message if there is one.
                         if ($errorcode == 0) {
                             $langstring = $istutor ? 'ppsubmissionerrorseelogs' : 'ppsubmissionerrorstudent';
                             $errorstring = isset($plagiarismfile->errormsg) ? get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg;
                         } else {
                             $errorstring = get_string('errorcode' . $plagiarismfile->errorcode, 'plagiarism_turnitin', display_size(TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE));
                         }
                         $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('x-red', $errorstring, 'plagiarism_turnitin'), array('title' => $errorstring, 'class' => 'tii_tooltip tii_error_icon'));
                         // Attach error text or resubmit link after icon depending on whether user is a student/teacher.
                         // Don't attach resubmit link if the user has not accepted the EULA.
                         if (!$istutor) {
                             $output .= html_writer::tag('div', $erroricon . ' ' . $errorstring, array('class' => 'warning clear'));
                         } else {
                             if ($errorcode == 3) {
                                 $output .= html_writer::tag('div', $erroricon, array('class' => 'clear'));
                             } else {
                                 $output .= html_writer::tag('div', $erroricon . ' ' . get_string('resubmittoturnitin', 'plagiarism_turnitin'), array('class' => 'clear pp_resubmit_link', 'id' => 'pp_resubmit_' . $plagiarismfile->id));
                                 $output .= html_writer::tag('div', $OUTPUT->pix_icon('loading', $errorstring, 'plagiarism_turnitin') . ' ' . get_string('resubmitting', 'plagiarism_turnitin'), array('class' => 'pp_resubmitting hidden'));
                                 // Pending status for after resubmission.
                                 $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin') . ': ' . get_string('pending', 'plagiarism_turnitin');
                                 $output .= html_writer::tag('div', $OUTPUT->pix_icon('tiiIcon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')) . $statusstr, array('class' => 'turnitin_status hidden'));
                                 // Show hidden data for potential forum post resubmissions
                                 if ($submissiontype == 'forum_post' && !empty($linkarray["content"])) {
                                     $output .= html_writer::tag('div', $linkarray["content"], array('class' => 'hidden', 'id' => 'content_' . $plagiarismfile->id));
                                 }
                                 if ($cm->modname == 'forum') {
                                     // Get forum data from the query string as we'll need this to recreate submission event.
                                     $querystrid = optional_param('id', 0, PARAM_INT);
                                     $discussionid = optional_param('d', 0, PARAM_INT);
                                     $reply = optional_param('reply', 0, PARAM_INT);
                                     $edit = optional_param('edit', 0, PARAM_INT);
                                     $delete = optional_param('delete', 0, PARAM_INT);
                                     $output .= html_writer::tag('div', $querystrid . '_' . $discussionid . '_' . $reply . '_' . $edit . '_' . $delete, array('class' => 'hidden', 'id' => 'forumdata_' . $plagiarismfile->id));
                                 }
                             }
                         }
                     } else {
                         if ($plagiarismfile->statuscode == 'deleted') {
                             $errorcode = isset($plagiarismfile->errorcode) ? $plagiarismfile->errorcode : 0;
                             if ($errorcode == 0) {
                                 $langstring = $istutor ? 'ppsubmissionerrorseelogs' : 'ppsubmissionerrorstudent';
                                 $errorstring = isset($plagiarismfile->errormsg) ? get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg;
                             } else {
                                 $errorstring = get_string('errorcode' . $plagiarismfile->errorcode, 'plagiarism_turnitin', display_size(TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE));
                             }
                             $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin') . ': ' . get_string('deleted', 'plagiarism_turnitin') . '<br />';
                             $statusstr .= get_string('because', 'plagiarism_turnitin') . '<br />"' . $errorstring . '"';
                             $output .= html_writer::tag('div', $OUTPUT->pix_icon('tiiIcon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')) . $statusstr, array('class' => 'turnitin_status'));
                         } else {
                             $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin') . ': ' . get_string('pending', 'plagiarism_turnitin');
                             $output .= html_writer::tag('div', $OUTPUT->pix_icon('tiiIcon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')) . $statusstr, array('class' => 'turnitin_status'));
                         }
                     }
                 }
             } else {
                 // Add Error if the user has not accepted EULA for submissions made before instant submission was removed.
                 $eulaerror = "";
                 if ($linkarray["userid"] != $USER->id && $submittinguser == $author && $istutor) {
                     // There is a moodle plagiarism bug where get_links is called twice, the first loop is incorrect and is killing
                     // this functionality. Have to check that user exists here first else there will be a fatal error.
                     if ($mdl_user = $DB->get_record('user', array('id' => $linkarray["userid"]))) {
                         // We need to check for security that the user is actually on the course.
                         if ($moduleobject->user_enrolled_on_course($context, $linkarray["userid"])) {
                             $user = new turnitintooltwo_user($linkarray["userid"], "Learner");
                             if ($user->user_agreement_accepted != 1) {
                                 $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('errorcode3', 'plagiarism_turnitin'), 'plagiarism_turnitin'), array('title' => get_string('errorcode3', 'plagiarism_turnitin'), 'class' => 'tii_tooltip tii_error_icon'));
                                 $eulaerror = html_writer::tag('div', $erroricon, array('class' => 'clear'));
                             }
                         }
                     }
                 }
                 // Show Turnitin Pending status or EULA error.
                 if (!empty($eulaerror)) {
                     $output .= $eulaerror;
                 } else {
                     $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin') . ': ' . get_string('pending', 'plagiarism_turnitin');
                     $output .= html_writer::tag('div', $OUTPUT->pix_icon('tiiIcon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')) . $statusstr, array('class' => 'turnitin_status'));
                 }
             }
             $output .= html_writer::tag('div', '', array('class' => 'clear'));
         }
         $output .= $OUTPUT->box_end(true);
     }
     // This comment is here as it is useful for product support.
     $plagiarismsettings = $this->get_settings($cm->id);
     $turnitinassignid = empty($plagiarismsettings['turnitin_assignid']) ? '' : $plagiarismsettings['turnitin_assignid'];
     $output .= html_writer::tag('span', '<!-- Turnitin Plagiarism plugin Version: ' . get_config('plagiarism_turnitin', 'version') . ' Course ID: ' . $coursedata->turnitin_cid . ' TII assignment ID: ' . $turnitinassignid . ' -->');
     return $output;
 }
 /**
  * Get the row for this submission in the inbox table
  *
  * @global object $CFG
  * @global type $OUTPUT
  * @param type $cm
  * @param type $turnitintooltwoassignment
  * @param type $parts
  * @param type $partid
  * @param type $submission
  * @param type $useroverallgrades
  * @param type $istutor
  * @return type
  */
 public function get_submission_inbox_row($cm, $turnitintooltwoassignment, $parts, $partid, $submission, &$useroverallgrades, $istutor, $context = 'all')
 {
     global $CFG, $OUTPUT, $USER, $DB;
     $config = turnitintooltwo_admin_config();
     $moodleuserid = substr($submission->userid, 0, 3) != 'nm-' && $submission->userid != 0 ? $submission->userid : 0;
     if (!$istutor) {
         $user = new turnitintooltwo_user($USER->id, "Learner");
     }
     $checkbox = "&nbsp;";
     if (!empty($submission->submission_objectid) && $istutor) {
         $checkbox = html_writer::checkbox('check_' . $submission->submission_objectid, $submission->submission_objectid, false, '', array("class" => "inbox_checkbox"));
     }
     if (!$istutor) {
         // If students viewing it will show 'digital receipt' link
         if (!empty($submission->submission_objectid)) {
             $studentname = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&do=digital_receipt&submissionid=' . $submission->submission_objectid . '&view_context=box', $OUTPUT->pix_icon('receipt', get_string('digitalreceipt', 'turnitintooltwo'), 'mod_turnitintooltwo', array('id' => 'tii_digital_receipt_icon')) . get_string('viewdigitalreceipt', 'turnitintooltwo'), array('class' => 'tii_digital_receipt'));
         } else {
             $studentname = "--";
         }
         //Determine whether the student can see the overall grade, based on the post time of all parts.
         $display_overall_grade = 1;
         foreach (array_keys($parts) as $ar_key => $ar_value) {
             if ($parts[$ar_value]->dtpost > time()) {
                 $display_overall_grade = 0;
             }
         }
     } else {
         if ($turnitintooltwoassignment->turnitintooltwo->anon && $parts[$partid]->unanon != 1) {
             if (empty($submission->submission_unanon) and $parts[$partid]->dtpost > time() and !empty($submission->submission_objectid)) {
                 // Anonymous marking is on, postdate has not passed and a submission has been made.
                 $studentname = html_writer::link('.unanonymise_form', get_string('anonenabled', 'turnitintooltwo'), array("class" => "unanonymise", "id" => "submission_" . $submission->submission_objectid));
             } else {
                 if (($parts[$partid]->dtpost <= time() or !empty($submission->submission_unanon)) and empty($submission->nmoodle)) {
                     // Post date has passed or anonymous marking disabled for user and user is a moodle user.
                     $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname));
                 } else {
                     if (($parts[$partid]->dtpost <= time() or !empty($submission->submission_unanon)) and !empty($submission->nmoodle)) {
                         // Post date has passed or anonymous marking disabled for user and user is a NON moodle user.
                         $studentname = html_writer::tag("span", format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonmoodleuser', 'turnitintooltwo') . ")", array("class" => "italic"));
                     } else {
                         // User has not made a submission.
                         $studentname = html_writer::tag("span", get_string('anonenabled', 'turnitintooltwo'), array("class" => "italic"));
                     }
                 }
             }
         } else {
             if (empty($submission->nmoodle)) {
                 // Link to user profile.
                 $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname));
             } else {
                 if (!empty($submission->nmoodle) && substr($submission->userid, 0, 3) != 'nm-') {
                     // Moodle User not enrolled on this course as a student.
                     $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonenrolledstudent', 'turnitintooltwo') . ")", array("class" => "italic"));
                 } else {
                     // Non Moodle user.
                     $studentname = html_writer::tag("span", format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonmoodleuser', 'turnitintooltwo') . ")", array("class" => "italic"));
                 }
             }
         }
     }
     // Submission title with link to open DV.
     if (!empty($submission->submission_objectid) and !empty($submission->submission_objectid)) {
         $title = $OUTPUT->box_start('default_open', 'default_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
         $title .= $OUTPUT->box(format_string($submission->submission_title), 'submission_title underline');
         $title .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'default_url_' . $submission->submission_objectid);
         $title .= $OUTPUT->box_end(true);
         $rawtitle = $submission->submission_title;
     } else {
         $title = "--";
         $rawtitle = "--";
     }
     $objectid = !empty($submission->submission_objectid) ? $submission->submission_objectid : "--";
     // Show date of submission or link to submit if it didn't work.
     if (empty($submission->submission_objectid) and !empty($submission->id)) {
         $rawmodified = 1;
         $modified = html_writer::link($CFG->wwwroot . "/mod/turnitintooltwo/view.php?id=" . $cm->id . "&action=manualsubmission" . "&sub=" . $submission->id . '&sesskey=' . sesskey(), $OUTPUT->pix_icon('icon-sml', get_string('submittoturnitin', 'turnitintooltwo'), 'mod_turnitintooltwo') . " " . get_string('submittoturnitin', 'turnitintooltwo'));
     } else {
         if (empty($submission->submission_objectid)) {
             $rawmodified = 0;
             $modified = "--";
         } else {
             $rawmodified = (int) $submission->submission_modified;
             $modified = userdate($submission->submission_modified, get_string('strftimedatetimeshort', 'langconfig'));
             if ($submission->submission_modified > $parts[$partid]->dtdue) {
                 $modified = html_writer::tag('span', $modified, array("class" => "late_submission"));
             }
         }
     }
     // Show Originality score with link to open document viewer.
     if (!empty($submission->id) && is_null($submission->submission_score) && $submission->submission_orcapable == 0) {
         // Don't show if there is no OR score and submission is not OR capable
         $rawscore = null;
         $score = '--';
     } else {
         if (!empty($submission->id) && !empty($submission->submission_objectid) && ($istutor || $turnitintooltwoassignment->turnitintooltwo->studentreports)) {
             // Show score.
             if (is_null($submission->submission_score)) {
                 $score = $OUTPUT->box_start('row_score', 'origreport_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
                 $score .= $OUTPUT->box('&nbsp;', 'score_colour score_colour_');
                 $score .= $OUTPUT->box(get_string('pending', 'turnitintooltwo'), 'origreport_score');
                 $rawscore = null;
             } else {
                 $score = $OUTPUT->box_start('row_score origreport_open', 'origreport_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
                 // Put EN flag if translated matching is on and that is the score used.
                 $transmatch = $submission->submission_transmatch == 1 ? 'EN' : '&nbsp;';
                 $score .= $OUTPUT->box($transmatch, 'score_colour score_colour_' . round($submission->submission_score, -1));
                 $score .= $OUTPUT->box($submission->submission_score . '%', 'origreport_score');
                 $rawscore = $submission->submission_score;
             }
             // Put in div placeholder for DV launch form.
             $score .= $OUTPUT->box('', 'launch_form', 'origreport_form_' . $submission->submission_objectid);
             // URL for DV launcher
             $score .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'origreport_url_' . $submission->submission_objectid);
             $score .= $OUTPUT->box_end(true);
         } else {
             $rawscore = null;
             $score = '--';
         }
     }
     // Show grade and link to DV.
     if ($config->usegrademark) {
         if ($turnitintooltwoassignment->turnitintooltwo->grade == 0) {
             //We set the grade column to N/A if there is no grade type set.
             $rawgrade = null;
             $grade = $OUTPUT->box('N/A', '');
         } else {
             if (isset($submission->submission_objectid) && ($istutor || !$istutor && $parts[$partid]->dtpost < time())) {
                 $submissiongrade = !is_null($submission->submission_grade) ? $submission->submission_grade : '';
                 if (is_null($submission->submission_grade) || $submission->submission_gmimaged == 0 && !$istutor) {
                     $submissiongrade = "--";
                 }
                 // Show warning to instructor if student can still resubmit.
                 $canresubmit = $turnitintooltwoassignment->turnitintooltwo->reportgenspeed > 0;
                 $tutorbeforeduedate = $istutor && time() < $parts[$partid]->dtdue;
                 $allowedlate = $turnitintooltwoassignment->turnitintooltwo->allowlate == 1 && empty($submission->nmoodle);
                 $class = $canresubmit && ($tutorbeforeduedate || $allowedlate) ? 'graded_warning' : '';
                 // Output grademark icon.
                 $grade = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-pencil fa-lg gm-blue')), 'grademark_open' . $class, 'grademark_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid, array('title' => $CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id));
                 // Show grade.
                 $grade .= $OUTPUT->box(html_writer::tag('span', $submissiongrade, array("class" => "grade")) . "/" . $parts[$partid]->maxmarks, 'grademark_grade');
                 // Put in div placeholder for DV launch form.
                 $grade .= $OUTPUT->box('', 'launch_form', 'grademark_form_' . $submission->submission_objectid);
                 // URL for DV launcher
                 $grade .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'grademark_url_' . $submission->submission_objectid);
                 $rawgrade = $submissiongrade == "--" ? null : $submissiongrade;
             } else {
                 if (!isset($submission->submission_objectid) && empty($submission->id) && $istutor) {
                     // Allow nothing submission if no submission has been made and this is a tutor
                     $grade = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-pencil fa-lg grey')), 'submit_nothing', 'submitnothing_0_' . $partid . '_' . $submission->userid);
                     $rawgrade = null;
                 } else {
                     $rawgrade = null;
                     $grade = $OUTPUT->box('--', '');
                 }
             }
         }
         // Show average grade if more than 1 part.
         if (count($parts) > 1 || $turnitintooltwoassignment->turnitintooltwo->grade < 0) {
             $overallgrade = '--';
             if ($submission->nmoodle != 1 && ($istutor || !$istutor && $parts[$partid]->dtpost < time())) {
                 if (!isset($useroverallgrades[$submission->userid])) {
                     $usersubmissions = $turnitintooltwoassignment->get_user_submissions($submission->userid, $turnitintooltwoassignment->turnitintooltwo->id);
                     $useroverallgrades[$submission->userid] = $turnitintooltwoassignment->get_overall_grade($usersubmissions);
                 }
                 if ($turnitintooltwoassignment->turnitintooltwo->grade == 0 || $useroverallgrades[$submission->userid] === '--' || !$istutor && $display_overall_grade == 0) {
                 } else {
                     if ($turnitintooltwoassignment->turnitintooltwo->grade < 0) {
                         // Scale.
                         $scale = $DB->get_record('scale', array('id' => $turnitintooltwoassignment->turnitintooltwo->grade * -1));
                         $scalearray = explode(",", $scale->scale);
                         $overallgrade = $scalearray[$useroverallgrades[$submission->userid] - 1];
                     } else {
                         $overallgrade = round($useroverallgrades[$submission->userid] / $turnitintooltwoassignment->turnitintooltwo->grade * 100, 1) . '%';
                     }
                 }
                 if ($overallgrade != '--') {
                     $overallgrade = html_writer::tag("span", $overallgrade, array("class" => "overallgrade_" . $submission->userid));
                 }
             }
         }
     }
     // Indicate whether student has seen grademark image.
     if ($istutor) {
         if (isset($submission->submission_objectid)) {
             $submissionattempts = !empty($submission->submission_attempts) ? $submission->submission_attempts : 0;
             if ($submissionattempts > 0) {
                 $studentread = $OUTPUT->pix_icon('icon-student-read', get_string('student_read', 'turnitintooltwo') . ' ' . userdate($submissionattempts), 'mod_turnitintooltwo', array("class" => "student_read_icon"));
             } else {
                 $studentread = $OUTPUT->pix_icon('icon-dot', get_string('student_notread', 'turnitintooltwo'), 'mod_turnitintooltwo', array("class" => "student_dot_icon"));
             }
         } else {
             $studentread = "--";
         }
     }
     // Upload Submission.
     if ((!isset($submission->submission_objectid) || $turnitintooltwoassignment->turnitintooltwo->reportgenspeed != 0) && empty($submission->nmoodle) && time() > $parts[$partid]->dtstart) {
         if (empty($submission->submission_objectid)) {
             $submission->submission_objectid = 0;
         }
         $uploadtext = !$istutor ? html_writer::tag('span', get_string('submitpaper', 'turnitintooltwo')) : '';
         $eulaaccepted = 0;
         if ($submission->userid == $USER->id) {
             $submission_user = new turnitintooltwo_user($submission->userid, "Learner");
             $coursedata = $turnitintooltwoassignment->get_course_data($turnitintooltwoassignment->turnitintooltwo->course);
             $submission_user->join_user_to_class($coursedata->turnitin_cid);
             $eulaaccepted = $submission_user->user_agreement_accepted == 0 ? $submission_user->get_accepted_user_agreement() : $submission_user->user_agreement_accepted;
         }
         $upload = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&part=' . $partid . '&user='******'&do=submitpaper&view_context=box_solid', $uploadtext . ' ' . html_writer::tag('i', '', array('class' => 'fa fa-cloud-upload fa-lg')), array("class" => "upload_box nowrap", "id" => "upload_" . $submission->submission_objectid . "_" . $partid . "_" . $submission->userid, 'data-eula' => $eulaaccepted, 'data-user-type' => $istutor));
         if (time() > $parts[$partid]->dtdue && $turnitintooltwoassignment->turnitintooltwo->allowlate == 0 && !$istutor) {
             $upload = "&nbsp;";
         }
     } else {
         $upload = "&nbsp;";
     }
     // Download submission in original format.
     if (!empty($submission->submission_objectid) && !empty($submission->id) && !$submission->submission_acceptnothing) {
         $download = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-cloud-download fa-lg')), 'download_original_open', 'downloadoriginal_' . $submission->submission_objectid . "_" . $partid . "_" . $moodleuserid);
         $download .= $OUTPUT->box('', 'launch_form', 'downloadoriginal_form_' . $submission->submission_objectid);
         // Add in LTI launch form incase Javascript is disabled.
         if (!$istutor) {
             $download .= html_writer::tag('noscript', $this->output_dv_launch_form("downloadoriginal", $submission->submission_objectid, $user->tii_user_id, "Learner", get_string('downloadsubmission', 'turnitintooltwo')));
         }
     } else {
         $download = "--";
     }
     $refresh = '--';
     if (!empty($submission->id) && $istutor) {
         $refresh = html_writer::tag('div', html_writer::tag('i', '', array('class' => 'fa fa-refresh fa-lg', 'title' => get_string('turnitinrefreshsubmissions', 'turnitintooltwo'))) . html_writer::tag('i', '', array('class' => 'fa fa-spinner fa-spin')), array('class' => 'refresh_row', 'id' => 'refreshrow_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid));
     }
     // Delete Link.
     $delete = "--";
     if ($istutor) {
         if (!empty($submission->id)) {
             $fnd = array("\n", "\r");
             $rep = array('\\n', '\\r');
             $confirmstring = empty($submission->submission_objectid) ? 'deleteconfirm' : 'turnitindeleteconfirm';
             $string = str_replace($fnd, $rep, get_string($confirmstring, 'turnitintooltwo'));
             $attributes = array("onclick" => "return confirm('" . $string . "');");
             $delete = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&action=deletesubmission&sub=' . $submission->id . '&sesskey=' . sesskey(), html_writer::tag('i', '', array('class' => 'fa fa-trash-o fa-lg')), $attributes);
         }
     } else {
         if (empty($submission->submission_objectid) && !empty($submission->id)) {
             $fnd = array("\n", "\r");
             $rep = array('\\n', '\\r');
             $string = str_replace($fnd, $rep, get_string('deleteconfirm', 'turnitintooltwo'));
             $attributes = array("onclick" => "return confirm('" . $string . "');");
             $delete = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&action=deletesubmission&sub=' . $submission->id . '&sesskey=' . sesskey(), html_writer::tag('i', '', array('class' => 'fa fa-trash-o fa-lg')), $attributes);
         }
     }
     $data = array($partid, $checkbox, $studentname, $rawtitle, $title, $objectid, $rawmodified, $modified);
     if ($istutor || !$istutor && $turnitintooltwoassignment->turnitintooltwo->studentreports) {
         $data[] = $rawscore;
         $data[] = $score;
     }
     if ($config->usegrademark) {
         $data[] = $rawgrade;
         $data[] = $grade;
         if (count($parts) > 1 || $turnitintooltwoassignment->turnitintooltwo->grade < 0) {
             $data[] = $overallgrade;
         }
     }
     if ($istutor) {
         $data[] = $studentread;
     }
     $data[] = $upload;
     $data[] = $download;
     if ($istutor) {
         $data[] = $refresh;
     }
     $data[] = $delete;
     return $data;
 }
Esempio n. 4
0
 /**
  *
  * @global type $CFG
  * @param type $linkarray
  * @return type
  */
 public function get_links($linkarray)
 {
     global $CFG, $DB, $OUTPUT, $PAGE, $USER;
     // Don't submit certain file types to Turnitin.
     if (!empty($linkarray["file"])) {
         $file = $linkarray["file"];
         $filearea = $file->get_filearea();
         $nonsubmittingareas = array("feedback_files", "introattachment");
         if (in_array($filearea, $nonsubmittingareas)) {
             return;
         }
     }
     // Set static variables.
     static $cm;
     static $forum;
     if (empty($cm)) {
         $cm = get_coursemodule_from_id('', $linkarray["cmid"]);
         if ($cm->modname == 'forum') {
             if (!($forum = $DB->get_record("forum", array("id" => $cm->instance)))) {
                 print_error('invalidforumid', 'forum');
             }
         }
     }
     static $plagiarismsettings;
     if (empty($plagiarismsettings)) {
         $plagiarismsettings = $this->get_settings($linkarray["cmid"]);
         if ($cm->modname == 'assign') {
             $plagiarismsettings["plagiarism_draft_submit"] = isset($plagiarismsettings["plagiarism_draft_submit"]) ? $plagiarismsettings["plagiarism_draft_submit"] : 0;
         }
     }
     // Exit if Turnitin is not being used for this module.
     if (empty($plagiarismsettings['use_turnitin'])) {
         return;
     }
     static $config;
     if (empty($config)) {
         $config = turnitintooltwo_admin_config();
     }
     static $moduletiienabled;
     if (empty($moduletiienabled)) {
         $moduletiienabled = $this->get_config_settings('mod_' . $cm->modname);
     }
     // Exit if Turnitin is not being used for this activity type.
     if (empty($moduletiienabled)) {
         return;
     }
     static $moduledata;
     if (empty($moduledata)) {
         $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance));
     }
     static $context;
     if (empty($context)) {
         $context = context_course::instance($cm->course);
     }
     static $coursedata;
     if (empty($coursedata)) {
         // Create the course/class in Turnitin if it doesn't already exist.
         $coursedata = turnitintooltwo_assignment::get_course_data($cm->course, 'PP');
         if (empty($coursedata->turnitin_cid)) {
             // Course may existed in a previous incarnation of this plugin.
             // Get this and save it in courses table if so.
             if ($turnitincid = $this->get_previous_course_id($cm)) {
                 $coursedata->turnitin_cid = $turnitincid;
                 $coursedata = $this->migrate_previous_course($coursedata, $turnitincid);
             } else {
                 // Otherwise create new course in Turnitin.
                 $tiicoursedata = $this->create_tii_course($cm, $coursedata);
                 $coursedata->turnitin_cid = $tiicoursedata->turnitin_cid;
                 $coursedata->turnitin_ctl = $tiicoursedata->turnitin_ctl;
             }
         }
     }
     // Work out if logged in user is a tutor on this module.
     static $istutor;
     switch ($cm->modname) {
         case "forum":
         case "workshop":
             if (empty($istutor)) {
                 $istutor = has_capability('plagiarism/turnitin:viewfullreport', $context);
             }
             break;
         default:
             if (empty($istutor)) {
                 $istutor = has_capability('mod/' . $cm->modname . ':grade', $context);
             }
             break;
     }
     // Define the timestamp for updating Peermark Assignments.
     if (empty($_SESSION["updated_pm"][$cm->id]) && $config->enablepeermark) {
         $_SESSION["updated_pm"][$cm->id] = time() - 60 * 5;
     }
     $output = "";
     // If a text submission has been made, we can only display links for current attempts so don't show links previous attempts.
     // This will need to be reworked when linkarray contains submission id.
     static $contentdisplayed;
     if ($cm->modname == 'assign' && !empty($linkarray["content"]) && $contentdisplayed == true) {
         return $output;
     }
     if ((!empty($linkarray["file"]) || !empty($linkarray["content"])) && !empty($linkarray["cmid"])) {
         // Include Javascript.
         $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/jquery-1.8.2.min.js');
         $PAGE->requires->js($jsurl);
         $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/turnitintooltwo.js');
         $PAGE->requires->js($jsurl);
         $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/plagiarism_plugin.js');
         $PAGE->requires->js($jsurl);
         $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/jquery.colorbox.js');
         $PAGE->requires->js($jsurl);
         $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/jquery.tooltipster.js');
         $PAGE->requires->js($jsurl);
         $PAGE->requires->string_for_js('closebutton', 'turnitintooltwo');
         // Initialise vars for working out whether we are submitting.
         $submitting = false;
         $submission_status = true;
         $identifier = '';
         // Get Assignment submission data and account for draft submissions which may not be submitted
         if ($cm->modname == 'assign') {
             if (!empty($linkarray["file"])) {
                 $submission = $DB->get_record('assign_submission', array('userid' => $linkarray["userid"], 'assignment' => $moduledata->id, 'id' => $file->get_itemid()));
             } else {
                 // This will need to be reworked when linkarray contains submission id.
                 $submissions = $DB->get_records('assign_submission', array('userid' => $linkarray["userid"], 'assignment' => $moduledata->id));
                 $submission = end($submissions);
             }
             if ($submission) {
                 $submission_status = $submission->status == "submitted" || $moduledata->submissiondrafts == 1 && $plagiarismsettings["plagiarism_draft_submit"] == 0 ? true : false;
             }
         }
         // Check whether a user's submission needs to be sent to Turnitin via Ajax.
         // Get File or Content information, for content only submit if it has been modified.
         $itemid = 0;
         if (!empty($linkarray["file"])) {
             $identifier = $file->get_pathnamehash();
             $itemid = $file->get_itemid();
             $submissiontype = 'file';
             $submitting = $submission_status ? true : false;
             // Get plagiarism file info to check if file was previously submitted and has been modified.
             $typefield = $CFG->dbtype == "oci" ? " to_char(submissiontype) " : " submissiontype ";
             $plagiarismfiles = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? AND identifier = ? AND (" . $typefield . " = ? OR " . $typefield . " IS NULL )", array($linkarray["userid"], $linkarray["cmid"], $identifier, $submissiontype, ''));
             $plagiarismfile = end($plagiarismfiles);
             if (!empty($plagiarismfile)) {
                 $submitting = $file->get_timemodified() > $plagiarismfile->lastmodified ? $submitting : false;
             }
         } else {
             if (!empty($linkarray["content"])) {
                 // Get turnitin text content details.
                 $submissiontype = $cm->modname == "forum" ? 'forum_post' : 'text_content';
                 switch ($cm->modname) {
                     case 'assign':
                         $moodletextsubmission = $DB->get_record('assignsubmission_onlinetext', array('submission' => $submission->id), 'onlinetext');
                         if (empty($moodletextsubmission)) {
                             $content = '';
                             $submission_status = false;
                         } else {
                             $content = $moodletextsubmission->onlinetext;
                         }
                         break;
                     case 'workshop':
                         $submission = $DB->get_record('workshop_submissions', array('authorid' => $linkarray["userid"], 'workshopid' => $moduledata->id));
                         $content = $linkarray["content"];
                         break;
                     case 'forum':
                         static $discussionid;
                         // Use query string id to check whether we are on forum home page.
                         $querystrid = optional_param('id', 0, PARAM_INT);
                         // Work out the discussion id from query string.
                         if (empty($discussionid)) {
                             $discussionid = optional_param('d', 0, PARAM_INT);
                         }
                         if (empty($discussionid)) {
                             $reply = optional_param('reply', 0, PARAM_INT);
                             $edit = optional_param('edit', 0, PARAM_INT);
                             $delete = optional_param('delete', 0, PARAM_INT);
                             $parent = '';
                             if ($reply != 0) {
                                 $parent = forum_get_post_full($reply);
                             } else {
                                 if ($edit != 0) {
                                     $parent = forum_get_post_full($edit);
                                 } else {
                                     if ($delete != 0) {
                                         $parent = forum_get_post_full($delete);
                                     }
                                 }
                             }
                             if (!empty($parent)) {
                                 $discussionid = $parent->discussion;
                             }
                         }
                         // Some forum types don't pass in certain values on main forum page.
                         if ((empty($discussionid) || $querystrid != 0) && ($forum->type == 'blog' || $forum->type == 'single')) {
                             if (!($discussion = $DB->get_record_sql('SELECT FD.id
                                                                 FROM {forum_posts} FP JOIN {forum_discussions} FD
                                                                 ON FP.discussion = FD.id
                                                                 WHERE FD.forum = ? AND FD.course = ?
                                                                 AND FP.userid = ? AND FP.message LIKE ? ', array($forum->id, $forum->course, $linkarray["userid"], $linkarray["content"])))) {
                                 print_error('notpartofdiscussion', 'forum');
                             }
                             $discussionid = $discussion->id;
                         }
                         $submission = $DB->get_record_select('forum_posts', " userid = ? AND message LIKE ? AND discussion = ? ", array($linkarray["userid"], $linkarray["content"], $discussionid));
                         $itemid = $submission->id;
                         $submission->timemodified = $submission->modified;
                         $content = $linkarray["content"];
                         break;
                 }
                 // Get plagiarism file info.
                 $identifier = sha1($content);
                 $typefield = $CFG->dbtype == "oci" ? " to_char(submissiontype) " : " submissiontype ";
                 switch ($cm->modname) {
                     case 'assign':
                     case 'workshop':
                         $plagiarismfile = $DB->get_record_select('plagiarism_turnitin_files', " userid = ? AND cm = ? AND " . $typefield . " = ? ", array($linkarray["userid"], $linkarray["cmid"], $submissiontype));
                         break;
                     case 'forum':
                         $plagiarismfile = $DB->get_record_select('plagiarism_turnitin_files', " userid = ? AND cm = ? AND identifier = ? AND " . $typefield . " = ? ", array($linkarray["userid"], $linkarray["cmid"], $identifier, $submissiontype));
                         break;
                 }
                 if (!empty($plagiarismfile)) {
                     $submitting = $submission->timemodified > $plagiarismfile->lastmodified && $plagiarismfile->identifier != $identifier ? true : false;
                 } else {
                     $submitting = true;
                 }
             }
         }
         // Group submissions where all students have to submit sets userid to 0;
         if ($linkarray['userid'] == 0 && !$istutor) {
             $linkarray['userid'] = $USER->id;
         }
         $output .= $OUTPUT->box_start('tii_links_container');
         // Show the EULA for a student if necessary.
         if ($linkarray["userid"] == $USER->id) {
             $eula = "";
             static $userid;
             if (empty($userid)) {
                 $userid = 0;
             }
             // Condition added to test for Moodle 2.7 as it calls this function twice.
             if ($CFG->branch >= 27 || $userid != $linkarray["userid"]) {
                 // Show EULA if necessary and we have a connection to Turnitin.
                 static $eulashown;
                 if (empty($eulashown)) {
                     $eulashown = false;
                 }
                 $user = new turnitintooltwo_user($USER->id, "Learner");
                 $success = $user->join_user_to_class($coursedata->turnitin_cid);
                 // $success is false if there is no Turnitin connection and null if user has previously been enrolled.
                 if ((is_null($success) || $success === true) && $eulashown == false) {
                     $eulaaccepted = $user->user_agreement_accepted == 0 ? $user->get_accepted_user_agreement() : $user->user_agreement_accepted;
                     $userid = $linkarray["userid"];
                     if ($eulaaccepted != 1) {
                         $eula_link = html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"] . '&cmd=useragreement&view_context=box_solid', get_string('turnitinppulapost', 'turnitintooltwo'), array("class" => "pp_turnitin_eula_link"));
                         $eula = html_writer::tag('div', $eula_link, array('class' => 'pp_turnitin_ula js_required', 'data-userid' => $user->id));
                         $submitting = false;
                     }
                     // Show EULA launcher and form placeholder.
                     if (!empty($eula)) {
                         $output .= $eula;
                         $turnitincomms = new turnitintooltwo_comms();
                         $turnitincall = $turnitincomms->initialise_api();
                         $customdata = array("disable_form_change_checker" => true, "elements" => array(array('html', $OUTPUT->box('', '', 'useragreement_inputs'))));
                         $eulaform = new turnitintooltwo_form($turnitincall->getApiBaseUrl() . TiiLTI::EULAENDPOINT, $customdata, 'POST', $target = 'eulaWindow', array('id' => 'eula_launch'));
                         $output .= $OUTPUT->box($eulaform->display(), 'tii_useragreement_form', 'useragreement_form');
                         $eulashown = true;
                     }
                 } else {
                     $submitting = false;
                 }
             }
             // If a user has just submitted then send to Turnitin via Ajax.
             if ($submitting && $submission_status) {
                 // Include Javascript for Submitting.
                 $jsurl = new moodle_url('/mod/turnitintooltwo/jquery/plagiarism_submission.js');
                 $PAGE->requires->js($jsurl);
                 // Forum posts have a lot of html stripped out so we have to get data to ajax differently
                 if ($submissiontype == 'forum_post') {
                     $output .= html_writer::start_tag('div', array('class' => 'plagiarism_submission'));
                     $output .= html_writer::tag('div', $identifier . '-' . $submissiontype, array('class' => 'plagiarism_submission_id'));
                     $output .= html_writer::tag('div', urlencode($linkarray["content"]), array('class' => 'plagiarism_submission_content'));
                     $output .= html_writer::tag('div', $linkarray["cmid"], array('class' => 'plagiarism_submission_cmid'));
                     $output .= html_writer::tag('div', $itemid, array('class' => 'plagiarism_submission_itemid'));
                     $output .= html_writer::end_tag('div');
                 } else {
                     $output .= html_writer::start_tag('div', array('class' => 'plagiarism_submission', 'id' => $identifier . '-' . $submissiontype));
                     $output .= html_writer::tag('div', $linkarray["cmid"], array('class' => 'plagiarism_submission_cmid'));
                     $output .= html_writer::tag('div', $itemid, array('class' => 'plagiarism_submission_itemid'));
                     $output .= html_writer::end_tag('div');
                 }
             }
         }
         // Check whether submission is a group submission - only applicable to assignment module.
         // If it's a group submission then other users in the group should be able to see the originality score
         // They can not open the DV though.
         $submissionusers = array($linkarray["userid"]);
         if ($cm->modname == "assign" && $CFG->branch > 23) {
             if ($moduledata->teamsubmission) {
                 $assignment = new assign($context, $cm, null);
                 if ($group = $assignment->get_submission_group($linkarray["userid"])) {
                     $users = groups_get_members($group->id);
                     $submissionusers = array_keys($users);
                 }
             }
         }
         // Display Links for files and contents.
         if ((!empty($linkarray["file"]) || !empty($linkarray["content"])) && ($istutor || $submission_status && in_array($USER->id, $submissionusers))) {
             // Prevent text content links being displayed for previous attempts as we have no way of getting the data.
             if (!empty($linkarray["content"]) && $linkarray["userid"] == $USER->id) {
                 $contentdisplayed = true;
             }
             // Get turnitin details - have to do this again as submission may have been made above.
             $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', array('userid' => $linkarray["userid"], 'cm' => $linkarray["cmid"], 'identifier' => $identifier), 'lastmodified DESC', '*', 0, 1);
             $plagiarismfile = current($plagiarismfiles);
             // Get user's grades.
             // Get Due date
             $duedate = 0;
             if (!empty($moduledata->duedate)) {
                 $duedate = $moduledata->duedate;
             } else {
                 if (!empty($moduledata->timedue)) {
                     $duedate = $moduledata->timedue;
                 }
             }
             // Get post date
             $postdate = 0;
             if ($cm->modname != "forum") {
                 // Populate gradeitem query
                 $queryarray = array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, 'itemnumber' => 0);
                 if ($gradeitem = $DB->get_record('grade_items', $queryarray)) {
                     switch ($gradeitem->hidden) {
                         case 1:
                             $postdate = strtotime('+1 month');
                             break;
                         case 0:
                             $postdate = time();
                             if ($CFG->branch >= 26 && $cm->modname == 'assign' && !empty($moduledata->markingworkflow)) {
                                 $gradesreleased = $DB->record_exists('assign_user_flags', array('userid' => $linkarray["userid"], 'assignment' => $cm->instance, 'workflowstate' => 'released'));
                                 $postdate = $gradesreleased ? time() : strtotime('+4 weeks', $duedate);
                             }
                             break;
                         default:
                             $postdate = $gradeitem->hidden;
                             break;
                     }
                 }
             }
             $currentgradequery = false;
             if ($istutor || $linkarray["userid"] == $USER->id) {
                 if ($cm->modname == 'forum') {
                     static $gradeitem;
                     if (empty($gradeitem)) {
                         $gradeitem = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course));
                     }
                     if ($gradeitem) {
                         $currentgradequery = $DB->get_record('grade_grades', array('userid' => $linkarray["userid"], 'itemid' => $gradeitem->id));
                     }
                 } else {
                     if ($cm->modname == 'workshop') {
                         if ($gradeitem) {
                             $currentgradequery = $DB->get_record('grade_grades', array('userid' => $linkarray["userid"], 'itemid' => $gradeitem->id));
                         }
                         $postdate = $moduledata->assessmentend;
                     } else {
                         if ($cm->modname == 'assign') {
                             if ($gradeitem) {
                                 $currentgradesquery = $DB->get_records('assign_grades', array('userid' => $linkarray["userid"], 'assignment' => $cm->instance), 'id DESC');
                                 $currentgradequery = current($currentgradesquery);
                             }
                         }
                     }
                 }
             }
             if ($plagiarismfile && (!$submitting || !$submission_status)) {
                 if ($plagiarismfile->statuscode == 'success') {
                     if ($istutor || $linkarray["userid"] == $USER->id) {
                         $output .= html_writer::tag('div', $OUTPUT->pix_icon('icon-sml', get_string('turnitinid', 'turnitintooltwo') . ': ' . $plagiarismfile->externalid, 'mod_turnitintooltwo', array('class' => 'turnitin_paper_id')) . get_string('turnitinid', 'turnitintooltwo') . ': ' . $plagiarismfile->externalid);
                     }
                     // Show Originality Report score and link.
                     if (($istutor || in_array($USER->id, $submissionusers) && $plagiarismsettings["plagiarism_show_student_report"]) && ((is_null($plagiarismfile->orcapable) || $plagiarismfile->orcapable == 1) && !is_null($plagiarismfile->similarityscore))) {
                         // This class is applied so that only the user who submitted or a tutor can open the DV.
                         $useropenclass = $USER->id == $linkarray["userid"] || $istutor ? 'pp_origreport_open' : '';
                         $output .= $OUTPUT->box_start('row_score pp_origreport ' . $useropenclass . ' origreport_' . $plagiarismfile->externalid . '_' . $linkarray["cmid"], $CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"]);
                         // Show score.
                         if ($plagiarismfile->statuscode == "pending") {
                             $output .= html_writer::tag('div', '&nbsp;', array('title' => get_string('pending', 'turnitintooltwo'), 'class' => 'tii_tooltip origreport_score score_colour score_colour_'));
                         } else {
                             // Put EN flag if translated matching is on and that is the score used.
                             $transmatch = $plagiarismfile->transmatch == 1 ? ' EN' : '';
                             if (is_null($plagiarismfile->similarityscore)) {
                                 $score = '&nbsp;';
                                 $titlescore = get_string('pending', 'turnitintooltwo');
                                 $class = 'score_colour_';
                             } else {
                                 $score = $plagiarismfile->similarityscore . '%';
                                 $titlescore = $plagiarismfile->similarityscore . '% ' . get_string('similarity', 'turnitintooltwo');
                                 $class = 'score_colour_' . round($plagiarismfile->similarityscore, -1);
                             }
                             $output .= html_writer::tag('div', $score . $transmatch, array('title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour ' . $class));
                         }
                         // Put in div placeholder for DV launch form.
                         $output .= $OUTPUT->box('', 'launch_form origreport_form_' . $plagiarismfile->externalid);
                         // Add url for launching DV from Forum post.
                         if ($cm->modname == 'forum') {
                             $output .= $OUTPUT->box($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"], 'origreport_forum_launch origreport_forum_launch_' . $plagiarismfile->externalid);
                         }
                         $output .= $OUTPUT->box_end(true);
                     }
                     if ($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable)) {
                         // This class is applied so that only the user who submitted or a tutor can open the DV.
                         $useropenclass = $USER->id == $linkarray["userid"] || $istutor ? 'pp_origreport_open' : '';
                         $output .= $OUTPUT->box_start('row_score pp_origreport ' . $useropenclass, '');
                         $output .= html_writer::tag('div', 'x', array('title' => get_string('notorcapable', 'turnitintooltwo'), 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable'));
                         $output .= $OUTPUT->box_end(true);
                     }
                     // Can grade and feedback be released to this student yet?
                     $released = $postdate <= time() && (!is_null($plagiarismfile->grade) || isset($currentgradequery->grade));
                     // Show link to open grademark.
                     if ($config->usegrademark && ($istutor || $linkarray["userid"] == $USER->id && $released) && !empty($gradeitem)) {
                         // Output grademark icon.
                         $output .= $OUTPUT->box_start('grade_icon', '');
                         $output .= html_writer::tag('div', $OUTPUT->pix_icon('icon-edit', get_string('grademark', 'turnitintooltwo'), 'mod_turnitintooltwo'), array('title' => get_string('grademark', 'turnitintooltwo'), 'class' => 'pp_grademark_open tii_tooltip grademark_' . $plagiarismfile->externalid . '_' . $linkarray["cmid"], 'id' => $CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"]));
                         // Add url for launching DV from Forum post.
                         if ($cm->modname == 'forum') {
                             $output .= $OUTPUT->box($CFG->wwwroot . '/plagiarism/turnitin/extras.php?cmid=' . $linkarray["cmid"], 'grademark_forum_launch grademark_forum_launch_' . $plagiarismfile->externalid);
                         }
                         // Put in div placeholder for DV launch form.
                         $output .= $OUTPUT->box('', 'launch_form grademark_form_' . $plagiarismfile->externalid);
                         $output .= $OUTPUT->box_end(true);
                     }
                     if (!$istutor && $config->usegrademark && !empty($plagiarismsettings["plagiarism_rubric"])) {
                         // Update assignment in case rubric is not stored in Turnitin yet.
                         $this->sync_tii_assignment($cm, $coursedata->turnitin_cid);
                         $rubricviewlink = html_writer::tag('div', html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/ajax.php?cmid=' . $cm->id . '&action=rubricview&view_context=box', '&nbsp;', array('class' => 'tii_tooltip rubric_view_pp_launch', 'id' => 'rubric_view_launch', 'title' => get_string('launchrubricview', 'turnitintooltwo'))) . html_writer::tag('span', '', array('class' => 'launch_form', 'id' => 'rubric_view_form')), array('class' => 'row_rubric_view'));
                         $output .= $rubricviewlink;
                     }
                     if ($config->enablepeermark) {
                         // If this module is already on Turnitin then refresh and get Peermark Assignments.
                         if (!empty($plagiarismsettings['turnitin_assignid'])) {
                             if ($_SESSION["updated_pm"][$cm->id] <= time() - 60 * 2) {
                                 $this->refresh_peermark_assignments($cm, $plagiarismsettings['turnitin_assignid']);
                                 $turnitintooltwoassignment = new turnitintooltwo_assignment($cm->instance, '', 'PP');
                                 $_SESSION["peermark_assignments"][$cm->id] = $turnitintooltwoassignment->get_peermark_assignments($plagiarismsettings['turnitin_assignid']);
                                 $_SESSION["updated_pm"][$cm->id] = time();
                             }
                             // Determine if we have any active Peermark Assignments.
                             static $peermarksactive;
                             if (!isset($peermarksactive)) {
                                 $peermarksactive = false;
                                 foreach ($_SESSION["peermark_assignments"][$cm->id] as $peermarkassignment) {
                                     if (time() > $peermarkassignment->dtstart) {
                                         $peermarksactive = true;
                                         break;
                                     }
                                 }
                             }
                             // Show Peermark Reviews link.
                             if ($istutor && count($_SESSION["peermark_assignments"][$cm->id]) > 0 || !$istutor && $peermarksactive) {
                                 $peermarkreviewslink = $OUTPUT->box_start('row_peermark_reviews', '');
                                 $peermarkreviewslink .= html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/ajax.php?cmid=' . $cm->id . '&action=peermarkreviews&view_context=box', '', array('title' => get_string('launchpeermarkreviews', 'turnitintooltwo'), 'class' => 'peermark_reviews_pp_launch tii_tooltip'));
                                 $peermarkreviewslink .= html_writer::tag('span', '', array('class' => 'launch_form', 'id' => 'peermark_reviews_form'));
                                 $peermarkreviewslink .= $OUTPUT->box_end(true);
                                 $output .= $peermarkreviewslink;
                             }
                         }
                     }
                 } else {
                     if ($plagiarismfile->statuscode == 'error') {
                         // Deal with legacy error issues.
                         if (!isset($plagiarismfile->errorcode)) {
                             $errorcode = 0;
                             if ($submissiontype == 'file') {
                                 if ($file->get_filesize() > TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE) {
                                     $errorcode = 2;
                                 }
                             }
                         } else {
                             $errorcode = $plagiarismfile->errorcode;
                         }
                         // Show error message if there is one.
                         if ($errorcode == 0) {
                             $langstring = $istutor ? 'ppsubmissionerrorseelogs' : 'ppsubmissionerrorstudent';
                             $errorstring = isset($plagiarismfile->errormsg) ? get_string($langstring, 'turnitintooltwo') : $plagiarismfile->errormsg;
                         } else {
                             $errorstring = get_string('errorcode' . $plagiarismfile->errorcode, 'turnitintooltwo', display_size(TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE));
                         }
                         $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('x-red', $errorstring, 'mod_turnitintooltwo'), array('title' => $errorstring, 'class' => 'tii_tooltip tii_error_icon'));
                         // If logged in as a student, attach error text after icon.
                         if (!$istutor) {
                             $output .= html_writer::tag('div', $erroricon . ' ' . $errorstring, array('class' => 'warning clear'));
                         } else {
                             $output .= html_writer::tag('div', $erroricon, array('class' => 'clear'));
                         }
                     }
                 }
             } else {
                 // Add Error to show that user has not accepted EULA.
                 if ($linkarray["userid"] != $USER->id && $istutor) {
                     // There is a moodle plagiarism bug where get_links is called twice, the first loop is incorrect and is killing
                     // this functionality. Have to check that user exists here first else there will be a fatal error.
                     if ($mdl_user = $DB->get_record('user', array('id' => $linkarray["userid"]))) {
                         // We also need to check for security that they are actually on the Course.
                         switch ($cm->modname) {
                             case 'assign':
                             case 'workshop':
                                 $capability = 'mod/' . $cm->modname . ':submit';
                                 break;
                             case 'forum':
                                 $capability = 'mod/' . $cm->modname . ':replypost';
                                 break;
                         }
                         if (has_capability($capability, $context, $linkarray["userid"])) {
                             $user = new turnitintooltwo_user($linkarray["userid"], "Learner");
                             if ($user->user_agreement_accepted != 1) {
                                 $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('notacceptedeula', 'turnitintooltwo'), 'mod_turnitintooltwo'), array('title' => get_string('notacceptedeula', 'turnitintooltwo'), 'class' => 'tii_tooltip tii_error_icon'));
                                 $output .= html_writer::tag('div', $erroricon, array('class' => 'clear'));
                             }
                         }
                     }
                 }
             }
             // Show error warning for submission
             $output .= html_writer::tag('div', '', array('class' => 'turnitin_submit_error warning clear turnitin_submit_error_' . $identifier));
             // Show success of submission
             $output .= html_writer::tag('div', '', array('class' => 'turnitin_submit_success success clear turnitin_submit_success_' . $identifier));
             $output .= html_writer::tag('div', '', array('class' => 'clear'));
         }
         $output .= $OUTPUT->box_end(true);
     }
     return $output;
 }