/**
 * builds and returns sosa relationship name in the active language
 *
 * @param string $sosa sosa number
 */
function get_sosa_name($sosa)
{
    global $LANGUAGE, $pgv_lang;
    if ($sosa < 2) {
        return "";
    }
    $sosaname = "";
    $sosanr = floor($sosa / 2);
    $gen = floor(log($sosanr) / log(2));
    // first try a generic algorithm, this is later overridden
    // by language specific algorithms.
    if (!empty($pgv_lang["sosa_{$sosa}"])) {
        $sosaname = $pgv_lang["sosa_{$sosa}"];
    } else {
        if ($gen > 2) {
            switch ($LANGUAGE) {
                case "danish":
                case "norwegian":
                case "swedish":
                    $sosaname = "";
                    $addname = "";
                    $father = UTF8_strtolower($pgv_lang["father"]);
                    $mother = UTF8_strtolower($pgv_lang["mother"]);
                    $grand = "be" . ($LANGUAGE == "danish" ? "dste" : "ste");
                    $great = "olde";
                    $tip = "tip" . ($LANGUAGE == "danish" ? "-" : "p-");
                    for ($i = $gen; $i > 2; $i--) {
                        $sosaname .= $tip;
                    }
                    if ($gen >= 2) {
                        $sosaname .= $great;
                    }
                    if ($gen == 1) {
                        $sosaname .= $grand;
                    }
                    for ($i = $gen; $i > 0; $i--) {
                        if (!(floor($sosa / pow(2, $i)) % 2)) {
                            $addname .= $father;
                        } else {
                            $addname .= $mother;
                        }
                        if ($gen % 2 && !($i % 2) || !($gen % 2) && $i % 2) {
                            $addname .= "s ";
                        }
                    }
                    if ($LANGUAGE == "swedish") {
                        $sosaname = $addname;
                    }
                    if ($sosa % 2 == 0) {
                        $sosaname .= $father;
                        if ($gen > 0) {
                            $addname .= $father;
                        }
                    } else {
                        $sosaname .= $mother;
                        if ($gen > 0) {
                            $addname .= $mother;
                        }
                    }
                    $sosaname = UTF8_str_split($sosaname);
                    $sosaname[0] = UTF8_strtoupper($sosaname[0]);
                    $sosaname = implode('', $sosaname);
                    if ($LANGUAGE != "swedish") {
                        if (!empty($addname)) {
                            $sosaname .= ($gen > 5 ? "<br />&nbsp;&nbsp;&nbsp;&nbsp;" : "") . " <small>(" . $addname . ")</small>";
                        }
                    }
                    break;
                case "dutch":
                    // reference: http://nl.wikipedia.org/wiki/Voorouder
                    // Our numbers are 2 less than those shown in the article.  We number parents
                    // as generation zero where the article numbers them as generation 2.
                    $sosaname = "";
                    // Please leave the following strings untranslated
                    if ($gen & 512) {
                        break;
                    }
                    // 512 or higher
                    if ($gen & 256) {
                        $sosaname .= "hoog";
                    }
                    // 256 to 511
                    if ($gen & 128) {
                        $sosaname .= "opper";
                    }
                    // 128 to 511
                    if ($gen & 64) {
                        $sosaname .= "aarts";
                    }
                    // 64 to 511
                    if ($gen & 32) {
                        $sosaname .= "voor";
                    }
                    // 32 to 511
                    if ($gen & 16) {
                        $sosaname .= "edel";
                    }
                    // 16 to 511
                    if ($gen & 8) {
                        $sosaname .= "stam";
                    }
                    // 8 to 511
                    if ($gen & 4) {
                        $sosaname .= "oud";
                    }
                    // 4 to 511
                    $gen = $gen & 3;
                    if ($gen == 3) {
                        $sosaname .= "betovergroot";
                    }
                    if ($gen == 2) {
                        $sosaname .= "overgroot";
                    }
                    if ($gen == 1) {
                        $sosaname .= "groot";
                    }
                    if ($sosa % 2 == 0) {
                        $sosaname .= $pgv_lang["father"];
                    } else {
                        $sosaname .= $pgv_lang["mother"];
                    }
                    $sosaname = strtolower($sosaname);
                    break;
                case "finnish":
                    $sosaname = "";
                    $father = UTF8_strtolower($pgv_lang["father"]);
                    $mother = UTF8_strtolower($pgv_lang["mother"]);
                    //		$father = "isä";
                    //		$mother = "äiti";
                    //		$pgv_lang["sosa_2"]= "äidin";	//Grand (mother)
                    for ($i = $gen; $i > 0; $i--) {
                        if (!(floor($sosa / pow(2, $i)) % 2)) {
                            $sosaname .= $father . "n";
                        } else {
                            $sosaname .= UTF8_substr($mother, 0, 2) . "din";
                        }
                    }
                    if ($sosa % 2 == 0) {
                        $sosaname .= $father;
                    } else {
                        $sosaname .= $mother;
                    }
                    $sosaname = UTF8_str_split($sosaname);
                    $sosaname[0] = UTF8_strtoupper($sosaname[0]);
                    $sosaname = implode('', $sosaname);
                    break;
                case "hebrew":
                    $sosaname = "";
                    $addname = "";
                    $father = $pgv_lang["father"];
                    $mother = $pgv_lang["mother"];
                    $greatf = $pgv_lang["sosa_22"];
                    $greatm = $pgv_lang["sosa_21"];
                    $of = $pgv_lang["sosa_23"];
                    $grandfather = $pgv_lang["sosa_4"];
                    $grandmother = $pgv_lang["sosa_5"];
                    //		$father = "Aba";
                    //		$mother = "Ima";
                    //		$grandfather = "Saba";
                    //		$grandmother = "Savta";
                    //		$greatf = " raba";
                    //		$greatm = " rabta";
                    //		$of = " shel ";
                    for ($i = $gen; $i >= 0; $i--) {
                        if ($i == 0) {
                            if (!($sosa % 2)) {
                                $addname .= "f";
                            } else {
                                $addname .= "m";
                            }
                        } else {
                            if (!(floor($sosa / pow(2, $i)) % 2)) {
                                $addname .= "f";
                            } else {
                                $addname .= "m";
                            }
                        }
                        if ($i == 0 || strlen($addname) == 3) {
                            if (strlen($addname) == 3) {
                                if (substr($addname, 2, 1) == "f") {
                                    $addname = $grandfather . $greatf;
                                } else {
                                    $addname = $grandmother . $greatm;
                                }
                            } else {
                                if (strlen($addname) == 2) {
                                    if (substr($addname, 1, 1) == "f") {
                                        $addname = $grandfather;
                                    } else {
                                        $addname = $grandmother;
                                    }
                                } else {
                                    if ($addname == "f") {
                                        $addname = $father;
                                    } else {
                                        $addname = $mother;
                                    }
                                }
                            }
                            $sosaname = $addname . ($i < $gen - 2 ? $of : "") . $sosaname;
                            $addname = "";
                        }
                    }
                    break;
                default:
                    $paternal = floor($sosa / pow(2, $gen)) == 2 ? "paternal" : "maternal";
                    $male = $sosa % 2 == 0 ? "male" : "female";
                    if (!empty($pgv_lang["sosa_{$paternal}_{$male}_n_generations"])) {
                        $sosaname = sprintf($pgv_lang["sosa_{$paternal}_{$male}_n_generations"], $gen + 1, $gen, $gen - 1);
                    }
            }
        }
    }
    if (!empty($sosaname)) {
        return "{$sosaname}<!-- sosa={$sosa} nr={$sosanr} gen={$gen} -->";
    } else {
        return "<!-- sosa={$sosa} nr={$sosanr} gen={$gen} -->";
    }
}
Example #2
0
/**
* add a new tag input field
*
* called for each fact to be edited on a form.
* Fact level=0 means a new empty form : data are POSTed by name
* else data are POSTed using arrays :
* glevels[] : tag level
*  islink[] : tag is a link
*     tag[] : tag name
*    text[] : tag value
*
* @param string $tag fact record to edit (eg 2 DATE xxxxx)
* @param string $upperlevel optional upper level tag (eg BIRT)
* @param string $label An optional label to echo instead of the default from the $factarray
* @param string $readOnly optional, when "READONLY", fact data can't be changed
* @param string $noClose optional, when "NOCLOSE", final "</td></tr>" won't be printed
* (so that additional text can be printed in the box)
* @param boolean $rowDisplay True to have the row displayed by default, false to hide it by default
*/
function add_simple_tag($tag, $upperlevel = "", $label = "", $readOnly = "", $noClose = "", $rowDisplay = true)
{
    global $factarray, $pgv_lang, $PGV_IMAGE_DIR, $PGV_IMAGES, $MEDIA_DIRECTORY, $TEMPLE_CODES;
    global $assorela, $tags, $emptyfacts, $main_fact, $TEXT_DIRECTION, $pgv_changes, $GEDCOM;
    global $NPFX_accept, $SPFX_accept, $NSFX_accept, $FILE_FORM_accept, $upload_count;
    global $tabkey, $STATUS_CODES, $SPLIT_PLACES, $pid, $linkToID;
    global $bdm, $PRIVACY_BY_RESN;
    global $lang_short_cut, $LANGUAGE;
    global $QUICK_REQUIRED_FACTS, $QUICK_REQUIRED_FAMFACTS, $PREFER_LEVEL2_SOURCES;
    if (substr($tag, 0, strpos($tag, "PLAC"))) {
        ?>
<script type="text/javascript">
		<!--
		function valid_lati_long(field, pos, neg) {
			// valid LATI or LONG according to Gedcom standard
			// pos (+) : N or E
			// neg (-) : S or W
			txt=field.value.toUpperCase();
			txt=txt.replace(/(^\s*)|(\s*$)/g,''); // trim
			txt=txt.replace(/ /g,':'); // N12 34 ==> N12.34
			txt=txt.replace(/\+/g,''); // +17.1234 ==> 17.1234
			txt=txt.replace(/-/g,neg); // -0.5698 ==> W0.5698
			txt=txt.replace(/,/g,'.'); // 0,5698 ==> 0.5698
			// 0�34'11 ==> 0:34:11
			txt=txt.replace(/\uB0/g,':'); // �
			txt=txt.replace(/\u27/g,':'); // '
			// 0:34:11.2W ==> W0.5698
			txt=txt.replace(/^([0-9]+):([0-9]+):([0-9.]+)(.*)/g, function($0, $1, $2, $3, $4) { var n=parseFloat($1); n+=($2/60); n+=($3/3600); n=Math.round(n*1E4)/1E4; return $4+n; });
			// 0:34W ==> W0.5667
			txt=txt.replace(/^([0-9]+):([0-9]+)(.*)/g, function($0, $1, $2, $3) { var n=parseFloat($1); n+=($2/60); n=Math.round(n*1E4)/1E4; return $3+n; });
			// 0.5698W ==> W0.5698
			txt=txt.replace(/(.*)([N|S|E|W]+)$/g,'$2$1');
			// 17.1234 ==> N17.1234
			if (txt!='' && txt.charAt(0)!=neg && txt.charAt(0)!=pos) txt=pos+txt;
			field.value = txt;
		}

		function toggle_lati_long() {
			tr = document.getElementsByTagName('tr');
			for (var i=0; i<tr.length; i++) {
				if (tr[i].id.indexOf("LATI")>=0 || tr[i].id.indexOf("LONG")>=0) {
					var disp = tr[i].style.display;
					if (disp=="none") {
						disp="table-row";
						if (document.all && !window.opera) disp = "inline"; // IE
					}
					else disp="none";
					tr[i].style.display=disp;
				}
			}
		}
		//-->
		</script>
		<?php 
    }
    if (!isset($noClose) && isset($readOnly) && $readOnly == "NOCLOSE") {
        $noClose = "NOCLOSE";
        $readOnly = "";
    }
    if (!isset($noClose) || $noClose != "NOCLOSE") {
        $noClose = "";
    }
    if (!isset($readOnly) || $readOnly != "READONLY") {
        $readOnly = "";
    }
    if (!isset($tabkey)) {
        $tabkey = 1;
    }
    if (empty($linkToID)) {
        $linkToID = $pid;
    }
    $subnamefacts = array("NPFX", "GIVN", "SPFX", "SURN", "NSFX", "_MARNM_SURN");
    @(list($level, $fact, $value) = explode(" ", $tag));
    // element name : used to POST data
    if ($level == 0) {
        if ($upperlevel) {
            $element_name = $upperlevel . "_" . $fact;
        } else {
            $element_name = $fact;
        }
        // ex: OCCU
    } else {
        $element_name = "text[]";
    }
    if ($level == 1) {
        $main_fact = $fact;
    }
    // element id : used by javascript functions
    if ($level == 0) {
        $element_id = $fact;
    } else {
        $element_id = $fact . floor(microtime() * 1000000);
    }
    // ex: SOUR56402
    if ($upperlevel) {
        $element_id = $upperlevel . "_" . $fact;
    }
    // ex: BIRT_DATE | DEAT_DATE ...
    // field value
    $islink = (substr($value, 0, 1) == "@" and substr($value, 0, 2) != "@#");
    if ($islink) {
        $value = trim(trim(substr($tag, strlen($fact) + 3)), " @\r");
    } else {
        $value = trim(substr($tag, strlen($fact) + 3));
    }
    if ($fact == 'REPO' || $fact == 'SOUR' || $fact == 'OBJE' || $fact == 'FAMC') {
        $islink = true;
    }
    // rows & cols
    switch ($fact) {
        case 'FORM':
            $rows = 1;
            $cols = 5;
            break;
        case 'LATI':
        case 'LONG':
        case 'NPFX':
        case 'SPFX':
        case 'NSFX':
            $rows = 1;
            $cols = 12;
            break;
        case 'DATE':
        case 'TIME':
        case 'TYPE':
            $rows = 1;
            $cols = 20;
            break;
        case 'GIVN':
        case 'SURN':
        case '_MARNM':
            $rows = 1;
            $cols = 25;
            break;
        case '_UID':
            $rows = 1;
            $cols = 50;
            break;
        case 'TEXT':
        case 'PUBL':
            $rows = 10;
            $cols = 70;
            break;
        case 'SHARED_NOTE_EDIT':
            $islink = 1;
            $fact = "NOTE";
            $rows = 15;
            $cols = 88;
            break;
        case 'SHARED_NOTE':
            $islink = 1;
            $fact = "NOTE";
            $rows = 1;
            $cols = $islink ? 8 : 40;
            break;
        case 'NOTE':
            if ($islink) {
                $rows = 1;
                $cols = $islink ? 8 : 40;
                break;
            } else {
                $rows = 10;
                $cols = 70;
                break;
            }
        case 'ADDR':
            $rows = 4;
            $cols = 40;
            break;
        case 'PAGE':
            $rows = 1;
            $cols = 50;
            break;
        default:
            $rows = 1;
            $cols = $islink ? 8 : 40;
            break;
    }
    // label
    $style = "";
    echo "<tr id=\"" . $element_id . "_tr\" ";
    if ($fact == "MAP" || $fact == "LATI" || $fact == "LONG") {
        echo " style=\"display:none;\"";
    }
    echo " >\n";
    if (in_array($fact, $subnamefacts) || $fact == "LATI" || $fact == "LONG") {
        echo "<td class=\"optionbox {$TEXT_DIRECTION} wrap width25\">";
    } else {
        echo "<td class=\"descriptionbox {$TEXT_DIRECTION} wrap width25\">";
    }
    // help link
    if (!in_array($fact, $emptyfacts)) {
        if ($fact == "DATE") {
            print_help_link("def_gedcom_date_help", "qm", "date");
        } else {
            if ($fact == "RESN") {
                print_help_link($fact . "_help", "qm");
            } else {
                if ($fact == "NOTE" && $islink) {
                    print_help_link("edit_add_SHARED_NOTE_help", "qm");
                } else {
                    print_help_link("edit_" . $fact . "_help", "qm");
                }
            }
        }
    }
    if ($fact == "_AKAN" || $fact == "_AKA" || $fact == "ALIA") {
        // Allow special processing for different languages
        $func = "fact_AKA_localisation_{$lang_short_cut[$LANGUAGE]}";
        if (function_exists($func)) {
            // Localise the AKA fact
            $func($fact, $pid);
        }
    } else {
        if ($fact == "AGNC" && !empty($main_fact)) {
            // Allow special processing for different languages
            $func = "fact_AGNC_localisation_{$lang_short_cut[$LANGUAGE]}";
            if (function_exists($func)) {
                // Localise the AGNC fact
                $func($fact, $main_fact);
            }
        }
    }
    if (PGV_DEBUG) {
        echo $element_name . "<br />\n";
    }
    // tag name
    if (!empty($label)) {
        if ($label == "Note" && $islink) {
            echo $pgv_lang["shared_note"];
        } else {
            echo $label;
        }
    } else {
        if ($fact == "NOTE" && $islink) {
            echo $pgv_lang["shared_note"];
        } else {
            if (isset($pgv_lang[$fact])) {
                echo $pgv_lang[$fact];
            } else {
                if (isset($factarray[$fact])) {
                    echo $factarray[$fact];
                } else {
                    echo $fact;
                }
            }
        }
    }
    echo "\n";
    // tag level
    if ($level > 0) {
        if ($fact == "TEXT" and $level > 1) {
            echo "<input type=\"hidden\" name=\"glevels[]\" value=\"" . ($level - 1) . "\" />";
            echo "<input type=\"hidden\" name=\"islink[]\" value=\"0\" />";
            echo "<input type=\"hidden\" name=\"tag[]\" value=\"DATA\" />";
            //-- leave data text[] value empty because the following TEXT line will
            //--- cause the DATA to be added
            echo "<input type=\"hidden\" name=\"text[]\" value=\"\" />";
        }
        echo "<input type=\"hidden\" name=\"glevels[]\" value=\"" . $level . "\" />\n";
        echo "<input type=\"hidden\" name=\"islink[]\" value=\"" . $islink . "\" />\n";
        echo "<input type=\"hidden\" name=\"tag[]\" value=\"" . $fact . "\" />\n";
        // Shared Notes Debug --------------------
        // echo "<br />Label = ".$label;
        // echo "<br />Level = ".$level;
        // echo "<br />Link = ".$islink;
        // echo "<br />Fact = ".$fact;
        // echo "<br />Value = ".$value;
        // End Debug -------------------
    }
    echo "\n</td>";
    // value
    echo "<td class=\"optionbox wrap\">\n";
    if (PGV_DEBUG) {
        echo $tag . "<br />\n";
    }
    // retrieve linked NOTE
    if ($fact == "NOTE" && $islink) {
        $noteid = $value;
    }
    if (in_array($fact, $emptyfacts) && (empty($value) || $value == "y" || $value == "Y")) {
        $value = strtoupper($value);
        //-- don't default anything to Y when adding events through people
        //-- default to Y when specifically adding one of these events
        if ($level == 1) {
            $value = "Y";
        }
        // default YES
        echo "<input type=\"hidden\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" value=\"" . $value . "\" />";
        if ($level <= 1) {
            echo "<input type=\"checkbox\" ";
            if ($value == "Y") {
                echo " checked=\"checked\"";
            }
            echo " onclick=\"if (this.checked) " . $element_id . ".value='Y'; else " . $element_id . ".value=''; \" />";
            echo $pgv_lang["yes"];
        }
    } else {
        if ($fact == "TEMP") {
            echo "<select tabindex=\"" . $tabkey . "\" name=\"" . $element_name . "\" >\n";
            echo "<option value=''>" . $pgv_lang["no_temple"] . "</option>\n";
            foreach ($TEMPLE_CODES as $code => $temple) {
                echo "<option value=\"{$code}\"";
                if ($code == $value) {
                    echo " selected=\"selected\"";
                }
                echo ">{$temple} ({$code})</option>\n";
            }
            echo "</select>\n";
        } else {
            if ($fact == "ADOP") {
                echo "<select tabindex=\"" . $tabkey . "\" name=\"" . $element_name . "\" >";
                foreach (array("BOTH" => $factarray["HUSB"] . "+" . $factarray["WIFE"], "HUSB" => $factarray["HUSB"], "WIFE" => $factarray["WIFE"]) as $k => $v) {
                    echo "<option value='{$k}'";
                    if ($value == $k) {
                        echo " selected=\"selected\"";
                    }
                    echo ">{$v}</option>";
                }
                echo "</select>\n";
            } else {
                if ($fact == "PEDI") {
                    echo "<select tabindex=\"" . $tabkey . "\" name=\"" . $element_name . "\" >";
                    foreach (array("" => $pgv_lang["unknown"], "birth" => $factarray["BIRT"], "adopted" => $pgv_lang["adopted"], "foster" => $pgv_lang["foster"], "sealing" => $pgv_lang["sealing"]) as $k => $v) {
                        echo "<option value='{$k}'";
                        if (UTF8_strtolower($value) == $k) {
                            echo " selected=\"selected\"";
                        }
                        echo ">{$v}</option>";
                    }
                    echo "</select>\n";
                } else {
                    if ($fact == "STAT") {
                        echo "<select tabindex=\"" . $tabkey . "\" name=\"" . $element_name . "\" >\n";
                        echo "<option value=''>No special status</option>\n";
                        foreach ($STATUS_CODES as $code => $status) {
                            echo "<option value=\"{$code}\"";
                            if ($code == $value) {
                                echo " selected=\"selected\"";
                            }
                            echo ">{$status}</option>\n";
                        }
                        echo "</select>\n";
                    } else {
                        if ($fact == "RELA") {
                            $text = strtolower($value);
                            // add current relationship if not found in default list
                            if (!array_key_exists($text, $assorela)) {
                                $assorela[$text] = $text;
                            }
                            echo "<select tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" >\n";
                            foreach ($assorela as $key => $value) {
                                echo "<option value=\"" . $key . "\"";
                                if ($key == $text) {
                                    echo " selected=\"selected\"";
                                }
                                echo ">" . $assorela["{$key}"] . "</option>\n";
                            }
                            echo "</select>\n";
                        } else {
                            if ($fact == "_PGVU") {
                                $text = strtolower($value);
                                echo "<select tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" >\n";
                                echo '<option value=""';
                                if ('' == $text) {
                                    echo ' selected="selected"';
                                }
                                echo ">-</option>\n";
                                foreach (get_all_users('asc', 'username') as $user_id => $user_name) {
                                    echo "<option value=\"" . $user_id . "\"";
                                    if ($user_id == $text) {
                                        echo " selected=\"selected\"";
                                    }
                                    echo ">" . $user_name . "</option>\n";
                                }
                                echo "</select>\n";
                            } else {
                                if ($fact == "RESN") {
                                    ?>
		<script type="text/javascript">
		<!--
		function update_RESN_img(resn_val) {
			document.getElementById("RESN_none").style.display="none";
			document.getElementById("RESN_locked").style.display="none";
			document.getElementById("RESN_privacy").style.display="none";
			document.getElementById("RESN_confidential").style.display="none";
			document.getElementById("RESN_"+resn_val).style.display="inline";
			if (resn_val=='none') resn_val='';
			document.getElementById("<?php 
                                    echo $element_id;
                                    ?>
").value=resn_val;
		}
		//-->
		</script>
		<?php 
                                    if (!$PRIVACY_BY_RESN && $level == 1) {
                                        // warn user that level 1 RESN tags have no effect when PRIVACY_BY_RESN is false
                                        echo "<small>" . $pgv_lang["resn_disabled"] . "</small>";
                                    }
                                    echo "<input type=\"hidden\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" value=\"" . $value . "\" />\n";
                                    echo "<table><tr valign=\"top\">\n";
                                    foreach (array("none", "locked", "privacy", "confidential") as $resn_index => $resn_val) {
                                        if ($resn_val == "none") {
                                            $resnv = "";
                                        } else {
                                            $resnv = $resn_val;
                                        }
                                        echo "<td><input tabindex=\"" . $tabkey . "\" type=\"radio\" name=\"RESN_radio\" onclick=\"update_RESN_img('" . $resn_val . "')\"";
                                        echo " value=\"" . $resnv . "\"";
                                        if ($value == $resnv) {
                                            echo " checked=\"checked\"";
                                        }
                                        echo " /><small>" . $pgv_lang[$resn_val] . "</small>";
                                        echo "<br />&nbsp;<img id=\"RESN_" . $resn_val . "\" src=\"images/RESN_" . $resn_val . ".gif\"  alt=\"" . $pgv_lang[$resn_val] . "\" title=\"" . $pgv_lang[$resn_val] . "\" border=\"0\"";
                                        if ($value == $resnv) {
                                            echo " style=\"display:inline\"";
                                        } else {
                                            echo " style=\"display:none\"";
                                        }
                                        echo " /></td>\n";
                                    }
                                    echo "</tr></table>\n";
                                } else {
                                    if ($fact == "_PRIM" or $fact == "_THUM") {
                                        echo "<select tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" >\n";
                                        echo "<option value=\"\"></option>\n";
                                        echo "<option value=\"Y\"";
                                        if ($value == "Y") {
                                            echo " selected=\"selected\"";
                                        }
                                        echo ">" . $pgv_lang["yes"] . "</option>\n";
                                        echo "<option value=\"N\"";
                                        if ($value == "N") {
                                            echo " selected=\"selected\"";
                                        }
                                        echo ">" . $pgv_lang["no"] . "</option>\n";
                                        echo "</select>\n";
                                    } else {
                                        if ($fact == "SEX") {
                                            echo "<select tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "\" name=\"" . $element_name . "\">\n<option value=\"M\"";
                                            if ($value == "M") {
                                                echo " selected=\"selected\"";
                                            }
                                            echo ">" . $pgv_lang["male"] . "</option>\n<option value=\"F\"";
                                            if ($value == "F") {
                                                echo " selected=\"selected\"";
                                            }
                                            echo ">" . $pgv_lang["female"] . "</option>\n<option value=\"U\"";
                                            if ($value == "U" || empty($value)) {
                                                echo " selected=\"selected\"";
                                            }
                                            echo ">" . $pgv_lang["unknown"] . "</option>\n</select>\n";
                                        } else {
                                            if ($fact == "TYPE" && $level == '3') {
                                                //-- Build array of currently defined values for this Media Fact
                                                foreach ($pgv_lang as $varname => $typeValue) {
                                                    if (substr($varname, 0, 6) == "TYPE__") {
                                                        if ($varname != "TYPE__other") {
                                                            $type[strtolower(substr($varname, 6))] = $typeValue;
                                                        }
                                                    }
                                                }
                                                //-- Sort the array into a meaningful order
                                                array_flip($type);
                                                asort($type);
                                                array_flip($type);
                                                //-- Add "Other" at the end of the list
                                                $type["other"] = $pgv_lang["TYPE__other"];
                                                //-- Build the selector for the Media "TYPE" Fact
                                                echo "<select tabindex=\"" . $tabkey . "\" name=\"text[]\">";
                                                if ($value == "") {
                                                    echo "<option selected=\"selected\" value=\"\" > " . $pgv_lang["choose"] . " </option>";
                                                }
                                                $selectedValue = strtolower($value);
                                                foreach ($type as $typeName => $typeValue) {
                                                    echo "<option value=\"" . $typeName . "\" ";
                                                    if ($selectedValue == $typeName) {
                                                        echo "selected=\"selected\" ";
                                                    }
                                                    echo "> " . $typeValue . " </option>";
                                                }
                                                echo "</select>";
                                            } else {
                                                if ($fact == "NAME" && $upperlevel != 'REPO' || $fact == "_MARNM") {
                                                    // Populated in javascript from sub-tags
                                                    echo "<input type=\"hidden\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" onchange=\"updateTextName('" . $element_id . "');\" value=\"" . PrintReady(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')) . "\" />";
                                                    echo "<span id=\"" . $element_id . "_display\">" . PrintReady(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')) . "</span>";
                                                    echo " <a href=\"#edit_name\" onclick=\"convertHidden('" . $element_id . "'); return false;\"> ";
                                                    if (isset($PGV_IMAGES["edit_indi"]["small"])) {
                                                        echo "<img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["edit_indi"]["small"] . "\" border=\"0\" width=\"20\" alt=\"" . $pgv_lang["edit_name"] . "\" align=\"top\" />";
                                                    } else {
                                                        echo "<span class=\"age\">[" . $pgv_lang["edit_name"] . "]</span>";
                                                    }
                                                    echo "</a>";
                                                } else {
                                                    // textarea
                                                    if ($rows > 1) {
                                                        echo "<textarea tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" rows=\"" . $rows . "\" cols=\"" . $cols . "\">" . PrintReady(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')) . "</textarea><br />\n";
                                                    } else {
                                                        // text
                                                        echo "<input tabindex=\"" . $tabkey . "\" type=\"text\" id=\"" . $element_id . "\" name=\"" . $element_name . "\" value=\"" . PrintReady(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')) . "\" size=\"" . $cols . "\" dir=\"ltr\"";
                                                        echo " class=\"{$fact}\"";
                                                        echo " autocomplete=\"off\"";
                                                        if (in_array($fact, $subnamefacts)) {
                                                            echo " onblur=\"updatewholename();\" onkeyup=\"updatewholename();\"";
                                                        }
                                                        if ($fact == "DATE") {
                                                            echo " onblur=\"valid_date(this);\" onmouseout=\"valid_date(this);\"";
                                                        }
                                                        if ($fact == "LATI") {
                                                            echo " onblur=\"valid_lati_long(this, 'N', 'S');\" onmouseout=\"valid_lati_long(this, 'N', 'S');\"";
                                                        }
                                                        if ($fact == "LONG") {
                                                            echo " onblur=\"valid_lati_long(this, 'E', 'W');\" onmouseout=\"valid_lati_long(this, 'E', 'W');\"";
                                                        }
                                                        //if ($fact=="FILE") echo " onchange=\"if (updateFormat) updateFormat(this.value);\"";
                                                        echo " " . $readOnly . " />\n";
                                                    }
                                                    // split PLAC
                                                    if ($fact == "PLAC" && $readOnly == "") {
                                                        echo "<div id=\"" . $element_id . "_pop\" style=\"display: inline;\">\n";
                                                        print_specialchar_link($element_id, false);
                                                        print_findplace_link($element_id);
                                                        echo "</div>\n";
                                                        echo "<a href=\"javascript:;\" onclick=\"toggle_lati_long();\"><img src=\"images/buttons/target.gif\" border=\"0\" align=\"middle\" alt=\"" . $factarray["LATI"] . " / " . $factarray["LONG"] . "\" title=\"" . $factarray["LATI"] . " / " . $factarray["LONG"] . "\" /></a>";
                                                        if ($SPLIT_PLACES) {
                                                            if (!function_exists("print_place_subfields")) {
                                                                require "includes/functions/functions_places.php";
                                                            }
                                                            setup_place_subfields($element_id);
                                                            print_place_subfields($element_id);
                                                        }
                                                    } else {
                                                        if (($cols > 20 || $fact == "NPFX") && $readOnly == "") {
                                                            print_specialchar_link($element_id, false);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // MARRiage TYPE : hide text field and show a selection list
    if ($fact == "TYPE" and $tags[0] == "MARR") {
        echo "<script type='text/javascript'>";
        echo "document.getElementById('" . $element_id . "').style.display='none'";
        echo "</script>";
        echo "<select tabindex=\"" . $tabkey . "\" id=\"" . $element_id . "_sel\" onchange=\"document.getElementById('" . $element_id . "').value=this.value;\" >\n";
        foreach (array("Unknown", "Civil", "Religious", "Partners") as $indexval => $key) {
            if ($key == "Unknown") {
                echo "<option value=\"\"";
            } else {
                echo "<option value=\"" . $key . "\"";
            }
            $a = strtolower($key);
            $b = strtolower($value);
            if (@strpos($a, $b) !== false or @strpos($b, $a) !== false) {
                echo " selected=\"selected\"";
            }
            echo ">" . $factarray["MARR_" . strtoupper($key)] . "</option>\n";
        }
        echo "</select>";
    }
    // popup links
    if ($readOnly == "") {
        if ($fact == "DATE") {
            print_calendar_popup($element_id);
        }
        if ($fact == "FAMC") {
            print_findfamily_link($element_id, "");
        }
        if ($fact == "FAMS") {
            print_findfamily_link($element_id, "");
        }
        if ($fact == "ASSO") {
            print_findindi_link($element_id, "");
        }
        if ($fact == "FILE") {
            print_findmedia_link($element_id, "0file");
        }
        if ($fact == "SOUR") {
            print_findsource_link($element_id);
            print_addnewsource_link($element_id);
            //print_autopaste_link($element_id, array("S1", "S2"), false, false, true);
            //-- checkboxes to apply '1 SOUR' to BIRT/MARR/DEAT as '2 SOUR'
            if ($level == 1) {
                echo '<br />';
                if ($PREFER_LEVEL2_SOURCES === '0') {
                    $level1_checked = '';
                    $level2_checked = '';
                } else {
                    if ($PREFER_LEVEL2_SOURCES === '1' || $PREFER_LEVEL2_SOURCES === true) {
                        $level1_checked = '';
                        $level2_checked = ' checked="checked"';
                    } else {
                        $level1_checked = ' checked="checked"';
                        $level2_checked = '';
                    }
                }
                if (strpos($bdm, 'B') !== false) {
                    echo '&nbsp;<input type="checkbox" name="SOUR_INDI" ', $level1_checked, ' value="Y" />';
                    echo $pgv_lang['individual'];
                    if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            if (!in_array($match, explode('|', PGV_EVENTS_DEAT))) {
                                echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="Y" />';
                                echo $factarray[$match];
                            }
                        }
                    }
                }
                if (strpos($bdm, 'D') !== false) {
                    if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            if (in_array($match, explode('|', PGV_EVENTS_DEAT))) {
                                echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="Y" />';
                                echo $factarray[$match];
                            }
                        }
                    }
                }
                if (strpos($bdm, 'M') !== false) {
                    echo '&nbsp;<input type="checkbox" name="SOUR_FAM" ', $level1_checked, ' value="Y" />';
                    echo $pgv_lang["family"];
                    if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="Y" />';
                            echo $factarray[$match];
                        }
                    }
                }
            }
        }
        if ($fact == "REPO") {
            print_findrepository_link($element_id);
            print_addnewrepository_link($element_id);
        }
        // Shared Notes Icons ========================================
        // $record=GedcomRecord::getInstance($value);
        if ($fact == "NOTE" && $islink) {
            print_findnote_link($element_id);
            print_addnewnote_link($element_id);
            if ($value != "") {
                echo "&nbsp;&nbsp;&nbsp;";
                print_editnote_link($value);
            }
            // If GEDFAct_assistant/_CENS/ module exists && we are on the INDI page
            // Then show the add Shared note assisted icon, if not  ... do not show
            if ($pid) {
                $type_pid = GedcomRecord::getInstance($pid);
                if (file_exists('modules/GEDFact_assistant/_CENS/census_1_ctrl.php') && $type_pid->getType() == "INDI") {
                    echo "&nbsp;&nbsp;&nbsp;";
                    print_addnewnote_assisted_link($element_id);
                }
            }
            echo "<br />";
        }
        // ===========================================================
        if ($fact == "OBJE") {
            print_findmedia_link($element_id, "1media");
        }
        if ($fact == "OBJE" && !$value) {
            print_addnewmedia_link($element_id);
            $value = "new";
        }
    }
    // current value
    if ($TEXT_DIRECTION == "ltr") {
        if ($fact == "DATE") {
            $date = new GedcomDate($value);
            echo $date->Display(false);
        }
        if (($fact == "ASSO" || $fact == "SOUR" || $fact == "OBJE" || $fact == "NOTE" && $islink) && $value) {
            $record = GedcomRecord::getInstance($value);
            if ($record) {
                echo ' ', PrintReady($record->getFullName()), ' (', $value, ')';
            } else {
                if ($value != "new") {
                    echo ' ', $value;
                }
            }
        }
    } else {
        if ($fact == "DATE") {
            $date = new GedcomDate($value);
            echo getRLM(), $date->Display(false), getRLM();
        }
        if (($fact == "ASSO" || $fact == "SOUR" || $fact == "OBJE" || $fact == "NOTE" && $islink) && $value) {
            $record = GedcomRecord::getInstance($value);
            if ($record) {
                echo getRLM(), PrintReady($record->getFullName()), ' ', getLRM(), '(', $value, ') ', getLRM(), getRLM();
            } else {
                if ($value != "new") {
                    echo getRLM(), $value, ' ', getRLM();
                }
            }
        }
    }
    /*
    	if ($fact=="NOTE" && $islink && $value!="") {
    		include('includes/functions/functions_print_lists.php'); 
    		echo "<tr><td class=\"descriptionbox ".$TEXT_DIRECTION." wrap width25\">";
    				print_help_link("edit_add_SHARED_NOTE_help", "qm");
    			//	echo $pgv_lang["admin_override"];
    			echo "Shared Note Links<br /><br />";
    		echo "</td><td class=\"optionbox wrap\">\n";
    			print_indi_list(fetch_linked_indi($value, "NOTE", "1"));
    		echo "</td></tr>\n";
    	}
    */
    // pastable values
    if ($readOnly == "") {
        if ($fact == "SPFX") {
            print_autopaste_link($element_id, $SPFX_accept);
        }
        if ($fact == "NSFX") {
            print_autopaste_link($element_id, $NSFX_accept);
        }
        if ($fact == "FORM") {
            print_autopaste_link($element_id, $FILE_FORM_accept, false, false);
        }
    }
    if ($noClose != "NOCLOSE") {
        echo "</td></tr>\n";
    }
    $tabkey++;
    return $element_id;
}
Example #3
0
function getRelationshipText_pl($relationshipDescription, $node, $pid1, $pid2)
{
    if ($relationshipDescription != false) {
        return UTF8_strtolower($relationshipDescription);
    }
    return false;
}
 /**
  * Compares to see if two people are the same, and it returns true if they are, but
  * false if they are not. It only compares the name, sex birthdate, and deathdate
  * of the person
  */
 static function ComparePeople(&$Person1, &$Person2)
 {
     $PersonName1 = $Person1->getFullName();
     $PersonSex1 = $Person1->getSex();
     $PersonBirth1 = $Person1->getEstimatedBirthDate();
     $PersonDeath1 = $Person1->getEstimatedDeathDate();
     $PersonName2 = $Person2->getFullName();
     $PersonSex2 = $Person2->getSex();
     $PersonBirth2 = $Person2->getEstimatedBirthDate();
     $PersonDeath2 = $Person2->getEstimatedDeathDate();
     $count = 0;
     $Probability = 0;
     if (!empty($PersonName1) && !empty($PersonName2)) {
         $lev = levenshtein(UTF8_strtolower($PersonName1), UTF8_strtolower($PersonName2));
         if ($lev < 4) {
             $Probability += 2;
         } else {
             $Probability -= 2;
         }
         $count += 2;
     }
     $sex_prob = array('UU' => 0, 'UF' => 0, 'UM' => 0, 'MU' => 0, 'FU' => 0, 'MM' => 1, 'FF' => 1, 'MF' => -2, 'FM' => -2);
     $Probability += $sex_prob[$PersonSex1 . $PersonSex2];
     $count++;
     if ($PersonBirth1->isOK() && $PersonBirth2->isOK()) {
         $diff = abs($PersonBirth1->JD() - $PersonBirth2->JD());
         if ($diff == 0) {
             $Probability += 2;
         } elseif ($diff < 366) {
             $Probability += 1;
         } else {
             $Probability -= 1;
         }
         $count++;
     }
     if ($PersonDeath1->isOK() && $PersonDeath2->isOK()) {
         $diff = abs($PersonDeath1->JD() - $PersonDeath2->JD());
         if ($diff == 0) {
             $Probability += 2;
         } elseif ($diff < 366) {
             $Probability += 1;
         } else {
             $Probability -= 1;
         }
         $count++;
     }
     $prob = $Probability / $count;
     if ($prob < 0.5) {
         return false;
     } else {
         return true;
     }
 }
Example #5
0
 static function _commonGivenQuery($sex = 'B', $type = 'list', $show_tot = false, $params = null)
 {
     global $TEXT_DIRECTION, $GEDCOM, $TBLPREFIX, $pgv_lang, $gBitDb;
     static $sort_types = array('count' => 'asort', 'rcount' => 'arsort', 'alpha' => 'ksort', 'ralpha' => 'krsort');
     static $sort_flags = array('count' => SORT_NUMERIC, 'rcount' => SORT_NUMERIC, 'alpha' => SORT_STRING, 'ralpha' => SORT_STRING);
     if (is_array($params) && isset($params[0]) && $params[0] != '' && $params[0] >= 0) {
         $threshold = strtolower($params[0]);
     } else {
         $threshold = 1;
     }
     if (is_array($params) && isset($params[1]) && $params[1] != '' && $params[1] >= 0) {
         $maxtoshow = strtolower($params[1]);
     } else {
         $maxtoshow = 10;
     }
     if (is_array($params) && isset($params[2]) && $params[2] != '' && isset($sort_types[strtolower($params[2])])) {
         $sorting = strtolower($params[2]);
     } else {
         $sorting = 'rcount';
     }
     switch ($sex) {
         case 'M':
             $sex_sql = "i_sex='M'";
             break;
         case 'F':
             $sex_sql = "i_sex='F'";
             break;
         case 'U':
             $sex_sql = "i_sex='U'";
             break;
         case 'B':
             $sex_sql = "i_sex!='U'";
             break;
     }
     $ged_id = get_id_from_gedcom($GEDCOM);
     $result = $gBitDb->query("SELECT n_givn, COUNT(*) AS num FROM {$TBLPREFIX}name JOIN {$TBLPREFIX}individuals ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type!='_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn");
     $nameList = array();
     while ($row = $result->fetchRow) {
         // Split "John Thomas" into "John" and "Thomas" and count against both totals
         foreach (explode(' ', $row[n_givn]) as $given) {
             $given = str_replace(array('*', '"'), '', $given);
             if (strlen($given) > 1) {
                 if (array_key_exists($given, $nameList)) {
                     $nameList[$given] += $row[num];
                 } else {
                     $nameList[$given] = $row[num];
                 }
             }
         }
     }
     arsort($nameList, SORT_NUMERIC);
     $nameList = array_slice($nameList, 0, $maxtoshow);
     if (count($nameList) == 0) {
         return '';
     }
     if ($type == 'chart') {
         return $nameList;
     }
     $common = array();
     foreach ($nameList as $given => $total) {
         if ($maxtoshow !== -1) {
             if ($maxtoshow-- <= 0) {
                 break;
             }
         }
         if ($total < $threshold) {
             break;
         }
         if ($show_tot) {
             $tot = PrintReady("[{$total}]");
             if ($TEXT_DIRECTION == 'ltr') {
                 $totL = '';
                 $totR = '&nbsp;' . $tot;
             } else {
                 $totL = $tot . '&nbsp;';
                 $totR = '';
             }
         } else {
             $totL = '';
             $totR = '';
         }
         switch ($type) {
             case 'table':
                 $common[] = '<tr><td class="optionbox">' . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . '</td><td class="optionbox">' . $total . '</td></tr>';
                 break;
             case 'list':
                 $common[] = "\t<li>{$totL}" . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . "{$totR}</li>\n";
                 break;
             case 'nolist':
                 $common[] = $totL . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . $totR;
                 break;
         }
     }
     if ($common) {
         switch ($type) {
             case 'table':
                 $lookup = array('M' => $pgv_lang['male'], 'F' => $pgv_lang['female'], 'U' => $pgv_lang['unknown'], 'B' => $pgv_lang['all']);
                 return '<table><tr><td colspan="2" class="descriptionbox center">' . $lookup[$sex] . '</td></tr><tr><td class="descriptionbox center">' . $pgv_lang['names'] . '</td><td class="descriptionbox center">' . $pgv_lang['count'] . '</td></tr>' . join('', $common) . '</table>';
             case 'list':
                 return "<ul>\n" . join("\n", $common) . "</ul>\n";
             case 'nolist':
                 return join(';&nbsp; ', $common);
         }
     } else {
         return '';
     }
 }
/**
* extract all places from the given record and insert them
* into the places table
* @param string $gedrec
*/
function update_places($gid, $ged_id, $gedrec)
{
    global $placecache, $TBLPREFIX, $gBitDb;
    if (!isset($placecache)) {
        $placecache = array();
    }
    $personplace = array();
    // import all place locations, but not control info such as
    // 0 HEAD/1 PLAC or 0 _EVDEF/1 PLAC
    $pt = preg_match_all("/^[2-9] PLAC (.+)/m", $gedrec, $match, PREG_SET_ORDER);
    for ($i = 0; $i < $pt; $i++) {
        $place = trim($match[$i][1]);
        $lowplace = UTF8_strtolower($place);
        //-- if we have already visited this place for this person then we don't need to again
        if (isset($personplace[$lowplace])) {
            continue;
        }
        $personplace[$lowplace] = 1;
        $places = explode(',', $place);
        //-- reverse the array to start at the highest level
        $secalp = array_reverse($places);
        $parent_id = 0;
        $level = 0;
        $search = true;
        foreach ($secalp as $indexval => $place) {
            $place = trim($place);
            $place = preg_replace('/\\\\"/', "", $place);
            $place = preg_replace("/[\\><]/", "", $place);
            $key = strtolower($place . "_" . $level . "_" . $parent_id);
            //-- if this place has already been added then we don't need to add it again
            if (isset($placecache[$key])) {
                $parent_id = $placecache[$key];
                if (!isset($personplace[$key])) {
                    $personplace[$key] = 1;
                    $gBitDb->query("INSERT INTO {$TBLPREFIX}placelinks (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)", array($parent_id, $gid, $ged_id));
                }
                $level++;
                continue;
            }
            //-- only search the database while we are finding places in it
            if ($search) {
                //-- check if this place and level has already been added
                $tmp = $gBitDb->getOne("SELECT p_id FROM {$TBLPREFIX}places WHERE p_level=? AND p_file=? AND p_parent_id=? AND p_place LIKE ?", array($level, $ged_id, $parent_id, $place));
                if ($tmp) {
                    $p_id = $tmp;
                } else {
                    $search = false;
                }
            }
            //-- if we are not searching then we have to insert the place into the db
            if (!$search) {
                $std_soundex = soundex_std($place);
                $dm_soundex = soundex_dm($place);
                $p_id = get_next_id("places", "p_id");
                $gBitDb->query("INSERT INTO {$TBLPREFIX}places (p_id, p_place, p_level, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (?,?,?,?,?,?,?)", array($p_id, $place, $level, $parent_id, $ged_id, $std_soundex, $dm_soundex));
            }
            $gBitDb->query("INSERT INTO {$TBLPREFIX}placelinks (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)", array($p_id, $gid, $ged_id));
            //-- increment the level and assign the parent id for the next place level
            $parent_id = $p_id;
            $placecache[$key] = $p_id;
            $personplace[$key] = 1;
            $level++;
        }
    }
    return;
}
Example #7
0
function search_notes($query, $geds, $match, $skip)
{
    global $TBLPREFIX, $GEDCOM, $DB_UTF8_COLLATION, $gBitDb;
    // No query => no results
    if (!$query) {
        return array();
    }
    // Convert the query into a SQL expression
    $querysql = array();
    // Convert the query into a regular expression
    $queryregex = array();
    foreach ($query as $q) {
        $queryregex[] = preg_quote(UTF8_strtoupper($q), '/');
        if ($DB_UTF8_COLLATION || !has_utf8($q)) {
            $querysql[] = "o_gedcom LIKE '%{$q}%'";
        } else {
            $querysql[] = "(o_gedcom LIKE '%{$q}% OR o_gedcom LIKE '%" . UTF8_strtoupper($q) . "%' OR o_gedcom LIKE '%" . UTF8_strtolower($q) . "%'";
        }
    }
    $sql = "SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM {$TBLPREFIX}other WHERE (" . implode(" {$match} ", $querysql) . ") AND o_type='NOTE' AND o_file IN (" . implode(',', $geds) . ')';
    // Group results by gedcom, to minimise switching between privacy files
    $sql .= ' ORDER BY ged_id';
    // Tags we might not want to search
    if (PGV_USER_IS_ADMIN) {
        $skipregex = '/^\\d (_UID|_PGVU|FILE|FORM|TYPE|CHAN|SUBM|REFN) .*(' . implode('|', $queryregex) . ')/im';
    } else {
        $skipregex = '/^\\d (_UID|_PGVU|FILE|FORM|TYPE|CHAN|SUBM|REFN|RESN) .*(' . implode('|', $queryregex) . ')/im';
    }
    $list = array();
    $result = $gBitDb->query($sql);
    $GED_ID = PGV_GED_ID;
    while ($row = $result->fetchRow()) {
        // Switch privacy file if necessary
        if ($row['ged_id'] != $GED_ID) {
            $GEDCOM = get_gedcom_from_id($row['ged_id']);
            load_privacy_file($row['ged_id']);
            $GED_ID = $row['ged_id'];
        }
        $note = Note::getInstance($row);
        // SQL may have matched on private data or gedcom tags, so check again against privatized data.
        $gedrec = UTF8_strtoupper($note->getGedcomRecord());
        foreach ($queryregex as $q) {
            if (!preg_match('/(\\n\\d|^0 @' . PGV_REGEX_XREF . '@) ' . PGV_REGEX_TAG . ' .*' . $q . '/i', $gedrec)) {
                continue 2;
            }
        }
        if ($skip && preg_match($skipregex, $gedrec)) {
            continue;
        }
        $list[] = $note;
    }
    // Switch privacy file if necessary
    if ($GED_ID != PGV_GED_ID) {
        $GEDCOM = get_gedcom_from_id(PGV_GED_ID);
        load_privacy_file(PGV_GED_ID);
    }
    return $list;
}