Exemplo n.º 1
0
/**
 * Outputs the HTML for the submission form
 *
 * @global object
 * @global object
 * @global object
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object for this activity
 * @param var $submissionid The Submission ID of the submission in turnitintool_submission
 * @return string returns the HTML of the form
 */
function turnitintool_view_submission_form($cm, $turnitintool, $submissionid = NULL)
{
    global $CFG, $USER, $COURSE;
    $optional_params = new stdClass();
    $optional_params->type = optional_param('type', 0, PARAM_CLEAN);
    $optional_params->userid = optional_param('userid', null, PARAM_CLEAN);
    $optional_params->agreement = optional_param('agreement', null, PARAM_CLEAN);
    $cansubmit = turnitintool_cansubmit($cm, $turnitintool, $USER);
    $totalusers = !$cansubmit ? 0 : count($cansubmit);
    if ($cansubmit and $totalusers > 0) {
        if ($CFG->branch >= 29) {
            $output = turnitintool_view_submission_form_post_29($cm, $turnitintool, $optional_params, $cansubmit);
        } else {
            $output = turnitintool_view_submission_form_pre_29($cm, $turnitintool, $optional_params, $cansubmit);
        }
    } else {
        $output = turnitintool_box_start('generalbox boxwidthwide boxaligncenter eightyfive', 'submitbox', true);
        if (turnitintool_count_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < " . time() . " AND dtdue > " . time()) == 0) {
            // Due date has passed
            $output .= get_string('nosubmissionsdue', 'turnitintool');
        } else {
            // Due date has not passed
            // Count the number of students (numusers) enrolled on this course
            $context = turnitintool_get_context('MODULE', $cm->id);
            $users = get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', turnitintool_module_group($cm), '', false);
            $numusers = !is_array($users) ? 0 : count($users);
            if ($numusers > 0) {
                $output .= get_string('submittedmax', 'turnitintool');
            } else {
                $output .= get_string('noenrolledstudents', 'turnitintool');
            }
        }
        $output .= turnitintool_box_end(true) . '<br />';
    }
    return $output;
}
Exemplo n.º 2
0
/**
 * Outputs the HTML for the submission form
 *
 * @global object
 * @global object
 * @global object
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object for this activity
 * @param var $submissionid The Submission ID of the submission in turnitintool_submission
 * @return string returns the HTML of the form
 */
