$src = src_expand($src);
    }
    $query = "\n        SELECT\n            source_id,\n            is_unused(source_id) AS unused,\n            get_source_text(source_id) AS src_txt,\n            source_date\n        FROM\n            sources\n        WHERE\n            source_text SIMILAR TO '%{$src}%'\n    ";
    if ($scope != 0) {
        $query .= "\n            AND\n                part_type = {$scope}\n        ";
    }
    if ($yr && $diff) {
        $query .= "\n            AND\n                EXTRACT(YEAR FROM source_date)\n                    BETWEEN {$yr} - {$diff} AND {$yr} + {$diff}\n        ";
    }
    if ($yr && !$diff) {
        $query .= "\n            AND\n                EXTRACT(YEAR FROM source_date) = {$yr}\n        ";
    }
    $query .= "\n        ORDER BY\n            source_date\n    ";
    $handle = pg_query($query);
    echo "<table>\n";
    while ($row = pg_fetch_assoc($handle)) {
        $id = $row['source_id'];
        echo '<tr>';
        echo td_numeric(square_brace(to_url('./source_manager.php', array('node' => $id), $id)));
        if ($row['unused'] == 't') {
            echo td(span_type(square_brace(italic($row['source_date'])) . ' ' . $row['src_txt'], 'faded'));
        } else {
            echo td(square_brace(italic($row['source_date'])) . ' ' . $row['src_txt']);
        }
        echo "</tr>\n";
    }
    echo "</table>\n";
    echo '<p>' . pg_num_rows($handle) . ' treff.</p>';
}
echo "</div>\n";
include "./footer.php";
if ($props['number_of_subsources']) {
    echo "<h3>{$_Subsources}:</h3>\n";
    echo "<table>";
    $handle = pg_query("\n        SELECT\n            source_id,\n            link_expand(source_text) AS txt,\n            sort_order,\n            source_date,\n            ecc(source_id) AS e,\n            rcc(source_id) AS r,\n            ssc(source_id) AS s,\n            usc(source_id) AS u,\n            spt.{$label} AS {$label}\n        FROM\n            sources, source_part_types spt\n        WHERE\n            spt.part_type_id = sources.part_type\n        AND\n            parent_id = {$self}\n        AND\n            source_id <> 0\n        ORDER BY\n            sort_order,\n            source_date,\n            source_text\n    ");
    // change between FALSE and TRUE to select terse / informative mode
    $friendly = TRUE;
    while ($row = pg_fetch_assoc($handle)) {
        $id = $row['source_id'];
        echo '<tr>';
        if ($friendly) {
            echo td(paren(to_url($_SERVER['PHP_SELF'], array('node' => $id), $_Select) . '&nbsp;/&nbsp;' . to_url('./forms/source_edit.php', array('person' => 0, 'source' => $id), $_Edit)));
            echo td_numeric(square_brace($row['sort_order']));
            echo td(paren($row[$label]));
        } else {
            echo td_numeric(square_brace(to_url($_SERVER['PHP_SELF'], array('node' => $id), $id, $_goto)));
            echo td_numeric(square_brace($row['sort_order']));
            echo td(paren(to_url('./forms/source_edit.php', array('person' => 0, 'source' => $id), $row[$label], $_edit)));
        }
        if ($row['e'] || $row['r'] || $row['s']) {
            echo td(square_brace(italic($row['source_date'])) . ' ' . $row['txt'] . node_details($row['e'], $row['r'], $row['s'], $row['u']));
        } else {
            // source is unused, print with gray text
            if ($show_delete) {
                // show link for source deletion
                echo td(span_type(square_brace(italic($row['source_date'])) . conc($row['txt']), "faded") . conc(paren(to_url('./forms/source_delete.php', array('node' => $self, 'id' => $id), bold($_delete)))));
            } else {
                echo td(span_type(square_brace(italic($row['source_date'])) . conc($row['txt']), "faded"));
            }
        }
        echo "</tr>\n";
    }