function print_bd($p, $g)
{
    // This func prints birth and death events for spouses and children,
    // appended with inline source citations if primary sources exists for
    // those events.
    // NOTE that the $g var is used to reference both
    // tag_groups.tag_group_id where birth = 1 and death = 3,
    // and sources.part_type where baptism = 1 and burial = 3.
    // If you have selected other part_type keys for your primary birth and
    // death sources, this func won't print source references to BD events.
    // In that case you may want to use the outcommented section of
    // pop_child() below which will cite sources to parent/child relations.
    if ($row = fetch_row_assoc("\n        SELECT\n            event_key,\n            tag_key,\n            event_date,\n            get_place_name(place_key) place_name\n        FROM\n            person_event_groups\n        WHERE\n            person = {$p}\n        AND\n            group_key = {$g}\n        ")) {
        $src = fetch_val("\n            SELECT\n                get_source_text(source_id)\n            FROM\n                event_citations e, sources s\n            WHERE\n                e.event_fk = " . $row['event_key'] . "\n            AND\n                e.source_fk = s.source_id\n            AND\n                s.part_type = {$g}\n            ORDER BY\n                s.source_date ASC\n            LIMIT 1\n        ");
        echo para(get_tag_name($row['tag_key']) . conc(fuzzydate($row['event_date'])) . conc($row['place_name']) . conc($src ? span_type(paren($src), "inline_source") : ''), "bmd");
    }
}
                if ($row['user_type'] != USER_NORMAL) {
                    break;
                }
                switch ($_REQUEST['option']) {
                    case 'activate':
                        if ($row['user_status'] != STATUS_ACTIVE) {
                            user_activate($id);
                        }
                        break;
                    case 'delete':
                        if (display_confirmation()) {
                            $sql = 'SELECT user_id, user_type
								FROM ' . USERS_TABLE . ' 
								WHERE user_id = ' . $id;
                            $result = $_CLASS['core_db']->query($sql);
                            $row = $_CLASS['core_db'] > fetch_row_assoc($result);
                            $_CLASS['core_db']->free_result($result);
                            if ($row['user_type'] != USER_BOT) {
                                break;
                            }
                            user_delete($id);
                            trigger_error($_CLASS['core_user']->lang['BOT_DELETED']);
                        }
                        break;
                }
            }
            if ($_REQUEST['mode'] == 'unactivated') {
                $status = STATUS_PENDING;
                $template = 'admin/users/unactivated.html';
                $link = 'users&mode=unactivated';
            } else {
 *   person_update.php                                                     *
 *   Yggdrasil: Update Persons Form and Action                             *
 *                                                                         *
 *   Copyright (C) 2006-2011 by Leif B. Kristensen <*****@*****.**>   *
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    $person = $_GET['person'];
    $title = "Edit Person {$person}";
    require "./form_header.php";
    echo "<h2>Rediger person {$person}</h2>\n";
    $row = fetch_row_assoc("SELECT * FROM persons WHERE person_id = {$person}");
    $gender = $row['gender'];
    $given = $row['given'];
    $patronym = $row['patronym'];
    $toponym = $row['toponym'];
    $surname = $row['surname'];
    $occupation = $row['occupation'];
    $epithet = $row['epithet'];
    form_begin('person_insert', $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    hidden_input('person', $person);
    radio_gender($gender);
    text_input("{$_Given}:", 50, 'given', $given);
    text_input("{$_Patronym}:", 50, 'patronym', $patronym);
    text_input("{$_Toponym}:", 50, 'toponym', $toponym);
    text_input("{$_Surname}:", 50, 'surname', $surname);
 *   Copyright (C) 2006-2011 by Leif B. Kristensen <*****@*****.**>   *
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    // do form
    $event = $_GET['event'];
    $person = $_GET['person'];
    $name = get_name($person);
    $title = "{$_Edit_event} #{$event} ({$_person} #{$person} {$name})";
    require "./form_header.php";
    echo "<h2>{$title}</h2>\n";
    $rec = fetch_row_assoc("SELECT tag_fk, place_fk, event_date, date2text(sort_date) AS sd, event_note\n                            FROM events WHERE event_id = {$event}");
    $note = note_from_db($rec['event_note']);
    $notelen = strlen($note);
    $notelen < 1000 ? $note_height = 5 : ($note_height = 20);
    $note_width = 100;
    form_begin('edit_event', $_SERVER['PHP_SELF']);
    hidden_input('person', $person);
    hidden_input('event', $event);
    hidden_input('posted', 1);
    select_tag($rec['tag_fk'], $person, $event);
    select_place($rec['place_fk']);
    date_input($rec['event_date'], $rec['sd']);
    textarea_input("{$_Text}:<br />{$notelen}", $note_height, $note_width, 'event_note', $note);
    source_input();
    text_input("{$_Age}:", 10, 'age', '', "({$_Adds_birth_event})");
    form_submit();
    $str .= ':';
    return $str;
}
if (!isset($_POST['posted'])) {
    $title = $_Edit_place_name;
    require "./form_header.php";
    $place_id = $_GET['place_id'];
    if ($place_id == 0) {
        // new place
        $level_1 = '';
        $level_2 = '';
        $level_3 = '';
        $level_4 = '';
        $level_5 = '';
    } else {
        $place = fetch_row_assoc("SELECT * FROM places WHERE place_id = {$place_id}");
        $level_1 = $place['level_1'];
        $level_2 = $place['level_2'];
        $level_3 = $place['level_3'];
        $level_4 = $place['level_4'];
        $level_5 = $place['level_5'];
    }
    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);
function get_sort($id, &$text, $sort)
{
    // parses sort order from text, returns sort order, modifies text
    // rewritten as wrapper for plgpgsql get_sort() function
    // note that $id is the parent id of a new source.
    $row = fetch_row_assoc("select * from get_sort({$id}, {$sort}, '{$text}')");
    $text = $row['string'];
    return $row['number'];
}
    echo "<h2>{$title}</h2>\n";
    form_begin('person_merge', $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    text_input("Person 1:", 10, 'person_1', $person);
    text_input("Person 2:", 10, 'person_2');
    form_submit();
    form_end();
    echo "</body>\n</html>\n";
} else {
    $person_1 = $_POST['person_1'];
    $person_2 = $_POST['person_2'];
    // To avoid messups, this script will run some checks to ensure that the
    // two merge candidates are sufficiently identical. As a minimum, we'll
    // check if given name, sex, and birth year are within bounds.
    $row_1 = fetch_row_assoc("\n        SELECT\n            given,\n            patronym,\n            gender,\n            f_year(get_pbdate({$person_1})) AS pbd\n        FROM\n            persons\n        WHERE\n            person_id = {$person_1}\n    ");
    $row_2 = fetch_row_assoc("\n        SELECT\n            given,\n            patronym,\n            gender,\n            f_year(get_pbdate({$person_2})) AS pbd\n        FROM\n            persons\n        WHERE\n            person_id = {$person_2}\n    ");
    $given_1f = fonetik($row_1['given']);
    $given_2f = fonetik($row_2['given']);
    $patronym_1f = fonetik($row_1['patronym']);
    $patronym_2f = fonetik($row_2['patronym']);
    $bdate_1 = $row_1['pbd'];
    $bdate_2 = $row_2['pbd'];
    $okay = true;
    $reason = '';
    // compare gender of candidates
    if ($row_1['gender'] != $row_2['gender']) {
        $okay = false;
        $reason .= " {$_Differing_genders}.";
    }
    // if both candidates have birth dates, compare them
    if ($bdate_1 && $bdate_2) {
 *                                                                         *
 *   Copyright (C) 2006-2011 by Leif B. Kristensen <*****@*****.**>   *
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    // do form
    $source = $_GET['source'];
    $event = $_GET['event'];
    $title = "{$_Edit_event} #{$event}";
    require "./form_header.php";
    echo "<h2>{$title}</h2>\n";
    $rec = fetch_row_assoc("\n        SELECT\n            tag_fk,\n            place_fk,\n            event_date,\n            date2text(sort_date) AS sd,\n            event_note\n        FROM\n            events\n        WHERE\n            event_id = {$event}\n    ");
    $note = note_from_db($rec['event_note']);
    $notelen = strlen($note);
    $notelen < 1000 ? $note_height = 10 : ($note_height = 20);
    $note_width = 80;
    form_begin('edit_event', $_SERVER['PHP_SELF']);
    hidden_input('source', $source);
    hidden_input('event', $event);
    hidden_input('posted', 1);
    select_tag($rec['tag_fk']);
    select_place($rec['place_fk']);
    date_input($rec['event_date'], $rec['sd']);
    textarea_input("{$_Text}:<br />{$notelen}", $note_height, $note_width, 'event_note', $note);
    form_submit();
    form_end();
    echo "<h3>{$_Citations}</h3>\n";
*/
require "../settings/settings.php";
require "../functions.php";
require "./forms.php";
require_once "../langs/{$language}.php";
if (!isset($_POST['posted'])) {
    $node = $_GET['node'];
    $id = $_GET['id'];
    $f_person = $_GET['person'];
    $title = "Rediger lenke";
    $form = 'linkage_edit';
    $focus = 'text';
    require "./form_header.php";
    echo "<h2>Rediger lenke {$id}</h2>\n";
    echo '<p>' . fetch_val("SELECT source_text FROM sources WHERE source_id={$node}") . "</p>\n";
    $row = fetch_row_assoc("SELECT * FROM source_linkage WHERE source_fk={$node} AND per_id={$id}");
    $person = $row['person_fk'] ? $row['person_fk'] : 0;
    form_begin($form, $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    hidden_input('node', $node);
    hidden_input('per_id', $id);
    hidden_input('f_person', $f_person);
    // role_fk
    select_role($row['role_fk']);
    person_id_input($person, 'person_fk', 'Person: ');
    select_surety($row['surety_fk']);
    text_input("Navn i kilden: ", 100, 's_name', $row['s_name']);
    textarea_input("Note: ", 5, 100, 'sl_note', $row['sl_note']);
    form_submit();
    form_end();
    echo "<h3>Personer nevnt i kilden:</h3>\n";
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    $person = $_GET['person'];
    $source = $_GET['source'];
    $self = isset($_GET['self']) ? $_GET['self'] : 0;
    $title = "{$_Edit_source} #{$source}";
    $template = fetch_val("SELECT template FROM templates WHERE source_fk = {$source}");
    $form = 'source_edit';
    $focus = 'text';
    require "./form_header.php";
    $row = fetch_row_assoc("SELECT * FROM sources WHERE source_id = {$source}");
    $psource = $row['parent_id'];
    $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);
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    $spt = $_GET['spt'];
    if ($spt == 0) {
        // new tag type
        $title = "{$_Insert} {$_source_type}";
        $description = '';
        $label_en = '';
        $label_nb = '';
        $is_leaf = 'f';
    } else {
        $title = "{$_Edit} {$_source_type} #{$spt}";
        $spt_row = fetch_row_assoc("\n            SELECT\n                label_en,\n                label_nb,\n                description,\n                is_leaf\n            FROM\n                source_part_types\n            WHERE\n                part_type_id = {$spt}\n        ");
        $label_en = $spt_row['label_en'];
        $label_nb = $spt_row['label_nb'];
        $description = $spt_row['description'];
        $is_leaf = $spt_row['is_leaf'];
    }
    require "./form_header.php";
    echo "<h2>{$title}</h2>\n";
    form_begin('spt_edit', $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    hidden_input('spt', $spt);
    text_input("Description:", 80, 'description', $description);
    text_input("Label (en):", 40, 'label_en', $label_en);
    text_input("Label (nb):", 40, 'label_nb', $label_nb);
    select_bool("Is leaf", 'is_leaf', $is_leaf);
    form_submit();
<?php

/***************************************************************************
 *   user_settings.php                                                     *
 *   Yggdrasil: User settings Form                                         *
 *                                                                         *
 *   Copyright (C) 2006-2011 by Leif B. Kristensen <*****@*****.**>   *
 *   All rights reserved. For terms of use, see LICENSE.txt                *
 ***************************************************************************/
require "../settings/settings.php";
require_once "../langs/{$language}.php";
require "../functions.php";
require "./forms.php";
if (!isset($_POST['posted'])) {
    $settings = fetch_row_assoc("\n        SELECT\n            username,\n            user_full_name,\n            user_email,\n            place_filter_level,\n            place_filter_content,\n            show_delete,\n            initials,\n            user_lang\n        FROM\n            user_settings\n        WHERE\n            username = current_user\n    ");
    $title = "{$_User_settings} for " . $settings['username'];
    require "./form_header.php";
    echo "<h2>{$title}</h2>\n";
    $form = 'user_settings';
    form_begin($form, $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    //section: user language
    echo "<tr><td colspan=\"2\"><b>{$_Language}</b></td></tr>\n";
    echo "<tr><td>{$_Language}:  </td><td>\n<select name=\"user_lang\">\n";
    echo "<option";
    if ($settings['user_lang'] == 'en') {
        echo " selected=\"selected\"";
    }
    echo " value=\"en\">English</option>\n";
    echo "<option";
    if ($settings['user_lang'] == 'nb') {
if (!isset($_POST['posted'])) {
    $tag = $_GET['tag'];
    if ($tag == 0) {
        // new tag type
        $title = "{$_Insert} {$_event_type}";
        $tag_group = 8;
        // group 'other' by default
        $tag_name = '';
        $gedcom_tag = 'NOTE';
        // GEDCOM tag = NOTE by default
        $tag_label = '';
        $tag_type = 1;
        // single-person by default
    } else {
        $title = "{$_Edit} {$_event_type} #{$tag}";
        $tag_row = fetch_row_assoc("SELECT * FROM tags WHERE tag_id = {$tag}");
        $tag_group = $tag_row['tag_group_fk'];
        $tag_name = $tag_row['tag_name'];
        $gedcom_tag = $tag_row['gedcom_tag'];
        $tag_label = $tag_row['tag_label'];
        $tag_type = $tag_row['tag_type_fk'];
    }
    require "./form_header.php";
    echo "<h2>{$title}</h2>\n";
    form_begin('tag_edit', $_SERVER['PHP_SELF']);
    hidden_input('posted', 1);
    hidden_input('tag', $tag);
    select_tag_group($tag_group);
    select_tag_type($tag_type);
    text_input("GEDCOM :", 10, 'gedcom_tag', $gedcom_tag);
    text_input("Tag name :", 80, 'tag_name', $tag_name);
// *****************************************************************************
//                               initialization
// *****************************************************************************
require "./settings/settings.php";
require_once "./langs/{$language}.php";
require "./functions.php";
// we'll display only raw dates here
pg_query("SET DATESTYLE TO GERMAN");
// $self = this node, default node is root
$self = isset($_GET['node']) ? $_GET['node'] : 0;
// set $self as active source
set_last_selected_source($self);
// localized source part type label
$label = 'label_' . $language;
// get all attributes of $self in one query
$props = fetch_row_assoc("\n    SELECT\n        ecc({$self}) AS number_of_events,\n        rcc({$self}) AS number_of_relations,\n        ssc({$self}) AS number_of_subsources,\n        usc({$self}) AS number_of_unused_subsources,\n        get_source_text({$self}) AS source_txt,\n        get_prev_page({$self}) AS prev_page,\n        get_next_page({$self}) AS next_page,\n        link_expand(source_text) AS node_txt,\n        parent_id,\n        sort_order,\n        source_date,\n        part_type,\n        spt.{$label},\n        spt.is_leaf\n    FROM\n        sources, source_part_types spt\n    WHERE\n        spt.part_type_id = sources.part_type\n    AND\n        source_id = {$self}\n");
$title_prev = get_source_plain_text($props['prev_page']);
$title_next = get_source_plain_text($props['next_page']);
$title = "S:{$self} " . get_source_plain_text($self);
// limit title tag to a sensible length
if (mb_strlen($title) > 80) {
    $title = mb_substr($title, 0, 80) . '...';
}
// var used by header.php to display context dependent menu items
$source_manager = true;
require "./header.php";
// *****************************************************************************
//                                   main
// *****************************************************************************
echo "<div class=\"normal\">\n";
echo "<h2>Node {$self}" . node_details($props['number_of_events'], $props['number_of_relations'], $props['number_of_subsources'], $props['number_of_unused_subsources']) . conc($props[$label], ': ');