Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/imscp/mod_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
00030 require_once($CFG->libdir.'/filelib.php');
00031 
00032 class mod_imscp_mod_form extends moodleform_mod {
00033     function definition() {
00034         global $CFG, $DB;
00035         $mform = $this->_form;
00036 
00037         $config = get_config('imscp');
00038 
00039         //-------------------------------------------------------
00040         $mform->addElement('header', 'general', get_string('general', 'form'));
00041         $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
00042         if (!empty($CFG->formatstringstriptags)) {
00043             $mform->setType('name', PARAM_TEXT);
00044         } else {
00045             $mform->setType('name', PARAM_CLEANHTML);
00046         }
00047         $mform->addRule('name', null, 'required', null, 'client');
00048         $this->add_intro_editor($config->requiremodintro);
00049 
00050         //-------------------------------------------------------
00051         $mform->addElement('header', 'content', get_string('contentheader', 'imscp'));
00052         $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp'));
00053 
00054         $options = array('-1'=>get_string('all'), '0'=>get_string('no'), '1'=>'1', '2'=>'2', '5'=>'5', '10'=>'10', '20'=>'20');
00055         $mform->addElement('select', 'keepold', get_string('keepold', 'imscp'), $options);
00056         $mform->setDefault('keepold', $config->keepold);
00057         $mform->setAdvanced('keepold', $config->keepold_adv);
00058 
00059         //-------------------------------------------------------
00060         $this->standard_coursemodule_elements();
00061 
00062         //-------------------------------------------------------
00063         $this->add_action_buttons();
00064     }
00065 
00066     function validation($data, $files) {
00067         global $USER;
00068 
00069         if ($errors = parent::validation($data, $files)) {
00070             return $errors;
00071         }
00072 
00073         $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
00074         $fs = get_file_storage();
00075 
00076         if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
00077             if (!$this->current->instance) {
00078                 $errors['package'] = get_string('required');
00079                 return $errors;
00080             }
00081         } else {
00082             $file = reset($files);
00083             if ($file->get_mimetype() != 'application/zip') {
00084                 $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
00085                 // better delete current file, it is not usable anyway
00086                 $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
00087             }
00088         }
00089 
00090         return $errors;
00091     }
00092 }
 All Data Structures Namespaces Files Functions Variables Enumerations