if ($txt && fetch_val("SELECT is_leaf({$src})") == 't') {
        echo "Cannot create subsource under source #{$src}. ";
        echo "Please go back and check your source reference.";
        die;
    }
    $event = $_POST['event'];
    $person = $_POST['person'];
    $tag = $_POST['tag_fk'];
    $place = $_POST['place_fk'];
    if ($place == 0) {
        $place = 1;
    }
    $note = note_to_db($_POST['event_note']);
    $event_date = pad_date($_POST['date_1']) . $_POST['date_type'] . pad_date($_POST['date_2']) . '1';
    $sort_date = parse_sort_date($_POST['sort_date'], $event_date);
    pg_query("BEGIN");
    pg_query("UPDATE EVENTS SET tag_fk={$tag}, place_fk={$place}, event_date='{$event_date}',\n                sort_date='{$sort_date}', event_note='{$note}' WHERE event_id = {$event}");
    set_last_selected_place($place);
    set_last_edit($person);
    $source_id = add_source($person, $tag, $event, $src, $txt);
    if ($tag == 31) {
        // hard-coded reference to probate
        pg_query("SELECT generate_probate_witnesses({$event})");
    }
    if ($_POST['age']) {
        // generate birth event
        add_birth($person, $event_date, $_POST['age'], $source_id);
    }
    pg_query("COMMIT");
    header("Location: {$app_root}/family.php?person={$person}");
}
    echo "<h2>{$title}</h2>\n";
    form_begin('place_edit', $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    hidden_input('place_id', $place_id);
    text_input(get_place_desc(1), 80, 'level_1', $level_1);
    text_input(get_place_desc(2), 80, 'level_2', $level_2);
    text_input(get_place_desc(3), 80, 'level_3', $level_3);
    text_input(get_place_desc(4), 80, 'level_4', $level_4);
    text_input(get_place_desc(5), 80, 'level_5', $level_5);
    form_submit();
    form_end();
    echo "</body>\n</html>\n";
} else {
    $place_id = $_POST['place_id'];
    $level_1 = note_to_db($_POST['level_1']);
    $level_2 = $_POST['level_2'];
    $level_3 = $_POST['level_3'];
    $level_4 = $_POST['level_4'];
    $level_5 = $_POST['level_5'];
    if ($place_id == 0) {
        // insert new place
        pg_query("BEGIN WORK");
        $place_id = fetch_val("\n            INSERT INTO places (\n                level_1,\n                level_2,\n                level_3,\n                level_4,\n                level_5\n            )\n            VALUES (\n                '{$level_1}',\n                '{$level_2}',\n                '{$level_3}',\n                '{$level_4}',\n                '{$level_5}'\n            )\n            RETURNING place_id\n        ");
        pg_query("COMMIT");
    } else {
        // modify existing place
        pg_query("\n            UPDATE places SET\n                level_1 = '{$level_1}',\n                level_2 = '{$level_2}',\n                level_3 = '{$level_3}',\n                level_4 = '{$level_4}',\n                level_5 = '{$level_5}'\n            WHERE place_id = {$place_id}\n        ");
    }
    set_last_selected_place($place_id);
    header("Location: {$app_root}/place_manager.php");
}