function build_tree($person, $henry, $level, $total) { // Recursive routine that does the major work. global $coparents, $descendants; $maxlevel = 15; $count = 0; $family = find_family($person); while (isset($family[$count][0])) { $coparent = $family[$count][1]; $coparents++; printf("<li>~ %s\n<ul class=\"descendants\">\n", get_name_and_dates('', $coparent)); while (isset($family[$count][1]) && $family[$count][1] == $coparent) { $henry[$level] = $count + 1; $descendants++; printf("<li>%s %s", get_henry($henry, $level), get_name_and_dates('', $family[$count][0])); if ($level == $maxlevel && has_descendants($family[$count][0])) { print " <strong>+</strong>"; } print "</li>\n"; if ($level < $maxlevel) { // point of recursion build_tree($family[$count][0], $henry, $level + 1, $total); } $count++; } echo "</ul></li>\n"; } return; }
function get_parents($p) { $row = fetch_row_assoc("\n SELECT\n get_parent({$p},1) AS father,\n get_parent({$p},2) AS mother\n "); $parents[0] = get_name_and_dates('', $row['father']); $parents[1] = get_name_and_dates('', $row['mother']); return $parents; }
* Yggdrasil: Search for couples * * * * Copyright (C) 2009-2011 by Leif B. Kristensen <*****@*****.**> * * All rights reserved. For terms of use, see LICENSE.txt * ***************************************************************************/ require "./settings/settings.php"; require_once "./langs/{$language}.php"; $title = "{$_Search_for_couples}"; $form = 'couple'; $focus = 'husb'; require "./header.php"; require "./functions.php"; echo "<div class=\"normal\">"; echo "<h2>{$title}</h2>\n"; echo "<form id=\"couple\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n<div>\n"; echo "{$_Husband}: <input type=\"text\" size=\"12\" name=\"husb\" />\n"; echo "{$_Wife}: <input type=\"text\" size=\"12\" name=\"wife\" />\n"; echo "<input type=\"submit\" value=\"{$_Search}\" />\n"; echo "</div>\n</form>\n\n"; $husb = isset($_GET['husb']) ? $_GET['husb'] : ''; $wife = isset($_GET['wife']) ? $_GET['wife'] : ''; if ($husb && $wife) { $handle = pg_query("select * from couples where p1n ilike '{$husb}%' and p2n ilike '{$wife}%'"); echo "<p>"; while ($row = pg_fetch_assoc($handle)) { echo $row['sort_date'] . ' ' . get_name_and_dates("./family.php", $row['p1']) . ' ' . get_name_and_dates("./family.php", $row['p2']) . "<br />\n"; } echo "</p>\n"; } echo "</div>\n"; include "./footer.php";
function build_tree($p) { // The indices of the tree array are plain Sosa-Stradonitz numbers. // The proband is number 1. The father of any person P in the pedigree // has index P * 2, the mother of P has P * 2 + 1. Missing persons are // assigned a 0. $tree_array[1] = $p; // hunt down ancestors for ($i = 1; $i < 16; $i++) { if ($tree_array[$i]) { $tree_array[$i * 2] = find_father($tree_array[$i]); } else { $tree_array[$i * 2] = 0; } if ($tree_array[$i]) { $tree_array[$i * 2 + 1] = find_mother($tree_array[$i]); } else { $tree_array[$i * 2 + 1] = 0; } } // populate name array $name[1] = get_name_and_dates('./family.php', $p); for ($i = 2; $i < 32; $i++) { if ($tree_array[$i]) { $name[$i] = get_name_and_dates('', $tree_array[$i]); } else { $name[$i] = ''; } } // if a gggparent has registered ancestors, append right arrow for ($i = 16; $i < 32; $i++) { if (has_parents($tree_array[$i])) { $name[$i] .= "</td><td rowspan=\"2\"><img src=\"./graphics/arr_rt.gif\" alt=\"\" />"; } } if (get_gender($p) == 1) { $pcolor = 'blue'; } elseif (get_gender($p) == 2) { $pcolor = 'red'; } else { $pcolor = 'green'; } // The following vars are space-saving abbreviations for the matrix below. // Each line in the matrix, except for the proband, occupies *two* table rows. // The reason is of course that the lines and angles are done with pure CSS. // Even if it's actually validating with W3C, the semantic fundamentalists // will hold their noses over such blatant table abuse. I may consider // rewriting it for SVG when IE supports it out of the box, and all earlier // versions of IE have gone to bit heaven. (I'm probably pushing up daisies // myself before that happens.) Until then, this format is understood by all // browsers more recent than Netscape 4. It's even (sort of) working in Lynx. // two empty cells $ec = "<td> </td><td> </td>"; // four empty cells in a two-by-two block $eb = "<td rowspan=\"2\" colspan=\"2\"> </td>"; // a red box for a female ancestor $red = "<td rowspan=\"2\" colspan=\"2\" class=\"red\">"; // a blue box for a male ancestor $blue = "<td rowspan=\"2\" colspan=\"2\" class=\"blue\">"; // a box for the proband $proband = "<td colspan=\"2\" class=\"{$pcolor}\">"; // the upper angle to a father box $tf = "<td> </td><td class=\"tofath\"> </td>"; // the lower angle to a mother box $tm = "<td> </td><td class=\"tomoth\"> </td>"; // vertical line $vl = "<td> </td><td class=\"vline\"> </td>"; // table row end and newline $nl = "</tr>\n<tr>"; // The Matrix From Hell. Don't mess with it. Note that every line in // the matrix is conditional, no need to print empty boxes. echo "<table cellspacing=\"0\"><!-- the pedigree monster table -->\n"; if ($name[16]) { echo "<tr>{$eb}{$eb}{$eb}{$ec}{$blue} 16 {$name['16']}</td>{$nl}{$tf}</tr>\n"; } if ($name[8]) { echo "<tr>{$eb}{$eb}{$ec}{$blue} 8 {$name['8']}</td>{$eb}{$nl}{$tf}</tr>\n"; } if ($name[17]) { echo "<tr>{$eb}{$eb}{$vl}{$tm}{$red} 17 {$name['17']}</td>{$nl}{$vl}{$ec}</tr>\n"; } if ($name[4]) { echo "<tr>{$eb}{$ec}{$blue} 4 {$name['4']}</td>{$eb}{$eb}{$nl}{$tf}</tr>\n"; } if ($name[18]) { echo "<tr>{$eb}{$vl}{$vl}{$ec}{$blue} 18 {$name['18']}</td>{$nl}{$vl}{$vl}{$tf}</tr>\n"; } if ($name[9]) { echo "<tr>{$eb}{$vl}{$tm}{$red} 9 {$name['9']}</td>{$eb}{$nl}{$vl}{$ec}</tr>\n"; } if ($name[19]) { echo "<tr>{$eb}{$vl}{$eb}{$tm}{$red} 19 {$name['19']}</td>{$nl}{$vl}{$ec}</tr>\n"; } if ($name[2]) { echo "<tr>{$ec}{$blue} 2 {$name['2']}</td>{$eb}{$eb}{$eb}{$nl}{$tf}</tr>\n"; } if ($name[20]) { echo "<tr>{$vl}{$vl}{$eb}{$ec}{$blue} 20 {$name['20']}</td>{$nl}{$vl}{$vl}{$tf}</tr>\n"; } if ($name[10]) { echo "<tr>{$vl}{$vl}{$ec}{$blue} 10 {$name['10']}</td>{$eb}{$nl}{$vl}{$vl}{$tf}</tr>\n"; } if ($name[21]) { echo "<tr>{$vl}{$vl}{$vl}{$tm}{$red} 21 {$name['21']}</td>{$nl}{$vl}{$vl}{$vl}{$ec} </tr>\n"; } if ($name[5]) { echo "<tr>{$vl}{$tm}{$red} 5 {$name['5']}</td>{$eb}{$eb}{$nl}{$vl}{$ec}</tr>\n"; } if ($name[22]) { echo "<tr>{$vl}{$eb}{$vl}{$ec}{$blue} 22 {$name['22']}</td>{$nl}{$vl}{$vl}{$tf}</tr>\n"; } if ($name[11]) { echo "<tr>{$vl}{$eb}{$tm}{$red} 11 {$name['11']}</td>{$eb}{$nl}{$vl}{$ec}</tr>\n"; } if ($name[23]) { echo "<tr>{$vl}{$eb}{$eb}{$tm}{$red} 23 {$name['23']}</td>{$nl}{$vl}{$ec}</tr>\n"; } echo "<tr>{$proband} 1 {$name['1']}</td>{$ec}{$ec}{$ec}{$ec}</tr>\n"; if ($name[24]) { echo "<tr>{$vl}{$eb}{$eb}{$ec}{$blue} 24 {$name['24']}</td>{$nl}{$vl}{$tf}</tr>"; } if ($name[12]) { echo "<tr>{$vl}{$eb}{$ec}{$blue} 12 {$name['12']}</td>{$eb}{$nl}{$vl}{$tf}</tr>\n"; } if ($name[25]) { echo "<tr>{$vl}{$eb}{$vl}{$tm}{$red} 25 {$name['25']}</td>{$nl}{$vl}{$vl}{$ec}</tr>\n"; } if ($name[6]) { echo "<tr>{$vl}{$ec}{$blue} 6 {$name['6']}</td>{$eb}{$eb}{$nl}{$vl}{$tf}</tr>\n"; } if ($name[26]) { echo "<tr>{$vl}{$vl}{$vl}{$ec}{$blue} 26 {$name['26']}</td>{$nl}{$vl}{$vl}{$vl}{$tf}</tr>\n"; } if ($name[13]) { echo "<tr>{$vl}{$vl}{$tm}{$red} 13 {$name['13']}</td>{$eb}{$nl}{$vl}{$vl}{$ec}</tr>\n"; } if ($name[27]) { echo "<tr>{$vl}{$vl}{$eb}{$tm}{$red} 27 {$name['27']}</td>{$nl}{$vl}{$vl}{$ec}</tr>\n"; } if ($name[3]) { echo "<tr>{$tm}{$red} 3 {$name['3']}</td>{$eb}{$eb}{$eb}{$nl}{$ec}</tr>\n"; } if ($name[28]) { echo "<tr>{$eb}{$vl}{$eb}{$ec}{$blue} 28 {$name['28']}</td>{$nl}{$vl}{$tf}</tr>\n"; } if ($name[14]) { echo "<tr>{$eb}{$vl}{$ec}{$blue} 14 {$name['14']}</td>{$eb}{$nl}{$vl}{$tf}</tr>\n"; } if ($name[29]) { echo "<tr>{$eb}{$vl}{$vl}{$tm}{$red} 29 {$name['29']}</td>{$nl}{$vl}{$vl}{$ec}</tr>\n"; } if ($name[7]) { echo "<tr>{$eb}{$tm}{$red} 7 {$name['7']}</td>{$eb}{$eb}{$nl}{$ec}</tr>\n"; } if ($name[30]) { echo "<tr>{$eb}{$eb}{$vl}{$ec}{$blue} 30 {$name['30']}</td>{$nl}{$vl}{$tf}</tr>\n"; } if ($name[15]) { echo "<tr>{$eb}{$eb}{$tm}{$red} 15 {$name['15']}</td>{$eb}{$nl}{$ec}</tr>\n"; } if ($name[31]) { echo "<tr>{$eb}{$eb}{$eb}{$tm}{$red} 31 {$name['31']}</td>{$nl}{$ec}</tr>\n"; } echo "</table>\n"; }
function show_parent($person, $gender) { // print names and lifespans of parents. // valid $gender values are 1=father, 2=mother global $language, $_Add, $_Insert, $_edit, $_delete, $_Father, $_father, $_Mother, $_mother, $_toolhelp_edit_parent, $_toolhelp_add_parent, $_toolhelp_insert_parent, $_toolhelp_delete_parent; $parent_id = fetch_val("SELECT get_parent({$person}, {$gender})"); $surety = fetch_val("\n SELECT get_lsurety((\n SELECT surety_fk\n FROM relations\n WHERE parent_fk = {$parent_id}\n AND child_fk = {$person}\n ), '{$language}')\n "); if ($gender == 1) { $Parent = $_Father; $parent = $_father; $para = '<p>'; $newline = '<br />'; } else { // $gender == 2 $Parent = $_Mother; $parent = $_mother; $para = ''; $newline = '</p>'; } echo $para . conc(bold($Parent) . ':') . conc(get_name_and_dates('', $parent_id)); if ($parent_id) { echo conc(curly_brace($surety)) . conc(span_type(paren(to_url('./forms/relation_edit.php', array('person' => $person, 'parent' => $parent_id), $_edit, sprintf($_toolhelp_edit_parent, $parent)) . ' / ' . to_url('./forms/relation_delete.php', array('person' => $person, 'parent' => $parent_id), $_delete, sprintf($_toolhelp_delete_parent, $parent))), "hotlink")) . cite(get_relation_id($person, $gender), 'relation', $person); } else { echo conc(span_type(paren(to_url('./forms/person_insert.php', array('person' => $person, 'addparent' => 'true', 'gender' => $gender), "{$_Add} {$parent}", sprintf($_toolhelp_add_parent, $parent)) . ' / ' . to_url('./forms/relation_edit.php', array('person' => $person, 'gender' => $gender), "{$_Insert} {$parent}", sprintf($_toolhelp_insert_parent, $parent))), "hotlink")); } echo "{$newline}\n"; }
} // by default, we will display the 50 most recently edited persons. if (!isset($given) && !isset($surname)) { $headline = "{$_The_last_50_edited}"; // This query is sluggish without the following db modification: // create index last_edited_persons_key on persons(last_edit,person_id); $query = "select person_id, last_edit from persons\n where is_merged(person_id) is false\n order by last_edit desc, person_id desc limit 50"; } else { if (substr($surname, 0, 1) == '!') { $literal = ltrim($surname, '!'); } else { $literal = "%{$surname}%"; } $headline = "{$_Search_result}"; $query = "SELECT\n person_id,\n get_pbdate(person_id) as pbd\n FROM\n persons\n WHERE\n given LIKE '%{$given}%'\n AND (\n patronym LIKE '%{$surname}%'\n OR toponym LIKE '{$literal}'\n OR surname LIKE '%{$surname}%'\n OR occupation LIKE '%{$surname}%'\n )\n AND is_merged(person_id) IS FALSE\n "; if ($bdate) { $query .= "\n AND f_year(get_pbdate(person_id))\n BETWEEN (({$bdate})::INTEGER - {$diff})\n AND (({$bdate})::INTEGER + {$diff})\n "; } $query .= "\n ORDER BY pbd"; } echo "<h3>{$headline}:</h3>\n"; $handle = pg_query($query); echo "<p>"; while ($row = pg_fetch_row($handle)) { $p = $row[0]; echo get_name_and_dates("./family.php", $p) . conc(child_of($p)) . "<br />\n"; } echo "</p>\n"; echo para(paren(fetch_num_rows($query) . conc($_persons))); echo "</div>\n"; include "./footer.php";