[ Index ] |
PHP Cross Reference of moodle-2.8 |
[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 * IMS CP configuration form 20 * 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 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 29 require_once($CFG->libdir.'/filelib.php'); 30 31 class mod_imscp_mod_form extends moodleform_mod { 32 function definition() { 33 global $CFG, $DB; 34 $mform = $this->_form; 35 36 $config = get_config('imscp'); 37 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); 45 } 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); 49 50 //------------------------------------------------------- 51 $mform->addElement('header', 'content', get_string('contentheader', 'imscp')); 52 $mform->setExpanded('content', true); 53 $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp')); 54 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); 59 60 //------------------------------------------------------- 61 $this->standard_coursemodule_elements(); 62 63 //------------------------------------------------------- 64 $this->add_action_buttons(); 65 } 66 67 function validation($data, $files) { 68 global $USER; 69 70 if ($errors = parent::validation($data, $files)) { 71 return $errors; 72 } 73 74 $usercontext = context_user::instance($USER->id); 75 $fs = get_file_storage(); 76 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; 81 } 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']); 88 } 89 } 90 91 return $errors; 92 } 93 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |