MDL-44745 Assign: Make the grading table use the fullname function from the assign...
[moodle.git] / mod / imscp / mod_form.php
blob417877c6705cdd2d149e474deaa1f38d8abcf8c9
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_imscp
22 * @copyright 2009 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
29 require_once($CFG->libdir.'/filelib.php');
31 class mod_imscp_mod_form extends moodleform_mod {
32 function definition() {
33 global $CFG, $DB;
34 $mform = $this->_form;
36 $config = get_config('imscp');
38 //-------------------------------------------------------
39 $mform->addElement('header', 'general', get_string('general', 'form'));
40 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
41 if (!empty($CFG->formatstringstriptags)) {
42 $mform->setType('name', PARAM_TEXT);
43 } else {
44 $mform->setType('name', PARAM_CLEANHTML);
46 $mform->addRule('name', null, 'required', null, 'client');
47 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
48 $this->add_intro_editor($config->requiremodintro);
50 //-------------------------------------------------------
51 $mform->addElement('header', 'content', get_string('contentheader', 'imscp'));
52 $mform->setExpanded('content', true);
53 $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp'));
55 $options = array('-1'=>get_string('all'), '0'=>get_string('no'), '1'=>'1', '2'=>'2', '5'=>'5', '10'=>'10', '20'=>'20');
56 $mform->addElement('select', 'keepold', get_string('keepold', 'imscp'), $options);
57 $mform->setDefault('keepold', $config->keepold);
58 $mform->setAdvanced('keepold', $config->keepold_adv);
60 //-------------------------------------------------------
61 $this->standard_coursemodule_elements();
63 //-------------------------------------------------------
64 $this->add_action_buttons();
67 function validation($data, $files) {
68 global $USER;
70 if ($errors = parent::validation($data, $files)) {
71 return $errors;
74 $usercontext = context_user::instance($USER->id);
75 $fs = get_file_storage();
77 if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
78 if (!$this->current->instance) {
79 $errors['package'] = get_string('required');
80 return $errors;
82 } else {
83 $file = reset($files);
84 if ($file->get_mimetype() != 'application/zip') {
85 $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
86 // better delete current file, it is not usable anyway
87 $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
91 return $errors;