Merge branch 'MDL-46477_m26' of https://github.com/shashirepo/moodle into MOODLE_26_S...
[moodle.git] / mod / imscp / mod_form.php
blob06eeccc77929e44a69f7e0d4a11098dba8bd3d6a
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 * IMS CP configuration form
21 * @package mod
22 * @subpackage imscp
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() {
34 global $CFG, $DB;
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);
44 } else {
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) {
69 global $USER;
71 if ($errors = parent::validation($data, $files)) {
72 return $errors;
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');
81 return $errors;
83 } else {
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']);
92 return $errors;