|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/lib/formslib.php'); 00030 00031 class workshop_submission_form extends moodleform { 00032 00033 function definition() { 00034 $mform = $this->_form; 00035 00036 $current = $this->_customdata['current']; 00037 $workshop = $this->_customdata['workshop']; 00038 $contentopts = $this->_customdata['contentopts']; 00039 $attachmentopts = $this->_customdata['attachmentopts']; 00040 00041 $mform->addElement('header', 'general', get_string('submission', 'workshop')); 00042 00043 $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop')); 00044 $mform->setType('title', PARAM_TEXT); 00045 $mform->addRule('title', null, 'required', null, 'client'); 00046 00047 $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts); 00048 $mform->setType('content', PARAM_RAW); 00049 00050 if ($workshop->nattachments > 0) { 00051 $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments); 00052 $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'), 00053 null, $attachmentopts); 00054 } 00055 00056 $mform->addElement('hidden', 'id', $current->id); 00057 $mform->setType('id', PARAM_INT); 00058 00059 $mform->addElement('hidden', 'cmid', $workshop->cm->id); 00060 $mform->setType('cmid', PARAM_INT); 00061 00062 $mform->addElement('hidden', 'edit', 1); 00063 $mform->setType('edit', PARAM_INT); 00064 00065 $mform->addElement('hidden', 'example', 0); 00066 $mform->setType('hidden', PARAM_INT); 00067 00068 $this->add_action_buttons(); 00069 00070 $this->set_data($current); 00071 } 00072 00073 function validation($data, $files) { 00074 global $CFG, $USER, $DB; 00075 00076 $errors = parent::validation($data, $files); 00077 00078 if (empty($data['id']) and empty($data['example'])) { 00079 // make sure there is no submission saved meanwhile from another browser window 00080 $sql = "SELECT COUNT(s.id) 00081 FROM {workshop_submissions} s 00082 JOIN {workshop} w ON (s.workshopid = w.id) 00083 JOIN {course_modules} cm ON (w.id = cm.instance) 00084 JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module) 00085 WHERE cm.id = ? AND s.authorid = ? AND s.example = 0"; 00086 00087 if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) { 00088 $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop'); 00089 } 00090 } 00091 00092 return $errors; 00093 } 00094 }