Only try deleting the calendar events if the id is defined
Replace deprecated print_continue with $OUTPUT->continue_button
Drop trailing ?> tags everywhere
Use user_picture::fields everywhere possible instead of hardcoding the user name fields
Fix some inconsistencies in SQL requests building