/** * Generates the HTML for the submission form in Moodle versions below 2.9 * * @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 object $optional_params The optional parameter object for this instance * @param object $cansubmit The list of students that can be submitted for * @return string returns the HTML of the form */ function turnitintool_view_submission_form_pre_29($cm, $turnitintool, $optional_params, $cansubmit) { global $CFG, $USER, $COURSE; $output = turnitintool_box_start('generalbox boxwidthwide boxaligncenter eightyfive', 'submitbox', true); if (has_capability('mod/turnitintool:grade', turnitintool_get_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() . "'", null, 'dtstart,dtdue,dtpost,id'); } else { $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "' AND dtdue > '" . time() . "'", NULL, '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 = new stdClass(); $table->width = '100%'; $table->id = 'uploadtable'; $table->class = 'uploadtable'; unset($cells); $cells = array(); $cells[0] = new stdClass(); $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 ($optional_params->type == 1) { $selected = array('', ' selected', '', ''); } else { if ($optional_params->type == 2) { $selected = array('', '', ' selected', ''); } else { if ($optional_params->type == 3) { $selected = array('', '', '', ' selected'); } else { $selected = array(' selected', '', '', ''); $optional_params->type = 0; } } } $cells[1] = new stdClass(); $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="' . $optional_params->type . '" />'; } else { if ($turnitintool->type == 1) { $optional_params->type = 1; $cells[1] = new stdClass(); $cells[1]->data = '<input id="submissiontype" name="submissiontype" type="hidden" value="1" />' . get_string('fileupload', 'turnitintool'); } else { if ($turnitintool->type == 2) { $optional_params->type = 2; $cells[1] = new stdClass(); $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=' . $optional_params->type . '" method="POST" name="submissionform">'; $table->rows[0] = new stdClass(); $table->rows[0]->class = 'r0'; $table->rows[0]->cells = $cells; $context = turnitintool_get_context('MODULE', $cm->id); if ($optional_params->type != 0) { $submissiontitle = optional_param('submissiontitle', '', PARAM_CLEAN); $disableform = false; if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) { $utype = "tutor"; // If tutor submitting on behalf of student unset($cells); $cells[0] = new stdClass(); $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] = new stdClass(); $cells[1]->data = '<select name="userid" id="userid" onchange="updateSubForm(submissionArray,stringsArray,this.form,' . $turnitintool->reportgenspeed . ')">'; $module_group = turnitintool_module_group($cm); $studentusers = array_keys(get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', $module_group, '', false)); foreach ($cansubmit as $courseuser) { // Filter Guest users, admins and grader users if (in_array($courseuser->id, $studentusers)) { if (!is_null($optional_params->userid) and $optional_params->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] = new stdClass(); $cells[1]->data = '<i>' . get_string('noenrolledstudents', 'turnitintool') . '</i>'; } $table->rows[1] = new stdClass(); $table->rows[1]->class = 'r1'; $table->rows[1]->cells = $cells; } else { $utype = "student"; // If student submitting unset($cells); $cells[0] = new stdClass(); $cells[0]->class = 'cell c0'; $cells[0]->data = ''; $cells[1] = new stdClass(); $cells[1]->data = '<input id="userid" name="userid" type="hidden" value="' . $USER->id . '" />'; $table->rows[1] = new stdClass(); $table->rows[1]->class = 'r1'; $table->rows[1]->cells = $cells; } if (!$disableform) { unset($cells); $cells[0] = new stdClass(); $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] = new stdClass(); $cells[1]->data = '<input type="text" name="submissiontitle" class="formwide" maxlength="200" value="' . $submissiontitle . '" /> <span id="submissionnotice"></span>'; $table->rows[2] = new stdClass(); $table->rows[2]->class = 'r0'; $table->rows[2]->cells = $cells; if (count($parts) > 1) { unset($cells); $cells[0] = new stdClass(); $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] = new stdClass(); $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] = new stdClass(); $table->rows[3]->class = 'r1'; $table->rows[3]->cells = $cells; } else { unset($cells); $cells[0] = new stdClass(); $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] = new stdClass(); $cells[1]->data = $part->partname . '<input type="hidden" name="submissionpart" value="' . $part->id . '" />'; break; } $table->rows[3] = new stdClass(); $table->rows[3]->class = 'r1'; $table->rows[3]->cells = $cells; } if ($optional_params->type == 1) { unset($cells); $cells[0] = new stdClass(); $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] = new stdClass(); $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] = new stdClass(); $table->rows[4]->class = 'r0'; $table->rows[4]->cells = $cells; } if ($optional_params->type == 2) { unset($cells); $submissiontext = optional_param('submissiontext', '', PARAM_CLEAN); $cells[0] = new stdClass(); $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] = new stdClass(); $cells[1]->data = '<textarea name="submissiontext" class="submissionText">' . $submissiontext . '</textarea>'; $table->rows[5] = new stdClass(); $table->rows[5]->class = 'r1'; $table->rows[5]->cells = $cells; } if ($optional_params->type == 3) { unset($cells); $submissionurl = optional_param('submissionurl', '', PARAM_CLEAN); $cells[0] = new stdClass(); $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] = new stdClass(); $cells[1]->data = '<input type="text" name="submissionurl" class="formwide" value="' . $submissionurl . '" />'; $table->rows[6] = new stdClass(); $table->rows[6]->class = 'r0'; $table->rows[6]->cells = $cells; } $checked = ''; if (!is_null($optional_params->agreement)) { $checked = ' checked'; } if (has_capability('mod/turnitintool:grade', $context) or empty($CFG->turnitin_agreement)) { unset($cells); $cells[0] = new stdClass(); $cells[0]->class = 'cell c0'; $cells[0]->data = ''; $cells[1] = new stdClass(); $cells[1]->data = '<input type="hidden" name="agreement" value="1" />'; $table->rows[7] = new stdClass(); $table->rows[7]->class = 'r1'; $table->rows[7]->cells = $cells; } else { unset($cells); $cells[0] = new stdClass(); $cells[0]->class = 'cell c0'; $cells[0]->data = '<input type="checkbox" name="agreement" value="1"' . $checked . ' />'; $cells[1] = new stdClass(); $cells[1]->data = $CFG->turnitin_agreement; $table->rows[7] = new stdClass(); $table->rows[7]->class = 'r1'; $table->rows[7]->cells = $cells; } unset($cells); $cells[0] = new stdClass(); $cells[0]->class = 'cell c0'; $cells[0]->data = ' '; $cells[1] = new stdClass(); $cells[1]->data = '<input name="submitbutton" type="submit" value="' . get_string('addsubmission', 'turnitintool') . '" />'; $table->rows[8] = new stdClass(); $table->rows[8]->class = 'r0'; $table->rows[8]->cells = $cells; } } $output .= turnitintool_print_table($table, true); if ($optional_params->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 />'; return $output; }
public function definition() { global $CFG, $USER, $COURSE, $cm, $turnitintool; $cm = $this->_customdata['cm']; $turnitintool = $this->_customdata['turnitintool']; $optional_params = $this->_customdata['optional_params']; $cansubmit = $this->_customdata['cansubmit']; if (has_capability('mod/turnitintool:grade', turnitintool_get_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_js = '<script language="javascript" type="text/javascript">' . PHP_EOL; $output_js .= '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_js .= '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() . "'", null, 'dtstart,dtdue,dtpost,id'); } else { $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "' AND dtdue > '" . time() . "'", NULL, '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_js .= 'submissionArray[' . $i . '] = new Array("' . $submission->userid . '","' . $submission->submission_part . '","' . $submission->submission_title . '","' . $submission->submission_unanon . '",' . $lockresubmission . ');' . PHP_EOL; $submittedparts[] = $submission->submission_part; $i++; } } $output_js .= '</script>' . PHP_EOL; echo $output_js; $mform = $this->_form; // Display file upload error if need be. if (isset($_SESSION["notice"]["type"]) and $_SESSION["notice"]["type"] == "error") { $mform->addElement('html', '<div id="upload_error" class="felement ftext error"><span id="upload_error_text" class="error">' . $_SESSION["notice"]["message"] . '</span></div>'); unset($_SESSION["notice"]["type"]); unset($_SESSION["notice"]["message"]); } if (!empty($parts)) { // Upload type. switch ($turnitintool->type) { case 0: $options = array("1" => "File Upload", "2" => "Text Submission"); $mform->addElement('select', 'submissiontype', get_string('selectoption', 'turnitintool'), $options, array("class" => "formnarrow")); $mform->addHelpButton('submissiontype', 'submissiontype', 'turnitintool'); break; case 1: case 2: $mform->addElement('hidden', 'submissiontype', $turnitintool->type); $mform->setType('submissiontype', PARAM_INT); } $istutor = turnitintool_istutor($USER->email); $userid = $USER->id; // User id if applicable. if ($istutor) { $mform->addElement('hidden', 'studentsname', $USER->id); $mform->setType('studentsname', PARAM_INT); } $context = turnitintool_get_context('MODULE', $cm->id); $submissiontitle = optional_param('submissiontitle', '', PARAM_CLEAN); $disableform = false; if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) { $utype = "tutor"; // If tutor submitting on behalf of student if (count($cansubmit) > 0) { $module_group = turnitintool_module_group($cm); $studentusers = array_keys(get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', $module_group, '', false)); // Append course users. $courseusers = array(); $selected = ""; foreach ($cansubmit as $courseuser) { // Filter Guest users, admins and grader users if (in_array($courseuser->id, $studentusers)) { if (!is_null($optional_params->userid) and $optional_params->userid == $courseuser->id) { $selected = $courseuser->id; } $courseusers[$courseuser->id] = $courseuser->lastname . ', ' . $courseuser->firstname; } } $select = $mform->addElement('select', 'userid', get_string('studentsname', 'turnitintool'), $courseusers, array("class" => "formnarrow", "onchange" => "updateSubForm(submissionArray,stringsArray,this.form," . $turnitintool->reportgenspeed . ")")); $mform->addHelpButton('userid', 'studentsname', 'turnitintool'); if ($selected != "") { $select->setSelected($selected); } if (empty($courseusers)) { $mform->addElement('static', 'allsubmissionsmade', get_string('allsubmissionsmade', 'turnitintool')); } } else { $mform->addElement('static', 'noenrolledstudents', get_string('noenrolledstudents', 'turnitintool')); } } else { // If student submitting $utype = "student"; $mform->addElement('hidden', 'userid', $USER->id); $mform->setType('userid', PARAM_INT); } if (!$disableform) { // Submission Title. $mform->addElement('text', 'submissiontitle', get_string('submissiontitle', 'turnitintool'), array("class" => "formwide")); $mform->setType('submissiontitle', PARAM_TEXT); $mform->addHelpButton('submissiontitle', 'submissiontitle', 'turnitintool'); $mform->addRule('submissiontitle', get_string('submissiontitleerror', 'turnitintool'), 'required', '', 'client'); // Handle assignment parts. if (count($parts) > 1) { foreach ($parts as $part) { $options_parts[$part->id] = $part->partname; } $mform->addElement('select', 'submissionpart', get_string('submissionpart', 'turnitintool'), $options_parts, array("class" => "formnarrow", "onchange" => "updateSubForm(submissionArray,stringsArray,this.form," . $turnitintool->reportgenspeed . ",'" . $utype . "')")); $mform->addHelpButton('submissionpart', 'submissionpart', 'turnitintool'); } else { foreach ($parts as $part) { $mform->addElement('hidden', 'submissionpart', $part->id); $mform->setType('submissionpart', PARAM_INT); break; } } // File input. $maxbytessite = $CFG->maxbytes == 0 || $CFG->maxbytes > TURNITINTOOL_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $CFG->maxbytes; $maxbytescourse = $COURSE->maxbytes == 0 || $COURSE->maxbytes > TURNITINTOOL_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $COURSE->maxbytes; $maxfilesize = get_user_max_upload_file_size(context_module::instance($cm->id), $maxbytessite, $maxbytescourse, $turnitintool->maxfilesize); $maxfilesize = $maxfilesize <= 0 ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $maxfilesize; $turnitintoolfileuploadoptions = array('maxbytes' => $maxfilesize, 'subdirs' => false, 'maxfiles' => 1, 'accepted_types' => array('.doc', '.docx', '.rtf', '.txt', '.pdf', '.htm', '.html', '.odt', '.eps', '.ps', '.wpd', '.hwp', '.ppt', '.pptx', '.ppsx', '.pps')); $mform->addElement('filemanager', 'submissionfile', get_string('filetosubmit', 'turnitintool'), null, $turnitintoolfileuploadoptions); $mform->addHelpButton('submissionfile', 'filetosubmit', 'turnitintool'); // Text input input. $mform->addElement('textarea', 'submissiontext', get_string('texttosubmit', 'turnitintool'), array("class" => "submissionText")); $mform->addHelpButton('submissiontext', 'texttosubmit', 'turnitintool'); $checked = ''; if (!is_null($optional_params->agreement)) { $checked = ' checked'; } if (has_capability('mod/turnitintool:grade', $context) or empty($CFG->turnitin_agreement)) { $mform->addElement('hidden', 'agreement', '1'); $mform->setType('agreement', PARAM_INT); } else { $mform->addElement('checkbox', 'agreement', '', $CFG->turnitin_agreement); $mform->setDefault('agreement', '1', true); } $mform->addElement('submit', 'submitbutton', get_string('addsubmission', 'turnitintool')); } } }