assignment MDL-23683 online assignment filearea changed for consistency from 'online_...
[moodle.git] / mod / assignment / type / online / file.php
CommitLineData
81625028 1<?php
f77cfb73 2
81625028 3require("../../../../config.php");
4require("../../lib.php");
5require("assignment.class.php");
f77cfb73 6
81625028 7$id = required_param('id', PARAM_INT); // Course Module ID
8$userid = required_param('userid', PARAM_INT); // User ID
f77cfb73 9
a6855934 10$PAGE->set_url('/mod/assignment/type/online/file.php', array('id'=>$id, 'userid'=>$userid));
f77cfb73 11
81625028 12if (! $cm = get_coursemodule_from_id('assignment', $id)) {
13 print_error('invalidcoursemodule');
14}
f77cfb73 15
81625028 16if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
17 print_error('invalidid', 'assignment');
18}
f77cfb73 19
81625028 20if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
21 print_error('coursemisconf', 'assignment');
22}
f77cfb73 23
81625028 24if (! $user = $DB->get_record("user", array("id"=>$userid))) {
25 print_error('usermisconf', 'assignment');
26}
f0a99707 27
81625028 28require_login($course->id, false, $cm);
f77cfb73 29
c561f44c
SH
30$context = get_context_instance(CONTEXT_MODULE, $cm->id);
31if (($USER->id != $user->id) && !has_capability('mod/assignment:grade', $context)) {
81625028 32 print_error('cannotviewassignment', 'assignment');
33}
f77cfb73 34
81625028 35if ($assignment->assignmenttype != 'online') {
36 print_error('invalidtype', 'assignment');
37}
3e7bf58a 38
81625028 39$assignmentinstance = new assignment_online($cm->id, $assignment, $cm, $course);
40
41if ($submission = $assignmentinstance->get_submission($user->id)) {
78946b9b 42 $PAGE->set_pagelayout('popup');
81625028 43 $PAGE->set_title(fullname($user,true).': '.$assignment->name);
44 echo $OUTPUT->header();
45 echo $OUTPUT->box_start('generalbox boxaligcenter', 'dates');
46 echo '<table>';
47 if ($assignment->timedue) {
48 echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
49 echo ' <td class="c1">'.userdate($assignment->timedue).'</td></tr>';
f77cfb73 50 }
81625028 51 echo '<tr><td class="c0">'.get_string('lastedited').':</td>';
52 echo ' <td class="c1">'.userdate($submission->timemodified);
53 /// Decide what to count
54 if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
55 echo ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')</td></tr>';
56 } else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
57 echo ' ('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')</td></tr>';
58 }
59 echo '</table>';
60 echo $OUTPUT->box_end();
f77cfb73 61
6aac01ca 62 $text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $context->id, 'mod_assignment', $assignmentinstance->filearea, $submission->id);
c561f44c 63 echo $OUTPUT->box(format_text($text, $submission->data2), 'generalbox boxaligncenter boxwidthwide');
81625028 64 echo $OUTPUT->close_window_button();
65 echo $OUTPUT->footer();
66} else {
67 print_string('emptysubmission', 'assignment');
68}