MDL-36266 Improve update notification message subject
[moodle.git] / mod / workshop / submission_form.php
blob3e9f889b26e874c23bb64fb81010579f227c9033
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * Submit an assignment or edit the already submitted work
21 * @package mod
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->dirroot . '/lib/formslib.php');
31 class workshop_submission_form extends moodleform {
33 function definition() {
34 $mform = $this->_form;
36 $current = $this->_customdata['current'];
37 $workshop = $this->_customdata['workshop'];
38 $contentopts = $this->_customdata['contentopts'];
39 $attachmentopts = $this->_customdata['attachmentopts'];
41 $mform->addElement('header', 'general', get_string('submission', 'workshop'));
43 $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop'));
44 $mform->setType('title', PARAM_TEXT);
45 $mform->addRule('title', null, 'required', null, 'client');
47 $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts);
48 $mform->setType('content', PARAM_RAW);
50 if ($workshop->nattachments > 0) {
51 $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments);
52 $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'),
53 null, $attachmentopts);
56 $mform->addElement('hidden', 'id', $current->id);
57 $mform->setType('id', PARAM_INT);
59 $mform->addElement('hidden', 'cmid', $workshop->cm->id);
60 $mform->setType('cmid', PARAM_INT);
62 $mform->addElement('hidden', 'edit', 1);
63 $mform->setType('edit', PARAM_INT);
65 $mform->addElement('hidden', 'example', 0);
66 $mform->setType('hidden', PARAM_INT);
68 $this->add_action_buttons();
70 $this->set_data($current);
73 function validation($data, $files) {
74 global $CFG, $USER, $DB;
76 $errors = parent::validation($data, $files);
78 if (empty($data['id']) and empty($data['example'])) {
79 // make sure there is no submission saved meanwhile from another browser window
80 $sql = "SELECT COUNT(s.id)
81 FROM {workshop_submissions} s
82 JOIN {workshop} w ON (s.workshopid = w.id)
83 JOIN {course_modules} cm ON (w.id = cm.instance)
84 JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
85 WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
87 if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
88 $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
92 return $errors;