global $CFG;
include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
$mform =& $this->_form;
- $mform->addElement('header', 'general', 'Gradeitems to be included'); // TODO: localize
+ $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_get_items($id)) {
// if grade_item ids are specified
if ($itemids) {
foreach ($itemids as $iid) {
- $params->id = $iid;
- $gradeitems[] = new grade_item($params);
+
+ if ($iid) {
+ $params->id = $iid;
+ $gradeitems[] = new grade_item($params);
+ }
}
} else {
// else we get all items for this course
}
if ($gradeitems) {
-
foreach ($gradeitems as $gradeitem) {
$gradeitem -> generate_final();
include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
$radio = array();
- $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('tab'), 'tab');
- $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('comma'), 'comma');
- $mform->addGroup($radio, 'separator', get_string('separator'), ' ', false);
+ $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
+ $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
+ $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
$mform->setDefault('separator', 'comma');
$this->add_action_buttons(false, get_string('submit'));
}
$newgradeitems = array(); // temporary array to keep track of what new headers are processed
+ $status = true;
+
while (!feof ($fp)) {
// add something
$line = split($csv_delimiter, fgets($fp,1024));
$value = preg_replace($csv_encode,$csv_delimiter2,trim($value));
switch ($map[$header[$key]]) {
- case 'userid': //
+ case 'userid': //
+ if (!$user = get_record('user','id', $value)) {
+ // user not found, abort whold import
+ import_cleanup($importcode);
+ notify("user mapping error, could not find user with id \"$value\"");
+ $status = false;
+ break 3;
+ }
$studentid = $value;
break;
case 'useridnumber':
- $user = get_record('user', 'idnumber', $value);
+ if (!$user = get_record('user', 'idnumber', $value)) {
+ // user not found, abort whold import
+ import_cleanup($importcode);
+ notify("user mapping error, could not find user with idnumber \"$value\"");
+ $status = false;
+ break 3;
+ }
$studentid = $user->id;
break;
case 'useremail':
- $user = get_record('user', 'email', $value);
+ if (!$user = get_record('user', 'email', $value)) {
+ import_cleanup($importcode);
+ notify("user mapping error, could not find user with email address \"$value\"");
+ $status = false;
+ break 3;
+ }
$studentid = $user->id;
break;
case 'username':
- $user = get_record('user', 'username', $value);
+ if (!$user = get_record('user', 'username', $value)) {
+ import_cleanup($importcode);
+ notify("user mapping error, could not find user with username \"$value\"");
+ $status = false;
+ break 3;
+ }
$studentid = $user->id;
break;
case 'new':
if (empty($newgradeitems[$key])) {
$newgradeitem->itemname = $header[$key];
- $newgradeitem->import_code = $importcode;
- $newgradeitems[$key] = insert_record('grade_import_newitem', $newgradeitem);
+ $newgradeitem->import_code = $importcode;
+
+ // failed to insert into new grade item buffer
+ if (!$newgradeitems[$key] = insert_record('grade_import_newitem', $newgradeitem)) {
+ $status = false;
+ import_cleanup($importcode);
+ notify(get_string('importfailed', 'grades'));
+ break 3;
+ }
// add this to grade_import_newitem table
// add the new id to $newgradeitem[$key]
}
$newgrade -> newgradeitem = $newgradeitems[$key];
$newgrade -> gradevalue = $value;
$newgrades[] = $newgrade;
- // if not, put it in
+ // if not, put it in
// else, insert grade into the table
break;
default:
// existing grade items
if (!empty($map[$header[$key]])) {
+ // non numeric grade value supplied, possibly mapped wrong column
+ if (!is_numeric($value)) {
+ $status = false;
+ import_cleanup($importcode);
+ notify(get_string('badgrade', 'grades'));
+ break 3;
+ }
+
// case of an id, only maps idnumber of a grade_item
include_once($CFG->libdir.'/grade/grade_item.php');
- $gradeitem = new grade_item(array('idnumber'=>$map[$header[$key]]));
+ if (!$gradeitem = new grade_item(array('idnumber'=>$map[$header[$key]]))) {
+ // supplied bad mapping, should not be possible since user
+ // had to pick mapping
+ $status = false;
+ import_cleanup($importcode);
+ notify(get_string('importfailed', 'grades'));
+ break 3;
+ }
+
unset($newgrade);
$newgrade -> itemid = $gradeitem->id;
$newgrade -> gradevalue = $value;
break;
}
}
-
+
+ // no user mapping supplied at all, or user mapping failed
if (empty($studentid) || !is_numeric($studentid)) {
// user not found, abort whold import
+ $status = false;
import_cleanup($importcode);
- error('user mapping error, could not find user!');
+ notify('user mapping error, could not find user!');
+ break;
}
// insert results of this students into buffer
foreach ($newgrades as $newgrade) {
$newgrade->import_code = $importcode;
$newgrade->userid = $studentid;
- insert_record('grade_import_values', $newgrade);
+ if (!insert_record('grade_import_values', $newgrade)) {
+ // could not insert into temporary table
+ $status = false;
+ import_cleanup($importcode);
+ notify(get_string('importfailed', 'grades'));
+ break 2;
+ }
}
}
}
/// at this stage if things are all ok, we commit the changes from temp table
- grade_import_commit($course->id, $importcode);
-
+ if ($status) {
+ grade_import_commit($course->id, $importcode);
+ }
// temporary file can go now
unlink($filename);
} else {
// course id needs to be passed for auth purposes
$mform->addElement('hidden', 'id', optional_param('id'));
- $mform->addElement('header', 'general', get_string('importfile'));
+ $mform->addElement('header', 'general', get_string('importfile', 'grades'));
// file upload
$mform->addElement('file', 'userfile', get_string('file'));
$mform->addRule('userfile', null, 'required');
$textlib = new textlib();
$encodings = $textlib->get_encodings();
- $mform->addElement('select', 'encoding', get_string('encoding'), $encodings);
+ $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
- $this->add_action_buttons(false, get_string('uploadgrades'));
+ $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
function get_userfile_name(){
// course id
$id = $this->_customdata['id'];
- $mform->addElement('header', 'general', get_string('identifier'));
+ $mform->addElement('header', 'general', get_string('identifier', 'grades'));
$mapfromoptions = array();
if ($header) {
$mapfromoptions[$h] = $h;
}
}
- $mform->addElement('select', 'mapfrom', get_string('mapfrom'), $mapfromoptions);
+ $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
//choose_from_menu($mapfromoptions, 'mapfrom');
$maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
//choose_from_menu($maptooptions, 'mapto');
- $mform->addElement('select', 'mapto', get_string('mapto'), $maptooptions);
+ $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
- $mform->addElement('header', 'general', get_string('mappings'));
+ $mform->addElement('header', 'general', get_string('mappings', 'grades'));
$gradeitems = array();
//echo '<input name="filename" value='.$newfilename.' type="hidden" />';
$mform->addElement('hidden', 'filename', $newfilename);
- $this->add_action_buttons(false, get_string('uploadgrades'));
+ $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
}
}
}
- notify(get_string('importsuccess'));
+ notify(get_string('importsuccess', 'grades'));
print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
// clean up
import_cleanup($importcode);
// no user found, abort
$status = false;
import_cleanup($importcode);
- notify(get_string('baduserid', 'grade'));
- notify(get_string('importfailed', 'grade'));
+ notify(get_string('baduserid', 'grades'));
+ notify(get_string('importfailed', 'grades'));
break;
}
if (!is_numeric($newgrade->gradevalue)) {
$status = false;
import_cleanup($importcode);
- notify(get_string('badgrade', 'grade'));
+ notify(get_string('badgrade', 'grades'));
break;
}
$status = false;
// could not insert into temp table
import_cleanup($importcode);
- notify(get_string('importfailed', 'grade'));
+ notify(get_string('importfailed', 'grades'));
break;
}
}
case 'exportxls':
case 'importcsv':
case 'importxml':
- $strcurpage = get_string($action);
+ $strcurpage = get_string($action, 'grades');
break;
default:
unset($strcurpage);
$string['allgrades'] = 'All grades by category';
$string['allstudents'] = 'All Students';
$string['average'] = 'Average';
+$string['badgrade'] = 'Supplied grade is invalid';
+$string['baduser'] = 'Supplied user is invalid';
$string['bonuspoints'] = 'Bonus Points';
$string['categories'] = 'Categories';
$string['category'] = 'Category';
$string['dropped'] = 'Dropped';
$string['dropxlowest'] = 'Drop X Lowest';
$string['dropxlowestwarning'] = 'Note: If you use drop x lowest the grading assumes that all items in the category have the same point value. If point values differ results will be unpredictable';
+$string['encoding'] = 'Encoding';
$string['errorgradevaluenonnumeric'] = 'Received non-numeric for low or high grade for';
$string['errornocategorizedid'] = 'Could not get an uncategorized id!';
$string['errornocourse'] = 'Could not get course information';
$string['errorreprintheadersnonnumeric'] = 'Received non-numeric value for reprint-headers';
$string['exceptions'] = 'Exceptions';
$string['excluded'] = 'Excluded';
+$string['exportods'] = 'Export ODS';
+$string['exporttxt'] = 'Export TXT';
+$string['exportxml'] = 'Export XML';
$string['extracredit'] = 'Extra Credit';
$string['extracreditwarning'] = 'Note: Setting all items for a category to extra credit will effectively remove them from the grade calculation. Since there will be no point total';
$string['forelementtypes'] = ' for the selected $a';
$string['gradehelp'] = 'Grade Help';
$string['gradeitem'] = 'Grade Item';
$string['gradeitemlocked'] = 'Grading locked';
+$string['gradeitemsinc'] = 'Grade items to be included';
$string['gradeitemaddusers'] = 'Exclude from Grading';
$string['gradeitemmembersselected'] = 'Excluded from Grading';
$string['gradeitemnonmembers'] = 'Included in Grading';
$string['highgradeascending'] = 'Sort by high grade ascending';
$string['highgradedescending'] = 'Sort by high grade descending';
$string['highgradeletter'] = 'High';
+$string['identifier'] = 'Identify user by';
+$string['importcsv'] = 'Import CSV';
+$string['importfailed'] = 'Import failed';
+$string['importfile'] = 'Import file';
+$string['importsuccess'] = 'Grade import success';
+$string['importxml'] = 'Import XML';
$string['incorrectcourseid'] = 'Course ID was incorrect';
$string['item'] = 'Item';
$string['items'] = 'Items';
$string['lock'] = 'Lock';
$string['lowest'] = 'Lowest';
$string['lowgradeletter'] = 'Low';
+$string['mapfrom'] = 'Map from';
+$string['mapto'] = 'Map to';
$string['max'] = 'Highest';
$string['maxgrade'] = 'Max Grade';
+$string['mappings'] = 'Grade item mappings';
$string['median'] = 'Median';
$string['min'] = 'Lowest';
$string['mode'] = 'Mode';
$string['savepreferences'] = 'Save Preferences';
$string['scaledpct'] = 'Scaled %%';
$string['selectdestination'] = 'Select destination of $a';
+$string['septab'] = 'Tab';
+$string['sepcomma'] = 'Comma';
+$string['separator'] = 'Separator';
$string['setcategories'] = 'Set Categories';
$string['setcategorieserror'] = 'You must first set the categories for your course before you can give weights to them.';
$string['setgradeletters'] = 'Set Grade Letters';
$string['totalweightnot100'] = 'The total weight is not equal to 100';
$string['uncategorised'] = 'Uncategorised';
$string['unlock'] = 'Unlock';
+$string['uploadgrades'] = 'Upload grades';
$string['useadvanced'] = 'Use Advanced Features';
$string['usepercent'] = 'Use Percent';
$string['useweighted'] = 'Use Weighted';