Commit | Line | Data |
---|---|---|
33e4dea6 DM |
1 | <?php |
2 | ||
53fad4b9 DM |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
33e4dea6 DM |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
53fad4b9 | 14 | // |
33e4dea6 DM |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
33e4dea6 | 18 | /** |
51508f25 | 19 | * View a single (usually the own) submission, submit own work. |
33e4dea6 DM |
20 | * |
21 | * @package mod-workshop | |
22 | * @copyright 2009 David Mudrak <david.mudrak@gmail.com> | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); | |
27 | require_once(dirname(__FILE__).'/lib.php'); | |
127032fe | 28 | require_once(dirname(__FILE__).'/locallib.php'); |
33e4dea6 DM |
29 | require_once(dirname(__FILE__).'/submission_form.php'); |
30 | ||
c1e883bb DM |
31 | $cmid = required_param('cmid', PARAM_INT); // course module id |
32 | $id = optional_param('id', 0, PARAM_INT); // submission id | |
33 | $edit = optional_param('edit', false, PARAM_BOOL); // open for editing? | |
33e4dea6 | 34 | |
c1e883bb DM |
35 | $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST); |
36 | $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); | |
33e4dea6 DM |
37 | |
38 | require_login($course, false, $cm); | |
33e4dea6 | 39 | if (isguestuser()) { |
b8ead2e6 | 40 | print_error('guestsarenotallowed'); |
33e4dea6 DM |
41 | } |
42 | ||
51508f25 DM |
43 | $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST); |
44 | $workshop = new workshop($workshop, $cm, $course); | |
45 | ||
46 | $PAGE->set_url(new moodle_url($workshop->submission_url(), array('cmid' => $cmid, 'id' => $id, 'edit' => $edit))); | |
33e4dea6 | 47 | |
127032fe | 48 | if ($id) { // submission is specified |
51508f25 | 49 | $submission = $workshop->get_submission_by_id($id); |
127032fe | 50 | } else { // no submission specified |
0dc47fb9 | 51 | if (!$submission = $workshop->get_submission_by_author($USER->id)) { |
65ba104c | 52 | $submission = new stdClass(); |
127032fe | 53 | $submission->id = null; |
00aca3c1 | 54 | $submission->authorid = $USER->id; |
53fad4b9 | 55 | } |
33e4dea6 | 56 | } |
c1e883bb | 57 | |
00aca3c1 | 58 | $ownsubmission = $submission->authorid == $USER->id; |
51508f25 DM |
59 | $canviewall = has_capability('mod/workshop:viewallsubmissions', $PAGE->context); |
60 | $cansubmit = has_capability('mod/workshop:submit', $PAGE->context); | |
00aca3c1 | 61 | $isreviewer = $DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'reviewerid' => $USER->id)); |
51508f25 | 62 | |
3dc78e5b DM |
63 | if ($submission->id and ($ownsubmission or $canviewall or $isreviewer)) { |
64 | // ok you can go | |
65 | } elseif (is_null($submission->id) and $cansubmit) { | |
66 | // ok you can go | |
67 | } else { | |
51508f25 | 68 | print_error('nopermissions'); |
c1e883bb DM |
69 | } |
70 | ||
71 | $maxfiles = $workshop->nattachments; | |
72 | $maxbytes = $workshop->maxbytes; | |
73 | $contentopts = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes); | |
75ff50df | 74 | $attachmentopts = array('subdirs' => true, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes); |
c1e883bb DM |
75 | $submission = file_prepare_standard_editor($submission, 'content', $contentopts, $PAGE->context, |
76 | 'workshop_submission_content', $submission->id); | |
77 | $submission = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $PAGE->context, | |
78 | 'workshop_submission_attachment', $submission->id); | |
79 | $mform = new workshop_submission_form(null, array('current' => $submission, 'cm' => $cm, 'workshop' => $workshop, | |
80 | 'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts)); | |
33e4dea6 | 81 | |
6e309973 | 82 | if ($mform->is_cancelled()) { |
c1e883bb DM |
83 | redirect($workshop->view_url()); |
84 | ||
51508f25 | 85 | } elseif ($cansubmit and $formdata = $mform->get_data()) { |
33e4dea6 | 86 | $timenow = time(); |
c1e883bb DM |
87 | if (empty($formdata->id)) { |
88 | $formdata->workshopid = $workshop->id; | |
89 | $formdata->example = 0; // todo add examples support | |
00aca3c1 | 90 | $formdata->authorid = $USER->id; |
c1e883bb | 91 | $formdata->timecreated = $timenow; |
33e4dea6 | 92 | } |
c1e883bb DM |
93 | $formdata->timemodified = $timenow; |
94 | $formdata->title = trim($formdata->title); | |
95 | $formdata->content = ''; // updated later | |
96 | $formdata->contentformat = FORMAT_HTML; // updated later | |
97 | $formdata->contenttrust = 0; // updated later | |
98 | if (empty($formdata->id)) { | |
99 | $formdata->id = $DB->insert_record('workshop_submissions', $formdata); | |
33e4dea6 | 100 | // todo add to log |
33e4dea6 | 101 | } |
33e4dea6 | 102 | // save and relink embedded images and save attachments |
c1e883bb DM |
103 | $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $PAGE->context, |
104 | 'workshop_submission_content', $formdata->id); | |
105 | $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $PAGE->context, | |
106 | 'workshop_submission_attachment', $formdata->id); | |
107 | // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten) | |
108 | $DB->update_record('workshop_submissions', $formdata); | |
109 | redirect($workshop->view_url()); | |
33e4dea6 DM |
110 | } |
111 | ||
0dc47fb9 DM |
112 | $PAGE->set_title($workshop->name); |
113 | $PAGE->set_heading($course->fullname); | |
39861053 | 114 | if ($edit) { |
b761e6d9 | 115 | $PAGE->navbar->add(get_string('mysubmission', 'workshop'), $workshop->submission_url(), navigation_node::TYPE_CUSTOM); |
39861053 | 116 | $PAGE->navbar->add(get_string('editingsubmission', 'workshop')); |
51508f25 | 117 | } elseif ($ownsubmission) { |
b761e6d9 | 118 | $PAGE->navbar->add(get_string('mysubmission', 'workshop')); |
51508f25 DM |
119 | } else { |
120 | $PAGE->navbar->add(get_string('submission', 'workshop')); | |
39861053 | 121 | } |
33e4dea6 | 122 | |
c1e883bb | 123 | // Output starts here |
39861053 | 124 | echo $OUTPUT->header(); |
51508f25 DM |
125 | $currenttab = 'submission'; |
126 | include(dirname(__FILE__) . '/tabs.php'); | |
0dc47fb9 | 127 | echo $OUTPUT->heading(format_string($workshop->name), 2); |
c1e883bb | 128 | |
3dc78e5b DM |
129 | // if in edit mode, display the form to edit the submission |
130 | ||
51508f25 | 131 | if ($edit and $ownsubmission) { |
c1e883bb DM |
132 | $mform->display(); |
133 | echo $OUTPUT->footer(); | |
134 | die(); | |
135 | } | |
136 | ||
3dc78e5b DM |
137 | // else display the submission |
138 | ||
139 | if ($submission->id) { | |
c1e883bb | 140 | $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); |
e9b0f0ab | 141 | echo $wsoutput->submission_full($submission, true); |
3dc78e5b DM |
142 | } else { |
143 | echo $OUTPUT->box(get_string('noyoursubmission', 'workshop')); | |
c1e883bb DM |
144 | } |
145 | ||
51508f25 | 146 | if ($ownsubmission and $workshop->submitting_allowed()) { |
c1e883bb DM |
147 | $editbutton = new html_form(); |
148 | $editbutton->method = 'get'; | |
149 | $editbutton->button->text = get_string('editsubmission', 'workshop'); | |
150 | $editbutton->url = new moodle_url($PAGE->url, array('edit' => 'on', 'id' => $submission->id)); | |
151 | echo $OUTPUT->button($editbutton); | |
152 | } | |
153 | ||
3dc78e5b DM |
154 | // and possibly display the submission's review(s) |
155 | ||
156 | $canviewallassessments = false; | |
157 | if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { | |
158 | $canviewallassessments = true; | |
159 | } elseif ($ownsubmission and $workshop->assessments_available()) { | |
160 | $canviewallassessments = true; | |
161 | } else { | |
162 | $canviewallassessments = false; | |
163 | } | |
164 | ||
165 | $canviewgrades = false; | |
166 | if ($isreviewer) { | |
167 | $canviewgrades = true; // reviewers can always see the grades they gave even they are not available yet | |
168 | } elseif ($ownsubmission or $canviewallassessments) { | |
169 | $canviewgrades = $workshop->grades_available(); // bool|null, see the function phpdoc | |
3dc78e5b DM |
170 | } |
171 | ||
172 | if ($isreviewer) { | |
407b1e91 | 173 | // display own assessment - todo |
3dc78e5b DM |
174 | $strategy = $workshop->grading_strategy_instance(); |
175 | } | |
176 | ||
177 | if ($canviewallassessments) { | |
407b1e91 | 178 | // display all assessments (except the eventual own one - that has been already displayed) - todo |
3dc78e5b DM |
179 | $strategy = $workshop->grading_strategy_instance(); |
180 | } | |
181 | ||
0dc47fb9 | 182 | echo $OUTPUT->footer(); |