[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 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. 14 // 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 18 /** 19 * Submit an assignment or edit the already submitted work 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 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->dirroot . '/lib/formslib.php'); 29 30 class workshop_submission_form extends moodleform { 31 32 function definition() { 33 $mform = $this->_form; 34 35 $current = $this->_customdata['current']; 36 $workshop = $this->_customdata['workshop']; 37 $contentopts = $this->_customdata['contentopts']; 38 $attachmentopts = $this->_customdata['attachmentopts']; 39 40 $mform->addElement('header', 'general', get_string('submission', 'workshop')); 41 42 $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop')); 43 $mform->setType('title', PARAM_TEXT); 44 $mform->addRule('title', null, 'required', null, 'client'); 45 46 $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts); 47 $mform->setType('content', PARAM_RAW); 48 49 if ($workshop->nattachments > 0) { 50 $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments); 51 $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'), 52 null, $attachmentopts); 53 } 54 55 $mform->addElement('hidden', 'id', $current->id); 56 $mform->setType('id', PARAM_INT); 57 58 $mform->addElement('hidden', 'cmid', $workshop->cm->id); 59 $mform->setType('cmid', PARAM_INT); 60 61 $mform->addElement('hidden', 'edit', 1); 62 $mform->setType('edit', PARAM_INT); 63 64 $mform->addElement('hidden', 'example', 0); 65 $mform->setType('example', PARAM_INT); 66 67 $this->add_action_buttons(); 68 69 $this->set_data($current); 70 } 71 72 function validation($data, $files) { 73 global $CFG, $USER, $DB; 74 75 $errors = parent::validation($data, $files); 76 77 if (empty($data['id']) and empty($data['example'])) { 78 // make sure there is no submission saved meanwhile from another browser window 79 $sql = "SELECT COUNT(s.id) 80 FROM {workshop_submissions} s 81 JOIN {workshop} w ON (s.workshopid = w.id) 82 JOIN {course_modules} cm ON (w.id = cm.instance) 83 JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module) 84 WHERE cm.id = ? AND s.authorid = ? AND s.example = 0"; 85 86 if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) { 87 $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop'); 88 } 89 } 90 91 if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) { 92 $whitelist = workshop::normalize_file_extensions($this->_customdata['workshop']->submissionfiletypes); 93 if ($whitelist) { 94 $draftfiles = file_get_drafarea_files($data['attachment_filemanager']); 95 if ($draftfiles) { 96 $wrongfiles = array(); 97 foreach ($draftfiles->list as $file) { 98 if (!workshop::is_allowed_file_type($file->filename, $whitelist)) { 99 $wrongfiles[] = $file->filename; 100 } 101 } 102 if ($wrongfiles) { 103 $a = array( 104 'whitelist' => workshop::clean_file_extensions($whitelist), 105 'wrongfiles' => implode(', ', $wrongfiles), 106 ); 107 $errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a); 108 } 109 } 110 } 111 } 112 113 return $errors; 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |