3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 if (!defined('MOODLE_INTERNAL')) {
19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
22 require_once $CFG->libdir
.'/formslib.php';
24 class grade_export_form
extends moodleform
{
25 function definition() {
26 global $CFG, $COURSE, $USER, $DB;
28 $mform =& $this->_form
;
29 if (isset($this->_customdata
)) { // hardcoding plugin names here is hacky
30 $features = $this->_customdata
;
35 $mform->addElement('header', 'options', get_string('options', 'grades'));
37 $mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
38 $mform->setDefault('export_feedback', 0);
40 $mform->addElement('advcheckbox', 'export_onlyactive', get_string('exportonlyactive', 'grades'));
41 $mform->setDefault('export_onlyactive', 0);
42 $mform->addHelpButton('export_onlyactive', 'exportonlyactive', 'grades');
44 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
45 $mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
47 if (!empty($features['updategradesonly'])) {
48 $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
50 /// selections for decimal points and format, MDL-11667, defaults to site settings, if set
51 //$default_gradedisplaytype = $CFG->grade_export_displaytype;
52 $options = array(GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
53 GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades'),
54 GRADE_DISPLAY_TYPE_LETTER
=> get_string('letter', 'grades'));
57 foreach ($options as $key=>$option) {
58 if ($key == $default_gradedisplaytype) {
59 $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
64 $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
65 $mform->setDefault('display', $CFG->grade_export_displaytype
);
67 //$default_gradedecimals = $CFG->grade_export_decimalpoints;
68 $options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
69 $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
70 $mform->setDefault('decimals', $CFG->grade_export_decimalpoints
);
71 $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER
);
73 if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
74 $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
78 if (!empty($features['includeseparator'])) {
80 $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
81 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
82 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
83 $mform->setDefault('separator', 'comma');
86 if (!empty($CFG->gradepublishing
) and !empty($features['publishing'])) {
87 $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
88 $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
89 $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
90 array($COURSE->id
, $USER->id
));
92 foreach ($keys as $key) {
93 $options[$key->value
] = $key->value
; // TODO: add more details - ip restriction, valid until ??
96 $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
97 $mform->addHelpButton('key', 'userkey', 'userkey');
98 $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
99 '<a href="'.$CFG->wwwroot
.'/grade/export/keymanager.php?id='.$COURSE->id
.'">'.get_string('keymanager', 'userkey').'</a>');
101 $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
102 $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
103 $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is
105 $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
106 $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
107 $mform->setDefault('validuntil', time()+
3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is
109 $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
110 $mform->disabledIf('validuntil', 'key', 'noteq', 1);
113 $mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
115 $switch = grade_get_setting($COURSE->id
, 'aggregationposition', $CFG->grade_aggregationposition
);
117 // Grab the grade_seq for this course
118 $gseq = new grade_seq($COURSE->id
, $switch);
120 if ($grade_items = $gseq->items
) {
121 $needs_multiselect = false;
122 $canviewhidden = has_capability('moodle/grade:viewhidden', context_course
::instance($COURSE->id
));
124 foreach ($grade_items as $grade_item) {
125 // Is the grade_item hidden? If so, can the user see hidden grade_items?
126 if ($grade_item->is_hidden() && !$canviewhidden) {
130 if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber
)) {
131 $mform->addElement('advcheckbox', 'itemids['.$grade_item->id
.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
132 $mform->hardFreeze('itemids['.$grade_item->id
.']');
134 $mform->addElement('advcheckbox', 'itemids['.$grade_item->id
.']', $grade_item->get_name(), null, array('group' => 1));
135 $mform->setDefault('itemids['.$grade_item->id
.']', 1);
136 $needs_multiselect = true;
140 if ($needs_multiselect) {
141 $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
145 $mform->addElement('hidden', 'id', $COURSE->id
);
146 $mform->setType('id', PARAM_INT
);
147 $this->add_action_buttons(false, get_string('submit'));