示例#1
0
/**
 * Outputs submission inbox for student submissions (Teacher View)
 *
 * @global object
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object for this activity
 * @param string $orderby The query string option for the ordering of the column
 * @return string Output of the tutor view submission inbox
 */
function turnitintool_view_all_submissions($cm, $turnitintool, $orderby = '1')
{
    global $CFG, $USER;
    $param_do = optional_param('do', null, PARAM_CLEAN);
    $param_reason = optional_param('reason', array(), PARAM_CLEAN);
    $module_group = turnitintool_module_group($cm);
    $context = turnitintool_get_context('COURSE', $turnitintool->course);
    $studentusers = get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id,u.firstname,u.lastname', '', '', '', $module_group, '', false);
    $studentuser_array = array_keys($studentusers);
    $scale = turnitintool_get_record('scale', 'id', $turnitintool->grade * -1);
    $parts = turnitintool_get_records_select('turnitintool_parts', 'turnitintoolid=' . $turnitintool->id . ' AND deleted != 1');
    $concat = turnitintool_sql_concat("COALESCE(u.id,0)", "'-'", "COALESCE(s.id,0)", "'-'", "COALESCE(s.submission_objectid,0)");
    $usifieldid = 'NULL';
    $usifield = '';
    $displayusi = 'false';
    if ($CFG->turnitin_enablepseudo and $CFG->turnitin_pseudolastname > 0) {
        $uf = turnitintool_get_record('user_info_field', 'id', $CFG->turnitin_pseudolastname);
        $usifield = $uf->name;
        $usifieldid = $CFG->turnitin_pseudolastname;
    }
    $group_in = join(',', $studentuser_array);
    $groupselect = $module_group != 0 ? "u.id IN ( select gm.userid from {groups_members} gm where gm.groupid = {$module_group} ) AND" : "";
    $query = "\nSELECT\n    {$concat} AS keyid,\n    s.id AS id,\n    u.id AS userid,\n    u.firstname AS firstname,\n    u.lastname AS lastname,\n    ud.data AS usi,\n    tu.turnitin_uid AS turnitin_uid,\n    p.id AS partid,\n    p.partname AS partname,\n    p.dtstart AS dtstart,\n    p.dtdue AS dtdue,\n    p.dtpost AS dtpost,\n    p.maxmarks AS maxmarks,\n    t.name AS assignmentname,\n    t.grade AS overallgrade,\n    t.anon AS anon,\n    t.id AS turnitintoolid,\n    s.submission_part AS submission_part,\n    s.submission_title AS submission_title,\n    s.submission_type AS submission_type,\n    s.submission_filename AS submission_filename,\n    s.submission_objectid AS submission_objectid,\n    s.submission_score AS submission_score,\n    s.submission_grade AS submission_grade,\n    s.submission_gmimaged AS submission_gmimaged,\n    s.submission_status AS submission_status,\n    s.submission_queued AS submission_queued,\n    s.submission_attempts AS submission_attempts,\n    s.submission_modified AS submission_modified,\n    s.submission_parent AS submission_parent,\n    s.submission_nmuserid AS submission_nmuserid,\n    s.submission_nmfirstname AS submission_nmfirstname,\n    s.submission_nmlastname AS submission_nmlastname,\n    s.submission_unanon AS submission_unanon,\n    s.submission_unanonreason AS submission_unanonreason,\n    s.submission_transmatch AS submission_transmatch\nFROM {turnitintool_submissions} s\n    LEFT JOIN\n        {user} u ON u.id = s.userid\n    LEFT JOIN\n        {turnitintool_parts} p ON p.id = s.submission_part\n    LEFT JOIN\n        {turnitintool} t ON t.id = p.turnitintoolid\n    LEFT JOIN\n        {turnitintool_users} tu ON u.id = tu.userid\n    LEFT JOIN\n        {user_info_data} ud ON u.id = ud.userid AND ud.fieldid = {$usifieldid}\nWHERE\n    {$groupselect}\n    s.turnitintoolid = " . $turnitintool->id . "\nORDER BY s.submission_grade DESC\n";
    $records = turnitintool_get_records_sql($query);
    $records = is_array($records) ? $records : array();
    $userrows = array();
    $subuser_array = array();
    $submissionids = array();
    foreach ($records as $record) {
        $turnitin_uid = !is_null($record->turnitin_uid) ? $record->turnitin_uid : $record->submission_nmuserid;
        $key = $record->userid . '-' . $turnitin_uid;
        $record->nonmoodle = $record->submission_nmuserid ? true : false;
        $userrows[$key][] = $record;
        if (!is_null($record->id)) {
            $submissionids[] = $record->id;
        }
        if (!is_null($record->userid)) {
            $subuser_array[] = $record->userid;
        }
    }
    $comments = array();
    if (count($submissionids) > 0) {
        $submission_string = join(',', $submissionids);
        $comments = turnitintool_get_records_sql('SELECT submissionid, count( id ) AS count FROM {turnitintool_comments} WHERE deleted = 0 AND submissionid IN ( ' . $submission_string . ' ) GROUP BY submissionid');
    }
    $nosubuser_array = (!$turnitintool->shownonsubmission or $turnitintool->anon) ? array() : array_diff($studentuser_array, $subuser_array);
    foreach ($nosubuser_array as $user) {
        $key = $studentusers[$user]->id . '-' . 0;
        $record = new stdClass();
        $record->userid = $studentusers[$user]->id;
        $record->firstname = $studentusers[$user]->firstname;
        $record->lastname = $studentusers[$user]->lastname;
        $userrows[$key][] = $record;
    }
    $table = new stdClass();
    $table->style = 'display: none;';
    $table->width = '100%';
    $table->id = 'inboxTable';
    $table->class = 'gradeTable';
    $table->tablealign = 'center';
    $n = 0;
    $table->rows[0] = new stdClass();
    $table->rows[0]->class = 'header';
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' namecell';
    $table->rows[0]->hcells[$n]->data = '<div>' . get_string('submissionstudent', 'turnitintool') . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '&nbsp;';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;' . $usifield . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '<div>' . get_string('objectid', 'turnitintool') . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' datecell';
    $table->rows[0]->hcells[$n]->data = '&nbsp;';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' datecell';
    $table->rows[0]->hcells[$n]->data = '<div>' . get_string('posted', 'turnitintool') . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '&nbsp;';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '<div>' . get_string('submissionorig', 'turnitintool') . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '&nbsp;';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '&nbsp;';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' markscell';
    $table->rows[0]->hcells[$n]->data = '<div>' . get_string('submissiongrade', 'turnitintool') . '</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $table->rows[0]->hcells[$n] = new stdClass();
    $table->rows[0]->hcells[$n]->class = 'header c' . $n . ' iconcell';
    $table->rows[0]->hcells[$n]->data = '<div>&nbsp;</div>';
    $n++;
    $i = 1;
    // $postdatepassed controls whether the inbox displays part view or student name view.
    $postdatepassed = 0;
    // Get the parts, count how many are passed the post date
    $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid=" . $turnitintool->id . " AND deleted=0");
    $postdate_count = 0;
    foreach ($parts as $part) {
        if ($part->dtpost < time()) {
            $postdate_count++;
        }
    }
    // If every part has passed the due date, switch to student name view.
    if ($postdate_count == count($parts)) {
        $postdatepassed = 1;
    }
    foreach ($userrows as $key => $userrow) {
        if (isset($userrow[0]->id)) {
            $overall_grade = turnitintool_overallgrade($userrow, $turnitintool->grade, $parts, $scale);
        }
        $rowcount = count($userrow) == 1 && !isset($userrow[0]->id) ? 0 : count($userrow);
        $submissionstring = $rowcount == 1 ? get_string('submission', 'turnitintool') : get_string('submissions', 'turnitintool');
        if (is_null($userrow[0]->firstname)) {
            $student = '<i>' . $userrow[0]->submission_nmlastname . ', ' . $userrow[0]->submission_nmfirstname . ' (' . get_string('nonmoodleuser', 'turnitintool') . ')</i> - (' . $rowcount . ' ' . $submissionstring . ')';
        } else {
            $student = '<b><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $userrow[0]->userid . '&course=' . $turnitintool->course . '">' . $userrow[0]->lastname . ', ' . $userrow[0]->firstname . '</a></b> - (' . $rowcount . ' ' . $submissionstring . ')';
        }
        foreach ($userrow as $submission) {
            $submission_postdate = (isset($submission->submission_part) and $parts[$submission->submission_part]->dtpost < time()) ? 0 : 1;
            $displayusi = ($turnitintool->anon == 1 and !$postdatepassed or !isset($CFG->turnitin_enablepseudo) or $CFG->turnitin_enablepseudo === "0") ? 'false' : 'true';
            $n = 0;
            if (!isset($submission->id) or is_null($submission->id)) {
                // Do blank user line and continue
                $nmuserid = isset($submission->submission_nmuserid) ? $submission->submission_nmuserid : 0;
                $grouprow = $submission->userid . '-' . $nmuserid;
                $table->rows[$i]->cells[$n] = new stdClass();
                $table->rows[$i]->cells[$n]->class = 'cell c' . $n;
                $table->rows[$i]->cells[$n]->data = $grouprow;
                $n++;
                $table->rows[$i]->cells[$n] = new stdClass();
                $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' hide';
                $table->rows[$i]->cells[$n]->data = $student;
                $n++;
                for ($j = 0; $j < 16; $j++) {
                    $table->rows[$i]->cells[$n] = new stdClass();
                    $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' hide';
                    if ($j == 4) {
                        $output = '00/00/00, 00:00:00';
                    } else {
                        $output = '&nbsp;&nbsp;';
                    }
                    $table->rows[$i]->cells[$n]->data = $output;
                    $n++;
                }
                $i++;
                continue;
            }
            $entryCount[$submission->userid] = !isset($entryCount[$submission->userid]) ? 1 : $entryCount[$submission->userid] + 1;
            $i++;
            $lastclass = $i == $rowcount ? ' lastmark' : ' leftmark';
            // Do Sort Row, Part Name if Anon and User Name if not
            if ($submission->anon and !$postdatepassed) {
                $grouprow = $submission->partid;
            } else {
                $grouprow = $submission->userid . '-' . $submission->submission_nmuserid;
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n;
            $table->rows[$i]->cells[$n]->data = $grouprow;
            $n++;
            // Do Sort header table
            if ($submission->anon and !$postdatepassed) {
                $grouptable = '<b>' . $submission->partname . '</b>';
            } else {
                $grouptable = $student;
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' hide';
            $table->rows[$i]->cells[$n]->data = $grouptable;
            $n++;
            // Do Submission Filelink / Anon Button Column
            $filelink = turnitintool_get_filelink($cm, $turnitintool, $submission);
            $doscript = '';
            if (!empty($submission->submission_objectid)) {
                $doscript = ' onclick="screenOpen(\'' . $filelink . '\',\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\');return false;"';
            }
            $length = 60;
            $truncate = strlen($submission->submission_title) > $length ? substr($submission->submission_title, 0, $length) . '...' : $submission->submission_title;
            if (!$turnitintool->anon or $postdatepassed) {
                $submission_link = '<b>' . $submission->partname . '</b>: <a href="' . $filelink . '" target="_blank" class="fileicon"' . $doscript . ' title="' . $submission->submission_title . '">' . $truncate . '</a>';
            } else {
                if ($submission->submission_unanon and $turnitintool->anon) {
                    $submission_link = '<b><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $userrow[0]->userid . '&course=' . $turnitintool->course . '">' . $userrow[0]->lastname . ', ' . $userrow[0]->firstname . '</a></b>: ';
                    $submission_link .= '<a href="' . $filelink . '" target="_blank" class="fileicon"' . $doscript . ' title="' . $submission->submission_title . '">' . $truncate . '</a>';
                } else {
                    if ($turnitintool->anon and !$postdatepassed) {
                        $reason = isset($param_reason[$submission->submission_objectid]) ? $param_reason[$submission->submission_objectid] : get_string('revealreason', 'turnitintool');
                        // If there is not an object ID, disable the reveal name button
                        $disabled = $submission->submission_objectid == null ? 'disabled' : '';
                        $submission_link = '<a href="' . $filelink . '" target="_blank" class="fileicon"' . $doscript . ' title="' . $submission->submission_title . '" style="line-height: 1.8em;">' . $truncate . '</a><br /><span id="anonform_' . $submission->submission_objectid . '" style="display: none;"><form action="' . $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions" method="POST" class="" onsubmit="return anonValidate(this.reason);">&nbsp;&nbsp;&nbsp;<input id="reason" name="reason[' . $submission->submission_objectid . ']" value="' . $reason . '" type="text" onclick="this.value=\'\';" /><input id="anonid" name="anonid" value="' . $submission->submission_objectid . '" type="hidden" />&nbsp;<input value="' . get_string('reveal', 'turnitintool') . '" type="submit" /></form></span><button id="studentname_' . $submission->submission_objectid . '" ' . $disabled . ' onclick="document.getElementById(\'anonform_' . $submission->submission_objectid . '\').style.display = \'block\';this.style.display = \'none\';">' . get_string('anonenabled', 'turnitintool') . '</button>';
                    }
                }
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . $lastclass;
            $table->rows[$i]->cells[$n]->data = $submission_link;
            $n++;
            // Output USI if required
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = (!isset($submission->usi) or $submission->anon and !$postdatepassed) ? '&nbsp;' : $submission->usi;
            $n++;
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = '&nbsp;';
            $n++;
            // Do Paper ID column
            $objectid = (is_null($submission->submission_objectid) or empty($submission->submission_objectid)) ? '-' : $submission->submission_objectid;
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = $objectid;
            $n++;
            // Do the hidden column for the submission date - used for sorting.
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' datecell';
            $table->rows[$i]->cells[$n]->data = $submission->submission_modified;
            $n++;
            // Do Submission to Turnitin Form
            $modified = '-';
            if (empty($submission->submission_objectid) and $turnitintool->autosubmission) {
                $modified = '<div class="submittoLinkSmall"><img src="' . $CFG->wwwroot . '/mod/turnitintool/icon.gif" /><a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&up=' . $submission->id . '">' . get_string('submittoturnitin', 'turnitintool') . '</a></div>';
            } else {
                if (!is_null($submission->id)) {
                    $modified = empty($submission->submission_objectid) ? '-' : userdate($submission->submission_modified, get_string('strftimedatetimeshort', 'langconfig'));
                    if ($submission->submission_modified > $submission->dtdue) {
                        $modified = '<span style="color: red;">' . $modified . '</span>';
                    }
                }
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' datecell';
            $table->rows[$i]->cells[$n]->data = $modified;
            $n++;
            // Get originality score if available
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = $submission->submission_score;
            $n++;
            $score = turnitintool_draw_similarityscore($cm, $turnitintool, $submission);
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = $score;
            $n++;
            // Get grade if available
            $grade = turnitintool_dogradeoutput($cm, $turnitintool, $submission, $submission->dtdue, $submission->dtpost, $submission->maxmarks);
            $grade = '<form action="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=allsubmissions" method="POST">' . $grade . '</form>';
            // Raw grade goes in hidden column for sorting
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            if ($turnitintool->grade == 0 or $overall_grade === '-') {
                $overall_grade = '-';
            } else {
                if ($turnitintool->grade < 0) {
                    // Scale
                    $scalearray = explode(",", $scale->scale);
                    // Array is zero indexed
                    // Scale positions are from 1 upward
                    $index = $overall_grade - 1;
                    $overall_grade = $index < 0 ? $scalearray[0] : $scalearray[$index];
                } else {
                    if ($turnitintool->gradedisplay == 2) {
                        // 2 is fraction
                        $overall_grade .= '/' . $turnitintool->grade;
                    } else {
                        if ($turnitintool->gradedisplay == 1) {
                            // 1 is percentage
                            $overall_grade = round($overall_grade / $turnitintool->grade * 100, 1) . '%';
                        }
                    }
                }
            }
            $overall_grade = ($turnitintool->anon and !$postdatepassed) ? '-' . $submission->submission_part : $overall_grade;
            $table->rows[$i]->cells[$n]->data = $overall_grade;
            $n++;
            $subgrade = $submission->submission_grade;
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = (!is_null($subgrade) and $subgrade != '-') ? $subgrade : 0;
            $n++;
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' markscell';
            $table->rows[$i]->cells[$n]->data = $grade;
            $n++;
            // Get Student View indicator
            $grademarkurl = $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&jumppage=grade';
            $grademarkurl .= '&userid=' . $USER->id . '&utp=2&objectid=' . $submission->submission_objectid;
            $warn = ($turnitintool->reportgenspeed > 0 and $submission->dtdue > time()) ? $warn = ',\'' . get_string('resubmissiongradewarn', 'turnitintool') . '\'' : '';
            if ($submission->submission_attempts > 0) {
                $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_read', 'turnitintool') . ' ' . userdate($submission->submission_attempts) . '" ';
                $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                $cells['studentview'] .= '><img style="position: relative; top: 4px;" src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-student-read.png" class="tiiicons" /></a>';
            } else {
                $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_notread', 'turnitintool') . '" ';
                $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                $cells['studentview'] .= '><img style="position: relative; top: 4px;" src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-dot.png" class="tiiicons" /></a>';
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' iconcell';
            $table->rows[$i]->cells[$n]->data = $cells['studentview'];
            $n++;
            // Get Feedback Icon if needed
            if (!$submission->nonmoodle) {
                $comment_count = isset($comments[$submission->id]) ? $comments[$submission->id]->count : 0;
                $notes = turnitintool_getnoteslink($cm, $turnitintool, $submission, $comment_count);
            } else {
                $notes = '-';
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' iconcell';
            $table->rows[$i]->cells[$n]->data = $notes;
            $n++;
            // Get Download Icon if needed
            if (!is_null($submission->submission_objectid)) {
                $downscript = ' onclick="screenOpen(this.href,\'' . $submission->id . '\',false,null,\'width=450,height=200\');return false;"';
                $download = '<a href="' . turnitintool_get_filelink($cm, $turnitintool, $submission, $download = true) . '" title="' . get_string('downloadsubmission', 'turnitintool') . '" target="_blank"' . $downscript . '><img src="pix/file-download.png" alt="' . get_string('downloadsubmission', 'turnitintool') . '" class="tiiicons" /></a>';
            } else {
                $download = '';
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' iconcell';
            $table->rows[$i]->cells[$n]->data = $download;
            $n++;
            // Get Refresh Icon if needed
            if (!is_null($submission->submission_objectid) && $submission->userid > 0) {
                $refresh = '<a class="refreshrow" style="cursor: pointer;" id="refreshrow-' . $cm->id . '-' . $turnitintool->id . '-' . $submission->id . '-' . $submission->submission_objectid . '" title="' . get_string('refresh', 'turnitintool') . '"><img src="pix/refresh.gif" alt="' . get_string('refresh', 'turnitintool') . '" class="tiiicons" /></a>';
            } else {
                $refresh = '';
            }
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' iconcell';
            $table->rows[$i]->cells[$n]->data = $refresh;
            $n++;
            // Get Delete Icon if needed
            $fnd = array("\n", "\r");
            $rep = array('\\n', '\\r');
            if (empty($submission->submission_objectid)) {
                $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('deleteconfirm', 'turnitintool')) . '\');"';
            } else {
                $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('turnitindeleteconfirm', 'turnitintool')) . '\')"';
            }
            $delete = '<a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&delete=' . $submission->id . '&do=' . $param_do . '"' . $confirm . ' title="' . get_string('deletesubmission', 'turnitintool') . '"><img src="pix/delete.png" alt="' . get_string('deletesubmission', 'turnitintool') . '" class="tiiicons" /></a>';
            $table->rows[$i]->cells[$n] = new stdClass();
            $table->rows[$i]->cells[$n]->class = 'cell c' . $n . ' iconcell';
            $table->rows[$i]->cells[$n]->data = $delete;
            $n++;
            $i++;
        }
    }
    $sessionrefresh = (isset($_SESSION['updatedscores'][$turnitintool->id]) and $_SESSION['updatedscores'][$turnitintool->id] > 0) ? '' : 'refreshSubmissionsAjax();';
    $output = "\n<script type=\"text/javascript\">\n    var users = " . json_encode($studentuser_array) . ";\n    var message = '" . get_string('turnitinenrollstudents', 'turnitintool') . "';\n    jQuery(document).ready(function() {\n        jQuery.inboxTable.init( '" . $cm->id . "', " . $displayusi . ", " . turnitintool_datatables_strings() . " );\n        jQuery('#loader').css( 'display', 'none' );\n        {$sessionrefresh}\n    });\n</script>";
    $output .= '
        <div class="tabLinks">
        <div style="display: none;" id="inboxNotice"><span style="background: url(pix/ajax-loader.gif) no-repeat left center;padding-left: 80px;">
        <span style="background: url(pix/ajax-loader.gif) no-repeat right center;padding-right: 80px;">' . get_string('turnitinloading', 'turnitintool') . '</span></span></div>
            <a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions' . '&update=1" onclick="refreshSubmissionsAjax();return false;" class="rightcor"><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/refresh.gif" alt="' . get_string('turnitinrefreshsubmissions', 'turnitintool') . '" class="tiiicons" /> ' . get_string('turnitinrefreshsubmissions', 'turnitintool') . '</a>
            <a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions' . '&enroll=1" onclick="enrolStudentsAjax( users, message );return false;" class="rightcor"><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/enrollicon.gif" alt="' . get_string('turnitinenrollstudents', 'turnitintool') . '" class="tiiicons" /> ' . get_string('turnitinenrollstudents', 'turnitintool') . '</a>
        </div>';
    if (count($table->rows) == 1) {
        // If we only have one row it's a header and we found no data to display
        $output .= '<div style="padding: 18px; margin: 0;text-align: center;vertical-align: center" class="navbar" id="loader">' . get_string('nosubmissions', 'turnitintool') . '</div><br /><br />';
    } else {
        $output .= '<div id="loader" style="padding: 18px; margin: 0;text-align: center;vertical-align: center" class="navbar">
        <noscript>Javascript Required</noscript>
        <script>
        jQuery("#loader span").css( "display", "inline" );
        </script><span style="display: none;background: url(pix/ajax-loader.gif) no-repeat left center;padding-left: 80px;">
        <span style="background: url(pix/ajax-loader.gif) no-repeat right center;padding-right: 80px;">' . get_string('turnitinloading', 'turnitintool') . '</span></span></div>';
        $output .= turnitintool_print_table($table, true);
    }
    return $output;
}
示例#2
0
/**
 * Outputs submission inbox for student submissions (Teacher View)
 *
 * @global object
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object for this activity
 * @param string $orderby The query string option for the ordering of the column
 * @return string Output of the tutor view submission inbox
 */
function turnitintool_view_all_submissions($cm, $turnitintool, $orderby = '1')
{
    global $CFG, $USER;
    $output_array = array();
    $output = '';
    $param_do = optional_param('do', null, PARAM_CLEAN);
    $param_reason = optional_param('reason', array(), PARAM_CLEAN);
    $param_from = optional_param('fr', 1, PARAM_CLEAN);
    $param_show = optional_param('sh', $turnitintool->perpage, PARAM_CLEAN);
    $javascriptUsers = '';
    $javascriptCount = '';
    $entryCount = array();
    if (!($parts = turnitintool_get_records_select('turnitintool_parts', 'turnitintoolid=' . $turnitintool->id . ' AND deleted=0'))) {
        turnitintool_print_error('partgeterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
        exit;
    }
    // Construct Styles (contain image links which do not seem to work when included in regular moodle css methods)
    $styles = '
        <style>
            .gradeTable .leftmark td.c0 {
                padding-left: 18px;
                background-image: url(pix/leftmarker.gif);
                background-position: 5px center;
                background-repeat: no-repeat;
            }
            .gradeTable .lastmark td.c0 {
                padding-left: 18px;
                background-image: url(pix/leftmarkerlast.gif);
                background-position: 5px center;
                background-repeat: no-repeat;
            }
            .gradeTable a.fileicon {
                padding-left: 18px;
                background-image: url(pix/fileicon.gif);
                background-position: 2px 0px;
                background-repeat: no-repeat;
            }
        </style>';
    // Create a blank query as a basis for building a query where the first query section may or may not be used
    $sql_query = '';
    $users = array();
    $postdatespassed = !turnitintool_count_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtpost > " . time()) ? 1 : 0;
    if (!$turnitintool->anon or $postdatespassed) {
        // If Multi Part and NOT Anonymous OR all post dates have passed
        // Get all enrolled students (by group) submitters and non submitters
        $context = get_context_instance(CONTEXT_COURSE, $turnitintool->course);
        $studentusers = get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id,u.firstname,u.lastname', '', '', '', turnitintool_module_group($cm), '', false);
        $studentusers = !$studentusers ? array() : $studentusers;
        foreach ($studentusers as $student) {
            $submission["firstname"] = $student->firstname;
            $submission["lastname"] = $student->lastname;
            $submission["avscore"] = NULL;
            $submission["avgrade"] = NULL;
            $submission["nonmoodle"] = 0;
            $submission["unanon"] = 1;
            $submission["count"] = 0;
            $submission["highscore"] = NULL;
            $submission["lowscore"] = NULL;
            $submission["mindate"] = NULL;
            $submission["maxdate"] = NULL;
            $submission["userid"] = $student->id;
            $users[$submission["userid"]] = $submission;
        }
        // Now get submissions that were made where a moodle userid is known
        // Contains moodle users both enrolled or not enrolled
        if ($submissions = turnitintool_get_records_select("turnitintool_submissions", "userid!=0 AND turnitintoolid=" . $turnitintool->id . " GROUP BY userid", "", "userid,avg(submission_score) AS avscore, " . "avg(submission_grade) AS avgrade,count(submission_nmuserid) AS count,max(submission_score) AS highscore," . "min(submission_score) AS lowscore, min(submission_modified) AS mindate, " . "max(submission_modified) AS maxdate, max(submission_objectid) AS objectid")) {
            foreach ($submissions as $submission_data) {
                $user = turnitintool_get_record('user', 'id', $submission_data->userid);
                $submission["firstname"] = $user->firstname;
                $submission["lastname"] = $user->lastname;
                $submission["avscore"] = $submission_data->avscore;
                $submission["avgrade"] = $submission_data->avgrade;
                $submission["unanon"] = 1;
                $submission["count"] = $submission_data->count;
                $submission["highscore"] = $submission_data->highscore;
                $submission["lowscore"] = $submission_data->lowscore;
                $submission["mindate"] = $submission_data->mindate;
                $submission["maxdate"] = $submission_data->maxdate;
                $submission["userid"] = $submission_data->userid;
                $submission["objectid"] = $submission_data->objectid;
                if (isset($users[$user->id])) {
                    // user is a moodle user ie in array from moodle user call above
                    $submission["nonmoodle"] = 0;
                    $users[$submission["userid"]] = $submission;
                } else {
                    if (turnitintool_module_group($cm) == 0) {
                        // user is not a moodle user ie not in array from moodle user call above
                        // and group list is set to all users
                        $submission["nonmoodle"] = 1;
                        $users[$submission["userid"]] = $submission;
                    }
                }
            }
        }
        // Filter out non submitters if the option is set ($turnitintool->shownonsubmission)
        if (!$turnitintool->shownonsubmission) {
            foreach ($users as $user) {
                if (is_null($user["avscore"])) {
                    unset($users[$user["userid"]]);
                }
            }
        }
        // Now get submissions that were made by a non moodle students
        // These are unknown to moodle possibly non-enrolled on turnitin
        // possibly real but not yet linked Turnitin users
        // if group list is set do not get these non group users
        if ($submissions = turnitintool_get_records_select("turnitintool_submissions", "userid=0 AND turnitintoolid=" . $turnitintool->id . " GROUP BY submission_nmuserid", "", "submission_nmuserid AS nmuserid,avg(submission_score) AS avscore, " . "avg(submission_grade) AS avgrade,count(submission_nmuserid) AS count,max(submission_score) AS highscore," . "min(submission_score) AS lowscore, min(submission_modified) AS mindate, " . "max(submission_modified) AS maxdate, max(submission_objectid) AS objectid") and turnitintool_module_group($cm) == 0) {
            foreach ($submissions as $submission_data) {
                $nm_user = turnitintool_get_record('turnitintool_submissions', 'submission_objectid', $submission_data->objectid);
                $submission["firstname"] = $nm_user->submission_nmfirstname;
                $submission["lastname"] = $nm_user->submission_nmlastname;
                $submission["avscore"] = $submission_data->avscore;
                $submission["avgrade"] = $submission_data->avgrade;
                $submission["nonmoodle"] = 1;
                $submission["unanon"] = 1;
                $submission["count"] = $submission_data->count;
                $submission["highscore"] = $submission_data->highscore;
                $submission["lowscore"] = $submission_data->lowscore;
                $submission["mindate"] = $submission_data->mindate;
                $submission["maxdate"] = $submission_data->maxdate;
                $submission["userid"] = "nm-" . $submission_data->nmuserid;
                $submission["objectid"] = $submission_data->objectid;
                $users[$submission["userid"]] = $submission;
            }
        }
        $lastname = array();
        $avscore = array();
        $avgrade = array();
        $mindate = array();
        $maxdate = array();
        $count = array();
        // Obtain the columns to sort on
        foreach ($users as $key => $row) {
            $lastname[$key] = $row['lastname'];
            $avscore[$key] = $row['avscore'];
            $avgrade[$key] = $row['avgrade'];
            $mindate[$key] = $row['mindate'];
            $maxdate[$key] = $row['maxdate'];
            $count[$key] = $row['count'];
        }
        // ORDER BY: 1: Av. Originality Score - Max-Min,
        //           2: Av. Originality Score - Min-Max,
        //           3: Av. Grade - Max-Min,
        //           4: Av. Grade - Min-Max,
        //           5: Submission Date - Min-Max,
        //           6: Submission Date - Max-Min,
        //           7: Students Last Name - A-Z,
        //           8: Student Last Name - Z-A
        if ($orderby == '1') {
            array_multisort($avscore, SORT_DESC, $count, SORT_DESC, $lastname, SORT_ASC, $users);
            $sub_order = 'submission_score DESC';
        } else {
            if ($orderby == '2') {
                array_multisort($avscore, SORT_ASC, $count, SORT_ASC, $lastname, SORT_ASC, $users);
                $sub_order = 'submission_score ASC';
            } else {
                if ($orderby == '3') {
                    array_multisort($avgrade, SORT_DESC, $count, SORT_DESC, $lastname, SORT_ASC, $users);
                    $sub_order = 'submission_grade DESC';
                } else {
                    if ($orderby == '4') {
                        array_multisort($avgrade, SORT_ASC, $count, SORT_ASC, $lastname, SORT_ASC, $users);
                        $sub_order = 'submission_grade ASC';
                    } else {
                        if ($orderby == '5') {
                            array_multisort($maxdate, SORT_DESC, $lastname, SORT_ASC, $users);
                            $sub_order = 'submission_modified DESC';
                        } else {
                            if ($orderby == '6') {
                                array_multisort($mindate, SORT_ASC, $lastname, SORT_ASC, $users);
                                $sub_order = 'submission_modified ASC';
                            } else {
                                if ($orderby == '7') {
                                    array_multisort($lastname, SORT_DESC, $count, SORT_DESC, $users);
                                    $sub_order = 'submission_title DESC';
                                } else {
                                    if ($orderby == '8') {
                                        array_multisort($lastname, SORT_ASC, $count, SORT_DESC, $users);
                                        $sub_order = 'submission_title ASC';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!is_array($users)) {
            $users = array();
        }
        $rs = 0;
        $totalentries = count($users);
        foreach ($users as $key => $values) {
            $rs++;
            if ($rs < $param_from) {
                continue;
            }
            if ($rs > $param_from - 1 + $param_show and $param_show != 0) {
                break;
            }
            $values = turnitintool_array_to_object($values);
            $javascriptUsers .= !empty($javascriptUsers) ? ',"' . $values->userid . '"' : '"' . $values->userid . '"';
            if ($values->userid != 0) {
                $where = "userid=" . $values->userid . " AND turnitintoolid=" . $turnitintool->id;
            } else {
                $where = "submission_nmuserid='" . str_replace('nm-', '', $values->userid) . "' AND turnitintoolid=" . $turnitintool->id;
            }
            if ($CFG->turnitin_enablepseudo and $CFG->turnitin_pseudolastname > 0) {
                $user_info = turnitintool_get_record('user_info_data', 'userid', $values->userid, 'fieldid', $CFG->turnitin_pseudolastname);
                $values->usi = isset($user_info->data) ? $user_info->data : '';
            }
            $entryCount[$values->userid] = 0;
            if ($submissions = turnitintool_get_records_select('turnitintool_submissions', $where, $sub_order)) {
                $values->count = count($submissions);
                if ($values->count > 0) {
                    // Draw Plus Link if there is more than one submission
                    $pluslink = '
                    <script language="javascript" type="text/javascript">
                    document.write("<a href=\\"javascript:;\\" onclick=\\"toggleview(\'' . $values->userid . '\',\'' . $values->count . '\');\\">");
                    </script>
                    <img src="pix/clearpixel.gif" class="plusminus" id="userblock_' . $values->userid . '" />
                    <script language="javascript" type="text/javascript">
                    document.write(\'</a>\');
                    document.getElementById(\'userblock_' . $values->userid . '\').src="pix/plus.gif";
                    </script>';
                } else {
                    // Draw a place holder spacer if there are less than one submissions
                    $pluslink = '
                    <img src="pix/clearpixel.gif" class="plusminus" id="userblock_' . $values->userid . '" />
                    ';
                }
                if ($CFG->turnitin_enablepseudo == 1 and $CFG->turnitin_pseudolastname > 0) {
                    $cells['usi'] = $values->usi;
                }
                $cells['objectid'] = '&nbsp;';
                $submissionstring = $values->count == 1 ? get_string('submission', 'turnitintool') : get_string('submissions', 'turnitintool');
                if ($values->nonmoodle) {
                    $cells['student'] = '<i>' . $pluslink . $values->lastname . ', ' . $values->firstname . ' (' . get_string('nonmoodleuser', 'turnitintool') . ')</i> - (' . $values->count . ' ' . $submissionstring . ')';
                } else {
                    $cells['student'] = '' . $pluslink . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $values->userid . '&course=' . $turnitintool->course . '">' . $values->lastname . ', ' . $values->firstname . '</a> - (' . $values->count . ' ' . $submissionstring . ')';
                }
                $cells['modified'] = '&nbsp;';
                $score = ($values->lowscore == $values->highscore or empty($values->lowscore)) ? $values->highscore . '%' : $values->lowscore . '% <b>&raquo;</b> ' . $values->highscore . '%';
                if ($score == '%') {
                    $score = '-';
                }
                $cells['score'] = $score;
                $usersubmissions[$values->userid] = $submissions;
                $overallgrade = turnitintool_overallgrade($turnitintool, $usersubmissions, $values->userid);
                if ($turnitintool->grade == 0 or $overallgrade === '-') {
                    $overallgrade = '-';
                } else {
                    if ($turnitintool->grade < 0) {
                        // Scale
                        $scale = turnitintool_get_record('scale', 'id', $turnitintool->grade * -1);
                        $scalearray = explode(",", $scale->scale);
                        $overallmax = count($scalearray);
                        // Array is zero indexed
                        // Scale positions are from 1 upward
                        $index = $overallgrade - 1;
                        $overallgrade = $scalearray[$index];
                    } else {
                        if ($turnitintool->gradedisplay == 2) {
                            // 2 is fraction
                            $overallgrade .= '/' . $turnitintool->grade;
                        } else {
                            if ($turnitintool->gradedisplay == 1) {
                                // 1 is percentage
                                $overallgrade = round($overallgrade / $turnitintool->grade * 100, 1) . '%';
                            }
                        }
                    }
                }
                $cells['grade'] = $overallgrade;
                $cells['studentview'] = '&nbsp;';
                $cells['feedback'] = '&nbsp;';
                $cells['download'] = '&nbsp;';
                $cells['delete'] = '&nbsp;';
                $cells['rowid'] = 'row_' . $values->userid . '_top';
                $cells['class'] = 'top';
                $output_array[] = $cells;
                $i = 0;
                foreach ($parts as $part) {
                    $tiiparts[$part->id] = $part;
                    $parthassubmissions[$part->id] = false;
                }
                foreach ($submissions as $submission) {
                    $entryCount[$values->userid] = !isset($entryCount[$values->userid]) ? 1 : $entryCount[$values->userid] + 1;
                    $i++;
                    $lastclass = $i == $values->count ? ' lastmark' : ' leftmark';
                    $cells['rowid'] = 'row_' . $values->userid . '_sub_' . $i;
                    $cells['class'] = 'submission' . $lastclass;
                    $part = $tiiparts[$submission->submission_part];
                    $parthassubmissions[$submission->submission_part] = true;
                    // ###############################
                    // Do Submission Filelink
                    // ###############################
                    $filelink = turnitintool_get_filelink($cm, $turnitintool, $submission);
                    $doscript = '';
                    if (!empty($submission->submission_objectid)) {
                        $doscript = ' onclick="screenOpen(\'' . $filelink . '\',\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\');return false;"';
                    }
                    $length = 60;
                    $truncate = strlen($part->partname . ' - ' . $submission->submission_title) > $length ? substr($part->partname . ' - ' . $submission->submission_title, 0, $length) . '...' : $part->partname . ' - ' . $submission->submission_title;
                    $cells['student'] = '<a href="' . $filelink . '" target="_blank" class="fileicon"' . $doscript . ' title="' . $part->partname . ' - ' . $submission->submission_title . '">' . $truncate . '</a>';
                    // ###############################
                    // Output USI if required
                    // ###############################
                    if ($CFG->turnitin_enablepseudo == 1 and $CFG->turnitin_pseudolastname > 0) {
                        unset($cells['usi']);
                        $cells['usi'] = '&nbsp;';
                    }
                    // ###############################
                    // Do Paper ID column
                    // ###############################
                    unset($cells['objectid']);
                    $cells['objectid'] = (is_null($submission->submission_objectid) or empty($submission->submission_objectid)) ? '-' : $submission->submission_objectid;
                    // ###############################
                    // Do Submission to Turnitin Form
                    // ###############################
                    $modified = '-';
                    if (empty($submission->submission_objectid) and $turnitintool->autosubmission) {
                        $modified = '<div class="submittoLinkSmall"><img src="' . $CFG->wwwroot . '/mod/turnitintool/icon.gif" /><a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&up=' . $submission->id . '">' . get_string('submittoturnitin', 'turnitintool') . '</a></div>';
                    } else {
                        if (!is_null($submission->id)) {
                            $modified = empty($submission->submission_objectid) ? '-' : userdate($submission->submission_modified, get_string('strftimedatetimeshort', 'langconfig'));
                            if ($submission->submission_modified > $part->dtdue) {
                                $modified = '<span style="color: red;">' . $modified . '</span>';
                            }
                        }
                    }
                    $cells['modified'] = $modified;
                    // ###################################
                    // Get originality score if available
                    // ###################################
                    $score = turnitintool_draw_similarityscore($cm, $turnitintool, $submission);
                    $cells['score'] = $score;
                    // ###################################
                    // Get grade if available
                    // ###################################
                    $grade = turnitintool_dogradeoutput($cm, $turnitintool, $submission);
                    $cells['grade'] = '<form action="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=allsubmissions" method="POST">' . $grade . '</form>';
                    // ###################################
                    // Get Student View indicator
                    // ###################################
                    $grademarkurl = $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&jumppage=grade';
                    $grademarkurl .= '&userid=' . $USER->id . '&utp=2&objectid=' . $submission->submission_objectid;
                    $warn = ($turnitintool->reportgenspeed == 1 and $part->dtpost > time()) ? $warn = ',\'' . get_string('resubmissiongradewarn', 'turnitintool') . '\'' : '';
                    if ($submission->submission_attempts > 0) {
                        $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_read', 'turnitintool') . ' ' . userdate($submission->submission_attempts) . '" ';
                        $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                        $cells['studentview'] .= '><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-student-read.png" class="tiiicons" /></a>';
                    } else {
                        $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_notread', 'turnitintool') . '" ';
                        $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                        $cells['studentview'] .= '><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-dot.png" class="tiiicons" /></a>';
                    }
                    // ###################################
                    // Get Feedback Icon if needed
                    // ###################################
                    if (!$values->nonmoodle) {
                        $notes = turnitintool_getnoteslink($cm, $turnitintool, $submission);
                    } else {
                        $notes = '-';
                    }
                    $cells['feedback'] = $notes;
                    // ###################################
                    // Get Download Icon if needed
                    // ###################################
                    if (!is_null($submission->submission_objectid)) {
                        $downscript = ' onclick="screenOpen(this.href,\'' . $submission->id . '\',false,null,\'width=450,height=200\');return false;"';
                        $download = '<a href="' . turnitintool_get_filelink($cm, $turnitintool, $submission, $download = true) . '" title="' . get_string('downloadsubmission', 'turnitintool') . '" target="_blank"' . $downscript . '><img src="pix/downloadicon.gif" alt="' . get_string('downloadsubmission', 'turnitintool') . '" class="tiiicons" /></a>';
                    } else {
                        $download = '';
                    }
                    $cells['download'] = $download;
                    // ###################################
                    // Get Delete Icon if needed
                    // ###################################
                    $fnd = array("\n", "\r");
                    $rep = array('\\n', '\\r');
                    if (empty($submission->submission_objectid)) {
                        $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('deleteconfirm', 'turnitintool')) . '\');"';
                    } else {
                        $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('turnitindeleteconfirm', 'turnitintool')) . '\')"';
                    }
                    if (empty($submission->submission_objectid) or has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
                        $delete = '<a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&delete=' . $submission->id . '&do=' . $param_do . '"' . $confirm . ' title="' . get_string('deletesubmission', 'turnitintool') . '"><img src="pix/trashicon.gif" alt="' . get_string('deletesubmission', 'turnitintool') . '" class="tiiicons" /></a>';
                    } else {
                        $delete = '-';
                    }
                    $cells['delete'] = $delete;
                    $output_array[] = $cells;
                }
            } else {
                $pluslink = '
                    <img src="pix/clearpixel.gif" class="plusminus" id="userblock_' . $values->userid . '" />
                    ';
                $cells['student'] = '<div class="student">' . $pluslink . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $values->userid . '&course=' . $turnitintool->course . '">' . $values->lastname . ', ' . $values->firstname . '</a> - (0 ' . get_string('submissions', 'turnitintool') . ')</div>';
                if ($CFG->turnitin_enablepseudo == 1 and $CFG->turnitin_pseudolastname > 0) {
                    $cells['usi'] = '<div class="student">' . $values->usi . '</div>';
                }
                $cells['objectid'] = '<div class="student">&nbsp;</div>';
                $cells['modified'] = '<div class="student">&nbsp;</div>';
                $cells['score'] = '<div class="student">&nbsp;</div>';
                $cells['grade'] = '<div class="student">&nbsp;</div>';
                $cells['studentview'] = '<div class="student">&nbsp;</div>';
                $cells['feedback'] = '<div class="student">&nbsp;</div>';
                $cells['download'] = '<div class="student">&nbsp;</div>';
                $cells['delete'] = '<div class="student">&nbsp;</div>';
                $cells['rowid'] = 'row_' . $values->userid . '_top';
                $cells['class'] = 'top';
                $output_array[] = $cells;
            }
        }
    } else {
        // If Anonymous
        $n = 0;
        $sql_query = '';
        $submissions = array();
        // Get Moodle User Submissions first
        if ($submissions_data = turnitintool_get_records_select("turnitintool_submissions", "turnitintoolid=" . $turnitintool->id, "", "id, userid, submission_score, submission_grade, submission_objectid, 0 AS nonmoodle," . "submission_part, submission_filename, submission_title, submission_gmimaged, " . "submission_unanon unanon, submission_modified, submission_attempts")) {
            foreach ($submissions_data as $submission_data) {
                $user = turnitintool_get_record('user', 'id', $submission_data->userid);
                $submission["userid"] = $submission_data->userid;
                $submission["firstname"] = isset($user->firstname) ? $user->firstname : null;
                $submission["lastname"] = isset($user->lastname) ? $user->lastname : null;
                $submission["submission_score"] = $submission_data->submission_score;
                $submission["submission_grade"] = $submission_data->submission_grade;
                $submission["submission_objectid"] = $submission_data->submission_objectid;
                $submission["nonmoodle"] = 0;
                $submission["submission_part"] = $submission_data->submission_part;
                $submission["submission_filename"] = $submission_data->submission_filename;
                $submission["submission_title"] = $submission_data->submission_title;
                $submission["submission_gmimaged"] = $submission_data->submission_gmimaged;
                $submission["unanon"] = $submission_data->unanon;
                $submission["submission_modified"] = $submission_data->submission_modified;
                $submission["submission_attempts"] = $submission_data->submission_attempts;
                $submission["id"] = $submission_data->id;
                $submissions[$submission["id"]] = $submission;
            }
        }
        // Now get the Non Moodle User submissions
        if ($submissions_data = turnitintool_get_records_select("turnitintool_submissions", "userid=0 AND turnitintoolid=" . $turnitintool->id, "", "id, submission_nmuserid AS userid, submission_nmfirstname AS firstname, submission_nmlastname AS lastname, " . "submission_score, submission_grade, submission_objectid, 0 AS nonmoodle," . "submission_part, submission_filename, submission_title, submission_gmimaged, " . "submission_unanon AS unanon, submission_modified, submission_attempts")) {
            foreach ($submissions_data as $submission_data) {
                $submission["userid"] = "nm-" . $submission_data->userid;
                $submission["firstname"] = $submission_data->firstname;
                $submission["lastname"] = $submission_data->lastname;
                $submission["submission_score"] = $submission_data->submission_score;
                $submission["submission_grade"] = $submission_data->submission_grade;
                $submission["submission_objectid"] = $submission_data->submission_objectid;
                $submission["nonmoodle"] = 1;
                $submission["submission_part"] = $submission_data->submission_part;
                $submission["submission_filename"] = $submission_data->submission_filename;
                $submission["submission_title"] = $submission_data->submission_title;
                $submission["submission_gmimaged"] = $submission_data->submission_gmimaged;
                $submission["unanon"] = $submission_data->unanon;
                $submission["submission_modified"] = $submission_data->submission_modified;
                $submission["submission_attempts"] = $submission_data->submission_attempts;
                $submission["id"] = $submission_data->id;
                $submissions[$submission["id"]] = $submission;
            }
        }
        $submission_part = array();
        $submission_score = array();
        $submission_grade = array();
        $submission_modified = array();
        $lastname = array();
        // Obtain the columns to sort on
        foreach ($submissions as $key => $row) {
            $lastname[$key] = $row['lastname'];
            $submission_part[$key] = $row['submission_part'];
            $submission_score[$key] = $row['submission_score'];
            $submission_grade[$key] = $row['submission_grade'];
            $submission_modified[$key] = $row['submission_modified'];
        }
        // ORDER BY: 1: Originality Score - Max-Min,
        //           2: Originality Score - Min-Max,
        //           3: Grade - Max-Min,
        //           4: Grade - Min-Max,
        //           5: Submitted Date - Min-Max,
        //           6: Submitted Date - Max-Min,
        //           7: Students Last Name - A-Z,
        //           8: Student Last Name - Z-A
        if ($orderby == '1') {
            array_multisort($submission_part, SORT_ASC, $submission_score, SORT_DESC, $submission_modified, SORT_DESC, $lastname, SORT_ASC, $submissions);
            $order_by = ' ORDER BY submission_part ASC,submission_score DESC,submission_modified DESC,lastname ASC';
        } else {
            if ($orderby == '2') {
                array_multisort($submission_part, SORT_ASC, $submission_score, SORT_ASC, $submission_modified, SORT_DESC, $lastname, SORT_ASC, $submissions);
                $order_by = ' ORDER BY submission_part ASC,submission_score ASC,submission_modified DESC,lastname ASC';
            } else {
                if ($orderby == '3') {
                    array_multisort($submission_part, SORT_ASC, $submission_grade, SORT_DESC, $submission_score, SORT_DESC, $lastname, SORT_ASC, $submissions);
                    $order_by = ' ORDER BY submission_part ASC,submission_grade DESC,submission_score DESC,lastname ASC';
                } else {
                    if ($orderby == '4') {
                        array_multisort($submission_part, SORT_ASC, $submission_grade, SORT_ASC, $submission_score, SORT_DESC, $lastname, SORT_ASC, $submissions);
                        $order_by = ' ORDER BY submission_part ASC,submission_grade ASC,submission_score DESC,lastname ASC';
                    } else {
                        if ($orderby == '5') {
                            array_multisort($submission_part, SORT_ASC, $submission_modified, SORT_DESC, $submission_score, SORT_DESC, $lastname, SORT_ASC, $submissions);
                            $order_by = ' ORDER BY submission_part ASC,submission_modified DESC,submission_score DESC,submission_modified DESC,lastname ASC';
                        } else {
                            if ($orderby == '6') {
                                array_multisort($submission_part, SORT_ASC, $submission_modified, SORT_ASC, $submission_score, SORT_DESC, $lastname, SORT_ASC, $submissions);
                                $order_by = ' ORDER BY submission_part ASC,submission_modified ASC,submission_score DESC,lastname ASC';
                            } else {
                                if ($orderby == '7') {
                                    array_multisort($submission_part, SORT_ASC, $lastname, SORT_DESC, $submission_score, SORT_DESC, $submissions);
                                    $order_by = ' ORDER BY submission_part ASC,lastname DESC,submission_score DESC';
                                } else {
                                    if ($orderby == '8') {
                                        array_multisort($submission_part, SORT_ASC, $lastname, SORT_ASC, $submission_score, SORT_DESC, $submissions);
                                        $order_by = ' ORDER BY submission_part ASC,lastname ASC,submission_score DESC';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!$submissions) {
            $submissions = array();
        }
        // Count the number of students enrolled on this course
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        $studentusers = get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', 0, '', false);
        $numstudents = !is_array($studentusers) ? 0 : count($studentusers);
        $totalentries = count($submissions);
        foreach ($parts as $part) {
            $parthassubmissions[$part->id] = false;
            $i = 0;
            $rs = 0;
            $entryCount[$part->id] = 0;
            foreach ($submissions as $submission) {
                $rs++;
                if ($rs < $param_from) {
                    continue;
                }
                if ($rs > $param_from - 1 + $param_show and $param_show != 0) {
                    break;
                }
                $parthassubmissions[$part->id] = true;
                $submission = turnitintool_array_to_object($submission);
                if ($part->id == $submission->submission_part) {
                    if (!isset($toprow) or $toprow != $part->id) {
                        // Count the number of submissions made to this part
                        $numsubs = turnitintool_count_records('turnitintool_submissions', 'submission_part', $part->id);
                        $javascriptUsers .= !empty($javascriptUsers) ? ',"' . $submission->submission_part . '"' : '"' . $submission->submission_part . '"';
                        if ($numsubs > 0) {
                            // Draw Plus Link if there are any submissions
                            $pluslink = '
                            <script language="javascript" type="text/javascript">
                            document.write("<a href=\\"javascript:;\\" onclick=\\"toggleview(\'' . $part->id . '\',\'' . $numsubs . '\');\\">");
                            </script>
                            <img src="pix/clearpixel.gif" class="plusminus" id="userblock_' . $part->id . '" />
                            <script language="javascript" type="text/javascript">
                            document.write(\'</a>\');
                            document.getElementById(\'userblock_' . $part->id . '\').src="pix/plus.gif";
                            </script>';
                        } else {
                            // Draw a place holder spacer if there are less than one submissions
                            $pluslink = '
                            <img src="pix/clearpixel.gif" class="plusminus" id="userblock_' . $part->id . '" />
                            ';
                        }
                        $cells['student'] = '<div class="student"><b>' . $pluslink . $part->partname . '</b> - (' . $numsubs . ' ' . get_string('submissions', 'turnitintool') . ' / ' . $numstudents . ' ' . get_string('students') . ')</div>';
                        $cells['objectid'] = '<div class="student">&nbsp;</div>';
                        $cells['modified'] = '<div class="student">&nbsp;</div>';
                        $cells['score'] = '<div class="student">&nbsp;</div>';
                        $cells['grade'] = '<div class="student">&nbsp;</div>';
                        $cells['studentview'] = '<div class="student">&nbsp;</div>';
                        $cells['feedback'] = '<div class="student">&nbsp;</div>';
                        $cells['download'] = '<div class="student">&nbsp;</div>';
                        $cells['delete'] = '<div class="student">&nbsp;</div>';
                        $cells['rowid'] = 'row_' . $part->id . '_top';
                        $cells['class'] = 'top';
                        $output_array[] = $cells;
                        $toprow = $part->id;
                    }
                    $entryCount[$part->id] = !isset($entryCount[$part->id]) ? 1 : $entryCount[$part->id] + 1;
                    $i++;
                    $lastclass = $i == $numsubs ? ' lastmark' : ' leftmark';
                    $cells['rowid'] = 'row_' . $part->id . '_sub_' . $i;
                    $cells['class'] = 'submission' . $lastclass;
                    // ###################################
                    // Do Student / Submission Filelink
                    // ###################################
                    if (!$submission->unanon and $part->dtpost > time() and !empty($submission->submission_filename) and !empty($submission->submission_objectid)) {
                        // Anonymous marking is on and postdate has not passed and a submission has been made
                        $reason = isset($param_reason[$submission->submission_objectid]) ? $param_reason[$submission->submission_objectid] : get_string('revealreason', 'turnitintool');
                        $namedisplay = '<b>' . get_string('student', 'turnitintool') . ':</b> <span id="studentname_' . $submission->submission_objectid . '"><i>' . get_string('anonenabled', 'turnitintool') . '</i><br /></span><span id="anonform_' . $submission->submission_objectid . '"><form action="' . $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions" method="POST" onsubmit="return anonValidate(this.reason);">&nbsp;&nbsp;&nbsp;<input id="reason" name="reason[' . $submission->submission_objectid . ']" value="' . $reason . '" type="text" onclick="this.value=\'\';" /><input id="anonid" name="anonid" value="' . $submission->submission_objectid . '" type="hidden" />&nbsp;<input value="' . get_string('reveal', 'turnitintool') . '" type="submit" /></form></span>';
                        $namedisplay .= '<script language="javascript" type="text/javascript">
            toggleAnonView(' . $submission->submission_objectid . ',false);
        </script>';
                    } else {
                        if (($part->dtpost <= time() or $submission->unanon) and !$submission->nonmoodle) {
                            // Post date has passed or anonymous marking disabled for user and user is a moodle user
                            $namedisplay = '<b>' . get_string('student', 'turnitintool') . ':</b> ' . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $submission->userid . '&course=' . $turnitintool->course . '">' . $submission->lastname . ', ' . $submission->firstname . '</a>';
                        } else {
                            if (($part->dtpost <= time() or $submission->unanon) and $submission->nonmoodle) {
                                // Post date has passed or anonymous marking disabled for user and user is a NON moodle user
                                $namedisplay = '<b>' . get_string('student', 'turnitintool') . ':</b> <i>' . $submission->lastname . ', ' . $submission->firstname . ' (' . get_string('nonmoodleuser', 'turnitintool') . ')</i>';
                            } else {
                                // User has not made a submission
                                $namedisplay = '<b>' . get_string('student', 'turnitintool') . ':</b> <i>' . get_string('anonenabled', 'turnitintool') . '</i>';
                            }
                        }
                    }
                    $title = '';
                    if (!empty($submission->submission_title)) {
                        $filelink = turnitintool_get_filelink($cm, $turnitintool, $submission);
                        // Create screen opener with a return checker but only for submissions with object ids
                        $doscript = '';
                        if (!empty($submission->submission_objectid)) {
                            $doscript = ' onclick="screenOpen(\'' . $filelink . '\',\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\');return false;"';
                        }
                        // Create download link to download submission from either Moodle or Turnitin
                        $downloadlink = turnitintool_get_filelink($cm, $turnitintool, $submission, $download = true);
                        $length = 60;
                        $truncate = strlen($submission->submission_title) > $length ? substr($submission->submission_title, 0, $length) . '...' : $submission->submission_title;
                        $title = '<b>' . get_string('file', 'turnitintool') . ':</b> <a href="' . $filelink . '" target="_blank" class="tiiicons"' . $doscript . ' title="' . $submission->submission_title . '">' . $truncate . '</a><br />';
                    } else {
                        $title = '<b>' . get_string('file', 'turnitintool') . ':</b> ' . get_string('nosubmission', 'turnitintool') . '<br />';
                    }
                    $cells['student'] = $title . $namedisplay;
                    // ###############################
                    // Do Paper ID column
                    // ###############################
                    $cells['objectid'] = (is_null($submission->submission_objectid) or empty($submission->submission_objectid)) ? '-' : $submission->submission_objectid;
                    // ###########################################
                    // Do Submission to Turnitin Form / Object ID
                    // ###########################################
                    $modified = '-';
                    if (empty($submission->submission_objectid) and $turnitintool->autosubmission) {
                        $modified = '<div class="submittoLinkSmall"><img src="' . $CFG->wwwroot . '/mod/turnitintool/icon.gif" /><a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&up=' . $submission->id . '">' . get_string('submittoturnitin', 'turnitintool') . '</a></div>';
                    } else {
                        if (!is_null($submission->id)) {
                            $modified = empty($submission->submission_objectid) ? '-' : userdate($submission->submission_modified, get_string('strftimedatetimeshort', 'langconfig'));
                            if ($submission->submission_modified > $part->dtdue) {
                                $modified = '<span style="color: red;">' . $modified . '</span>';
                            }
                        }
                    }
                    $cells['modified'] = $modified;
                    // ###################################
                    // Get originality score if available
                    // ###################################
                    $score = turnitintool_draw_similarityscore($cm, $turnitintool, $submission);
                    $cells['score'] = $score;
                    // ###################################
                    // Get grade if available
                    // ###################################
                    $grade = turnitintool_dogradeoutput($cm, $turnitintool, $submission);
                    $cells['grade'] = '<form action="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=allsubmissions" method="POST">' . $grade . '</form>';
                    // ###################################
                    // Get Student View indicator
                    // ###################################
                    $grademarkurl = $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&jumppage=grade';
                    $grademarkurl .= '&userid=' . $USER->id . '&utp=2&objectid=' . $submission->submission_objectid;
                    $warn = ($turnitintool->reportgenspeed == 1 and $part->dtpost > time()) ? $warn = ',\'' . get_string('resubmissiongradewarn', 'turnitintool') . '\'' : '';
                    if ($submission->submission_attempts > 0) {
                        $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_read', 'turnitintool') . ' ' . userdate($submission->submission_attempts) . '" ';
                        $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                        $cells['studentview'] .= '><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-student-read.png" class="tiiicons" /></a>';
                    } else {
                        $cells['studentview'] = '<a href="' . $grademarkurl . '" title="' . get_string('student_notread', 'turnitintool') . '" ';
                        $cells['studentview'] .= ' onclick="screenOpen(this.href,\'' . $submission->id . '\',\'' . $turnitintool->autoupdates . '\'' . $warn . ');return false;"';
                        $cells['studentview'] .= '><img src="' . $CFG->wwwroot . '/mod/turnitintool/pix/icon-dot.png" class="tiiicons" /></a>';
                    }
                    // ###################################
                    // Get Feedback Icon if needed
                    // ###################################
                    if (!$submission->nonmoodle and !is_null($submission->id)) {
                        $notes = turnitintool_getnoteslink($cm, $turnitintool, $submission);
                    } else {
                        $notes = '-';
                    }
                    $cells['feedback'] = $notes;
                    // ###################################
                    // Get Download Icon if needed
                    // ###################################
                    if (!is_null($submission->submission_objectid) and $part->dtpost <= time()) {
                        $downscript = ' onclick="screenOpen(this.href,\'' . $submission->id . '\',false,null,\'width=450,height=200\');return false;"';
                        $download = '<a href="' . turnitintool_get_filelink($cm, $turnitintool, $submission, $download = true) . '" title="' . get_string('downloadsubmission', 'turnitintool') . '" target="_blank"' . $downscript . '><img src="pix/downloadicon.gif" alt="' . get_string('downloadsubmission', 'turnitintool') . '" class="tiiicons" /></a>';
                    } else {
                        $download = '';
                    }
                    $cells['download'] = $download;
                    // ###################################
                    // Get Delete Icon if needed
                    // ###################################
                    $fnd = array("\n", "\r");
                    $rep = array('\\n', '\\r');
                    if (empty($submission->submission_objectid)) {
                        $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('deleteconfirm', 'turnitintool')) . '\');"';
                    } else {
                        $confirm = ' onclick="return confirm(\'' . str_replace($fnd, $rep, get_string('turnitindeleteconfirm', 'turnitintool')) . '\')"';
                    }
                    if ((empty($submission->submission_objectid) or has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) and !is_null($submission->id)) {
                        $delete = '<a href="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&delete=' . $submission->id . '&do=' . $param_do . '"' . $confirm . ' title="' . get_string('deletesubmission', 'turnitintool') . '"><img src="pix/trashicon.gif" alt="' . get_string('deletesubmission', 'turnitintool') . '" class="tiiicons" /></a>';
                    } else {
                        $delete = '-';
                    }
                    $cells['delete'] = $delete;
                    $output_array[] = $cells;
                }
            }
            $n++;
        }
        $output = '
        <script language="javascript" type="text/javascript">
            function toggleAnonView(userview,onoff) {
                var anonform=document.getElementById(\'anonform_\'+userview);
                var studentname=document.getElementById(\'studentname_\'+userview);
                if (onoff==true) {
                    anonform.style.display="inline";
                    studentname.innerHTML="' . get_string('anonenabled', 'turnitintool') . '";
                } else {
                    anonform.style.display="none";
                    studentname.innerHTML="<input value=\\"' . get_string('anonenabled', 'turnitintool') . '\\" type=\\"button\\" onclick=\\"toggleAnonView("+userview+",true)\\" />";
                }
            }
            function anonValidate(reason) {
                if (!reason.value || reason.value=="' . get_string('revealreason', 'turnitintool') . '") {
                    reason.style.color="red";
                    reason.style.borderColor="red";
                    alert("' . get_string('revealerror', 'turnitintool') . '");
                    return false;
                } else {
                    return true;
                }

            }
        </script>';
    }
    if (!isset($output_array) or count($output_array) == 0) {
        // If no students enrolled
        $output_array = array(array('student' => '<div class="student">' . get_string('nosubmissions', 'turnitintool') . '</div>', 'objectid' => '<div class="student">&nbsp;</div>', 'modified' => '<div class="student">&nbsp;</div>', 'score' => '<div class="student">&nbsp;</div>', 'grade' => '<div class="student">&nbsp;</div>', 'studentview' => '<div class="student">&nbsp;</div>', 'feedback' => '<div class="student">&nbsp;</div>', 'download' => '<div class="student">&nbsp;</div>', 'delete' => '<div class="student">&nbsp;</div>'));
        if ($CFG->turnitin_enablepseudo == 1 and $CFG->turnitin_pseudolastname > 0) {
            $output_array[0]['usi'] = '<div class="student">&nbsp;</div>';
        }
    }
    foreach ($entryCount as $thisCount) {
        $javascriptCount .= !empty($javascriptCount) ? ',"' . $thisCount . '"' : '"' . $thisCount . '"';
    }
    $output .= $styles . '
        <script language="javascript" type="text/javascript">
            var users= new Array(' . $javascriptUsers . ');
            var count= new Array(' . $javascriptCount . ');
        </script>
        <script src="turnitintool.js" language="javascript" type="text/javascript"></script>
            ';
    $output .= turnitintool_output_inboxfilter($cm, $turnitintool, $param_from, $param_show, $totalentries);
    $output .= turnitintool_draw_submission_table($cm, $turnitintool, $output_array);
    $output .= '
        <script language="javascript" type="text/javascript">
            assignmentcheck(' . $turnitintool->id . ');
            setuserchoice();
        ';
    if ($turnitintool->numparts == 1) {
        $output .= 'toggleshowall();
        ';
    }
    $output .= '</script>';
    return $output;
}