<?php
/***********************************************************
	File: findid.php
	Project: phpGedView
	Author: John Finlay
	Posts to: none
	Comments:
		Popup window that will allow a user to search for a id

	Change Log:
		9/03/02 - File Created (yalnifj)
		5/30/03 - Added search filter and birth dates

	phpGedView: Genealogy Viewer
    Copyright (C) 2002 to 2003  John Finlay and Others

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

***********************************************************/
# $Id: findid.php,v 1.36 2004/11/14 10:08:23 roland-d Exp $
require("config.php");
if (!isset($action)) $action="";
if (!isset($name_filter)) $name_filter="";

print_simple_header($pgv_lang["find_individual"]);
if (isset($name_filter)) $name_filter = stripslashes($name_filter);
?>
<script language="JavaScript" type="text/javascript">
	function paste_id(id) {
		window.opener.paste_id(id);
		window.close();
	}
</script>
<div class ="center">
<span class="subheaders"><?php print $pgv_lang["find_individual"]; ?></span>
<form name="filter" method="post">
<input type="hidden" name="action" value="filter" />
<?php print $pgv_lang["name_contains"]; ?> <input type="text" name="name_filter" value="<?php print $name_filter;?>" />
<input type="submit" value="<?php print $pgv_lang["filter"];?>" /><br />
</form>
<?php
if ($action=="filter") {
	if (!isset($name_filter)) $name_filter="";
	$names = preg_split("/[\s,]+/", $name_filter);
	$num_names = count($names);
	if (!empty($name_filter)) $sindilist = search_indis_names($names);
	else $sindilist = get_indi_list();
	if (count($sindilist)==0) {
		print "<b>".$pgv_lang["no_results"]."</b><br />";
	}
	print "\n\t<table class=\"list_table $TEXT_DIRECTION\">\n\t\t<tr>\n\t\t<td class=\"list_value\">";
	uasort($sindilist, "itemsort");
	reset($sindilist);
	foreach($sindilist as $key=>$value) {
		$names = preg_split("/,/", $value["name"]);
		$value["name"] = check_NN($names);
		$indirec = find_person_record($key);
		$disp = displayDetails($indirec);
		if ($disp || showLivingName($indirec)) {
 		    print "\n\t\t\t<a href=\"#\" onclick=\"paste_id('$key');\"><span class=\"list_item\" dir=\"$TEXT_DIRECTION\">".PrintReady($value["name"]);
			if (!$disp) {
				print "--<i>".$pgv_lang["private"]."</i>";
			}
			else {
				$bpos1 = strpos($indirec, "1 BIRT");
				if ($bpos1) {
					print "--<i>".$pgv_lang["birth"]." ";
					$birthrec = substr($indirec, $bpos1+1);
					$bt = preg_match("/1 [A-Z]{4}/", $birthrec, $match);
					if ($bt>0) {
						$bpos2 = strpos($birthrec, $match[0]);
						if ($bpos2) $birthrec = substr($birthrec, 0, $bpos2);
					}
					$dct = preg_match("/2 DATE (.*)/", $birthrec, $match);
					if ($dct>0) print get_changed_date($match[1]);
					$pct = preg_match("/2 PLAC (.*)/", $birthrec, $match);
					if ($pct>0) print " <span dir=\"$TEXT_DIRECTION\">".PrintReady(" - ".$match[1])."</span>"; 
				}
				print "</i>";
			}
		    print "</span></a><br />\n";
	    }
	}
	print "</td></tr></table>";
}
print "</div>";
?>
<script language="JavaScript" type="text/javascript">
document.filter.name_filter.focus();
</script>
<?php
print_simple_footer();
?>
