[ 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 if (!defined('MOODLE_INTERNAL')) { 19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 20 } 21 22 require_once $CFG->libdir.'/formslib.php'; 23 24 class grade_import_form extends moodleform { 25 function definition () { 26 global $COURSE, $USER, $CFG, $DB; 27 28 $mform =& $this->_form; 29 30 if (isset($this->_customdata)) { 31 $features = $this->_customdata; 32 } else { 33 $features = array(); 34 } 35 36 // course id needs to be passed for auth purposes 37 $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT)); 38 $mform->setType('id', PARAM_INT); 39 40 $mform->addElement('header', 'general', get_string('importfile', 'grades')); 41 42 $mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades')); 43 $mform->setDefault('feedback', 0); 44 45 // Restrict the possible upload file types. 46 if (!empty($features['acceptedtypes'])) { 47 $acceptedtypes = $features['acceptedtypes']; 48 } else { 49 $acceptedtypes = '*'; 50 } 51 52 // File upload. 53 $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes)); 54 $mform->disabledIf('userfile', 'url', 'noteq', ''); 55 56 $mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"'); 57 $mform->setType('url', PARAM_URL); 58 $mform->disabledIf('url', 'userfile', 'noteq', ''); 59 60 if (!empty($CFG->gradepublishing)) { 61 $mform->addElement('header', 'publishing', get_string('publishing', 'grades')); 62 $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey')); 63 $keys = $DB->get_records_select('user_private_key', 64 "script='grade/import' AND instance=? AND userid=?", 65 array($COURSE->id, $USER->id)); 66 if ($keys) { 67 foreach ($keys as $key) { 68 $options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ?? 69 } 70 } 71 $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options); 72 $mform->addHelpButton('key', 'userkey', 'userkey'); 73 $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'), 74 '<a href="'.$CFG->wwwroot.'/grade/import/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>'); 75 76 $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80)); 77 $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey'); 78 $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is 79 80 $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true)); 81 $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey'); 82 $mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is 83 84 $mform->disabledIf('iprestriction', 'key', 'noteq', 1); 85 $mform->disabledIf('validuntil', 'key', 'noteq', 1); 86 87 $mform->disabledIf('iprestriction', 'url', 'eq', ''); 88 $mform->disabledIf('validuntil', 'url', 'eq', ''); 89 $mform->disabledIf('key', 'url', 'eq', ''); 90 } 91 92 $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); 93 } 94 95 function validation($data, $files) { 96 $err = parent::validation($data, $files); 97 if (empty($data['url']) and empty($data['userfile'])) { 98 if (array_key_exists('url', $data)) { 99 $err['url'] = get_string('required'); 100 } 101 if (array_key_exists('userfile', $data)) { 102 $err['userfile'] = get_string('required'); 103 } 104 105 } else if (array_key_exists('url', $data) and $data['url'] != clean_param($data['url'], PARAM_URL)) { 106 $err['url'] = get_string('error'); 107 } 108 109 return $err; 110 } 111 } 112
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 |