/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will create a new instance and return the id number
 * of the new instance.
 *
 * @param object $bigbluebutton An object from the form in mod_form.php
 * @return int The id of the newly inserted bigbluebutton record
 */
function bigbluebutton_add_instance($bigbluebutton)
{
    $bigbluebutton->timecreated = time();
    if (record_exists('bigbluebutton', 'meetingID', $bigbluebutton->name)) {
        error("A meeting with that name already exists.");
        return false;
    }
    $bigbluebutton->moderatorpass = bigbluebutton_rand_string(16);
    $bigbluebutton->viewerpass = bigbluebutton_rand_string(16);
    $bigbluebutton->meetingid = bigbluebutton_rand_string(16);
    return insert_record('bigbluebutton', $bigbluebutton);
}
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will create a new instance and return the id number
 * of the new instance.
 *
 * @param object $bigbluebutton An object from the form in mod_form.php
 * @return int The id of the newly inserted bigbluebutton record
 */
function bigbluebutton_add_instance($bigbluebutton)
{
    global $DB;
    $bigbluebutton->timecreated = time();
    if ($DB->record_exists('bigbluebutton', array('name' => $bigbluebutton->name))) {
        print_error("A meeting with that name already exists.");
        return false;
    }
    $bigbluebutton->moderatorpass = bigbluebutton_rand_string(16);
    $bigbluebutton->viewerpass = bigbluebutton_rand_string(16);
    $bigbluebutton->meetingid = bigbluebutton_rand_string(16);
    return $DB->insert_record('bigbluebutton', $bigbluebutton);
}
$salt = trim($CFG->BigBlueButtonSecuritySalt);
$url = trim(trim($CFG->BigBlueButtonServerURL), '/') . '/';
$logoutURL = $CFG->wwwroot;
if (isset($_POST['submit']) && $_POST['submit'] == 'end') {
    //
    // A request to end the meeting
    //
    if (!($bigbluebutton = get_record('bigbluebutton', 'id', $a))) {
        error("BigBlueButton ID {$a} is incorrect");
    }
    print get_string('index_ending', 'bigbluebutton');
    $meetingID = $bigbluebutton->meetingid;
    $modPW = $bigbluebutton->moderatorpass;
    $getArray = BigBlueButton::endMeeting($meetingID, $modPW, $url, $salt);
    // print_object( $getArray );
    $bigbluebutton->meetingid = bigbluebutton_rand_string(16);
    if (!update_record('bigbluebutton', $bigbluebutton)) {
        notice("Unable to assign a new meetingid");
    } else {
        redirect('index.php?id=' . $id);
    }
}
// print_object( $bigbluebuttons );
foreach ($bigbluebuttons as $bigbluebutton) {
    $info = null;
    $joinURL = null;
    $user = null;
    $result = null;
    $users = "-";
    $running = "-";
    $actions = "-";