redirect_error(ERROR_COURSE_NONE); } $sections = $user->getTeamteachableSections(); if (!$sections) { redirect_error(ERROR_TEAMTEACH_MISSING); } $add_form = new teamteach_add_form(); $accept_form = new teamteach_accept_form(); $pending_form = new teamteach_pending_form(); $remove_form = new teamteach_remove_form(); $heading = null; if ($data = $add_form->get_data()) { try { // Process the validated data for adding a new team teaching entry $new_teamteach = new CoursePrefsTeamTeach($user->getId(), $add_form->section_selections, $add_form->secondary_teamteaches, 'todo', 1); $new_teamteach->save(); $heading = get_string('email_sent', 'block_courseprefs'); // Send off email informing primary teacher of foreign section of team teaching invitation teamteach_email($new_teamteach, $user); // Refresh add, pending, and remove forms due to new information $add_form = new teamteach_add_form(); $pending_form = new teamteach_pending_form(); $remove_form = new teamteach_remove_form(); } catch (Exception $ex) { $heading = get_string('changes_not_saved', 'block_courseprefs'); add_to_log(SITEID, 'courseprefs', 'update', 'blocks/courseprefs/teamteach.php', 'Unable to save teamteach object'); } } else { if ($data = $accept_form->get_data()) { // Prematurely set heading that the form submission was processed and necessary emails were sent $heading = get_string('email_sent', 'block_courseprefs');