Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / grade / edit / settings / form.php
blob070c7ca04a17d7567f24369c4f867f8ebfd4a08a
1 <?php //$Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // //
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. //
16 // //
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: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once($CFG->libdir.'/formslib.php');
28 /**
29 * First implementation of the preferences in the form of a moodleform.
30 * TODO add "reset to site defaults" button
32 class course_settings_form extends moodleform {
34 function definition() {
35 global $USER, $CFG;
37 $mform =& $this->_form;
39 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
40 $can_view_admin_links = false;
41 if (has_capability('moodle/grade:manage', $systemcontext)) {
42 $can_view_admin_links = true;
45 // General settings
46 $strchangedefaults = get_string('changedefaults', 'grades');
47 $mform->addElement('header', 'general', get_string('generalsettings', 'grades'));
48 if ($can_view_admin_links) {
49 $link = '<a href="' . $CFG->wwwroot . '/admin/settings.php?section=gradessettings">' . $strchangedefaults . '</a>';
50 $mform->addElement('static', 'generalsettingslink', $link);
52 $options = array(-1 => get_string('default', 'grades'),
53 GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
54 GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
55 $default_gradedisplaytype = $CFG->grade_aggregationposition;
56 foreach ($options as $key=>$option) {
57 if ($key == $default_gradedisplaytype) {
58 $options[-1] = get_string('defaultprev', 'grades', $option);
59 break;
62 $mform->addElement('select', 'aggregationposition', get_string('aggregationposition', 'grades'), $options);
63 $mform->setHelpButton('aggregationposition', array('aggregationposition', get_string('aggregationposition', 'grades'), 'grade'));
65 // Grade item settings
66 $mform->addElement('header', 'grade_item_settings', get_string('gradeitemsettings', 'grades'));
67 if ($can_view_admin_links) {
68 $link = '<a href="' . $CFG->wwwroot . '/admin/settings.php?section=gradeitemsettings">' . $strchangedefaults . '</a>';
69 $mform->addElement('static', 'gradeitemsettingslink', $link);
72 $options = array(-1 => get_string('default', 'grades'),
73 GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
74 GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
75 GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
76 $default_gradedisplaytype = $CFG->grade_displaytype;
77 foreach ($options as $key=>$option) {
78 if ($key == $default_gradedisplaytype) {
79 $options[-1] = get_string('defaultprev', 'grades', $option);
80 break;
83 $mform->addElement('select', 'displaytype', get_string('gradedisplaytype', 'grades'), $options);
84 $mform->setHelpButton('displaytype', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'));
87 $options = array(-1=> get_string('defaultprev', 'grades', $CFG->grade_decimalpoints), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
88 $mform->addElement('select', 'decimalpoints', get_string('decimalpoints', 'grades'), $options);
89 $mform->setHelpButton('decimalpoints', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'));
91 // add setting options for plugins
92 $types = array('report', 'export', 'import');
94 foreach($types as $type) {
95 foreach (get_list_of_plugins('grade/'.$type) as $plugin) {
96 // Include all the settings commands for this plugin if there are any
97 if (file_exists($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php')) {
98 require_once($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php');
99 $functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
100 if (function_exists($functionname)) {
101 $mform->addElement('header', 'grade_'.$type.$plugin, get_string('modulename', 'grade'.$type.'_'.$plugin, NULL, $CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lang/'));
102 if ($can_view_admin_links) {
103 $link = '<a href="' . $CFG->wwwroot . '/admin/settings.php?section=gradereport' . $plugin . '">' . $strchangedefaults . '</a>';
104 $mform->addElement('static', 'gradeitemsettingslink', $link);
106 $functionname($mform);
112 $mform->addElement('hidden', 'id');
113 $mform->setType('id', PARAM_INT);
115 $this->add_action_buttons();