Commit | Line | Data |
---|---|---|
e060e33d | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
8ad36f4c | 17 | |
e77bcaa3 | 18 | require_once '../../../config.php'; |
235b07fb | 19 | require_once $CFG->libdir.'/gradelib.php'; |
e77bcaa3 | 20 | require_once $CFG->dirroot.'/grade/lib.php'; |
21 | require_once '../grade_import_form.php'; | |
22 | require_once '../lib.php'; | |
b4355273 | 23 | |
c69b02bb | 24 | $id = required_param('id', PARAM_INT); // course id |
25 | $separator = optional_param('separator', '', PARAM_ALPHA); | |
26 | $verbosescales = optional_param('verbosescales', 1, PARAM_BOOL); | |
7f999ccb | 27 | |
a6855934 | 28 | $url = new moodle_url('/grade/import/csv/index.php', array('id'=>$id)); |
beebcf26 | 29 | if ($separator !== '') { |
30 | $url->param('separator', $separator); | |
31 | } | |
32 | if ($verbosescales !== 1) { | |
33 | $url->param('verbosescales', $verbosescales); | |
34 | } | |
35 | $PAGE->set_url($url); | |
36 | ||
233ae5a3 | 37 | define('GRADE_CSV_LINE_LENGTH', 4096); |
38 | ||
f400841b | 39 | if (!$course = $DB->get_record('course', array('id'=>$id))) { |
e77bcaa3 | 40 | print_error('nocourseid'); |
41 | } | |
42 | ||
43 | require_login($course); | |
44 | $context = get_context_instance(CONTEXT_COURSE, $id); | |
45 | require_capability('moodle/grade:import', $context); | |
46 | require_capability('gradeimport/csv:view', $context); | |
741bde47 | 47 | |
1dc9f2e2 | 48 | $separatemode = (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); |
49 | $currentgroup = groups_get_course_group($course); | |
50 | ||
741bde47 | 51 | // sort out delimiter |
7f999ccb | 52 | if (isset($CFG->CSV_DELIMITER)) { |
d5b36b40 | 53 | $csv_delimiter = $CFG->CSV_DELIMITER; |
7f999ccb | 54 | |
55 | if (isset($CFG->CSV_ENCODE)) { | |
56 | $csv_encode = '/\&\#' . $CFG->CSV_ENCODE . '/'; | |
57 | } | |
c69b02bb | 58 | } else if ($separator == 'tab') { |
59 | $csv_delimiter = "\t"; | |
c69b02bb | 60 | $csv_encode = ""; |
7f999ccb | 61 | } else { |
d5b36b40 | 62 | $csv_delimiter = ","; |
c69b02bb | 63 | $csv_encode = '/\&\#44/'; |
7f999ccb | 64 | } |
65 | ||
dc482cfa | 66 | print_grade_page_head($course->id, 'import', 'csv', get_string('importcsv', 'grades')); |
f0b9c95b | 67 | |
68 | // set up import form | |
c69b02bb | 69 | $mform = new grade_import_form(null, array('includeseparator'=>!isset($CFG->CSV_DELIMITER), 'verbosescales'=>true)); |
f0b9c95b | 70 | |
71 | // set up grade import mapping form | |
72 | $header = ''; | |
73 | $gradeitems = array(); | |
74 | if ($id) { | |
75 | if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) { | |
76 | foreach ($grade_items as $grade_item) { | |
77 | // skip course type and category type | |
78 | if ($grade_item->itemtype == 'course' || $grade_item->itemtype == 'category') { | |
79 | continue; | |
80 | } | |
81 | ||
99c228aa | 82 | $displaystring = null; |
83 | if (!empty($grade_item->itemmodule)) { | |
84 | $displaystring = get_string('modulename', $grade_item->itemmodule).': '.$grade_item->get_name(); | |
85 | } else { | |
86 | $displaystring = $grade_item->get_name(); | |
87 | } | |
88 | $gradeitems[$grade_item->id] = $displaystring; | |
f0b9c95b | 89 | } |
90 | } | |
91 | } | |
92 | ||
93 | if ($importcode = optional_param('importcode', '', PARAM_FILE)) { | |
94 | $filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode; | |
95 | $fp = fopen($filename, "r"); | |
e8aad16f | 96 | $headers = fgets($fp, GRADE_CSV_LINE_LENGTH); |
83e364c4 | 97 | $header = explode($csv_delimiter, $headers); |
99c228aa | 98 | fclose($fp); |
f0b9c95b | 99 | } |
100 | ||
101 | $mform2 = new grade_import_mapping_form(null, array('gradeitems'=>$gradeitems, 'header'=>$header)); | |
102 | ||
103 | // if import form is submitted | |
294ce987 | 104 | if ($formdata = $mform->get_data()) { |
f0b9c95b | 105 | |
106 | // Large files are likely to take their time and memory. Let PHP know | |
107 | // that we'll take longer, and that the process should be recycled soon | |
108 | // to free up memory. | |
109 | @set_time_limit(0); | |
346c5887 | 110 | raise_memory_limit(MEMORY_EXTRA); |
f0b9c95b | 111 | |
112 | // use current (non-conflicting) time stamp | |
113 | $importcode = get_new_importcode(); | |
71904f4d | 114 | $filename = make_upload_directory('temp/gradeimport/cvs/'.$USER->id); |
f0b9c95b | 115 | $filename = $filename.'/'.$importcode; |
116 | ||
117 | $text = $mform->get_file_content('userfile'); | |
118 | // trim utf-8 bom | |
119 | $textlib = textlib_get_instance(); | |
120 | /// normalize line endings and do the encoding conversion | |
121 | $text = $textlib->convert($text, $formdata->encoding); | |
122 | $text = $textlib->trim_utf8_bom($text); | |
123 | // Fix mac/dos newlines | |
124 | $text = preg_replace('!\r\n?!',"\n",$text); | |
125 | $fp = fopen($filename, "w"); | |
126 | fwrite($fp,$text); | |
127 | fclose($fp); | |
128 | ||
129 | $fp = fopen($filename, "r"); | |
130 | ||
131 | // --- get header (field names) --- | |
e8aad16f | 132 | $header = explode($csv_delimiter, fgets($fp, GRADE_CSV_LINE_LENGTH)); |
f0b9c95b | 133 | |
134 | // print some preview | |
135 | $numlines = 0; // 0 preview lines displayed | |
136 | ||
c018f973 | 137 | echo $OUTPUT->heading(get_string('importpreview', 'grades')); |
f0b9c95b | 138 | echo '<table>'; |
139 | echo '<tr>'; | |
140 | foreach ($header as $h) { | |
141 | $h = clean_param($h, PARAM_RAW); | |
142 | echo '<th>'.$h.'</th>'; | |
143 | } | |
144 | echo '</tr>'; | |
145 | while (!feof ($fp) && $numlines <= $formdata->previewrows) { | |
e8aad16f | 146 | $lines = explode($csv_delimiter, fgets($fp, GRADE_CSV_LINE_LENGTH)); |
f0b9c95b | 147 | echo '<tr>'; |
148 | foreach ($lines as $line) { | |
99c228aa | 149 | echo '<td>'.$line.'</td>'; |
f0b9c95b | 150 | } |
151 | $numlines ++; | |
152 | echo '</tr>'; | |
153 | } | |
154 | echo '</table>'; | |
155 | ||
156 | // display the mapping form with header info processed | |
157 | $mform2 = new grade_import_mapping_form(null, array('gradeitems'=>$gradeitems, 'header'=>$header)); | |
c69b02bb | 158 | $mform2->set_data(array('importcode'=>$importcode, 'id'=>$id, 'verbosescales'=>$verbosescales, 'separator'=>$separator)); |
f0b9c95b | 159 | $mform2->display(); |
160 | ||
294ce987 | 161 | //} else if (($formdata = data_submitted()) && !empty($formdata->map)) { |
d24832f9 | 162 | |
f0b9c95b | 163 | // else if grade import mapping form is submitted |
294ce987 | 164 | } else if ($formdata = $mform2->get_data()) { |
ba74762b | 165 | |
8108909a | 166 | $importcode = clean_param($formdata->importcode, PARAM_FILE); |
167 | $filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode; | |
168 | ||
169 | if (!file_exists($filename)) { | |
f39c16e0 | 170 | print_error('cannotuploadfile'); |
8108909a | 171 | } |
eff9c473 | 172 | |
b4355273 | 173 | if ($fp = fopen($filename, "r")) { |
174 | // --- get header (field names) --- | |
d5b36b40 | 175 | $header = explode($csv_delimiter, clean_param(fgets($fp,GRADE_CSV_LINE_LENGTH), PARAM_RAW)); |
ba74762b | 176 | |
b4355273 | 177 | foreach ($header as $i => $h) { |
178 | $h = trim($h); $header[$i] = $h; // remove whitespace | |
ba74762b | 179 | } |
b4355273 | 180 | } else { |
771dc7b2 | 181 | print_error('cannotopenfile'); |
b4355273 | 182 | } |
ba74762b | 183 | |
b263e539 | 184 | $map = array(); |
b4355273 | 185 | // loops mapping_0, mapping_1 .. mapping_n and construct $map array |
b263e539 | 186 | foreach ($header as $i => $head) { |
df2f5268 | 187 | if (isset($formdata->{'mapping_'.$i})) { |
188 | $map[$i] = $formdata->{'mapping_'.$i}; | |
189 | } | |
eff9c473 | 190 | } |
85e287de | 191 | |
6ef4878b | 192 | // if mapping information is supplied |
eff9c473 | 193 | $map[clean_param($formdata->mapfrom, PARAM_RAW)] = clean_param($formdata->mapto, PARAM_RAW); |
85e287de | 194 | |
ffe8ee55 | 195 | // check for mapto collisions |
196 | $maperrors = array(); | |
e8aad16f | 197 | foreach ($map as $i => $j) { |
ffe8ee55 | 198 | if ($j == 0) { |
199 | // you can have multiple ignores | |
ba74762b | 200 | continue; |
ffe8ee55 | 201 | } else { |
202 | if (!isset($maperrors[$j])) { | |
ba74762b | 203 | $maperrors[$j] = true; |
ffe8ee55 | 204 | } else { |
ba74762b | 205 | // collision |
ec69f4ab | 206 | fclose($fp); |
ffe8ee55 | 207 | unlink($filename); // needs to be uploaded again, sorry |
f39c16e0 | 208 | print_error('cannotmapfield', '', '', $j); |
ffe8ee55 | 209 | } |
210 | } | |
211 | } | |
212 | ||
3f8bcf7c | 213 | // Large files are likely to take their time and memory. Let PHP know |
214 | // that we'll take longer, and that the process should be recycled soon | |
215 | // to free up memory. | |
7f999ccb | 216 | @set_time_limit(0); |
346c5887 | 217 | raise_memory_limit(MEMORY_EXTRA); |
ba74762b | 218 | |
d9617050 | 219 | // we only operate if file is readable |
220 | if ($fp = fopen($filename, "r")) { | |
ba74762b | 221 | |
b4355273 | 222 | // read the first line makes sure this doesn't get read again |
e8aad16f | 223 | $header = explode($csv_delimiter, fgets($fp, GRADE_CSV_LINE_LENGTH)); |
ba74762b | 224 | |
b89ef1db | 225 | $newgradeitems = array(); // temporary array to keep track of what new headers are processed |
f115f8c8 | 226 | $status = true; |
ba74762b | 227 | |
d9617050 | 228 | while (!feof ($fp)) { |
229 | // add something | |
e8aad16f | 230 | $line = explode($csv_delimiter, fgets($fp, GRADE_CSV_LINE_LENGTH)); |
ba74762b | 231 | |
46decdf5 | 232 | if(count($line) <= 1){ |
233 | // there is no data on this line, move on | |
234 | continue; | |
235 | } | |
236 | ||
741bde47 | 237 | // array to hold all grades to be inserted |
b89ef1db | 238 | $newgrades = array(); |
b4355273 | 239 | // array to hold all feedback |
ba74762b | 240 | $newfeedbacks = array(); |
741bde47 | 241 | // each line is a student record |
ba74762b | 242 | foreach ($line as $key => $value) { |
d9617050 | 243 | //decode encoded commas |
eff9c473 | 244 | $value = clean_param($value, PARAM_RAW); |
c69b02bb | 245 | $value = trim($value); |
d5b36b40 JH |
246 | if (!empty($csv_encode)) { |
247 | $value = preg_replace($csv_encode, $csv_delimiter, $value); | |
c69b02bb | 248 | } |
eff9c473 | 249 | |
b4355273 | 250 | /* |
251 | * the options are | |
252 | * 1) userid, useridnumber, usermail, username - used to identify user row | |
253 | * 2) new - new grade item | |
254 | * 3) id - id of the old grade item to map onto | |
255 | * 3) feedback_id - feedback for grade item id | |
256 | */ | |
257 | ||
258 | $t = explode("_", $map[$key]); | |
259 | $t0 = $t[0]; | |
260 | if (isset($t[1])) { | |
8108909a | 261 | $t1 = (int)$t[1]; |
b4355273 | 262 | } else { |
ba74762b | 263 | $t1 = ''; |
b4355273 | 264 | } |
ba74762b | 265 | |
b4355273 | 266 | switch ($t0) { |
f115f8c8 | 267 | case 'userid': // |
5c75a0a3 | 268 | if (!$user = $DB->get_record('user', array('id' => $value))) { |
6ef4878b | 269 | // user not found, abort whole import |
f115f8c8 | 270 | import_cleanup($importcode); |
c3b834b4 | 271 | echo $OUTPUT->notification("user mapping error, could not find user with id \"$value\""); |
f115f8c8 | 272 | $status = false; |
ba74762b | 273 | break 3; |
f115f8c8 | 274 | } |
d9617050 | 275 | $studentid = $value; |
276 | break; | |
277 | case 'useridnumber': | |
5c75a0a3 | 278 | if (!$user = $DB->get_record('user', array('idnumber' => $value))) { |
6ef4878b | 279 | // user not found, abort whole import |
f115f8c8 | 280 | import_cleanup($importcode); |
c3b834b4 | 281 | echo $OUTPUT->notification("user mapping error, could not find user with idnumber \"$value\""); |
f115f8c8 | 282 | $status = false; |
ba74762b | 283 | break 3; |
f115f8c8 | 284 | } |
d9617050 | 285 | $studentid = $user->id; |
286 | break; | |
287 | case 'useremail': | |
5c75a0a3 | 288 | if (!$user = $DB->get_record('user', array('email' => $value))) { |
f115f8c8 | 289 | import_cleanup($importcode); |
c3b834b4 | 290 | echo $OUTPUT->notification("user mapping error, could not find user with email address \"$value\""); |
f115f8c8 | 291 | $status = false; |
ba74762b | 292 | break 3; |
f115f8c8 | 293 | } |
ba74762b | 294 | $studentid = $user->id; |
d9617050 | 295 | break; |
296 | case 'username': | |
5c75a0a3 | 297 | if (!$user = $DB->get_record('user', array('username' => $value))) { |
f115f8c8 | 298 | import_cleanup($importcode); |
c3b834b4 | 299 | echo $OUTPUT->notification("user mapping error, could not find user with username \"$value\""); |
f115f8c8 | 300 | $status = false; |
ba74762b | 301 | break 3; |
f115f8c8 | 302 | } |
d9617050 | 303 | $studentid = $user->id; |
304 | break; | |
b89ef1db | 305 | case 'new': |
306 | // first check if header is already in temp database | |
ba74762b | 307 | |
308 | if (empty($newgradeitems[$key])) { | |
309 | ||
ace9051c | 310 | $newgradeitem = new stdClass(); |
b89ef1db | 311 | $newgradeitem->itemname = $header[$key]; |
8108909a | 312 | $newgradeitem->importcode = $importcode; |
313 | $newgradeitem->importer = $USER->id; | |
ba74762b | 314 | |
df2f5268 | 315 | // insert into new grade item buffer |
a8f3a651 | 316 | $newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem); |
ba74762b | 317 | } |
ace9051c | 318 | $newgrade = new stdClass(); |
c22e335d | 319 | $newgrade->newgradeitem = $newgradeitems[$key]; |
e8aad16f SH |
320 | |
321 | // if the user has a grade for this grade item | |
322 | if (trim($value) != '-') { | |
323 | // instead of omitting the grade we could insert one with finalgrade set to 0 | |
324 | // we do not have access to grade item min grade | |
df2f5268 | 325 | $newgrade->finalgrade = $value; |
326 | $newgrades[] = $newgrade; | |
327 | } | |
b89ef1db | 328 | break; |
ffe8ee55 | 329 | case 'feedback': |
b4355273 | 330 | if ($t1) { |
8108909a | 331 | // case of an id, only maps id of a grade_item |
332 | // this was idnumber | |
333 | if (!$gradeitem = new grade_item(array('id'=>$t1, 'courseid'=>$course->id))) { | |
334 | // supplied bad mapping, should not be possible since user | |
335 | // had to pick mapping | |
336 | $status = false; | |
337 | import_cleanup($importcode); | |
c3b834b4 | 338 | echo $OUTPUT->notification(get_string('importfailed', 'grades')); |
8108909a | 339 | break 3; |
340 | } | |
341 | ||
b4355273 | 342 | // t1 is the id of the grade item |
ace9051c | 343 | $feedback = new stdClass(); |
c22e335d | 344 | $feedback->itemid = $t1; |
345 | $feedback->feedback = $value; | |
ffe8ee55 | 346 | $newfeedbacks[] = $feedback; |
b4355273 | 347 | } |
ba74762b | 348 | break; |
d9617050 | 349 | default: |
b89ef1db | 350 | // existing grade items |
8108909a | 351 | if (!empty($map[$key])) { |
ba74762b | 352 | // case of an id, only maps id of a grade_item |
b4355273 | 353 | // this was idnumber |
235b07fb | 354 | if (!$gradeitem = new grade_item(array('id'=>$map[$key], 'courseid'=>$course->id))) { |
f115f8c8 | 355 | // supplied bad mapping, should not be possible since user |
356 | // had to pick mapping | |
357 | $status = false; | |
358 | import_cleanup($importcode); | |
c3b834b4 | 359 | echo $OUTPUT->notification(get_string('importfailed', 'grades')); |
b263e539 | 360 | break 3; |
361 | } | |
ba74762b | 362 | |
b263e539 | 363 | // check if grade item is locked if so, abort |
8108909a | 364 | if ($gradeitem->is_locked()) { |
b263e539 | 365 | $status = false; |
366 | import_cleanup($importcode); | |
c3b834b4 | 367 | echo $OUTPUT->notification(get_string('gradeitemlocked', 'grades')); |
ba74762b | 368 | break 3; |
b4355273 | 369 | } |
370 | ||
ace9051c | 371 | $newgrade = new stdClass(); |
c22e335d | 372 | $newgrade->itemid = $gradeitem->id; |
c69b02bb | 373 | if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) { |
374 | if ($value === '' or $value == '-') { | |
375 | $value = null; // no grade | |
376 | } else { | |
377 | $scale = $gradeitem->load_scale(); | |
378 | $scales = explode(',', $scale->scale); | |
dc482cfa | 379 | $scales = array_map('trim', $scales); //hack - trim whitespace around scale options |
c69b02bb | 380 | array_unshift($scales, '-'); // scales start at key 1 |
381 | $key = array_search($value, $scales); | |
382 | if ($key === false) { | |
383 | echo "<br/>t0 is $t0"; | |
384 | echo "<br/>grade is $value"; | |
385 | $status = false; | |
386 | import_cleanup($importcode); | |
c3b834b4 | 387 | echo $OUTPUT->notification(get_string('badgrade', 'grades')); |
c69b02bb | 388 | break 3; |
389 | } | |
390 | $value = $key; | |
391 | } | |
392 | $newgrade->finalgrade = $value; | |
393 | } else { | |
394 | if ($value === '' or $value == '-') { | |
395 | $value = null; // no grade | |
dc482cfa | 396 | |
c69b02bb | 397 | } else if (!is_numeric($value)) { |
398 | // non numeric grade value supplied, possibly mapped wrong column | |
399 | echo "<br/>t0 is $t0"; | |
400 | echo "<br/>grade is $value"; | |
401 | $status = false; | |
402 | import_cleanup($importcode); | |
c3b834b4 | 403 | echo $OUTPUT->notification(get_string('badgrade', 'grades')); |
c69b02bb | 404 | break 3; |
405 | } | |
406 | $newgrade->finalgrade = $value; | |
407 | } | |
b89ef1db | 408 | $newgrades[] = $newgrade; |
ba74762b | 409 | } // otherwise, we ignore this column altogether |
741bde47 | 410 | // because user has chosen to ignore them (e.g. institution, address etc) |
b263e539 | 411 | break; |
d9617050 | 412 | } |
7f999ccb | 413 | } |
b4355273 | 414 | |
f115f8c8 | 415 | // no user mapping supplied at all, or user mapping failed |
ce40b793 | 416 | if (empty($studentid) || !is_numeric($studentid)) { |
6ef4878b | 417 | // user not found, abort whole import |
f115f8c8 | 418 | $status = false; |
ce40b793 | 419 | import_cleanup($importcode); |
c3b834b4 | 420 | echo $OUTPUT->notification('user mapping error, could not find user!'); |
b263e539 | 421 | break; |
ce40b793 | 422 | } |
b4355273 | 423 | |
1dc9f2e2 | 424 | if ($separatemode and !groups_is_member($currentgroup, $studentid)) { |
425 | // not allowed to import into this group, abort | |
426 | $status = false; | |
427 | import_cleanup($importcode); | |
c3b834b4 | 428 | echo $OUTPUT->notification('user not member of current group, can not update!'); |
1dc9f2e2 | 429 | break; |
430 | } | |
431 | ||
b89ef1db | 432 | // insert results of this students into buffer |
8108909a | 433 | if ($status and !empty($newgrades)) { |
ba74762b | 434 | |
b89ef1db | 435 | foreach ($newgrades as $newgrade) { |
ba74762b | 436 | |
3ee5c201 | 437 | // check if grade_grade is locked and if so, abort |
8108909a | 438 | if (!empty($newgrade->itemid) and $grade_grade = new grade_grade(array('itemid'=>$newgrade->itemid, 'userid'=>$studentid))) { |
439 | if ($grade_grade->is_locked()) { | |
b263e539 | 440 | // individual grade locked |
441 | $status = false; | |
442 | import_cleanup($importcode); | |
c3b834b4 | 443 | echo $OUTPUT->notification(get_string('gradelocked', 'grades')); |
b263e539 | 444 | break 2; |
445 | } | |
446 | } | |
447 | ||
8108909a | 448 | $newgrade->importcode = $importcode; |
449 | $newgrade->userid = $studentid; | |
450 | $newgrade->importer = $USER->id; | |
fc29e51b | 451 | $DB->insert_record('grade_import_values', $newgrade); |
b89ef1db | 452 | } |
85e287de | 453 | } |
b4355273 | 454 | |
455 | // updating/inserting all comments here | |
8108909a | 456 | if ($status and !empty($newfeedbacks)) { |
b4355273 | 457 | foreach ($newfeedbacks as $newfeedback) { |
8108909a | 458 | $sql = "SELECT * |
d24832f9 | 459 | FROM {grade_import_values} |
5c75a0a3 | 460 | WHERE importcode=? AND userid=? AND itemid=? AND importer=?"; |
461 | if ($feedback = $DB->get_record_sql($sql, array($importcode, $studentid, $newfeedback->itemid, $USER->id))) { | |
8108909a | 462 | $newfeedback->id = $feedback->id; |
5c75a0a3 | 463 | $DB->update_record('grade_import_values', $newfeedback); |
8108909a | 464 | |
b4355273 | 465 | } else { |
466 | // the grade item for this is not updated | |
8108909a | 467 | $newfeedback->importcode = $importcode; |
468 | $newfeedback->userid = $studentid; | |
469 | $newfeedback->importer = $USER->id; | |
5c75a0a3 | 470 | $DB->insert_record('grade_import_values', $newfeedback); |
b4355273 | 471 | } |
472 | } | |
473 | } | |
7f999ccb | 474 | } |
b4355273 | 475 | |
ba74762b | 476 | /// at this stage if things are all ok, we commit the changes from temp table |
f115f8c8 | 477 | if ($status) { |
478 | grade_import_commit($course->id, $importcode); | |
479 | } | |
d9617050 | 480 | // temporary file can go now |
ec69f4ab | 481 | fclose($fp); |
d9617050 | 482 | unlink($filename); |
483 | } else { | |
9d555b44 | 484 | print_error('cannotreadfile'); |
85e287de | 485 | } |
d9617050 | 486 | |
7f999ccb | 487 | } else { |
1dc9f2e2 | 488 | groups_print_course_menu($course, 'index.php?id='.$id); |
489 | echo '<div class="clearer"></div>'; | |
490 | ||
741bde47 | 491 | // display the standard upload file form |
7f999ccb | 492 | $mform->display(); |
493 | } | |
b4355273 | 494 | |
5a931394 | 495 | echo $OUTPUT->footer(); |
6c3ef410 | 496 |