/** * is the person alive in the given year * @param string $indirec the persons raw gedcom record * @param int $year the year to check if they are alive in * @return int return 0 if the person is alive, negative number if they died earlier, positive number if they will be born in the future */ function check_alive($indirec, $year) { global $MAX_ALIVE_AGE; if (is_dead($indirec, $year)) { return -1; } // Died before year? $deathrec = get_sub_record(1, "1 DEAT", $indirec); if (preg_match("/\\d DATE (.*)/", $deathrec, $match)) { $ddate = new GedcomDate($match[1]); $dyear = $ddate->gregorianYear(); if ($year > $dyear) { return -1; } } // Born after year? $birthrec = get_sub_record(1, "1 BIRT", $indirec); if (preg_match("/\\d DATE (.*)/", $birthrec, $match)) { $bdate = new GedcomDate($match[1]); $byear = $bdate->gregorianYear(); if ($year < $byear) { return 1; } } // Born before year and died after year if (isset($byear) && isset($dyear) && $year >= $byear && $year <= $dyear) { return 0; } // If no death record than check all dates; $years = array(); $subrecs = get_all_subrecords($indirec, "CHAN", true, true, false); foreach ($subrecs as $ind => $subrec) { if (preg_match("/\\d DATE (.*)/", $subrec, $match)) { $date = new GedcomDate($match[1]); $datey = $date->gregorianYear(); if ($datey) { $years[] = $datey; } } } // Events both before and after year if (count($years) > 1 && $year >= $years[0] && $year <= $years[count($years) - 1]) { return 0; } foreach ($years as $ind => $year1) { if ($year1 - $year > $MAX_ALIVE_AGE) { return -1; } } return 0; }