$text = $row['source_text'];
 $ret = $self ? $source : $psource;
 $sort = $row['sort_order'];
 $source_date = $row['source_date'];
 $part_type = $row['part_type'] ? $row['part_type'] : 0;
 $ch_part_type = $row['ch_part_type'] ? $row['ch_part_type'] : 0;
 $spt_label = fetch_val("SELECT get_spt_label({$part_type})");
 echo "<h2>{$_Edit_source} {$source} ({$spt_label})</h2>\n";
 echo "<p><a href=\"../source_manager.php?node={$source}\">{$_To} {$_Source_Manager}</a></p>";
 echo "<p>" . str_replace('./family.php', '../family.php', get_source_text($source)) . "</p>\n";
 form_begin($form, $_SERVER['PHP_SELF']);
 hidden_input('posted', 1);
 hidden_input('person', $person);
 hidden_input('source', $source);
 hidden_input('ret', $ret);
 source_num_input("{$_Parent_node}:", 'psource', $psource);
 editarea_input("{$_Text}:", 20, 100, 'text', $text);
 if (fetch_val("SELECT is_leaf({$source})") == 'f') {
     textarea_input('Template:', 3, 100, 'template', $template);
     select_source_type("Type", 'part_type', $part_type);
     select_source_type("{$_Subtype}:", 'ch_part_type', $ch_part_type);
 } else {
     hidden_input('template', false);
     hidden_input('part_type', $part_type);
     hidden_input('ch_part_type', 0);
 }
 text_input("{$_Sort_order}:", 20, 'sort', $sort);
 text_input("{$_Source_date}:", 20, 'source_date', $source_date);
 form_submit();
 form_end();
 $row = fetch_row("SELECT ecc({$source}), rcc({$source}), ssc({$source})");
require "./forms.php";
require_once "../langs/{$language}.php";
if (!isset($_POST['posted'])) {
    $node = $_GET['node'];
    $title = "{$_Add_source}";
    $form = 'source_add';
    $focus = 'text';
    require "./form_header.php";
    // if there's a template for this source group, get it
    $template = fetch_val("\n        SELECT template\n        FROM templates\n        WHERE source_fk = {$node}\n    ");
    $part_type = fetch_val("\n        SELECT ch_part_type\n        FROM sources\n        WHERE source_id = {$node}\n    ");
    $spt_label = fetch_val("SELECT get_spt_label({$part_type})");
    echo "<h2>{$_Add_source} ({$spt_label})</h2>\n";
    form_begin($form, $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    source_num_input("{$_Parent_node}:", 'node', $node);
    editarea_input("{$_Text}:", 20, 100, 'text', $template);
    if (fetch_val("\n        SELECT is_leaf FROM source_part_types WHERE part_type_id = {$part_type}\n    ") == 't') {
        hidden_input('template', false);
        hidden_input('part_type', $part_type);
        hidden_input('ch_part_type', 0);
    } else {
        textarea_input('Template:', 3, 100, 'template');
        select_source_type('Type:', 'part_type', $part_type);
        select_source_type("{$_Subtype}:", 'ch_part_type', 0);
    }
    text_input("{$_Sort_order}:", 20, 'sort');
    text_input("{$_Source_date}:", 20, 'source_date');
    form_submit();
    form_end();
    echo "</body>\n</html>\n";
function source_input()
{
    // print source number and textarea input.
    global $_Source, $_Text;
    source_num_input($_Source, "source_id", 0);
    editarea_input("{$_Text}: ", 10, 100, 'source_text');
}