groups_get_activity_group($cm, true);
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choicegroup/view.php?id=' . $id);
}
$allresponses = choicegroup_get_response_data($choicegroup, $cm);
// Big function, approx 6 SQL calls per user
if (has_capability('mod/choicegroup:readresponses', $context)) {
    choicegroup_show_reportlink($choicegroup, $allresponses, $cm);
}
echo '<div class="clearer"></div>';
if ($choicegroup->intro) {
    echo $OUTPUT->box(format_module_intro('choicegroup', $choicegroup, $cm->id), 'generalbox', 'intro');
}
//if user has already made a selection, and they are not allowed to update it, show their selected answer.
if (isloggedin() && $current !== false) {
    if ($choicegroup->multipleenrollmentspossible == 1) {
        $currents = choicegroup_get_user_answer($choicegroup, $USER, TRUE);
        $names = array();
        foreach ($currents as $current) {
            $names[] = format_string($current->name);
        }
        $formatted_names = join(' ' . get_string("and", "choicegroup") . ' ', array_filter(array_merge(array(join(', ', array_slice($names, 0, -1))), array_slice($names, -1))));
        echo $OUTPUT->box(get_string("yourselection", "choicegroup", userdate($choicegroup->timeopen)) . ": " . $formatted_names, 'generalbox', 'yourselection');
    } else {
        echo $OUTPUT->box(get_string("yourselection", "choicegroup", userdate($choicegroup->timeopen)) . ": " . format_string($current->name), 'generalbox', 'yourselection');
    }
}
/// Print the form
$choicegroupopen = true;
$timenow = time();
if ($choicegroup->timeclose != 0) {
    if ($choicegroup->timeopen > $timenow) {
/**
 * Obtains the automatic completion state for this choicegroup based on any conditions
 * in forum settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not, $type if conditions not set.
 */
function choicegroup_get_completion_state($course, $cm, $userid, $type)
{
    global $DB;
    // Get choicegroup details
    $choicegroup = $DB->get_record('choicegroup', array('id' => $cm->instance), '*', MUST_EXIST);
    // If completion option is enabled, evaluate it and return true/false
    if ($choicegroup->completionsubmit) {
        $useranswer = choicegroup_get_user_answer($choicegroup, $userid);
        return $useranswer !== false;
    } else {
        // Completion option is not enabled so just return $type
        return $type;
    }
}
if ($usesections) {
    $modinfo = get_fast_modinfo($course->id);
    $sections = $modinfo->get_section_info_all();
}
$table = new html_table();
if ($usesections) {
    $table->head = array($strsectionname, get_string("question"), get_string("answer"));
    $table->align = array("center", "left", "left");
} else {
    $table->head = array(get_string("question"), get_string("answer"));
    $table->align = array("left", "left");
}
$currentsection = "";
foreach ($choicegroups as $choicegroup) {
    $choicegroup_groups = choicegroup_get_groups($choicegroup);
    $answer = choicegroup_get_user_answer($choicegroup, $USER->id);
    if (!empty($answer->id)) {
        $aa = $answer->name;
    } else {
        $aa = "";
    }
    if ($usesections) {
        $printsection = "";
        if ($choicegroup->section !== $currentsection) {
            if ($choicegroup->section) {
                $printsection = get_section_name($course, $sections[$choicegroup->section]);
            }
            if ($currentsection !== "") {
                $table->data[] = 'hr';
            }
            $currentsection = $choicegroup->section;