2010-01-04 17:38:29 +00:00
|
|
|
<?php
|
|
|
|
|
2010-01-04 17:47:09 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
2010-01-04 17:38:29 +00:00
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2010-01-04 17:47:09 +00:00
|
|
|
//
|
2010-01-04 17:38:29 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
2010-01-04 17:50:03 +00:00
|
|
|
* Submit own assignment or edit the already submitted own work
|
2010-01-04 17:38:29 +00:00
|
|
|
*
|
|
|
|
* @package mod-workshop
|
|
|
|
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
|
|
|
|
require_once(dirname(__FILE__).'/lib.php');
|
2010-01-04 17:42:37 +00:00
|
|
|
require_once(dirname(__FILE__).'/locallib.php');
|
2010-01-04 17:38:29 +00:00
|
|
|
require_once(dirname(__FILE__).'/submission_form.php');
|
|
|
|
|
2010-01-04 17:50:03 +00:00
|
|
|
$cmid = required_param('cmid', PARAM_INT); // course module id
|
|
|
|
$id = optional_param('id', 0, PARAM_INT); // submission id
|
|
|
|
$edit = optional_param('edit', false, PARAM_BOOL); // open for editing?
|
2010-01-04 17:38:29 +00:00
|
|
|
|
2010-01-04 17:50:03 +00:00
|
|
|
$cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
|
|
|
|
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
2010-01-04 17:38:29 +00:00
|
|
|
|
|
|
|
require_login($course, false, $cm);
|
2010-01-04 17:48:33 +00:00
|
|
|
require_capability('mod/workshop:submit', $PAGE->context);
|
2010-01-04 17:38:29 +00:00
|
|
|
if (isguestuser()) {
|
2010-01-04 17:48:33 +00:00
|
|
|
print_error('guestsarenotallowed');
|
2010-01-04 17:38:29 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:20 +00:00
|
|
|
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
|
2010-01-04 17:49:01 +00:00
|
|
|
$workshop = new workshop($workshop, $cm, $course);
|
2010-01-04 17:38:29 +00:00
|
|
|
|
2010-01-04 17:42:37 +00:00
|
|
|
if ($id) { // submission is specified
|
2010-01-04 17:48:20 +00:00
|
|
|
$submission = $DB->get_record('workshop_submissions', array('id' => $id, 'workshopid' => $workshop->id), '*', MUST_EXIST);
|
2010-01-04 17:42:37 +00:00
|
|
|
} else { // no submission specified
|
2010-01-04 17:48:20 +00:00
|
|
|
if (!$submission = $workshop->get_submission_by_author($USER->id)) {
|
2010-01-04 17:55:02 +00:00
|
|
|
$submission = new stdClass();
|
2010-01-04 17:42:37 +00:00
|
|
|
$submission->id = null;
|
2010-01-04 17:50:03 +00:00
|
|
|
$submission->userid = $USER->id;
|
2010-01-04 17:47:09 +00:00
|
|
|
}
|
2010-01-04 17:38:29 +00:00
|
|
|
}
|
2010-01-04 17:50:03 +00:00
|
|
|
|
|
|
|
if ($submission->userid !== $USER->id) {
|
|
|
|
print_error('nopermissiontoviewpage', 'error', $workshop->view_url());
|
|
|
|
}
|
|
|
|
|
|
|
|
$maxfiles = $workshop->nattachments;
|
|
|
|
$maxbytes = $workshop->maxbytes;
|
|
|
|
$contentopts = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
|
|
|
|
$attachmentopts = array('subdirs' => false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
|
|
|
|
$submission = file_prepare_standard_editor($submission, 'content', $contentopts, $PAGE->context,
|
|
|
|
'workshop_submission_content', $submission->id);
|
|
|
|
$submission = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $PAGE->context,
|
|
|
|
'workshop_submission_attachment', $submission->id);
|
|
|
|
$mform = new workshop_submission_form(null, array('current' => $submission, 'cm' => $cm, 'workshop' => $workshop,
|
|
|
|
'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts));
|
2010-01-04 17:38:29 +00:00
|
|
|
|
2010-01-04 17:46:05 +00:00
|
|
|
if ($mform->is_cancelled()) {
|
2010-01-04 17:50:03 +00:00
|
|
|
redirect($workshop->view_url());
|
|
|
|
|
|
|
|
} elseif ($formdata = $mform->get_data()) {
|
2010-01-04 17:38:29 +00:00
|
|
|
$timenow = time();
|
2010-01-04 17:50:03 +00:00
|
|
|
if (empty($formdata->id)) {
|
|
|
|
$formdata->workshopid = $workshop->id;
|
|
|
|
$formdata->example = 0; // todo add examples support
|
|
|
|
$formdata->userid = $USER->id;
|
|
|
|
$formdata->timecreated = $timenow;
|
2010-01-04 17:38:29 +00:00
|
|
|
}
|
2010-01-04 17:50:03 +00:00
|
|
|
$formdata->timemodified = $timenow;
|
|
|
|
$formdata->title = trim($formdata->title);
|
|
|
|
$formdata->content = ''; // updated later
|
|
|
|
$formdata->contentformat = FORMAT_HTML; // updated later
|
|
|
|
$formdata->contenttrust = 0; // updated later
|
|
|
|
if (empty($formdata->id)) {
|
|
|
|
$formdata->id = $DB->insert_record('workshop_submissions', $formdata);
|
2010-01-04 17:38:29 +00:00
|
|
|
// todo add to log
|
|
|
|
}
|
|
|
|
// save and relink embedded images and save attachments
|
2010-01-04 17:50:03 +00:00
|
|
|
$formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $PAGE->context,
|
|
|
|
'workshop_submission_content', $formdata->id);
|
|
|
|
$formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $PAGE->context,
|
|
|
|
'workshop_submission_attachment', $formdata->id);
|
|
|
|
// store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
|
|
|
|
$DB->update_record('workshop_submissions', $formdata);
|
|
|
|
redirect($workshop->view_url());
|
2010-01-04 17:38:29 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:20 +00:00
|
|
|
$PAGE->set_url('mod/workshop/submission.php', array('cmid' => $cm->id));
|
|
|
|
$PAGE->set_title($workshop->name);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
2010-01-04 18:00:12 +00:00
|
|
|
if ($edit) {
|
2010-01-04 18:00:54 +00:00
|
|
|
$PAGE->navbar->add(get_string('mysubmission', 'workshop'), $workshop->submission_url(), navigation_node::TYPE_CUSTOM);
|
2010-01-04 18:00:12 +00:00
|
|
|
$PAGE->navbar->add(get_string('editingsubmission', 'workshop'));
|
2010-01-04 18:00:54 +00:00
|
|
|
} else {
|
|
|
|
$PAGE->navbar->add(get_string('mysubmission', 'workshop'));
|
2010-01-04 18:00:12 +00:00
|
|
|
}
|
2010-01-04 17:38:29 +00:00
|
|
|
|
2010-01-04 17:50:03 +00:00
|
|
|
// Output starts here
|
2010-01-04 18:00:12 +00:00
|
|
|
echo $OUTPUT->header();
|
2010-01-04 17:48:20 +00:00
|
|
|
echo $OUTPUT->heading(format_string($workshop->name), 2);
|
2010-01-04 17:50:03 +00:00
|
|
|
|
|
|
|
if ($edit) {
|
|
|
|
$mform->display();
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($submission->id)) {
|
|
|
|
$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
|
2010-01-04 18:01:40 +00:00
|
|
|
echo $wsoutput->submission_full($submission, true);
|
2010-01-04 17:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($workshop->submitting_allowed()) {
|
|
|
|
$editbutton = new html_form();
|
|
|
|
$editbutton->method = 'get';
|
|
|
|
$editbutton->button->text = get_string('editsubmission', 'workshop');
|
|
|
|
$editbutton->url = new moodle_url($PAGE->url, array('edit' => 'on', 'id' => $submission->id));
|
|
|
|
echo $OUTPUT->button($editbutton);
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:20 +00:00
|
|
|
echo $OUTPUT->footer();
|