|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00018 if (!defined('MOODLE_INTERNAL')) { 00019 die('Direct access to this script is forbidden.'); 00020 } 00021 00022 require_once $CFG->libdir.'/formslib.php'; 00023 00024 class grade_import_form extends moodleform { 00025 function definition () { 00026 global $COURSE, $USER, $CFG, $DB; 00027 00028 $mform =& $this->_form; 00029 00030 // course id needs to be passed for auth purposes 00031 $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT)); 00032 $mform->setType('id', PARAM_INT); 00033 00034 $mform->addElement('header', 'general', get_string('importfile', 'grades')); 00035 00036 $mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades')); 00037 $mform->setDefault('feedback', 0); 00038 00039 // file upload 00040 $mform->addElement('filepicker', 'userfile', get_string('file')); 00041 $mform->disabledIf('userfile', 'url', 'noteq', ''); 00042 00043 $mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"'); 00044 $mform->disabledIf('url', 'userfile', 'noteq', ''); 00045 00046 if (!empty($CFG->gradepublishing)) { 00047 $mform->addElement('header', 'publishing', get_string('publishing', 'grades')); 00048 $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey')); 00049 $keys = $DB->get_records_select('user_private_key', 00050 "script='grade/import' AND instance=? AND userid=?", 00051 array($COURSE->id, $USER->id)); 00052 if ($keys) { 00053 foreach ($keys as $key) { 00054 $options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ?? 00055 } 00056 } 00057 $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options); 00058 $mform->addHelpButton('key', 'userkey', 'userkey'); 00059 $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'), 00060 '<a href="'.$CFG->wwwroot.'/grade/import/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>'); 00061 00062 $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80)); 00063 $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey'); 00064 $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is 00065 00066 $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true)); 00067 $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey'); 00068 $mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is 00069 00070 $mform->disabledIf('iprestriction', 'key', 'noteq', 1); 00071 $mform->disabledIf('validuntil', 'key', 'noteq', 1); 00072 00073 $mform->disabledIf('iprestriction', 'url', 'eq', ''); 00074 $mform->disabledIf('validuntil', 'url', 'eq', ''); 00075 $mform->disabledIf('key', 'url', 'eq', ''); 00076 } 00077 00078 $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); 00079 } 00080 00081 function validation($data, $files) { 00082 $err = parent::validation($data, $files); 00083 if (empty($data['url']) and empty($data['userfile'])) { 00084 if (array_key_exists('url', $data)) { 00085 $err['url'] = get_string('required'); 00086 } 00087 if (array_key_exists('userfile', $data)) { 00088 $err['userfile'] = get_string('required'); 00089 } 00090 00091 } else if (array_key_exists('url', $data) and $data['url'] != clean_param($data['url'], PARAM_URL)) { 00092 $err['url'] = get_string('error'); 00093 } 00094 00095 return $err; 00096 } 00097 } 00098