bigbluebutton_bbb_view_close_window_manually();
         }
     }
     break;
 case 'join':
     if (isset($bbbsession) && !is_null($bbbsession)) {
         //See if the session is in progress
         if (bigbluebuttonbn_isMeetingRunning($bbbsession['meetingid'], $bbbsession['endpoint'], $bbbsession['shared_secret'])) {
             /// Since the meeting is already running, we just join the session
             bigbluebutton_bbb_view_execute_join($bbbsession, $cm, $context, $bigbluebuttonbn);
         } else {
             // If user is administrator, moderator or if is viewer and no waiting is required
             if ($bbbsession['administrator'] || $bbbsession['moderator'] || !$bbbsession['wait']) {
                 /// Prepare the metadata
                 $metadata = array("meta_bn-origin" => $bbbsession['origin'], "meta_bbb-origin-version" => $bbbsession['originVersion'], "meta_bbb-origin-server-name" => $bbbsession['originServerName'], "meta_bbb-origin-server-common-name" => $bbbsession['originServerCommonName'], "meta_bbb-origin-tag" => $bbbsession['originTag'], "meta_bbb-context" => $bbbsession['course']->fullname, "meta_bbb-recording-name" => isset($name) && $name != '' ? $name : $bbbsession['contextActivityName'], "meta_bbb-recording-description" => isset($description) && $description != '' ? $description : $bbbsession['contextActivityDescription'], "meta_bbb-recording-tags" => isset($tags) && $tags != '' ? $tags : $bbbsession['contextActivityTags']);
                 if (bigbluebuttonbn_server_offers_bn_capabilities() && bigbluebuttonbn_get_cfg_recordingready_enabled()) {
                     $metadata["meta_bn-recording-ready-url"] = $bbbsession['recordingReadyURL'];
                 }
                 /// Set the duration for the meeting
                 if (bigbluebuttonbn_get_cfg_scheduled_duration_enabled()) {
                     $durationtime = bigbluebuttonbn_get_duration($bigbluebuttonbn->openingtime, $bigbluebuttonbn->closingtime);
                     if ($durationtime > 0) {
                         $bbbsession['welcome'] .= '<br><br>' . str_replace("%duration%", '' . $durationtime, get_string('bbbdurationwarning', 'bigbluebuttonbn'));
                     }
                 } else {
                     $durationtime = 0;
                 }
                 /// Execute the create command
                 $response = bigbluebuttonbn_getCreateMeetingArray($bbbsession['meetingname'], $bbbsession['meetingid'], $bbbsession['welcome'], $bbbsession['modPW'], $bbbsession['viewerPW'], $bbbsession['shared_secret'], $bbbsession['endpoint'], $bbbsession['logoutURL'], $bbbsession['record'] ? 'true' : 'false', $durationtime, $bbbsession['voicebridge'], $bbbsession['userlimit'], $metadata, $bbbsession['presentation']['name'], $bbbsession['presentation']['url']);
                 if (!$response) {
                     // If the server is unreachable, then prompts the user of the necessary action
        // calculated duration for 'scheduled session' feature
        $settings->add(new admin_setting_configcheckbox('bigbluebuttonbn_scheduled_duration_enabled', get_string('config_scheduled_duration_enabled', 'bigbluebuttonbn'), get_string('config_scheduled_duration_enabled_description', 'bigbluebuttonbn'), 1));
        // compensatory time for 'scheduled session' feature
        $settings->add(new admin_setting_configtext('bigbluebuttonbn_scheduled_duration_compensation', get_string('config_scheduled_duration_compensation', 'bigbluebuttonbn'), get_string('config_scheduled_duration_compensation_description', 'bigbluebuttonbn'), 10, PARAM_INT));
        // pre-opening time for 'scheduled session' feature
        $settings->add(new admin_setting_configtext('bigbluebuttonbn_scheduled_pre_opening', get_string('config_scheduled_pre_opening', 'bigbluebuttonbn'), get_string('config_scheduled_pre_opening_description', 'bigbluebuttonbn'), 10, PARAM_INT));
    }
    //// Configuration for defining the default role/user that will be moderator on new activities
    if (!isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_moderator_default)) {
        $settings->add(new admin_setting_heading('bigbluebuttonbn_permission', get_string('config_permission', 'bigbluebuttonbn'), get_string('config_permission_description', 'bigbluebuttonbn')));
        // UI for 'permissions' feature
        $roles = bigbluebuttonbn_get_roles('all', 'array');
        $owner = array('owner' => get_string('mod_form_field_participant_list_type_owner', 'bigbluebuttonbn'));
        $settings->add(new admin_setting_configmultiselect('bigbluebuttonbn_moderator_default', get_string('config_permission_moderator_default', 'bigbluebuttonbn'), get_string('config_permission_moderator_default_description', 'bigbluebuttonbn'), array_keys($owner), array_merge($owner, $roles)));
    }
    //// Configuration for "send notifications" feature
    if (!isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_sendnotifications_enabled)) {
        $settings->add(new admin_setting_heading('bigbluebuttonbn_feature_sendnotifications', get_string('config_feature_sendnotifications', 'bigbluebuttonbn'), get_string('config_feature_sendnotifications_description', 'bigbluebuttonbn')));
        // UI for 'send notifications' feature
        $settings->add(new admin_setting_configcheckbox('bigbluebuttonbn_sendnotifications_enabled', get_string('config_feature_sendnotifications_enabled', 'bigbluebuttonbn'), get_string('config_feature_sendnotifications_enabled_description', 'bigbluebuttonbn'), 1));
    }
    //// Configuration for extended BN capabilities
    if (bigbluebuttonbn_server_offers_bn_capabilities()) {
        //// Configuration for 'notify users when recording ready' feature
        if (!isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingready_enabled)) {
            $settings->add(new admin_setting_heading('bigbluebuttonbn_extended_capabilities', get_string('config_extended_capabilities', 'bigbluebuttonbn'), get_string('config_extended_capabilities_description', 'bigbluebuttonbn')));
            // UI for 'notify users when recording ready' feature
            $settings->add(new admin_setting_configcheckbox('bigbluebuttonbn_recordingready_enabled', get_string('config_extended_feature_recordingready_enabled', 'bigbluebuttonbn'), get_string('config_extended_feature_recordingready_enabled_description', 'bigbluebuttonbn'), 0));
        }
    }
}