require_once('../../../config.php');
include_once($CFG->libdir.'/gradelib.php');
-
$id = required_param('id', PARAM_INT); // course id
$course = get_record('course', 'id', $id); // actual course
// if mapping informatioin is supplied
$map[clean_param($formdata->mapfrom, PARAM_RAW)] = clean_param($formdata->mapto, PARAM_RAW);
+ // check for mapto collisions
+ $maperrors = array();
+ foreach ($map as $i=>$j) {
+ if ($j == 0) {
+ // you can have multiple ignores
+ continue;
+ } else {
+ if (!isset($maperrors[$j])) {
+ $maperrors[$j] = true;
+ } else {
+ // collision
+ unlink($filename); // needs to be uploaded again, sorry
+ error('mapping collision detected, 2 fields maps to the same grdae item '.$j);
+ }
+ }
+ }
+
// Large files are likely to take their time and memory. Let PHP know
// that we'll take longer, and that the process should be recycled soon
// to free up memory.
// if not, put it in
// else, insert grade into the table
break;
- case 'feeback':
+ case 'feedback':
if ($t1) {
// t1 is the id of the grade item
$feedback -> itemid = $t1;
$feedback -> feedback = $value;
- $newfeedback[] = $feedback;
+ $newfeedbacks[] = $feedback;
}
break;
default:
if (!empty($map[$key]) && $value!=="") {
// non numeric grade value supplied, possibly mapped wrong column
- if (!is_numeric($value)) {
+ if (!is_numeric($value)) {
+ echo "<br/>t0 is $t0";
+ echo "<br/>grade is $value";
$status = false;
import_cleanup($importcode);
notify(get_string('badgrade', 'grades'));
// updating/inserting all comments here
if (!empty($newfeedbacks)) {
foreach ($newfeedbacks as $newfeedback) {
- if ($feedback = get_record('grade_import_values', 'importcode', $importcode, 'userid', $studentid, 'itemid', $newfeedback->itemid)) {
+ if ($feedback = get_record('grade_import_values', 'import_code', $importcode, 'userid', $studentid, 'itemid', $newfeedback->itemid)) {
$newfeedback ->id = $feedback ->id;
update_record('grade_import_values', $newfeedback);
} else {
function definition () {
global $CFG;
-
$mform =& $this->_form;
// this is an array of headers
$mform->addElement('header', 'general', get_string('identifier', 'grades'));
$mapfromoptions = array();
-
+
if ($header) {
foreach ($header as $i=>$h) {
$mapfromoptions[$i] = $h;
$mform->addElement('header', 'general', get_string('mappings', 'grades'));
- $gradeitems = $this->_customdata['gradeitems'];
+ // add a comment option
+
+ if ($gradeitems = $this->_customdata['gradeitems']) {
+ $comments = array();
+ foreach ($gradeitems as $itemid => $itemname) {
+ $comments['feedback_'.$itemid] = 'comments for '.$itemname;
+ }
+ }
include_once($CFG->libdir.'/gradelib.php');
if ($header) {
$i = 0; // index
foreach ($header as $h) {
-
- $h = trim($h);
- // this is the order of the headers
- // $mform->addElement('hidden', 'maps[]', $h);
-
- // this is what they map to
- $mapfromoptions = array('0'=>'ignore', 'new'=>'new gradeitem') + $gradeitems;
- $mform->addElement('select', 'mapping_'.$i, s($h), $mapfromoptions);
+ $h = trim($h);
+ // this is what each header maps to
+ $mform->addElement('selectgroups',
+ 'mapping_'.$i, s($h),
+ array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
+ 'gradeitems'=>$gradeitems,
+ 'comments'=>$comments));
$i++;
}
}
-
+
// find a non-conflicting file name based on time stamp
$newfilename = 'cvstemp_'.time();
while (file_exists($CFG->dataroot.'/temp/'.$newfilename)) {
$newfilename = 'cvstemp_'.time();
}
-
+
// move the uploaded file
move_uploaded_file($filename, $CFG->dataroot.'/temp/'.$newfilename);
-
+
// course id needs to be passed for auth purposes
$mform->addElement('hidden', 'map', 1);
$mform->setType('map', PARAM_INT);
$mform->addElement('hidden', 'filename', $newfilename);
$mform->setType('filename', PARAM_FILE);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
-
+
}
}
?>
$course = get_record('course', 'id', $id); // actual course
// capability check
+require_login($id);
require_capability('moodle/course:managegrades', get_context_instance(CONTEXT_COURSE, $course->id));
require_once('../lib.php');
require_once('../grade_import_form.php');
require_once($CFG->dirroot.'/grade/lib.php');
+// print header
$strgrades = get_string('grades', 'grades');
$actionstr = get_string('importxml', 'grades');
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
break;
}
+ // grade item locked, abort
+ if ($gradeitem->locked) {
+ $status = false;
+ notify(get_string('gradeitemlocked', 'grades'));
+ break 3;
+ }
+
+ // check if grade_grades is locked and if so, abort
+ if ($grade_grades = new grade_grades(array('itemid'=>$gradeitem->id, 'userid'=>$result['#']['student'][0]['#']))) {
+ if ($grade_grades->locked) {
+ // individual grade locked, abort
+ $status = false;
+ notify(get_string('gradegradeslocked', 'grades'));
+ break 2;
+ }
+ }
unset($newgrade);
if (isset($result['#']['score'][0]['#'])) {
notify(get_string('baduserid', 'grades'));
notify(get_string('importfailed', 'grades'));
break;
- }
+ }
// check grade value is a numeric grade
if (!is_numeric($newgrade->rawgrade)) {