} else {
$plugin = 'unknown';
}
+
+ $mform->addElement('header', 'options', get_string('options'));
+
$mform->addElement('advcheckbox', 'export_letters', get_string('exportletters', 'grades'));
$mform->setDefault('export_letters', 0);
- $mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'),
- false, true, false, get_string("exportlettershelp", 'grades')));
+ $mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'), false, true, false, get_string("exportlettershelp", 'grades')));
+
+ $mform->addElement('advcheckbox', 'publish', get_string('publish', 'grades'));
+ $mform->setDefault('publish', 0);
+ $mform->setHelpButton('publish', array(false, get_string('publish', 'grades'), false, true, false, get_string("publishhelp", 'grades')));
+
+ $mform->addElement('textarea', 'iplist', get_string('iplist', 'grades'), array('cols' => 40, 'rows' => 5));
+ $mform->setHelpButton('iplist', array(false, get_string('iplist', 'grades'), false, true, false, get_string("iplisthelp", 'grades')));
+
+ $mform->addElement('password', 'password', get_string('password'));
+ $mform->setHelpButton('password', array(false, get_string('password', 'grades'), false, true, false, get_string("passwordhelp", 'grades')));
$mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
if ($grade_items = grade_item::fetch_all(array('courseid'=>$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->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[]', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id));
}
-
+
$mform->addElement($element);
}
}
-
+
if ($noidnumber) {
- $mform->addElement('static', 'noidnumber', '', get_string('noidnumber'));
+ $mform->addElement('static', 'noidnumber', '', get_string('noidnumber'));
}
-
+
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
$mform->setType('previewrows', PARAM_INT);
var $columnidnumbers = array(); // Collect all gradeitem id numbers
var $students = array();
var $course; // course
+ var $publish; // Whether to publish this data via URL, or dump it to browser as usual
// common strings
var $strgrades;
* @param boolean $export_letters Whether to export letter grade_items as literal letters, or as numerical values
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
*/
- function grade_export($id, $itemids = '', $export_letters=false) {
+ function grade_export($id, $itemids = '', $export_letters=false, $publish=false) {
global $CFG, $COURSE;
if ($export_letters) {
$letters = $report->get_grade_letters();
}
+ $this->publish = $publish;
$this->strgrades = get_string("grades");
$this->strgrade = get_string("grade");
$this->itemids = $itemids;
$i = 0;
foreach ($this->grades as $studentid => $studentgrades) {
-
+
// number of preview rows
if ($i++ == $rows) {
- break;
+ break;
}
echo '<tr>';
$student = $this->students[$studentid];
global $CFG;
+ $retval = '';
+
/// Whether this plugin is entitled to update export time
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
/// Print names of all the fields
- echo get_string("firstname")."$this->separator".
+ $retval .= get_string("firstname")."$this->separator".
get_string("lastname")."{$this->separator}".
get_string("idnumber")."{$this->separator}".
get_string("institution")."{$this->separator}".
get_string("email");
foreach ($this->columns as $column) {
$column = strip_tags($column);
- echo "{$this->separator}$column";
+ $retval .= "{$this->separator}$column";
/// add a column_feedback column
if ($feedback) {
- echo "{$this->separator}{$column}_feedback";
+ $retval .= "{$this->separator}{$column}_feedback";
}
}
- echo "{$this->separator}".get_string("total")."\n";
+ $retval .= "{$this->separator}".get_string("total")."\n";
/// Print all the lines of data.
foreach ($this->grades as $studentid => $studentgrades) {
if (empty($this->totals[$student->id])) {
$this->totals[$student->id] = '';
}
- echo "$student->firstname{$this->separator}$student->lastname{$this->separator}$student->idnumber{$this->separator}$student->institution{$this->separator}$student->department{$this->separator}$student->email";
+ $retval .= "$student->firstname{$this->separator}$student->lastname{$this->separator}$student->idnumber{$this->separator}$student->institution{$this->separator}$student->department{$this->separator}$student->email";
foreach ($studentgrades as $gradeitemid => $grade) {
$grade = strip_tags($grade);
- echo "{$this->separator}$grade";
+ $retval .= "{$this->separator}$grade";
if ($feedback) {
- echo "{$this->separator}".array_shift($this->comments[$student->id]);
+ $retval .= "{$this->separator}".array_shift($this->comments[$student->id]);
}
/// if export flag needs to be set
$grade_grade->update();
}
}
- echo "{$this->separator}".$this->totals[$student->id];
- echo "\n";
+ $retval .= "{$this->separator}".$this->totals[$student->id];
+ $retval .= "\n";
}
+ echo $retval;
+
exit;
}
}
/**
* To be implemented by child classes
+ * @param boolean $feedback
+ * @param boolean $publish Whether to output directly, or send as a file
+ * @return string
*/
function print_grades($feedback = false) {
global $CFG;
+ $retval = '';
+
/// Whether this plugin is entitled to update export time
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
/// Calculate file name
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
- //header("Content-type: text/xml; charset=UTF-8");
- //header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
-
/// time stamp to ensure uniqueness of batch export
- echo '<results batch="xml_export_'.time().'">';
+ $retval .= '<results batch="xml_export_'.time().'">';
foreach ($this->columnidnumbers as $index => $idnumber) {
// studentgrades[] index should match with corresponding $index
foreach ($this->grades as $studentid => $studentgrades) {
- echo '<result>';
+ $retval .= '<result>';
// state can be new, or regrade
// require comparing of timestamps in db
$grade_grade = new grade_grade($params);
// if exported, check grade_history, if modified after export, set state to regrade
+ $status = 'new';
if (!empty($grade_grade->exported)) {
//TODO: use timemodified or something else instead
/* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grade->exported)) {
$status = 'new';
}
- echo '<state>'.$status.'</state>';
+ $retval .= '<state>'.$status.'</state>';
// only need id number
- echo '<assignment>'.$idnumber.'</assignment>';
+ $retval .= '<assignment>'.$idnumber.'</assignment>';
// this column should be customizable to use either student id, idnumber, uesrname or email.
- echo '<student>'.$studentid.'</student>';
- echo '<score>'.$studentgrades[$index].'</score>';
+ $retval .= '<student>'.$studentid.'</student>';
+ $retval .= '<score>'.$studentgrades[$index].'</score>';
if ($feedback) {
- echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
+ $retval .= '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
}
- echo '</result>';
+ $retval .= '</result>';
// timestamp this if needed
if ($export) {
}
}
}
- echo '</results>';
+ $retval .= '</results>';
+
+ if ($this->publish) {
+ header("Content-type: text/xml; charset=UTF-8");
+ header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
+ }
+
+ echo $retval;
+
exit;
}
}
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()) {
// print the grades on screen for feedbacks
- $export = new grade_export($id, $data->itemids, $data->export_letters);
+ $export = new grade_export($id, $data->itemids, $data->export_letters, $data->publish);
+
+ if ($data->publish) {
+ // Record an entry in the 'published' table: people can now access this data by URL
+ }
+
$export->display_grades($feedback, $data->previewrows);
// this redirect should trigger a download prompt
BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
BLOCK_R_MAX_WIDTH);
-
- print_header($SITE->fullname, $SITE->fullname, 'home', '',
+ $navigation = build_navigation(array(array('name' => get_string('home'), 'link' => null, 'type' => 'misc')));
+ print_header($SITE->fullname, $SITE->fullname, $navigation, '',
'<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
true, '', user_login_string($SITE).$langmenu);