[ 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 require_once($CFG->libdir.'/gradelib.php'); 24 25 class grade_import_form extends moodleform { 26 function definition (){ 27 global $COURSE; 28 29 $mform =& $this->_form; 30 31 if (isset($this->_customdata)) { // hardcoding plugin names here is hacky 32 $features = $this->_customdata; 33 } else { 34 $features = array(); 35 } 36 37 // course id needs to be passed for auth purposes 38 $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT)); 39 $mform->setType('id', PARAM_INT); 40 $mform->addElement('header', 'general', get_string('importfile', 'grades')); 41 42 // Restrict the possible upload file types. 43 if (!empty($features['acceptedtypes'])) { 44 $acceptedtypes = $features['acceptedtypes']; 45 } else { 46 $acceptedtypes = '*'; 47 } 48 49 // File upload. 50 $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes)); 51 $mform->addRule('userfile', null, 'required'); 52 $encodings = core_text::get_encodings(); 53 $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); 54 55 if (!empty($features['includeseparator'])) { 56 $radio = array(); 57 $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab'); 58 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma'); 59 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon'); 60 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon'); 61 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false); 62 $mform->setDefault('separator', 'comma'); 63 } 64 65 if (!empty($features['verbosescales'])) { 66 $options = array(1=>get_string('yes'), 0=>get_string('no')); 67 $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options); 68 } 69 70 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000); 71 $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize 72 $mform->setType('previewrows', PARAM_INT); 73 $mform->addElement('checkbox', 'forceimport', get_string('forceimport', 'grades')); 74 $mform->addHelpButton('forceimport', 'forceimport', 'grades'); 75 $mform->setDefault('forceimport', false); 76 $mform->setType('forceimport', PARAM_BOOL); 77 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); 78 $mform->setType('groupid', PARAM_INT); 79 $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); 80 } 81 } 82 83 class grade_import_mapping_form extends moodleform { 84 85 function definition () { 86 global $CFG, $COURSE; 87 $mform =& $this->_form; 88 89 // this is an array of headers 90 $header = $this->_customdata['header']; 91 // course id 92 93 $mform->addElement('header', 'general', get_string('identifier', 'grades')); 94 $mapfromoptions = array(); 95 96 if ($header) { 97 foreach ($header as $i=>$h) { 98 $mapfromoptions[$i] = s($h); 99 } 100 } 101 $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions); 102 103 $maptooptions = array( 104 'userid' => get_string('userid', 'grades'), 105 'username' => get_string('username'), 106 'useridnumber' => get_string('idnumber'), 107 'useremail' => get_string('email'), 108 '0' => get_string('ignore', 'grades') 109 ); 110 $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions); 111 112 $mform->addElement('header', 'general', get_string('mappings', 'grades')); 113 114 // Add a feedback option. 115 $feedbacks = array(); 116 if ($gradeitems = $this->_customdata['gradeitems']) { 117 foreach ($gradeitems as $itemid => $itemname) { 118 $feedbacks['feedback_'.$itemid] = get_string('feedbackforgradeitems', 'grades', $itemname); 119 } 120 } 121 122 if ($header) { 123 $i = 0; // index 124 foreach ($header as $h) { 125 $h = trim($h); 126 // This is what each header maps to. 127 $headermapsto = array( 128 get_string('others', 'grades') => array( 129 '0' => get_string('ignore', 'grades'), 130 'new' => get_string('newitem', 'grades') 131 ), 132 get_string('gradeitems', 'grades') => $gradeitems, 133 get_string('feedbacks', 'grades') => $feedbacks 134 ); 135 $mform->addElement('selectgroups', 'mapping_'.$i, s($h), $headermapsto); 136 $i++; 137 } 138 } 139 140 // course id needs to be passed for auth purposes 141 $mform->addElement('hidden', 'map', 1); 142 $mform->setType('map', PARAM_INT); 143 $mform->setConstant('map', 1); 144 $mform->addElement('hidden', 'id', $this->_customdata['id']); 145 $mform->setType('id', PARAM_INT); 146 $mform->setConstant('id', $this->_customdata['id']); 147 $mform->addElement('hidden', 'iid', $this->_customdata['iid']); 148 $mform->setType('iid', PARAM_INT); 149 $mform->setConstant('iid', $this->_customdata['iid']); 150 $mform->addElement('hidden', 'importcode', $this->_customdata['importcode']); 151 $mform->setType('importcode', PARAM_FILE); 152 $mform->setConstant('importcode', $this->_customdata['importcode']); 153 $mform->addElement('hidden', 'verbosescales', 1); 154 $mform->setType('verbosescales', PARAM_INT); 155 $mform->setConstant('verbosescales', $this->_customdata['verbosescales']); 156 $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); 157 $mform->setType('groupid', PARAM_INT); 158 $mform->setConstant('groupid', groups_get_course_group($COURSE)); 159 $mform->addElement('hidden', 'forceimport', $this->_customdata['forceimport']); 160 $mform->setType('forceimport', PARAM_BOOL); 161 $mform->setConstant('forceimport', $this->_customdata['forceimport']); 162 $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); 163 164 } 165 }
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 |