diff --git a/attendance.php b/attendance.php index 3104624..8f6bdcd 100644 --- a/attendance.php +++ b/attendance.php @@ -54,7 +54,7 @@ if ($attforsession->rotateqrcode == 1) { // Check the token. if ($secrethash !== $_COOKIE[$cookiename]) { // Flag error. - print_error('qr_cookie_error', 'mod_attendance', $url); + throw new moodle_exception('qr_cookie_error', 'mod_attendance', $url); } } else { // Check password. @@ -73,7 +73,7 @@ if ($attforsession->rotateqrcode == 1) { setcookie($cookiename, $secrethash, time() + (60 * 5), "/"); } else { // Flag error. - print_error('qr_pass_wrong', 'mod_attendance', $url); + throw new moodle_exception('qr_pass_wrong', 'mod_attendance', $url); } } } @@ -103,7 +103,7 @@ if ($attforsession->autoassignstatus && (empty($attforsession->studentpassword)) $statusid = attendance_session_get_highest_status($att, $attforsession); $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); if (empty($statusid)) { - print_error('attendance_no_status', 'mod_attendance', $url); + throw new moodle_exception('attendance_no_status', 'mod_attendance', $url); } $take = new stdClass(); $take->status = $statusid; @@ -114,7 +114,7 @@ if ($attforsession->autoassignstatus && (empty($attforsession->studentpassword)) // Redirect back to the view page. redirect($url, get_string('studentmarked', 'attendance')); } else { - print_error('attendance_already_submitted', 'mod_attendance', $url); + throw new moodle_exception('attendance_already_submitted', 'mod_attendance', $url); } } @@ -136,7 +136,7 @@ if (!empty($qrpass) && !empty($attforsession->autoassignstatus)) { $fromform->status = attendance_session_get_highest_status($att, $attforsession); if (empty($fromform->status)) { $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); - print_error('attendance_no_status', 'mod_attendance', $url); + throw new moodle_exception('attendance_no_status', 'mod_attendance', $url); } if (!empty($fromform->status)) { @@ -147,7 +147,7 @@ if (!empty($qrpass) && !empty($attforsession->autoassignstatus)) { // Redirect back to the view page. redirect($url, get_string('studentmarked', 'attendance')); } else { - print_error('attendance_already_submitted', 'mod_attendance', $url); + throw new moodle_exception('attendance_already_submitted', 'mod_attendance', $url); } } } @@ -181,7 +181,7 @@ if ($mform->is_cancelled()) { $fromform->status = attendance_session_get_highest_status($att, $attforsession); if (empty($fromform->status)) { $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); - print_error('attendance_no_status', 'mod_attendance', $url); + throw new moodle_exception('attendance_no_status', 'mod_attendance', $url); } } @@ -193,7 +193,7 @@ if ($mform->is_cancelled()) { // Redirect back to the view page. redirect($url, get_string('studentmarked', 'attendance')); } else { - print_error('attendance_already_submitted', 'mod_attendance', $url); + throw new moodle_exception('attendance_already_submitted', 'mod_attendance', $url); } } diff --git a/classes/structure.php b/classes/structure.php index c5d349f..839bd33 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -550,7 +550,7 @@ class mod_attendance_structure { global $DB; if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) { - print_error('No such session in this course'); + throw new moodle_exception('No such session in this course'); } $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS; @@ -720,7 +720,7 @@ class mod_attendance_structure { if (substr($key, 0, 7) == 'remarks') { $sid = substr($key, 7); if (!(is_numeric($sid))) { // Sanity check on $sid. - print_error('nonnumericid', 'attendance'); + throw new moodle_exception('nonnumericid', 'attendance'); } $sesslog[$sid] = new stdClass(); $sesslog[$sid]->studentid = $sid; // We check is_numeric on this above. diff --git a/db/upgrade.php b/db/upgrade.php index 2ea545d..d3f1c16 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -650,6 +650,5 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2021050700, 'attendance'); } - return $result; } diff --git a/export.php b/export.php index 24b7a7c..458dbc7 100644 --- a/export.php +++ b/export.php @@ -132,7 +132,7 @@ if ($formdata = $mform->get_data()) { } } } else { - print_error('sessionsnotfound', 'attendance', $att->url_manage()); + throw new moodle_exception('sessionsnotfound', 'mod_attendance', $att->url_manage()); } $setnumber = -1; @@ -207,7 +207,7 @@ if ($formdata = $mform->get_data()) { } exit; } else { - print_error('studentsnotfound', 'attendance', $att->url_manage()); + throw new moodle_exception('studentsnotfound', 'mod_attendance', $att->url_manage()); } } diff --git a/messageselect.php b/messageselect.php index 99d712a..d22075e 100644 --- a/messageselect.php +++ b/messageselect.php @@ -56,9 +56,8 @@ if (!empty($messagebody['text'])) { $messagebody = $messagebody['text']; } $PAGE->set_url($url); -if (!$course = $DB->get_record('course', array('id' => $id))) { - print_error('invalidcourseid'); -} +$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); + require_login($course); $coursecontext = context_course::instance($id); // Course context. $systemcontext = context_system::instance(); // SYSTEM context. diff --git a/preferences.php b/preferences.php index fe3e21a..12e0921 100644 --- a/preferences.php +++ b/preferences.php @@ -93,7 +93,7 @@ switch ($att->pageparams->action) { break; case mod_attendance_preferences_page_params::ACTION_DELETE: if (attendance_has_logs_for_status($att->pageparams->statusid)) { - print_error('cantdeletestatus', 'attendance', "attsettings.php?id=$id"); + throw new moodle_exception('cantdeletestatus', 'attendance', "attsettings.php?id=$id"); } $confirm = optional_param('confirm', null, PARAM_INT); diff --git a/renderables.php b/renderables.php index 3a5b9ca..5bd7645 100644 --- a/renderables.php +++ b/renderables.php @@ -583,11 +583,11 @@ class attendance_user_data implements renderable { $parts = explode('sess', substr($key, 7)); $stid = $parts[0]; if (!(is_numeric($stid))) { // Sanity check on $stid. - print_error('nonnumericid', 'attendance'); + throw new moodle_exception('nonnumericid', 'attendance'); } $sessid = $parts[1]; if (!(is_numeric($sessid))) { // Sanity check on $sessid. - print_error('nonnumericid', 'attendance'); + throw new moodle_exception('nonnumericid', 'attendance'); } $dbsession = $this->sessionslog[$sessid]; diff --git a/sessions.php b/sessions.php index 091c7bb..a68c8ef 100644 --- a/sessions.php +++ b/sessions.php @@ -148,7 +148,7 @@ switch ($att->pageparams->action) { } $sessid = optional_param_array('sessid', '', PARAM_SEQUENCE); if (empty($sessid)) { - print_error('nosessionsselected', 'attendance', $att->url_manage()); + throw new moodle_exception('nosessionsselected', 'mod_attendance', $att->url_manage()); } $sessionsinfo = $att->get_sessions_info($sessid); @@ -191,7 +191,7 @@ switch ($att->pageparams->action) { } if ($slist === '') { - print_error('nosessionsselected', 'attendance', $att->url_manage()); + throw new moodle_exception('nosessionsselected', 'mod_attendance', $att->url_manage()); } break; diff --git a/warnings.php b/warnings.php index bfb1ab8..a4f8bff 100644 --- a/warnings.php +++ b/warnings.php @@ -107,7 +107,7 @@ if ($data = $mform->get_data()) { $notify = $DB->get_record('attendance_warning', array('id' => $data->notid)); if (!empty($id) && $data->idnumber != $att->id) { // Someone is trying to update a record for a different attendance. - print_error('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); } else { $notify = new stdClass(); $notify->id = $data->notid;