MDL-11050 grade export must use formslib properly - no data_submitted()!
This commit is contained in:
@@ -6,7 +6,7 @@ class grade_export_form extends moodleform {
|
||||
global $CFG, $COURSE, $USER;
|
||||
|
||||
$mform =& $this->_form;
|
||||
if (isset($this->_customdata['plugin'])) {
|
||||
if (isset($this->_customdata['plugin'])) { // hardcoding plugin names here is hacky
|
||||
$plugin = $this->_customdata['plugin'];
|
||||
} else {
|
||||
$plugin = 'unknown';
|
||||
@@ -44,18 +44,17 @@ class grade_export_form extends moodleform {
|
||||
|
||||
$mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
|
||||
|
||||
$id = $this->_customdata['id']; // course id
|
||||
$mform->addElement('hidden', 'id', $id);
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) {
|
||||
$mform->addElement('hidden', 'id', $COURSE->id);
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$COURSE->id))) {
|
||||
$noidnumber = false;
|
||||
foreach ($grade_items as $grade_item) {
|
||||
|
||||
if ($plugin != 'xmlexport' || $grade_item->idnumber) {
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
|
||||
$element->setChecked(1);
|
||||
} else {
|
||||
$noidnumber = true;
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id));
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id));
|
||||
}
|
||||
|
||||
$mform->addElement($element);
|
||||
|
||||
+1
-13
@@ -25,20 +25,8 @@
|
||||
|
||||
require_once($CFG->dirroot.'/lib/gradelib.php');
|
||||
require_once($CFG->dirroot.'/grade/lib.php');
|
||||
require_once($CFG->dirroot.'/grade/export/grade_export_form.php');
|
||||
|
||||
/**
|
||||
* Prints all grade items for selection
|
||||
* @input int id - course id
|
||||
*/
|
||||
function print_gradeitem_selections($id, $params = array()) {
|
||||
global $CFG;
|
||||
// print all items for selections
|
||||
// make this a standard function in lib maybe
|
||||
include_once('grade_export_form.php');
|
||||
$mform = new grade_export_form(qualified_me(), array('id'=>$id)+$params);
|
||||
$mform->display();
|
||||
|
||||
}
|
||||
/**
|
||||
* Base export class
|
||||
*/
|
||||
|
||||
@@ -47,13 +47,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'ods');
|
||||
// process post information
|
||||
if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
if (!is_array($data->itemids)) {
|
||||
$itemidsurl = $data->itemids;
|
||||
} else {
|
||||
$mform = new grade_export_form();
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data->itemids) {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
} else {
|
||||
//error?
|
||||
$itemidsurl = '';
|
||||
}
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
@@ -66,6 +69,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id);
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
?>
|
||||
|
||||
@@ -3,7 +3,8 @@ require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class grade_export_txt_form extends moodleform {
|
||||
function definition (){
|
||||
global $CFG;
|
||||
global $CFG, $COURSE;
|
||||
|
||||
include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -13,11 +14,10 @@ class grade_export_txt_form extends moodleform {
|
||||
false, true, false, get_string("exportlettershelp", 'grades')));
|
||||
|
||||
$mform->addElement('header', 'general', 'Gradeitems to be included'); // TODO: localize
|
||||
$id = $this->_customdata['id']; // course id
|
||||
$mform->addElement('hidden', 'id', $id);
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) {
|
||||
$mform->addElement('hidden', 'id', $COURSE->id);
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$COURSE->id))) {
|
||||
foreach ($grade_items as $grade_item) {
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
|
||||
$element = new HTML_QuickForm_advcheckbox('itemids['.$grade_item->id.']', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id));
|
||||
$element->setChecked(1);
|
||||
$mform->addElement($element);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_txt.php';
|
||||
require_once 'grade_export_txt_form.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
@@ -47,14 +48,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'txt');
|
||||
// process post information
|
||||
if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// $itemids consists of ints and ",", will be cleaned in the main export class
|
||||
if (!is_array($data->itemids)) {
|
||||
$itemidsurl = $data->itemids;
|
||||
} else {
|
||||
$mform = new grade_export_txt_form();
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data->itemids) {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
} else {
|
||||
//error?
|
||||
$itemidsurl = '';
|
||||
}
|
||||
|
||||
$export = new grade_export($id, $data->itemids, $data->export_letters);
|
||||
@@ -66,8 +69,6 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
}
|
||||
|
||||
// print the form to choose what grade_items to export
|
||||
include_once('grade_export_txt_form.php');
|
||||
$mform = new grade_export_txt_form(qualified_me(), array('id'=>$id));
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
|
||||
@@ -47,13 +47,16 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'xls');
|
||||
// process post information
|
||||
if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
if (!is_array($data->itemids)) {
|
||||
$itemidsurl = $data->itemids;
|
||||
} else {
|
||||
$mform = new grade_export_form();
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data->itemids) {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
} else {
|
||||
//error?
|
||||
$itemidsurl = '';
|
||||
}
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
@@ -66,6 +69,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id);
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
?>
|
||||
|
||||
@@ -48,13 +48,15 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'xml');
|
||||
|
||||
// process post information
|
||||
if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
$mform = new grade_export_form(null, array('plugin'=>'xmlexport'));
|
||||
|
||||
if (!is_array($data->itemids)) {
|
||||
$itemidsurl = $data->itemids;
|
||||
} else {
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data->itemids) {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
} else {
|
||||
//error?
|
||||
$itemidsurl = '';
|
||||
}
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
@@ -68,12 +70,16 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
print_continue('export.php?id='.$id.'&itemids='.$itemidsurl.'&export_letters='.$data->export_letters);
|
||||
|
||||
} else {
|
||||
if ($data->key == 1) {
|
||||
$data->key = create_user_key('grade/export', $USER->id, $COURSE->id, $data->iprestriction, $data->validuntil);
|
||||
}
|
||||
$link = $CFG->wwwroot.'/grade/export/xml/dump.php?id='.$id.'&itemids='.$itemidsurl.'&export_letters='.$data->export_letters.'&key='.$data->key;
|
||||
echo "<a href=\"$link\">$link</a>";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id, array('plugin'=>'xmlexport'));
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user