%name: Age at event-$64% %version: v12.3.0.3% 25 Jan 2022 %wikipage:Age at event% %author:Michel Kirsch from Charleroi-Hainaut-Belgium:https://tng.lythgoes.net/wiki/index.php?title=User:MichelKirsch% %description:
Ce Mod affichera l'âge de la personne au moment de l'événement. L'âge N'est PAS affiché s'il n'y a pas de date de naissance ou s'il n'y a pas de date pour l'événement ou si un âge est déjà encodé pour cet événement.
This Mod will display the age of the person at the time of the event. Age is NOT displayed if there is no date of birth or if there is no event date or if an age is already encoded for this event% List of modifications ====================== 12.3.0.1 16 dec 2021 - First official version 1a 16 dec - change the use of parameters line 70 1b xxxxxx - change explanations for the parameters (not published) 1d 18 dec - rewrite display logic - review parameters (one with 5 options) - display age even an age is encoded for the event 1e 20 dec - rewrite some locations to complies with Census and Mobile enhancements Mods - rewrite the logic for $datewidth 1f 20 dec - Fix the problem of "ghost" age (global $aged in doCustomEvents function of personlib) 1g 21 dec - Fix compatibility with Optional Person Row by changing location #3 in getperson.php 1h 21 dec - Fix compat with Group custom events (changing target of loc #9) - Place provided for ef-Event Edition mod's icon before date (7.6 instead 7 px/char) 1i-1j - passed 1k 21 dec - Add a fourth option (Age 45 years) which is the TNG default display 1M 22 dec - Uses the Brent's modified code for personlib, loc #9 1N 22 dec - Option 5 (after the date) now handled by the showEvent function to avoid $custevent['eventdate'] to be modified - Delete Brent's modif for Census+ 2 23 dec - 1N as published version. 2a 24 dec - Changing logic in personlib.php Loc#3 because date was not displayed under some conditions 2b 27 dec - Changing personlib Loc#9 (Census+ Mod), getperson Loc#3 (Remove gender row Mod) - fix problem with name (space is preceeding the mod name - Ron) 3 25 Jan 2022 - Uses TNG age() function - Add parameter : user decide if he want to use the altbirhdate for calculations if there is no birthdate - Fix problems when there are events with date for a family : don't calculate the age (there is no birthrow !) beta versions ============= Beta 1 : 07 Dec - En test sur wiki : https://tng.community/index.php?/forums/topic/15899-age-automaticly-calculated-pr-event/ 2 07 dec - modify the way of $aged is displayed for allow the mod working with my Group Custom Event Mod 3 08 dec - modify location 1/2 4 09 dec - Changing place to display age after the event (fact[0]), not after the date 5 09 dec - Fix a bug when birtdate is not null but is empty 6 10 dec - Add conditionnal and bold string if aged is negative - modifying calculation to avoid warnings and problems with PHP 7 (Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence) 7 10 dec - changing calculation to avoid non numeric value warning in PHP 7+ - recode to simplify ===================================================== =================== Modify files ==================== ===================================================== ========================================= ========= Program files ================= ========================================= =================== getperson.php ================ %target:getperson.php% ============= Location #1 ========= %location:% include($cms['tngpath'] . "personlib.php" ); %end:% %insert:after% // Age at event Mod - Loc #1 - MichelK // if display age after the date, set the datewidth = longuestDate + space enough for displaying the age // Test if isset($datewidth) because this variable is disabled when Mobile Site enhancements is installed if ($aae_displayWhere == 5 AND isset($datewidth)) { $aae_datewidth = aae_get_maxwidth($personID); $temp_datewidth = $datewidth; } else $temp_datewidth = $aae_datewidth = 0; // Age at event Mod %end:% ============= Location #2 ========= %location:% $persontext .= beginSection("info"); %end:% %insert:before% // Age at event Mod - Loc #2 - MichelK // Change the datewidth if ($aae_displayWhere == 5 AND isset($datewidth)) { if($datewidth < $aae_datewidth) $datewidth = $aae_datewidth; } // Age at event Mod - MichelK %end:% ============= Location #3 ========= %location:% if ( $row['sex'] == "M" ) { %end:% %insert:before% // Age at event Mod - Loc #3 - MichelK if ($aae_displayWhere == 5 AND isset($datewidth)) $datewidth = $temp_datewidth; // restore $datewidth even if it is not modified // Age at event Mod - MichelK %end:% ================================================== =================== globallib.php ================ ================================================== %target:globallib.php% ============= Location #1 ========= %location:% if ($age <> "") { %end:% %insert:before% // Age at event Mod - MichelK if (isset($row['stop_formatting']) && $row['stop_formatting'] == 1) return $age; // Age at event Mod - MichelK %end:% ================================================== =================== personlib.php ================ ================================================== %target:personlib.php% ============= Location #1 ========= %location:% function doStrong($string) { %end:% %insert:before% // Age at event Mod - Loc #1 - MichelK //parameters (Mod Manager options) $aae_displayWhere = 5; // 1:after Detail - 2: before Detail - 3: after Place - 4: before Place - 5: After Date $displayAs = 3; // 1: (45 year) - 2: (45 years old) - 3: (Age 45) - 4: (Age 45 years) $displayAlways = 0; // display the calculated age even an age is already encoded for the considered event // Age at event Mod - MichelK %end:% ============= Location #2 ========= %location:% $myindexlist = array('type','event','entity','date','place','collapse','fact','xnote'); %end:% %insert:before% // Age at event Mod - Loc #2 - MichelK global $aae_displayWhere; if(isset($data['aae_age'])) $my_age = $data['aae_age']; else $my_age = ""; // Age at event Mod - MichelK %end:% ============= Location #3 ========= %location:% if( !$data['place'] && $cite ) { %end:% %insert:before% // Age at event Mod - Loc #3 - MichelK if( $my_age != "") if ( (!$data['place'] AND ($aae_displayWhere == 3 OR $aae_displayWhere == 4)) OR $aae_displayWhere == 5 ) // display after date $output .= $my_age; // Age at event Mod - MichelK %end:% ============= Location #4 ========= %location:% $output .= ">" . $data['place']; %end:% %insert:before% // Age at event Mod - Loc #4 - MichelK if ($aae_displayWhere == 4 && $my_age != "") // display age before the place $output .= ">$my_age " . $data['place']; else // Age at event Mod - MichelK %end:% ============= Location #5 ========= %location:% $cite \n"; %end:% %insert:after% // Age at event Mod - Loc #5 - MichelK if ($aae_displayWhere == 3 && $my_age != "") // display age after the place $output = str_ireplace("$cite \n","$my_age $cite \n",$output); // displays age after the glass and before the sources // Age at event Mod - MichelK %end:% ============= Location #6 ========= %location:% while ( $custevent = tng_fetch_assoc( $custevents ) ) { %end:% %insert:before% // Age at event Mod - Loc #6 - MichelK global $tngconfig; if (substr($entityID,0,1) == $tngconfig['personprefix']) // standard is "I" or "P" $birthrow = aae_get_birthdates($entityID, $tree); // Age at event Mod - MichelK %end:% ============= Location #7 ========= %location:% while ( $custevent = tng_fetch_assoc( $custevents ) ) { %end:% %insert:after% // Age at event Mod - Loc #7 - MichelK $aged = ""; if (isset($birthrow)) $aged = aae_get_formatted_age($birthrow, $custevent);// Age at event Mod - Loc #7 - MichelK // Age at event Mod - MichelK %end:% ======= Location #8 ========= %location:% setEvent( array( "text"=>$displayval, "date"=>$custevent['eventdate'], "place"=>$custevent['eventplace'], "fact"=>$fact, "xnote"=>$xnote, "event"=>$eventID, %end:% %insert:before% // Age at event Mod - Loc #8 - MichelK global $aae_displayWhere; // display age at right location switch ($aae_displayWhere){ case 1: //after the detail if(isset($fact[0])) $fact[0] .= $aged; else $fact[0] = $aged; break; case 2: // before the Detail if(isset($fact[0])) $fact[0] = $aged . " " . $fact[0]; else $fact[0] = $aged; break; case 3: // After the place break; // handled in showevent. If we do it here, place will be altered and can't be searched. If there is no place, magnifying glas will follow the age case 4: // before the place break; // same remark case 5: // after the date break; // handled in showEvent to avoid $custevent['eventdate'] to be modified default: $mymsg = "Age at event Mod Error - Parameter displayAs not correctly set - Must be in (1..5)"; if(isset($fact[0])) $fact[0] .= $mymsg; else $fact[0] = $mymsg; } // Age at event Mod - MichelK %end:% ======= Location #9 ========= %location:% "nomap"=> $nomap, "collapse"=> %end:% %trimreplace:% "nomap"=> $nomap, /* Age at event #9 */ "aae_age"=>$aged, /* Age at event #9 */"collapse"=> %end:% ======= Location #10 ========= %location:% function endSection( $section ) { return " \n"; } %end:% %insert:after% // Age at event Mod - Loc #10 - MichelK // functions used by the Mod function aae_get_birthdates($myentityID, $mytree) { global $tngconfig, $people_table; $agerow = array(); if (substr($myentityID,0,1) == $tngconfig['personprefix']){ // its a person $mysql = "SELECT birthdate, birthdatetr, altbirthdate, altbirthdatetr FROM $people_table WHERE personID = '$myentityID' AND gedcom = '$mytree' "; $myresult = tng_query($mysql); if ($myresult && tng_num_rows($myresult) > 0) $agerow = tng_fetch_assoc($myresult); } return $agerow; } function aae_get_formatted_age( $birthrow, $event) { global $displayAs, $displayAlways; $aged = ""; $listOfEventsToExclude = "ReView"; if( $listOfEventsToExclude != ""){ $listOfEventsToExclude = strtoupper(preg_replace('/\s/', '', $listOfEventsToExclude)); //suppress all occurences of spaces and set in uppercase $events_array = explode(",",$listOfEventsToExclude); if (in_array($event['tag'],$events_array)) // This tag is exluded of the age calculation return $aged; } global $text; $use_altbirthdate = 1; // Mod Manager parameter // use TNG age() function to calculate the age. Fill in the deathdates with eventdates sot he age is calculated between birth and dummy death $birthrow['deathdate'] = $event['eventdate']; $birthrow['deathdatetr'] = $event['eventdatetr']; $birthrow['burialdate'] = ''; // these 3 lines to avoid warnings $birthrow['burialdatetr'] = "0000-00-00"; $birthrow['living'] = "0"; $birthrow['stop_formatting'] = 1; // will stop the TNG formatting done in the age() function if ($use_altbirthdate != 1) // Don't use altbirthdate if there is no birthdate (Parameter) => no birthdate = no age returned $birthrow['birthdate'] = $birthrow['birthdatetr'] = ""; $eventage = age($birthrow); // format with display 1-2-3-4 if ($eventage != ""){ switch ($displayAs) { case 1: $aged = " (" . $eventage . " " . $text['years'] . ")"; break; case 2: $aged = " (" . $eventage . " " . $text['yearsold'] . ")"; break; case 3: $aged = " (" . $text['age'] . " " . $eventage . ")"; break; case 4: $aged = " (" . $text['age'] . " " . $eventage . " " . $text['years'] .")"; // this the TNG default display break; default: // = case 4 $aged = " (" . $text['age'] . " " . $eventage . " " . $text['years'] .")"; // this the TNG default display break; } // set the age in bold if < 0 or different or an already encoded age in the event if ($eventage < 0 OR ($event['age'] != "" AND $eventage != $event['age'])) $aged = '' . $aged . ""; } else $aged = $eventage; return $aged; } function aae_get_maxwidth($entityID){ global $events_table, $eventtypes_table, $tree, $text, $displayAs; // determines the length of the display - 6 char for the age himself "(100 )" + 1 if bolded + 3 for ef_ee_icon if needed + 2 if signs ~ or < $agelength = 12; switch ($displayAs) { case 1: $msglength = strlen($text['years']); break; case 2: $msglength = strlen($text['yearsold']); break; case 3: $msglength = strlen($text['age']); break; default: // case 2 $msglength = strlen($text['yearsold']); break; } $query = "SELECT eventdate,eventdatetr FROM ($events_table, $eventtypes_table) WHERE persfamID = \"$entityID\" AND $events_table.eventtypeID = $eventtypes_table.eventtypeID AND gedcom = \"$tree\" AND keep = \"1\" AND parenttag = \"\" ORDER BY eventdatetr"; $evenements = tng_query($query); // determines the width to give for the field date $longuestdate = 0; while ($evenement = tng_fetch_assoc( $evenements ) ) { $mydate = $evenement['eventdate']; if (strlen($mydate) > $longuestdate) $longuestdate = strlen($mydate); } $mydatewidth = round( 7 * ($longuestdate + $agelength + $msglength)); // in pixels, with 7 pixels/char return $mydatewidth; } // Age at event Mod - MichelK %end:% ====================================== ========== Language files ============ ====================================== ========== French-UTF8 ================ %target:languages/French-UTF8/cust_text.php% %fileoptional:% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "ans"; // Age at event Mod - Michel Kirsch %end:% ========== French ================ %target:languages/French/cust_text.php% %fileoptional:% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "ans"; // Age at event Mod - Michel Kirsch %end:% ========== Dutch-UTF8 ================ %target:languages/Dutch-UTF8/cust_text.php% %fileoptional:% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "jaren oud"; // Age at event Mod - Michel Kirsch %end:% ========== English-UTF8 ================ %target:languages/English-UTF8/cust_text.php% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "years old"; // Age at event Mod - Michel Kirsch %end:% ========== English ================ %target:languages/English/cust_text.php% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "years old"; // Age at event Mod - Michel Kirsch %end:% ========== German-UTF8 ================ %target:languages/German-UTF8/cust_text.php% %fileoptional:% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "jahre alt"; // Age at event Mod - Michel Kirsch %end:% ========== Norwegian-UTF8 ================ %target:languages/Norwegian-UTF8/cust_text.php% %fileoptional:% %location:% //Mods should put their changes before this line, local changes should come after it. %end:% %insert:before% // Age at event Mod - Michel Kirsch $text['yearsold'] = "år gammel"; // Age at event Mod - Michel Kirsch %end:% ===================================== ============= Parameters ============ ===================================== %target:personlib.php% ================== $listOfEventsToExclude =========== %parameter:$listOfEventsToExclude:ReView% %desc:
Entrez ici les événements (tags) pour lesquels l'âge ne doit pas être affiché. Séparez chaque tag par une virgule, avec ou sans espaces, en minuscules ou majuscules. Exemple: ReView, oc cu, RESI
N'ajoutez pas de guillemets !


