3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * IMS CP configuration form
23 * @copyright 2009 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
29 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
30 require_once($CFG->libdir
.'/filelib.php');
32 class mod_imscp_mod_form
extends moodleform_mod
{
33 function definition() {
35 $mform = $this->_form
;
37 $config = get_config('imscp');
39 //-------------------------------------------------------
40 $mform->addElement('header', 'general', get_string('general', 'form'));
41 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
42 if (!empty($CFG->formatstringstriptags
)) {
43 $mform->setType('name', PARAM_TEXT
);
45 $mform->setType('name', PARAM_CLEANHTML
);
47 $mform->addRule('name', null, 'required', null, 'client');
48 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
49 $this->add_intro_editor($config->requiremodintro
);
51 //-------------------------------------------------------
52 $mform->addElement('header', 'content', get_string('contentheader', 'imscp'));
53 $mform->setExpanded('content', true);
54 $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp'));
56 $options = array('-1'=>get_string('all'), '0'=>get_string('no'), '1'=>'1', '2'=>'2', '5'=>'5', '10'=>'10', '20'=>'20');
57 $mform->addElement('select', 'keepold', get_string('keepold', 'imscp'), $options);
58 $mform->setDefault('keepold', $config->keepold
);
59 $mform->setAdvanced('keepold', $config->keepold_adv
);
61 //-------------------------------------------------------
62 $this->standard_coursemodule_elements();
64 //-------------------------------------------------------
65 $this->add_action_buttons();
68 function validation($data, $files) {
71 if ($errors = parent
::validation($data, $files)) {
75 $usercontext = context_user
::instance($USER->id
);
76 $fs = get_file_storage();
78 if (!$files = $fs->get_area_files($usercontext->id
, 'user', 'draft', $data['package'], 'id', false)) {
79 if (!$this->current
->instance
) {
80 $errors['package'] = get_string('required');
84 $file = reset($files);
85 if ($file->get_mimetype() != 'application/zip') {
86 $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
87 // better delete current file, it is not usable anyway
88 $fs->delete_area_files($usercontext->id
, 'user', 'draft', $data['package']);