$cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST);
    if ($CFG->version < '2014051200') {
        //This is valid before v2.7
        add_to_log($course->id, 'bigbluebuttonbn', 'meeting ended', "index.php?id={$course->id}", '');
    } else {
        //This is valid before v2.7
        $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_ended::create(array('context' => $context, 'objectid' => $bigbluebuttonbn->id));
        $event->trigger();
    }
    echo get_string('index_ending', 'bigbluebuttonbn');
    $meetingID = $bigbluebuttonbn->meetingid . '-' . $course->id . '-' . $bigbluebuttonbn->id;
    $modPW = $bigbluebuttonbn->moderatorpass;
    if ($g != '0') {
        $getArray = bigbluebuttonbn_wrap_simplexml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID . '[' . $g . ']', $modPW, $url, $salt));
    } else {
        $getArray = bigbluebuttonbn_wrap_simplexml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID, $modPW, $url, $salt));
    }
    redirect('index.php?id=' . $id);
} else {
    if ($CFG->version < '2014051200') {
        //This is valid before v2.7
        add_to_log($course->id, 'bigbluebuttonbn', 'activity management viewed', "index.php?id={$course->id}", '');
    } else {
        //This is valid after v2.7
        $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_activity_management_viewed::create(array('context' => $context));
        $event->trigger();
    }
}
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
    $cm = get_coursemodule_from_id('bigbluebuttonbn', $bigbluebuttonbn->coursemodule, 0, false, MUST_EXIST);
    if (groups_get_activity_groupmode($cm) > 0) {
function bigbluebuttonbn_doEndMeeting($meetingID, $modPW, $URL, $SALT)
{
    $xml = bigbluebuttonbn_wrap_simplexml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID, $modPW, $URL, $SALT));
    if ($xml) {
        //If the xml packet returned failure it displays the message to the user
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
    } else {
        //If the server is unreachable, then prompts the user of the necessary action
        return null;
    }
}
    if ($bigbluebuttonbn->participants == null || $bigbluebuttonbn->participants == "" || $bigbluebuttonbn->participants == "[]") {
        //The room that is being used comes from a previous version
        $moderator = has_capability('mod/bigbluebuttonbn:moderate', $context);
    } else {
        $moderator = bigbluebuttonbn_is_moderator($USER->id, get_user_roles($context, $USER->id, true), $bigbluebuttonbn->participants);
    }
    $administrator = has_capability('moodle/category:manage', $context);
    if ($moderator || $administrator) {
        bigbluebuttonbn_event_log(BIGBLUEBUTTON_EVENT_MEETING_ENDED, $bigbluebuttonbn, $context, $cm);
        echo get_string('index_ending', 'bigbluebuttonbn');
        $meetingID = $bigbluebuttonbn->meetingid . '-' . $course->id . '-' . $bigbluebuttonbn->id;
        $modPW = $bigbluebuttonbn->moderatorpass;
        if ($g != '0') {
            $getArray = bigbluebuttonbn_wrap_xml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID . '[' . $g . ']', $modPW, $endpoint, $shared_secret));
        } else {
            $getArray = bigbluebuttonbn_wrap_xml_load_file(bigbluebuttonbn_getEndMeetingURL($meetingID, $modPW, $endpoint, $shared_secret));
        }
        redirect('index.php?id=' . $id);
    }
}
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
    $cm = get_coursemodule_from_id('bigbluebuttonbn', $bigbluebuttonbn->coursemodule, 0, false, MUST_EXIST);
    //User roles
    if ($bigbluebuttonbn->participants == null || $bigbluebuttonbn->participants == "" || $bigbluebuttonbn->participants == "[]") {
        //The room that is being used comes from a previous version
        $moderator = has_capability('mod/bigbluebuttonbn:moderate', $context);
    } else {
        $moderator = bigbluebuttonbn_is_moderator($USER->id, get_user_roles($context, $USER->id, true), $bigbluebuttonbn->participants);
    }
    $administrator = has_capability('moodle/category:manage', $context);
    if (groups_get_activity_groupmode($cm) > 0) {