function print_marriage($p, $p2 = 0)
{
    global $_Married, $language;
    $handle = pg_query("\n        SELECT\n            event_date,\n            place_name,\n            spouse\n        FROM\n            marriages\n        WHERE\n            person = {$p}\n    ");
    while ($row = pg_fetch_assoc($handle)) {
        if (!$p2 || $p2 != $row['spouse']) {
            echo para($_Married . conc(fuzzydate($row['event_date'])) . conc($row['place_name']) . conc(fetch_val("SELECT prepose(4, '{$language}')")) . conc(linked_name($row['spouse'])) . conc(child_of($row['spouse'])), "bmd");
        }
    }
}
$place_id = $_GET['place_id'];
$place_name = fetch_val("SELECT get_place_name({$place_id})");
$title = "Hendelser knyttet til stedsnavn \"{$place_name}\"";
require "./header.php";
echo "<div class=\"normal\">\n";
echo "<h2>{$title}</h2>\n";
echo "<p><a href=\"./place_manager.php\">Alle stedsnavn</a></p>\n";
echo "<table>\n";
echo "<tr><th>ID</th><th>Hendelse</th><th>Dato</th><th>Deltagere</th></tr>\n";
$handle = pg_query("SELECT event_id, event_name, event_date, p1, p2\n                        FROM place_events WHERE place_fk = {$place_id} ORDER BY event_date");
while ($row = pg_fetch_assoc($handle)) {
    unset($participant_list);
    $event = $row['event_id'];
    $p_handle = pg_query("SELECT person_fk FROM participants\n                            WHERE event_fk = {$event} ORDER BY sort_order");
    while ($parts = pg_fetch_row($p_handle)) {
        $participant_list[] = linked_name($parts[0], './family.php');
    }
    echo "<tr>";
    echo "<td>" . $row['event_id'] . "</td>";
    echo "<td>" . $row['event_name'] . "</td>";
    echo "<td>" . fuzzydate($row['event_date']) . "</td>";
    echo '<td>' . join($participant_list, ', ') . '</td>';
    //    echo "<td>" . $row['p1'] . ' ' . linked_name($row['p1'], './family.php') . "</td>";
    //    if ($row['p2'])
    //        echo "<td>" . $row['p2'] . ' ' . linked_name($row['p2'], './family.php') . "</td>";
    echo "</tr>\n";
}
echo "</table>\n";
echo "<p><a href=\"./place_manager.php\">Alle stedsnavn</a></p>\n";
echo "</div>\n";
include "./footer.php";
function lifespan($born, $died)
{
    return paren(fuzzydate($born) . '&nbsp;-&nbsp;' . fuzzydate($died));
}
 *                                                                         *
 *   Copyright (C) 2006-2011 by Leif B. Kristensen <*****@*****.**>   *
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
// This script is basically a report listing events and persons associated
// with a tag. It is accessed from the Tag Manager via the 'report' link.
require "./settings/settings.php";
require "./functions.php";
require_once "./langs/{$language}.php";
$tag = $_GET['tag'];
$tag_name = fetch_val("SELECT get_tag_name({$tag})");
$title = "{$_All} {$_events} {$_of} type {$tag_name}";
require "./header.php";
echo "<div class=\"normal\">\n";
echo "<h2>{$title}</h2>\n";
$handle = pg_query("\n    SELECT\n        event_id,\n        event_name,\n        event_date,\n        place_name,\n        p1,\n        p2\n    FROM\n        tag_events\n    WHERE\n        tag_fk = {$tag}\n    ORDER BY\n        event_date,\n        event_id\n");
while ($row = pg_fetch_assoc($handle)) {
    echo '<p>[' . $row['event_id'] . '] ';
    echo $row['event_name'];
    echo ' ' . fuzzydate($row['event_date']);
    echo ' ' . $row['place_name'] . ': ';
    echo list_participants($row['event_id']);
    // print source(s)
    $innerhandle = pg_query("\n    SELECT\n        source_text\n    FROM\n        event_notes\n    WHERE\n        note_id = " . $row['event_id']);
    while ($row = pg_fetch_assoc($innerhandle)) {
        echo conc(paren($_Source . ':' . conc(ltrim($row['source_text']))));
    }
    echo "</p>\n";
}
echo "</div>\n";
include "./footer.php";
        echo "<h3>Personer nevnt i kilden:</h3>\n";
        list_mentioned($self, 1);
    } else {
        echo para(to_url('./forms/linkage_add.php', array('node' => $self), 'Legg til lenke'));
    }
}
// *****************************************************************************
// section I: print list of events cited by this source
// *****************************************************************************
if ($props['number_of_events']) {
    echo "<h3>{$_Events}:</h3>\n<ol>";
    $handle = pg_query("\n        SELECT\n            e.event_id,\n            e.tag_fk,\n            e.event_date,\n            get_place_name(e.place_fk) AS event_place,\n            link_expand(e.event_note) AS event_note,\n            get_event_type(e.event_id) AS event_type\n        FROM\n            events e,\n            event_citations s\n        WHERE\n            e.event_id = s.event_fk\n        AND\n            s.source_fk = {$self}\n        ORDER BY\n            get_event_type(e.event_id),\n            e.sort_date,\n            e.event_id\n    ");
    while ($row = pg_fetch_assoc($handle)) {
        $event = $row['event_id'];
        echo '<li>';
        echo square_brace($event) . conc(italic(get_tag_name($row['tag_fk']))) . conc(fuzzydate($row['event_date'])) . conc($row['event_place']);
        if ($row['event_type'] < 3) {
            // event has one or two participants, print names inline
            echo conc(list_participants($event), ': ');
        }
        echo conc($row['event_note'], ': ');
        echo ' ' . paren(to_url('./forms/source_event_edit.php', array('event' => $event, 'source' => $self), $_edit) . ' / ' . to_url('./forms/citation_delete.php', array('person' => 0, 'event' => $event, 'source' => $self), $_delete));
        if ($row['event_type'] == 3) {
            // event has any number of participants, print names as ordered list
            $subhandle = pg_query("\n                SELECT\n                    person_fk,\n                    is_principal,\n                    sort_order\n                FROM\n                    participants\n                WHERE\n                    event_fk={$event}\n                ORDER BY\n                    sort_order\n            ");
            echo '<ul>';
            while ($subrow = pg_fetch_assoc($subhandle)) {
                $participant = $subrow['person_fk'];
                $bp = $subrow['is_principal'] == 't' ? ' H ' : ' B ';
                echo '<li> ';
                // print link to edit sort order