function turnitintool_view_submission_form($cm, $turnitintool, $submissionid = NULL)
{
    global $CFG, $USER, $COURSE;
    $param_type = optional_param('type', 0, PARAM_CLEAN);
    $param_userid = optional_param('userid', null, PARAM_CLEAN);
    $param_agreement = optional_param('agreement', null, PARAM_CLEAN);
    $cansubmit = turnitintool_cansubmit($cm, $turnitintool, $USER);
    $totalusers = !$cansubmit ? 0 : count($cansubmit);
    if ($cansubmit and $totalusers > 0) {
        $output = turnitintool_box_start('generalbox boxwidthwide boxaligncenter eightyfive', 'submitbox', true);
        if (has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
            $submissions = turnitintool_get_records_select('turnitintool_submissions', 'turnitintoolid=' . $turnitintool->id);
        } else {
            $submissions = turnitintool_get_records_select('turnitintool_submissions', 'userid=' . $USER->id . ' AND turnitintoolid=' . $turnitintool->id);
        }
        $output .= '<script language="javascript" type="text/javascript">' . PHP_EOL;
        $output .= 'var stringsArray = new Array("' . get_string('addsubmission', 'turnitintool') . '","' . get_string('resubmit', 'turnitintool') . '","' . get_string('resubmission', 'turnitintool') . '","' . get_string('resubmissionnotenabled', 'turnitintool') . '","' . get_string('anonenabled', 'turnitintool') . '");' . PHP_EOL;
        $output .= 'var submissionArray = new Array();' . PHP_EOL;
        if ($turnitintool->allowlate == 1) {
            $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "'", 'dtstart,dtdue,dtpost,id');
        } else {
            $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "' AND dtdue > '" . time() . "'", 'dtstart,dtdue,dtpost,id');
        }
        if (is_array($submissions)) {
            $i = 0;
            foreach ($submissions as $submission) {
                $lockresubmission = 0;
                if (isset($parts[$submission->submission_part]) and $parts[$submission->submission_part]->dtdue < time()) {
                    $lockresubmission = 1;
                }
                $output .= 'submissionArray[' . $i . '] = new Array("' . $submission->userid . '","' . $submission->submission_part . '","' . $submission->submission_title . '","' . $submission->submission_unanon . '",' . $lockresubmission . ');' . PHP_EOL;
                $submittedparts[] = $submission->submission_part;
                $i++;
            }
        }
        $output .= '</script>' . PHP_EOL;
        $table->width = '100%';
        $table->id = 'uploadtable';
        $table->class = 'uploadtable';
        unset($cells);
        $cells = array();
        $cells[0]->class = 'cell c0';
        $cells[0]->data = get_string('submissiontype', 'turnitintool') . turnitintool_help_icon('submissiontype', get_string('submissiontype', 'turnitintool'), 'turnitintool', true, false, '', true);
        if ($turnitintool->type == 0) {
            if ($param_type == 1) {
                $selected = array('', ' selected', '', '');
            } else {
                if ($param_type == 2) {
                    $selected = array('', '', ' selected', '');
                } else {
                    if ($param_type == 3) {
                        $selected = array('', '', '', ' selected');
                    } else {
                        $selected = array(' selected', '', '', '');
                        $param_type = 0;
                    }
                }
            }
            $cells[1]->class = 'cell c1';
            $cells[1]->data = '<select onchange="turnitintool_jumptopage(this.value)">';
            $cells[1]->data .= '<option label="Select Submission Type" value="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=submissions"' . $selected[0] . '>Select Submission Type</option>';
            $cells[1]->data .= '<option label="-----------------" value="#">-----------------</option>';
            $typearray = turnitintool_filetype_array(false);
            foreach ($typearray as $typekey => $typevalue) {
                $cells[1]->data .= '
                <option label="' . $typevalue . '" value="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=submissions&type=' . $typekey . '"' . $selected[$typekey] . '>' . $typevalue . '</option>';
            }
            $cells[1]->data .= '
            </select>
            <input id="submissiontype" name="submissiontype" type="hidden" value="' . $param_type . '" />';
        } else {
            if ($turnitintool->type == 1) {
                $param_type = 1;
                $cells[1]->data = '<input id="submissiontype" name="submissiontype" type="hidden" value="1" />' . get_string('fileupload', 'turnitintool');
            } else {
                if ($turnitintool->type == 2) {
                    $param_type = 2;
                    $cells[1]->data = '<input id="submissiontype" name="submissiontype" type="hidden" value="2" />' . get_string('textsubmission', 'turnitintool');
                }
            }
        }
        $output .= '<b>' . get_string('submit', 'turnitintool') . '</b><br />
    <form enctype="multipart/form-data" action="' . $CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=submissions&type=' . $param_type . '" method="POST" name="submissionform">';
        $table->rows[0]->class = 'r0';
        $table->rows[0]->cells = $cells;
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        if ($param_type != 0) {
            $submissiontitle = optional_param('submissiontitle', '', PARAM_CLEAN);
            $disableform = false;
            if (has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
                $utype = "tutor";
                // If tutor submitting on behalf of student
                unset($cells);
                $cells[0]->class = 'cell c0';
                $cells[0]->data = get_string('studentsname', 'turnitintool') . turnitintool_help_icon('studentsname', get_string('studentsname', 'turnitintool'), 'turnitintool', true, false, '', true);
                if (count($cansubmit) > 0) {
                    $cells[1]->data = '<select name="userid" id="userid" onchange="updateSubForm(submissionArray,stringsArray,this.form,' . $turnitintool->reportgenspeed . ')">';
                    foreach ($cansubmit as $courseuser) {
                        // Filter Guest users, admins and grader users
                        if (has_capability('mod/turnitintool:submit', $context, $courseuser->id, false)) {
                            if (!is_null($param_userid) and $param_userid == $courseuser->id) {
                                $selected = ' selected';
                            } else {
                                $selected = '';
                            }
                            $cells[1]->data .= '<option label="' . $courseuser->firstname . ' ' . $courseuser->lastname . '" value="' . $courseuser->id . '"' . $selected . '>' . $courseuser->lastname . ', ' . $courseuser->firstname . '</option>';
                        }
                    }
                    $cells[1]->data .= '</select>';
                    if ($cells[1]->data == '<select id="userid" name="userid">' . '</select>') {
                        $cells[1]->data = '<i>' . get_string('allsubmissionsmade', 'turnitintool') . '</i>';
                        $disableform = true;
                    }
                } else {
                    $cells[1]->data = '<i>' . get_string('noenrolledstudents', 'turnitintool') . '</i>';
                }
                $table->rows[1]->class = 'r1';
                $table->rows[1]->cells = $cells;
            } else {
                $utype = "student";
                // If student submitting
                unset($cells);
                $cells[0]->class = 'cell c0';
                $cells[0]->data = '';
                $cells[1]->data = '<input id="userid" name="userid" type="hidden" value="' . $USER->id . '" />';
                $table->rows[1]->class = 'r1';
                $table->rows[1]->cells = $cells;
            }
            if (!$disableform) {
                unset($cells);
                $cells[0]->class = 'cell c0';
                $cells[0]->data = get_string('submissiontitle', 'turnitintool') . turnitintool_help_icon('submissiontitle', get_string('submissiontitle', 'turnitintool'), 'turnitintool', true, false, '', true);
                $cells[1]->data = '<input type="text" name="submissiontitle" class="formwide" maxlength="200" value="' . $submissiontitle . '" />&nbsp;<span id="submissionnotice"></span>';
                $table->rows[2]->class = 'r0';
                $table->rows[2]->cells = $cells;
                if (count($parts) > 1) {
                    unset($cells);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = get_string('submissionpart', 'turnitintool') . turnitintool_help_icon('submissionpart', get_string('submissionpart', 'turnitintool'), 'turnitintool', true, false, '', true);
                    $cells[1]->data = '<select name="submissionpart" class="formwide" onchange="updateSubForm(submissionArray,stringsArray,this.form,' . $turnitintool->reportgenspeed . ',\'' . $utype . '\')">';
                    $i = 0;
                    foreach ($parts as $part) {
                        // Do parts that have not yet been submitted to
                        $cells[1]->data .= '<option label="' . $part->partname . '" value="' . $part->id . '">' . $part->partname . '</option>';
                        $i++;
                    }
                    $cells[1]->data .= '</select>';
                    $table->rows[3]->class = 'r1';
                    $table->rows[3]->cells = $cells;
                } else {
                    unset($cells);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = get_string('submissionpart', 'turnitintool') . turnitintool_help_icon('submissionpart', get_string('submissionpart', 'turnitintool'), 'turnitintool', true, false, '', true);
                    foreach ($parts as $part) {
                        // Do parts that have not yet been submitted to
                        $cells[1]->data = $part->partname . '<input type="hidden" name="submissionpart" value="' . $part->id . '" />';
                        break;
                    }
                    $table->rows[3]->class = 'r1';
                    $table->rows[3]->cells = $cells;
                }
                if ($param_type == 1) {
                    unset($cells);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = get_string('filetosubmit', 'turnitintool') . turnitintool_help_icon('filetosubmit', get_string('filetosubmit', 'turnitintool'), 'turnitintool', true, false, '', true);
                    $cells[1]->data = '<input type="hidden" name="MAX_FILE_SIZE" value="' . $turnitintool->maxfilesize . '" />';
                    $cells[1]->data .= '<input type="file" name="submissionfile" size="55%" />';
                    $table->rows[4]->class = 'r0';
                    $table->rows[4]->cells = $cells;
                }
                if ($param_type == 2) {
                    unset($cells);
                    $submissiontext = optional_param('submissiontext', '', PARAM_CLEAN);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = get_string('texttosubmit', 'turnitintool') . turnitintool_help_icon('texttosubmit', get_string('texttosubmit', 'turnitintool'), 'turnitintool', true, false, '', true);
                    $cells[1]->data = '<textarea name="submissiontext" class="submissionText">' . $submissiontext . '</textarea>';
                    $table->rows[5]->class = 'r1';
                    $table->rows[5]->cells = $cells;
                }
                if ($param_type == 3) {
                    unset($cells);
                    $submissionurl = optional_param('submissionurl', '', PARAM_CLEAN);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = get_string('urltosubmit', 'turnitintool') . turnitintool_help_icon('urltosubmit', get_string('urltosubmit', 'turnitintool'), 'turnitintool', true, false, '', true);
                    $cells[1]->data = '<input type="text" name="submissionurl" class="formwide" value="' . $submissionurl . '" />';
                    $table->rows[6]->class = 'r0';
                    $table->rows[6]->cells = $cells;
                }
                $checked = '';
                if (!is_null($param_agreement)) {
                    $checked = ' checked';
                }
                if (has_capability('mod/turnitintool:grade', $context) or empty($CFG->turnitin_agreement)) {
                    unset($cells);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = '';
                    $cells[1]->data = '<input type="hidden" name="agreement" value="1" />';
                    $table->rows[7]->class = 'r1';
                    $table->rows[7]->cells = $cells;
                } else {
                    unset($cells);
                    $cells[0]->class = 'cell c0';
                    $cells[0]->data = '<input type="checkbox" name="agreement" value="1"' . $checked . ' />';
                    $cells[1]->data = $CFG->turnitin_agreement;
                    $table->rows[7]->class = 'r1';
                    $table->rows[7]->cells = $cells;
                }
                unset($cells);
                $cells[0]->class = 'cell c0';
                $cells[0]->data = '&nbsp;';
                $cells[1]->data = '<input name="submitbutton" type="submit" value="' . get_string('addsubmission', 'turnitintool') . '" />';
                $table->rows[8]->class = 'r0';
                $table->rows[8]->cells = $cells;
            }
        }
        $output .= turnitintool_print_table($table, true);
        if ($param_type > 0) {
            $output .= '
                    <script language="javascript" type="text/javascript">updateSubForm(submissionArray,stringsArray,document.submissionform,' . $turnitintool->reportgenspeed . ',"' . $utype . '");</script>
            </form>
                    ';
        }
        $output .= turnitintool_box_end(true) . '<br />';
    } else {
        $output = turnitintool_box_start('generalbox boxwidthwide boxaligncenter eightyfive', 'submitbox', true);
        if (turnitintool_count_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < " . time() . " AND dtdue > " . time()) == 0) {
            // Due date has passed
            $output .= get_string('nosubmissionsdue', 'turnitintool');
        } else {
            // Due date has not passed
            // Count the number of students (numusers) enrolled on this course
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
            $users = get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', turnitintool_module_group($cm), '', false);
            $numusers = !is_array($users) ? 0 : count($users);
            if ($numusers > 0) {
                $output .= get_string('submittedmax', 'turnitintool');
            } else {
                $output .= get_string('noenrolledstudents', 'turnitintool');
            }
        }
        $output .= turnitintool_box_end(true) . '<br />';
    }
    return $output;
}