1
<?php // $Id: grade_export_form.php,v 1.27.2.8 2008/03/03 10:21:41 nicolasconnault Exp $
3
///////////////////////////////////////////////////////////////////////////
5
// NOTICE OF COPYRIGHT //
7
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8
// http://moodle.com //
10
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12
// This program is free software; you can redistribute it and/or modify //
13
// it under the terms of the GNU General Public License as published by //
14
// the Free Software Foundation; either version 2 of the License, or //
15
// (at your option) any later version. //
17
// This program is distributed in the hope that it will be useful, //
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20
// GNU General Public License for more details: //
22
// http://www.gnu.org/copyleft/gpl.html //
24
///////////////////////////////////////////////////////////////////////////
26
require_once $CFG->libdir.'/formslib.php';
28
class grade_export_form extends moodleform {
29
function definition() {
30
global $CFG, $COURSE, $USER;
32
$mform =& $this->_form;
33
if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
34
$features = $this->_customdata;
39
$mform->addElement('header', 'options', get_string('options', 'grades'));
41
$mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
42
$mform->setDefault('export_feedback', 0);
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[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
81
$radio[] = &MoodleQuickForm::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
if ($keys = get_records_select('user_private_key', "script='grade/export' AND instance={$COURSE->id} AND userid={$USER->id}")) {
90
foreach ($keys as $key) {
91
$options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
94
$mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
95
$mform->setHelpButton('key', array('userkey', get_string('userkey', 'userkey'), 'grade'));
96
$mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
97
'<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>');
99
$mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
100
$mform->setHelpButton('iprestriction', array('keyiprestriction', get_string('keyiprestriction', 'userkey'), 'userkey'));
101
$mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is
103
$mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
104
$mform->setHelpButton('validuntil', array('keyvaliduntil', get_string('keyvaliduntil', 'userkey'), 'userkey'));
105
$mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is
107
$mform->disabledIf('iprestriction', 'key', 'noteq', 1);
108
$mform->disabledIf('validuntil', 'key', 'noteq', 1);
111
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
113
$switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
115
// Grab the grade_seq for this course
116
$gseq = new grade_seq($COURSE->id, $switch);
118
if ($grade_items = $gseq->items) {
119
$needs_multiselect = false;
120
foreach ($grade_items as $grade_item) {
121
if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
122
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
123
$mform->hardFreeze('itemids['.$grade_item->id.']');
125
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
126
$mform->setDefault('itemids['.$grade_item->id.']', 1);
127
$needs_multiselect = true;
131
if ($needs_multiselect) {
132
$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
136
$mform->addElement('hidden', 'id', $COURSE->id);
137
$this->add_action_buttons(false, get_string('submit'));