1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains the forms to create and edit an instance of this module 19 * 20 * @package mod_imscp 21 * @copyright 2009 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once($CFG->dirroot.'/course/moodleform_mod.php'); 28 require_once($CFG->libdir.'/filelib.php'); 29 30 /** 31 * IMS CP configuration form 32 * 33 * @package mod_imscp 34 * @copyright 2009 Petr Skoda {@link http://skodak.org} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_imscp_mod_form extends moodleform_mod { 38 /** 39 * Define the form - called by parent constructor 40 */ 41 public function definition() { 42 global $CFG, $DB; 43 $mform = $this->_form; 44 45 $config = get_config('imscp'); 46 47 // Title and description. 48 $mform->addElement('header', 'general', get_string('general', 'form')); 49 $mform->addElement('text', 'name', get_string('name'), array('size' => '48')); 50 if (!empty($CFG->formatstringstriptags)) { 51 $mform->setType('name', PARAM_TEXT); 52 } else { 53 $mform->setType('name', PARAM_CLEANHTML); 54 } 55 $mform->addRule('name', null, 'required', null, 'client'); 56 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 57 $this->standard_intro_elements(); 58 59 // IMS-CP file upload. 60 $mform->addElement('header', 'content', get_string('contentheader', 'imscp')); 61 $mform->setExpanded('content', true); 62 $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp')); 63 64 $options = array('-1' => get_string('all'), '0' => get_string('no'), 65 '1' => '1', '2' => '2', '5' => '5', '10' => '10', '20' => '20'); 66 $mform->addElement('select', 'keepold', get_string('keepold', 'imscp'), $options); 67 $mform->setDefault('keepold', $config->keepold); 68 $mform->setAdvanced('keepold', $config->keepold_adv); 69 70 $this->standard_coursemodule_elements(); 71 72 $this->add_action_buttons(); 73 } 74 75 /** 76 * Perform minimal validation on the settings form 77 * @param array $data 78 * @param array $files 79 */ 80 public function validation($data, $files) { 81 global $USER; 82 83 if ($errors = parent::validation($data, $files)) { 84 return $errors; 85 } 86 87 $usercontext = context_user::instance($USER->id); 88 $fs = get_file_storage(); 89 90 if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) { 91 if (!$this->current->instance) { 92 $errors['package'] = get_string('required'); 93 return $errors; 94 } 95 } else { 96 $file = reset($files); 97 if ($file->get_mimetype() != 'application/zip') { 98 $errors['package'] = get_string('invalidfiletype', 'error', '', $file); 99 // Better delete current file, it is not usable anyway. 100 $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']); 101 } 102 } 103 104 return $errors; 105 } 106 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body