groups_remove_member($answer_value_group_id, $USER->id);
                    $event = \mod_choicegroup\event\choice_removed::create($eventparams);
                    $event->add_record_snapshot('course_modules', $cm);
                    $event->add_record_snapshot('course', $course);
                    $event->add_record_snapshot('choicegroup', $choicegroup);
                    $event->trigger();
                }
            }
        }
    } else {
        // multipleenrollmentspossible != 1
        $timenow = time();
        if (has_capability('mod/choicegroup:deleteresponses', $context)) {
            if ($action == 'delete') {
                //some responses need to be deleted
                choicegroup_delete_responses($userids, $choicegroup, $cm, $course);
                //delete responses.
                redirect("view.php?id={$cm->id}");
            }
        }
        $answer = optional_param('answer', '', PARAM_INT);
        if (empty($answer)) {
            redirect("view.php?id={$cm->id}", get_string('mustchooseone', 'choicegroup'));
        } else {
            choicegroup_user_submit_response($answer, $choicegroup, $USER->id, $course, $cm);
        }
    }
    redirect("view.php?id={$cm->id}", get_string('choicegroupsaved', 'choicegroup'));
} else {
    echo $OUTPUT->header();
}
$strchoicegroup = get_string("modulename", "choicegroup");
$strchoicegroups = get_string("modulenameplural", "choicegroup");
$strresponses = get_string("responses", "choicegroup");

$eventparams = array(
    'context' => $context,
    'objectid' => $choicegroup->id
);
$event = \mod_choicegroup\event\report_viewed::create($eventparams);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('choicegroup', $choicegroup);
$event->trigger();

if (data_submitted() && $action == 'delete' && has_capability('mod/choicegroup:deleteresponses',$context) && confirm_sesskey()) {
    choicegroup_delete_responses($grpsmemberids, $choicegroup, $cm, $course); //delete responses.
    redirect("report.php?id=$cm->id");
}

if (!$download) {
    $PAGE->navbar->add($strresponses);
    $PAGE->set_title(format_string($choicegroup->name).": $strresponses");
    $PAGE->set_heading(format_string($course->fullname));
    echo $OUTPUT->header();
    /// Check to see if groups are being used in this choicegroup
    $groupmode = groups_get_activity_groupmode($cm);
    if ($groupmode) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choicegroup/report.php?id='.$id);
    }
} else {