$PAGE->set_heading($SITE->fullname);
$message = '';
$id = '';
$delete = false;
$organisations = array();
$record = null;
if (isset($_REQUEST['id'])) {
    $id = $_REQUEST['id'];
    if ($id != '0') {
        $record = read_organisation($id);
        if (isset($_REQUEST['delete'])) {
            $delete = true;
        }
    }
} else {
    $recs = get_organisation_records();
    if ($recs) {
        // Do they have a choice?
        $organisations[0] = get_string('new_organisation', 'local_obu_application');
        // The 'New Organisation' option
        foreach ($recs as $rec) {
            $organisations[$rec->id] = $rec->name;
        }
    } else {
        // No, they don't...
        $id = '0';
        // ...so it's gottabee a new one
    }
}
$parameters = ['id' => $id, 'delete' => $delete, 'organisations' => $organisations, 'record' => $record];
$mform = new mdl_organisation_form(null, $parameters);
function get_organisations()
{
    $organisations = array();
    $recs = get_organisation_records();
    foreach ($recs as $rec) {
        if ($rec->code != 0) {
            $organisations[$rec->id] = $rec->name;
        }
    }
    asort($organisations);
    return $organisations;
}