Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/import/grade_import_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 
00018 if (!defined('MOODLE_INTERNAL')) {
00019     die('Direct access to this script is forbidden.');    
00020 }
00021 
00022 require_once $CFG->libdir.'/formslib.php';
00023 require_once($CFG->libdir.'/gradelib.php');
00024 
00025 class grade_import_form extends moodleform {
00026     function definition (){
00027         global $COURSE;
00028 
00029         $mform =& $this->_form;
00030 
00031         if (isset($this->_customdata)) {  // hardcoding plugin names here is hacky
00032             $features = $this->_customdata;
00033         } else {
00034             $features = array();
00035         }
00036 
00037         // course id needs to be passed for auth purposes
00038         $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
00039         $mform->setType('id', PARAM_INT);
00040         $mform->addElement('header', 'general', get_string('importfile', 'grades'));
00041         // file upload
00042         $mform->addElement('filepicker', 'userfile', get_string('file'));
00043         $mform->addRule('userfile', null, 'required');
00044         $textlib = textlib_get_instance();
00045         $encodings = $textlib->get_encodings();
00046         $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
00047 
00048         if (!empty($features['includeseparator'])) {
00049             $radio = array();
00050             $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
00051             $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
00052             $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
00053             $mform->setDefault('separator', 'comma');
00054         }
00055 
00056         if (!empty($features['verbosescales'])) {
00057             $options = array(1=>get_string('yes'), 0=>get_string('no'));
00058             $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
00059         }
00060 
00061         $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
00062         $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
00063         $mform->setType('previewrows', PARAM_INT);
00064         $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
00065         $mform->setType('groupid', PARAM_INT);
00066         $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
00067     }
00068 }
00069 
00070 class grade_import_mapping_form extends moodleform {
00071 
00072     function definition () {
00073         global $CFG, $COURSE;
00074         $mform =& $this->_form;
00075 
00076         // this is an array of headers
00077         $header = $this->_customdata['header'];
00078         // course id
00079 
00080         $mform->addElement('header', 'general', get_string('identifier', 'grades'));
00081         $mapfromoptions = array();
00082 
00083         if ($header) {
00084             foreach ($header as $i=>$h) {
00085                 $mapfromoptions[$i] = s($h);
00086             }
00087         }
00088         $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
00089 
00090         $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
00091         $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
00092 
00093         $mform->addElement('header', 'general', get_string('mappings', 'grades'));
00094 
00095         // add a comment option
00096 
00097         $comments = array();
00098         if ($gradeitems = $this->_customdata['gradeitems']) {
00099             foreach ($gradeitems as $itemid => $itemname) {
00100                 $comments['feedback_'.$itemid] = 'comments for '.$itemname;
00101             }
00102         }
00103 
00104         if ($header) {
00105             $i = 0; // index
00106             foreach ($header as $h) {
00107                 $h = trim($h);
00108                 // this is what each header maps to
00109                 $mform->addElement('selectgroups', 'mapping_'.$i, s($h),
00110                     array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
00111                     'gradeitems'=>$gradeitems,
00112                     'comments'=>$comments));
00113                 $i++;
00114             }
00115         }
00116 
00117         // course id needs to be passed for auth purposes
00118         $mform->addElement('hidden', 'map', 1);
00119         $mform->setType('map', PARAM_INT);
00120         $mform->addElement('hidden', 'id');
00121         $mform->setType('id', PARAM_INT);
00122         $mform->addElement('hidden', 'importcode');
00123         $mform->setType('importcode', PARAM_FILE);
00124         $mform->addElement('hidden', 'verbosescales', 1);
00125         $mform->setType('separator', PARAM_ALPHA);
00126         $mform->addElement('hidden', 'separator', 'comma');
00127         $mform->setType('verbosescales', PARAM_INT);
00128         $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
00129         $mform->setType('groupid', PARAM_INT);
00130         $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
00131 
00132     }
00133 }
 All Data Structures Namespaces Files Functions Variables Enumerations