Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/export/grade_export_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 
00024 class grade_export_form extends moodleform {
00025     function definition() {
00026         global $CFG, $COURSE, $USER, $DB;
00027 
00028         $mform =& $this->_form;
00029         if (isset($this->_customdata)) {  // hardcoding plugin names here is hacky
00030             $features = $this->_customdata;
00031         } else {
00032             $features = array();
00033         }
00034 
00035         $mform->addElement('header', 'options', get_string('options', 'grades'));
00036 
00037         $mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
00038         $mform->setDefault('export_feedback', 0);
00039 
00040         $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
00041         $mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
00042 
00043         if (!empty($features['updategradesonly'])) {
00044             $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
00045         }
00047         //$default_gradedisplaytype = $CFG->grade_export_displaytype;
00048         $options = array(GRADE_DISPLAY_TYPE_REAL       => get_string('real', 'grades'),
00049                          GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
00050                          GRADE_DISPLAY_TYPE_LETTER     => get_string('letter', 'grades'));
00051 
00052         /*
00053         foreach ($options as $key=>$option) {
00054             if ($key == $default_gradedisplaytype) {
00055                 $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
00056                 break;
00057             }
00058         }
00059         */
00060         $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
00061         $mform->setDefault('display', $CFG->grade_export_displaytype);
00062 
00063         //$default_gradedecimals = $CFG->grade_export_decimalpoints;
00064         $options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
00065         $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
00066         $mform->setDefault('decimals', $CFG->grade_export_decimalpoints);
00067         $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
00068         /*
00069         if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
00070             $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
00071         }
00072         */
00073 
00074         if (!empty($features['includeseparator'])) {
00075             $radio = array();
00076             $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
00077             $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
00078             $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
00079             $mform->setDefault('separator', 'comma');
00080         }
00081 
00082         if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
00083             $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
00084             $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
00085             $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
00086                             array($COURSE->id, $USER->id));
00087             if ($keys) {
00088                 foreach ($keys as $key) {
00089                     $options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
00090                 }
00091             }
00092             $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
00093             $mform->addHelpButton('key', 'userkey', 'userkey');
00094             $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
00095                     '<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>');
00096 
00097             $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
00098             $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
00099             $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is
00100 
00101             $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
00102             $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
00103             $mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is
00104 
00105             $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
00106             $mform->disabledIf('validuntil', 'key', 'noteq', 1);
00107         }
00108 
00109         $mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
00110 
00111         $switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
00112 
00113         // Grab the grade_seq for this course
00114         $gseq = new grade_seq($COURSE->id, $switch);
00115 
00116         if ($grade_items = $gseq->items) {
00117             $needs_multiselect = false;
00118             $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $COURSE->id));
00119 
00120             foreach ($grade_items as $grade_item) {
00121                 // Is the grade_item hidden? If so, can the user see hidden grade_items?
00122                 if ($grade_item->is_hidden() && !$canviewhidden) {
00123                     continue;
00124                 }
00125 
00126                 if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
00127                     $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
00128                     $mform->hardFreeze('itemids['.$grade_item->id.']');
00129                 } else {
00130                     $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
00131                     $mform->setDefault('itemids['.$grade_item->id.']', 1);
00132                     $needs_multiselect = true;
00133                 }
00134             }
00135 
00136             if ($needs_multiselect) {
00137                 $this->add_checkbox_controller(1, null, null, 1); // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
00138             }
00139         }
00140 
00141         $mform->addElement('hidden', 'id', $COURSE->id);
00142         $mform->setType('id', PARAM_INT);
00143         $this->add_action_buttons(false, get_string('submit'));
00144 
00145     }
00146 }
00147 
 All Data Structures Namespaces Files Functions Variables Enumerations