function webauto_test_passed($grade, $url) { global $USER, $OUTPUT; success_out("Test passed - congratulations"); if ($USER->displayname === false || !isset($_SESSION['lti'])) { line_out('Not setup to return a grade..'); return false; } $LTI = $_SESSION['lti']; $old_grade = isset($LTI['grade']) ? $LTI['grade'] : 0.0; if ($grade < $old_grade) { line_out('New grade is not higher than your previous grade=' . $old_grade); line_out('Sending your previous high score'); $grade = $old_grade; } gradeUpdateJson(json_encode(array("url" => $url))); $debug_log = array(); $retval = LTIX::gradeSend($grade, false, $debug_log); $OUTPUT->dumpDebugArray($debug_log); if ($retval == true) { $success = "Grade sent to server (" . $grade . ")"; } else { if (is_string($retval)) { $failure = "Grade not sent: " . $retval; } else { echo "<pre>\n"; var_dump($retval); echo "</pre>\n"; $failure = "Internal error"; } } if (strlen($success) > 0) { success_out($success); error_log($success); } else { if (strlen($failure) > 0) { error_out($failure); error_log($failure); } else { error_log("No status"); } } return true; }
use Tsugi\Util\LTI; use Tsugi\Util\Caliper; // Retrieve the launch data if present $LTI = LTIX::requireData(); $p = $CFG->dbprefix; $displayname = $USER->displayname; if (isset($_POST['grade'])) { $gradetosend = $_POST['grade'] + 0.0; if ($gradetosend < 0.0 || $gradetosend > 1.0) { $_SESSION['error'] = "Grade out of range"; header('Location: ' . addSession('index.php')); return; } // Use LTIX to send the grade back to the LMS. $debug_log = array(); $retval = LTIX::gradeSend($gradetosend, false, $debug_log); $_SESSION['debug_log'] = $debug_log; if ($retval === true) { $_SESSION['success'] = "Grade {$gradetosend} sent to server."; } else { if (is_string($retval)) { $_SESSION['error'] = "Grade not sent: " . $retval; } else { echo "<pre>\n"; var_dump($retval); echo "</pre>\n"; die; } } // Redirect to ourself header('Location: ' . addSession('index.php'));
} else { if ($server_grade > 0.0) { $newrow['note'] .= ' Server grade retrieved.'; } else { $newrow['note'] .= ' Server grade checked.'; } } $row['server_grade'] = $server_grade; $newrow['retrieved_at'] = $row['time_now']; $row['retrieved_at'] = $row['time_now']; } // Now check to see if we need to update the server_grade if ($row['server_grade'] < $row['grade']) { error_log("Patching server grade: " . session_id() . " result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at']); $debug_log = array(); $status = LTIX::gradeSend($row['grade'], $row, $debug_log); if ($status === true) { $newrow['note'] .= " Server grade updated."; } else { echo '<pre class="alert alert-danger">' . "\n"; $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at'] . "\n" . "error=" . $server_grade; echo "Problem Updating Grade: " . session_safe_id() . " " . $msg; error_log("Problem Updating Grade: " . session_id() . "\n" . $msg . "\n" . "service=" . $row['service'] . " sourcedid=" . $row['sourcedid']); echo "\nProblem Retrieving Grade - Please take a screen shot of this page.\n"; echo "</pre>\n"; $newrow['note'] .= " Problem Updating Server Grade"; } } $newrows[] = $newrow; } Table::pagedTable($newrows, $searchfields);
function webauto_test_passed($grade, $url) { global $displayname; global $OUTPUT; success_out("Test passed - congratulations"); if ($displayname === false || !isset($_SESSION['lti'])) { line_out('Not setup to return a grade..'); exit; } if (!isset($_GET['grade'])) { line_out('Dry run - grade of (' . intval($grade * 100) . '%) was not sent.'); exit; } gradeUpdateJson(json_encode(array("url" => $url))); $debug_log = array(); $retval = LTIX::gradeSend($grade, false, $debug_log); $OUTPUT->dumpDebugArray($debug_log); if ($retval == true) { $success = "Grade sent to server (" . intval($grade * 100) . "%)"; } else { if (is_string($retval)) { $failure = "Grade not sent: " . $retval; } else { echo "<pre>\n"; var_dump($retval); echo "</pre>\n"; $failure = "Internal error"; } } if (strlen($success) > 0) { success_out($success); error_log($success); } else { if (strlen($failure) > 0) { error_out($failure); error_log($failure); } else { error_log("No status"); } } }
$assn_json = json_decode($row['json']); $assn_id = $row['assn_id']; } if ($assn_id == false) { jsonError('This assignment is not yet set up'); return; } // Compute the user's grade $grade = computeGrade($assn_id, $assn_json, $user_id); if ($grade <= 0) { jsonError('Nothing to grade for this user', $row); return; } // Lookup the result row if we are grading the non-current user $result = false; if ($user_id != $USER->id) { $result = lookupResult($LTI, $user_id); } // Send the grade $debug_log = array(); $status = LTIX::gradeSend($grade, $result, $debug_log); // This is the slow bit if ($status === true) { if ($user_id != $USER->id) { jsonOutput(array("status" => $status, "debug" => $debug_log)); } else { jsonOutput(array("status" => $status, "grade" => $grade, "debug" => $debug_log)); } } else { jsonError($status, $debug_log); }
header('Location: ' . addSession('student.php?user_id=' . $user_id)); } return; } // Compute grade $computed_grade = computeGrade($assn_id, $assn_json, $user_id); // Does not cache if (isset($_POST['resendSubmit'])) { $result = lookupResult($LTI, $user_id); // Does not cache // Force a resend $_SESSION['lti']['grade'] = -1; // Force a resend $result['grade'] = -1; $debug_log = array(); $status = LTIX::gradeSend($computed_grade, $result, $debug_log); // This is the slow bit if ($status === true) { $_SESSION['success'] = 'Grade submitted to server'; } else { error_log("Problem sending grade " . $status); $_SESSION['error'] = 'Error: ' . $status; } $_SESSION['debug_log'] = $debug_log; header('Location: ' . addSession('student.php?user_id=' . $user_id)); return; } // Retrieve our grades... $grades_received = retrieveSubmissionGrades($submit_id); // Handle incoming post to delete a grade entry if (isset($_POST['grade_id']) && isset($_POST['deleteGrade'])) {
} unset($_SESSION['peer_submit_id']); $submit_id = $_POST['submit_id'] + 0; $stmt = $PDOX->queryReturnError("INSERT INTO {$p}peer_grade\n (submit_id, user_id, points, note, created_at, updated_at)\n VALUES ( :SID, :UID, :POINTS, :NOTE, NOW(), NOW())\n ON DUPLICATE KEY UPDATE points = :POINTS, note = :NOTE, updated_at = NOW()", array(':SID' => $submit_id, ':UID' => $USER->id, ':POINTS' => $points, ':NOTE' => $_POST['note'])); Cache::clear('peer_grade'); if (!$stmt->success) { $_SESSION['error'] = $stmt->errorImplode; header('Location: ' . addSession($url_goback)); return; } // Attempt to update the user's grade, may take a second.. $grade = computeGrade($assn_id, $assn_json, $user_id); $_SESSION['success'] = 'Grade submitted'; if ($grade > 0) { $result = lookupResult($LTI, $user_id); $status = LTIX::gradeSend($grade, $result); // This is the slow bit if ($status === true) { $_SESSION['success'] = 'Grade submitted to server'; } else { error_log("Problem sending grade " . $status); } } header('Location: ' . addSession($url_goback)); return; } unset($_SESSION['peer_submit_id']); $submit_id = false; $submit_json = null; if ($user_id === false) { // Load the the 10 oldest ungraded submissions
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $computed_grade = computeGrade($assn_id, $assn_json, $row['user_id']); $s2 = $PDOX->queryDie("UPDATE {$CFG->dbprefix}peer_submit SET regrade=1\n WHERE submit_id = :SID", array(":SID" => $row['submit_id'])); if ($row['grade'] >= $computed_grade) { echo htmlent_utf8($row['displayname']) . ' (' . htmlent_utf8($row['email']) . ') '; if ($row['grade'] > $computed_grade) { echo 'grade=' . $row['grade'] . ' computed=' . $computed_grade . " (unchanged)<br/>\n"; } else { echo 'grade=' . $row['grade'] . " (matched)<br/>\n"; } $unchanged++; continue; } $s2 = $PDOX->queryDie("UPDATE {$CFG->dbprefix}lti_result\n SET grade=:GRA, updated_at=NOW()\n WHERE result_id = :RID", array(":GRA" => $computed_grade, ":RID" => $row['result_id'])); // Send the grade to the server $status = LTIX::gradeSend($computed_grade, $row); // This is the slow bit if ($status === true) { echo htmlent_utf8($row['displayname']) . ' (' . htmlent_utf8($row['email']) . ') '; echo "Grade {$computed_grade} submitted to server<br/>\n"; $changed++; } else { echo '<pre class="alert alert-danger">' . "\n"; $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " computed_grade=" . $computed_grade . "\n" . "error=" . $status; echo_log("Problem Sending Grade: " . session_id() . "\n" . $msg . "\n" . "result_url=" . $row['result_url'] . " service_key=" . $row['service_key'] . " sourcedid=" . $row['sourcedid']); echo "</pre>\n"; $OUTPUT->togglePre("Error sending grade", $LastPOXGradeResponse); flush(); echo "Problem sending grade " . $status . "<br/>\n"; $fail++; continue;