Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / grade / edit / grade_form.php
blobad6c1338670b4a3542cbed9fcc813ba0e3c1aa79
1 <?php //$Id$
3 require_once $CFG->libdir.'/formslib.php';
5 class edit_grade_form extends moodleform {
7 function definition() {
8 global $CFG, $COURSE;
10 $mform =& $this->_form;
12 $grade_item = $this->_customdata['grade_item'];
13 $gpr = $this->_customdata['gpr'];
15 /// information fields
16 $mform->addElement('static', 'user', get_string('user'));
17 $mform->addElement('static', 'itemname', get_string('itemname', 'grades'));
19 /// actual grade - numeric or scale
20 if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
21 // numeric grade
22 $mform->addElement('text', 'finalgrade', get_string('finalgrade', 'grades'));
24 } else if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
25 // scale grade
26 $scaleopt = array();
27 $scaleopt[-1] = get_string('nograde');
29 $i = 1;
30 if ($scale = get_record('scale', 'id', $grade_item->scaleid)) {
31 foreach (split(",", $scale->scale) as $option) {
32 $scaleopt[$i] = $option;
33 $i++;
37 $mform->addElement('select', 'finalgrade', get_string('finalgrade', 'grades'), $scaleopt);
40 $mform->addElement('advcheckbox', 'hidden', get_string('hidden', 'grades'));
41 $mform->addElement('advcheckbox', 'overridden', get_string('overridden', 'grades'));
42 $mform->addElement('advcheckbox', 'excluded', get_string('excluded', 'grades'));
44 /// locking
45 $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
46 $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
47 $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
49 // Feedback format is automatically converted to html if user has enabled editor
50 $mform->addElement('htmleditor', 'feedback', get_string('feedback', 'grades'),
51 array('rows'=>'15', 'course'=>$COURSE->id, 'cols'=>'45'));
52 $mform->setType('text', PARAM_RAW); // to be cleaned before display, no XSS risk
53 $mform->addElement('format', 'feedbackformat', get_string('format'));
54 $mform->setHelpButton('feedbackformat', array('textformat', get_string('helpformatting')));
56 // hidden params
57 $mform->addElement('hidden', 'id', 0);
58 $mform->setType('id', PARAM_INT);
60 $mform->addElement('hidden', 'itemid', 0);
61 $mform->setType('itemid', PARAM_INT);
63 $mform->addElement('hidden', 'userid', 0);
64 $mform->setType('userid', PARAM_INT);
66 $mform->addElement('hidden', 'courseid', $COURSE->id);
67 $mform->setType('courseid', PARAM_INT);
69 /// add return tracking info
70 $gpr->add_mform_elements($mform);
72 //-------------------------------------------------------------------------------
73 // buttons
74 $this->add_action_buttons();
77 function definition_after_data() {
78 global $CFG;
80 $mform =& $this->_form;
81 $grade_item = $this->_customdata['grade_item'];
83 if ($userid = $mform->getElementValue('userid')) {
84 $user = get_record('user', 'id', $userid);
85 $username = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'">'.fullname($user).'</a>';
86 $user_el =& $mform->getElement('user');
87 $user_el->setValue($username);
90 if ($grade_item->itemtype == 'mod') {
91 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
92 $itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$grade_item->itemmodule.'/view.php?id='.$cm->id.'">'.$grade_item->get_name().'</a>';
93 } else {
94 $itemname = $grade_item->get_name();
96 $itemname_el =& $mform->getElement('itemname');
97 $itemname_el->setValue($itemname);