Enter here the events (tags) for which the age should not be displayed. Separate each tag with a comma, with or without spaces, in lower or upper case. Example: ReView, oc cu, RESI
Don't add quotes !

default: (ReView)
% ================== $use_altbirthdate =========== %parameter:$use_altbirthdate:1% %desc:
Si ce paramètres est sur 1, l'âge est calculé sur la date de baptême (altbirthdate) s'il n'y a pas de date de naissance exploitable
N'ajoutez pas de guillemets !


If this parameter is set to 1, the calculated age will be calculated on the christening date (altbirthdate) if thee is no birthdate.
Don't add quotes !

default: (1)
% ================== $aae_displayWhere =========== %parameter:$aae_displayWhere:5% %desc:
Choisissez où afficher l'âge. N'ajoutez pas de guillemets !
Choose where to display the age. Don't add quotes !

1 => After the 'Detail' of the event - Après le 'Détail' de l'événement.
2 => Before the 'Detail' of the event - Avant le 'Détail' de l'événement.
3 => After the 'Place' of the event - Après le 'Lieu' de l'événement.
4 => Before the 'Place' of the event - Avant le 'Lieu' de l'événement.
5 => After the 'Date' of the event - Après la 'Date' de l'événement.
(Mobile Site Enhancements Mod : Age can be split ! - L'Age peut être scindé en deux !)
default: (3)
% ================== $displayAs =========== %parameter:$displayAs:3% %desc:
Règlez sur 1, 2 ou 3 pour obtenir l'affichage qui vous convient.
N'ajoutez pas de guillemets !


Set this parameter to display age as you want.
Don't add quotes !

1 - (45 ans) - (45 years) - (45 jaren) - (45 år)
2 - (45 ans) - (45 years old) - (45 jaren oud) - (45 år gammel)
3 - (Age 45) - (Age 45) - (Leeftijd 45) - (Alder 45)
4 - (Agé de 45 ans) - (Age 45 years)
default: (4)
% ================== $displayAlways =========== %parameter:$displayAlways:0% %desc:
Si ce paramètres est sur 1, l'âge calculé sera affiché même si un âge est déjà encodé pour l'événement. Si une différence est constatée entre les deux âges, l'âge calculé sera affiché en gras
N'ajoutez pas de guillemets !


If this parameter is set to 1, the calculated age will be displayed even if an age is already encoded for the event. If there is a difference between the two ages, the calculated age will be displayed in bold.
Don't add quotes !

default: (0)
%