Moodle release 2.7
[moodle.git] / grade / export / grade_export_form.php
blob1772b0ade72172734cb5df6ff2cfa2d2b67523ba
1 <?php
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.
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;
31 } else {
32 $features = array();
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);
39 $coursecontext = context_course::instance($COURSE->id);
40 if (has_capability('moodle/course:viewsuspendedusers', $coursecontext)) {
41 $mform->addElement('advcheckbox', 'export_onlyactive', get_string('exportonlyactive', 'grades'));
42 $mform->setType('export_onlyactive', PARAM_BOOL);
43 $mform->setDefault('export_onlyactive', 1);
44 $mform->addHelpButton('export_onlyactive', 'exportonlyactive', 'grades');
45 } else {
46 $mform->addElement('hidden', 'export_onlyactive', 1);
47 $mform->setType('export_onlyactive', PARAM_BOOL);
48 $mform->setConstant('export_onlyactive', 1);
51 $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
52 $mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
54 if (!empty($features['updategradesonly'])) {
55 $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
57 /// selections for decimal points and format, MDL-11667, defaults to site settings, if set
58 //$default_gradedisplaytype = $CFG->grade_export_displaytype;
59 $options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
60 GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
61 GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
64 foreach ($options as $key=>$option) {
65 if ($key == $default_gradedisplaytype) {
66 $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
67 break;
71 $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
72 $mform->setDefault('display', $CFG->grade_export_displaytype);
74 //$default_gradedecimals = $CFG->grade_export_decimalpoints;
75 $options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
76 $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
77 $mform->setDefault('decimals', $CFG->grade_export_decimalpoints);
78 $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
80 if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
81 $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
85 if (!empty($features['includeseparator'])) {
86 $radio = array();
87 $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
88 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
89 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
90 $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
91 $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
92 $mform->setDefault('separator', 'comma');
95 if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
96 $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
97 $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
98 $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
99 array($COURSE->id, $USER->id));
100 if ($keys) {
101 foreach ($keys as $key) {
102 $options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
105 $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
106 $mform->addHelpButton('key', 'userkey', 'userkey');
107 $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
108 '<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>');
110 $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
111 $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
112 $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is
113 $mform->setType('iprestriction', PARAM_RAW_TRIMMED);
115 $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
116 $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
117 $mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is
118 $mform->setType('validuntil', PARAM_INT);
120 $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
121 $mform->disabledIf('validuntil', 'key', 'noteq', 1);
124 $mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
126 $switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
128 // Grab the grade_seq for this course
129 $gseq = new grade_seq($COURSE->id, $switch);
131 if ($grade_items = $gseq->items) {
132 $needs_multiselect = false;
133 $canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
135 foreach ($grade_items as $grade_item) {
136 // Is the grade_item hidden? If so, can the user see hidden grade_items?
137 if ($grade_item->is_hidden() && !$canviewhidden) {
138 continue;
141 if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
142 $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
143 $mform->hardFreeze('itemids['.$grade_item->id.']');
144 } else {
145 $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
146 $mform->setDefault('itemids['.$grade_item->id.']', 1);
147 $needs_multiselect = true;
151 if ($needs_multiselect) {
152 $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
156 $mform->addElement('hidden', 'id', $COURSE->id);
157 $mform->setType('id', PARAM_INT);
158 $this->add_action_buttons(false, get_string('submit'));