. */ namespace Fisharebest\Webtrees\Functions; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Database; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Media; use Fisharebest\Webtrees\Note; use Fisharebest\Webtrees\Place; use Fisharebest\Webtrees\Repository; use Fisharebest\Webtrees\Source; use Fisharebest\Webtrees\Stats; use Fisharebest\Webtrees\Tree; use Rhumsaa\Uuid\Uuid; /** * Class FunctionsPrintLists - create sortable lists using datatables.net */ class FunctionsPrintLists { /** * Generate a SURN,GIVN and GIVN,SURN sortable name for an individual. * This allows table data to sort by surname or given names. * * Use AAAA as a separator (instead of ","), as Javascript localeCompare() * ignores punctuation and "ANN,ROACH" would sort after "ANNE,ROACH", * instead of before it. * * @param Individual $individual * * @return string[] */ private static function sortableNames(Individual $individual) { $names = $individual->getAllNames(); $primary = $individual->getPrimaryName(); list($surn, $givn) = explode(',', $names[$primary]['sort']); $givn = str_replace('@P.N.', 'AAAA', $givn); $surn = str_replace('@N.N.', 'AAAA', $surn); return array( $surn . 'AAAA' . $givn, $givn . 'AAAA' . $surn, ); } /** * Print a table of individuals * * @param Individual[] $indiviudals * @param string $option * * @return string */ public static function individualTable($indiviudals, $option = '') { global $controller, $WT_TREE; $table_id = 'table-indi-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable( { dom: \'<"H"<"filtersH_' . $table_id . '">T<"dt-clear">pf<"dt-clear">irl>t<"F"pl<"dt-clear"><"filtersF_' . $table_id . '">>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth: false, processing: true, retrieve: true, columns: [ /* Given names */ { type: "text" }, /* Surnames */ { type: "text" }, /* SOSA numnber */ { type: "num", visible: ' . ($option === 'sosa' ? 'true' : 'false') . ' }, /* Birth date */ { type: "num" }, /* Anniversary */ { type: "num" }, /* Birthplace */ { type: "text" }, /* Children */ { type: "num" }, /* Deate date */ { type: "num" }, /* Anniversary */ { type: "num" }, /* Age */ { type: "num" }, /* Death place */ { type: "text" }, /* Last change */ { visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, /* Filter sex */ { sortable: false }, /* Filter birth */ { sortable: false }, /* Filter death */ { sortable: false }, /* Filter tree */ { sortable: false } ], sorting: [[' . ($option === 'sosa' ? '4, "asc"' : '1, "asc"') . ']], displayLength: 20, pagingType: "full_numbers" }); jQuery("#' . $table_id . '") /* Hide/show parents */ .on("click", ".btn-toggle-parents", function() { jQuery(this).toggleClass("ui-state-active"); jQuery(".parents", jQuery(this).closest("table").DataTable().rows().nodes()).slideToggle(); }) /* Hide/show statistics */ .on("click", ".btn-toggle-statistics", function() { jQuery(this).toggleClass("ui-state-active"); jQuery("#indi_list_table-charts_' . $table_id . '").slideToggle(); }) /* Filter buttons in table header */ .on("click", "button[data-filter-column]", function() { var btn = jQuery(this); // De-activate the other buttons in this button group btn.siblings().removeClass("ui-state-active"); // Apply (or clear) this filter var col = jQuery("#' . $table_id . '").DataTable().column(btn.data("filter-column")); if (btn.hasClass("ui-state-active")) { btn.removeClass("ui-state-active"); col.search("").draw(); } else { btn.addClass("ui-state-active"); col.search(btn.data("filter-value")).draw(); } }); jQuery(".indi-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $stats = new Stats($WT_TREE); // Bad data can cause "longest life" to be huge, blowing memory limits $max_age = min($WT_TREE->getPreference('MAX_ALIVE_AGE'), $stats->longestLifeAge()) + 1; // Inititialise chart data $deat_by_age = array(); for ($age = 0; $age <= $max_age; $age++) { $deat_by_age[$age] = ''; } $birt_by_decade = array(); $deat_by_decade = array(); for ($year = 1550; $year < 2030; $year += 10) { $birt_by_decade[$year] = ''; $deat_by_decade[$year] = ''; } $html = '
'; $hundred_years_ago = new Date(date('Y') - 100); $unique_indis = array(); // Don't double-count indis with multiple names. foreach ($indiviudals as $key => $individual) { if (!$individual->canShowName()) { continue; } if ($individual->isPendingAddtion()) { $class = ' class="new"'; } elseif ($individual->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Extract Given names and Surnames for sorting list($surn_givn, $givn_surn) = self::sortableNames($individual); $html .= ''; // Hidden column for sortable name $html .= ''; // SOSA $html .= ''; // Birth date $birth_dates = $individual->getAllBirthDates(); $html .= ''; // Birth anniversary if (isset($birth_dates[0]) && $birth_dates[0]->gregorianYear() >= 1550 && $birth_dates[0]->gregorianYear() < 2030 && !isset($unique_indis[$individual->getXref()])) { $birt_by_decade[(int) ($birth_dates[0]->gregorianYear() / 10) * 10] .= $individual->getSex(); $anniversary = Date::getAge($birth_dates[0], null, 2); } else { $anniversary = ''; } $html .= ''; // Birth place $html .= ''; // Number of children $number_of_children = $individual->getNumberOfChildren(); $html .= ''; // Death date $death_dates = $individual->getAllDeathDates(); $html .= ''; // Death anniversary if (isset($death_dates[0]) && $death_dates[0]->gregorianYear() >= 1550 && $death_dates[0]->gregorianYear() < 2030 && !isset($unique_indis[$individual->getXref()])) { $birt_by_decade[(int) ($death_dates[0]->gregorianYear() / 10) * 10] .= $individual->getSex(); $anniversary = Date::getAge($death_dates[0], null, 2); } else { $anniversary = ''; } $html .= ''; // Age at death if (isset($birth_dates[0]) && isset($death_dates[0])) { $age_at_death = Date::getAge($birth_dates[0], $death_dates[0], 0); $age_at_death_sort = Date::getAge($birth_dates[0], $death_dates[0], 2); if (!isset($unique_indis[$individual->getXref()]) && $age >= 0 && $age <= $max_age) { $deat_by_age[$age_at_death] .= $individual->getSex(); } } else { $age_at_death = ''; $age_at_death_sort = PHP_INT_MAX; } $html .= ''; // Death place $html .= ''; // Last change $html .= ''; // Filter by sex $html .= ''; // Filter by birth date $html .= ''; // Filter by death date $html .= ''; // Filter by roots/leaves $html .= ''; $html .= ''; $unique_indis[$individual->getXref()] = true; } $html .= '
' . GedcomTag::getLabel('GIVN') . ' ' . GedcomTag::getLabel('SURN') . ' ' . /* I18N: Abbreviation for “Sosa-Stradonitz number”. This is an individual’s surname, so may need transliterating into non-latin alphabets. */ I18N::translate('Sosa') . ' ' . GedcomTag::getLabel('BIRT') . ' ' . GedcomTag::getLabel('PLAC') . ' ' . GedcomTag::getLabel('DEAT') . ' ' . GedcomTag::getLabel('AGE') . ' ' . GedcomTag::getLabel('PLAC') . ' ' . GedcomTag::getLabel('CHAN') . '
'; foreach ($individual->getAllNames() as $num => $name) { if ($name['type'] == 'NAME') { $title = ''; } else { $title = 'title="' . strip_tags(GedcomTag::getLabel($name['type'], $individual)) . '"'; } if ($num == $individual->getPrimaryName()) { $class = ' class="name2"'; $sex_image = $individual->getSexImage(); } else { $class = ''; $sex_image = ''; } $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . '' . $sex_image . '
'; } $html .= $individual->getPrimaryParentsNames('parents details1', 'none'); $html .= '
'; if ($option === 'sosa') { $html .= '' . I18N::number($key) . ''; } $html .= ''; foreach ($birth_dates as $n => $birth_date) { if ($n > 0) { $html .= '
'; } $html .= $birth_date->display(true); } $html .= '
' . $anniversary . ''; foreach ($individual->getAllBirthPlaces() as $n => $birth_place) { $tmp = new Place($birth_place, $individual->getTree()); if ($n > 0) { $html .= '
'; } $html .= ''; $html .= FunctionsPrint::highlightSearchHits($tmp->getShortName()) . ''; } $html .= '
' . I18N::number($number_of_children) . ''; foreach ($death_dates as $num => $death_date) { if ($num) { $html .= '
'; } $html .= $death_date->display(true); } $html .= '
' . $anniversary . '' . $age_at_death . ''; foreach ($individual->getAllDeathPlaces() as $n => $death_place) { $tmp = new Place($death_place, $individual->getTree()); if ($n > 0) { $html .= '
'; } $html .= ''; $html .= FunctionsPrint::highlightSearchHits($tmp->getShortName()) . ''; } $html .= '
' . $individual->lastChangeTimestamp() . '
'; return $html; } /** * Print a table of families * * @param Family[] $families * * @return string */ public static function familyTable($families) { global $WT_TREE, $controller; $table_id = 'table-fam-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable( { dom: \'<"H"<"filtersH_' . $table_id . '"><"dt-clear">pf<"dt-clear">irl>t<"F"pl<"dt-clear"><"filtersF_' . $table_id . '">>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth: false, processing: true, retrieve: true, columns: [ /* Given names */ { type: "text" }, /* Surnames */ { type: "text" }, /* Age */ { type: "num" }, /* Given names */ { type: "text" }, /* Surnames */ { type: "text" }, /* Age */ { type: "num" }, /* Marriage date */ { type: "num" }, /* Anniversary */ { type: "num" }, /* Marriage place */ { type: "text" }, /* Children */ { type: "num" }, /* Last change */ { visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, /* Filter marriage */ { sortable: false }, /* Filter alive/dead */ { sortable: false }, /* Filter tree */ { sortable: false } ], sorting: [[1, "asc"]], displayLength: 20, pagingType: "full_numbers" }); jQuery("#' . $table_id . '") /* Hide/show parents */ .on("click", ".btn-toggle-parents", function() { jQuery(this).toggleClass("ui-state-active"); jQuery(".parents", jQuery(this).closest("table").DataTable().rows().nodes()).slideToggle(); }) /* Hide/show statistics */ .on("click", ".btn-toggle-statistics", function() { jQuery(this).toggleClass("ui-state-active"); jQuery("#fam_list_table-charts_' . $table_id . '").slideToggle(); }) /* Filter buttons in table header */ .on("click", "button[data-filter-column]", function() { var btn = $(this); // De-activate the other buttons in this button group btn.siblings().removeClass("ui-state-active"); // Apply (or clear) this filter var col = jQuery("#' . $table_id . '").DataTable().column(btn.data("filter-column")); if (btn.hasClass("ui-state-active")) { btn.removeClass("ui-state-active"); col.search("").draw(); } else { btn.addClass("ui-state-active"); col.search(btn.data("filter-value")).draw(); } }); jQuery(".fam-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $stats = new Stats($WT_TREE); $max_age = max($stats->oldestMarriageMaleAge(), $stats->oldestMarriageFemaleAge()) + 1; // init chart data $marr_by_age = array(); for ($age = 0; $age <= $max_age; $age++) { $marr_by_age[$age] = ''; } $birt_by_decade = array(); $marr_by_decade = array(); for ($year = 1550; $year < 2030; $year += 10) { $birt_by_decade[$year] = ''; $marr_by_decade[$year] = ''; } $html = '
'; $hundred_years_ago = new Date(date('Y') - 100); foreach ($families as $family) { // Retrieve husband and wife $husb = $family->getHusband(); if (is_null($husb)) { $husb = new Individual('H', '0 @H@ INDI', null, $family->getTree()); } $wife = $family->getWife(); if (is_null($wife)) { $wife = new Individual('W', '0 @W@ INDI', null, $family->getTree()); } if (!$family->canShow()) { continue; } if ($family->isPendingAddtion()) { $class = ' class="new"'; } elseif ($family->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Husband name(s) // Extract Given names and Surnames for sorting list($surn_givn, $givn_surn) = self::sortableNames($husb); $html .= ''; // Hidden column for sortable name $html .= ''; // Husband age $mdate = $family->getMarriageDate(); $hdate = $husb->getBirthDate(); if ($hdate->isOK() && $mdate->isOK()) { if ($hdate->gregorianYear() >= 1550 && $hdate->gregorianYear() < 2030) { $birt_by_decade[(int) ($hdate->gregorianYear() / 10) * 10] .= $husb->getSex(); } $hage = Date::getAge($hdate, $mdate, 0); if ($hage >= 0 && $hage <= $max_age) { $marr_by_age[$hage] .= $husb->getSex(); } } $html .= ''; // Wife name(s) // Extract Given names and Surnames for sorting list($surn_givn, $givn_surn) = self::sortableNames($wife); $html .= ''; // Hidden column for sortable name $html .= ''; // Wife age $mdate = $family->getMarriageDate(); $wdate = $wife->getBirthDate(); if ($wdate->isOK() && $mdate->isOK()) { if ($wdate->gregorianYear() >= 1550 && $wdate->gregorianYear() < 2030) { $birt_by_decade[(int) ($wdate->gregorianYear() / 10) * 10] .= $wife->getSex(); } $wage = Date::getAge($wdate, $mdate, 0); if ($wage >= 0 && $wage <= $max_age) { $marr_by_age[$wage] .= $wife->getSex(); } } $html .= ''; // Marriage date $html .= ''; // Marriage anniversary $html .= ''; // Marriage place $html .= ''; // Number of children $html .= ''; // Last change $html .= ''; // Filter by marriage date $html .= ''; // Filter by alive/dead $html .= ''; // Filter by roots/leaves $html .= ''; } $html .= '
' . GedcomTag::getLabel('GIVN') . ' ' . GedcomTag::getLabel('SURN') . ' ' . GedcomTag::getLabel('AGE') . ' ' . GedcomTag::getLabel('GIVN') . ' ' . GedcomTag::getLabel('SURN') . ' ' . GedcomTag::getLabel('AGE') . ' ' . GedcomTag::getLabel('MARR') . ' ' . GedcomTag::getLabel('PLAC') . ' ' . GedcomTag::getLabel('CHAN') . '
'; foreach ($husb->getAllNames() as $num => $name) { if ($name['type'] == 'NAME') { $title = ''; } else { $title = 'title="' . strip_tags(GedcomTag::getLabel($name['type'], $husb)) . '"'; } if ($num == $husb->getPrimaryName()) { $class = ' class="name2"'; $sex_image = $husb->getSexImage(); } else { $class = ''; $sex_image = ''; } // Only show married names if they are the name we are filtering by. if ($name['type'] != '_MARNM' || $num == $husb->getPrimaryName()) { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . '' . $sex_image . '
'; } } // Husband parents $html .= $husb->getPrimaryParentsNames('parents details1', 'none'); $html .= '
' . Date::getAge($hdate, $mdate, 2) . ''; foreach ($wife->getAllNames() as $num => $name) { if ($name['type'] == 'NAME') { $title = ''; } else { $title = 'title="' . strip_tags(GedcomTag::getLabel($name['type'], $wife)) . '"'; } if ($num == $wife->getPrimaryName()) { $class = ' class="name2"'; $sex_image = $wife->getSexImage(); } else { $class = ''; $sex_image = ''; } // Only show married names if they are the name we are filtering by. if ($name['type'] != '_MARNM' || $num == $wife->getPrimaryName()) { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . '' . $sex_image . '
'; } } // Wife parents $html .= $wife->getPrimaryParentsNames('parents details1', 'none'); $html .= '
' . Date::getAge($wdate, $mdate, 2) . ''; if ($marriage_dates = $family->getAllMarriageDates()) { foreach ($marriage_dates as $n => $marriage_date) { if ($n) { $html .= '
'; } $html .= '
' . $marriage_date->display(true) . '
'; } if ($marriage_dates[0]->gregorianYear() >= 1550 && $marriage_dates[0]->gregorianYear() < 2030) { $marr_by_decade[(int) ($marriage_dates[0]->gregorianYear() / 10) * 10] .= $husb->getSex() . $wife->getSex(); } } elseif ($family->getFacts('_NMR')) { $html .= I18N::translate('no'); } elseif ($family->getFacts('MARR')) { $html .= I18N::translate('yes'); } else { $html .= ' '; } $html .= '
' . Date::getAge($family->getMarriageDate(), null, 2) . ''; foreach ($family->getAllMarriagePlaces() as $n => $marriage_place) { $tmp = new Place($marriage_place, $family->getTree()); if ($n) { $html .= '
'; } $html .= ''; $html .= FunctionsPrint::highlightSearchHits($tmp->getShortName()) . ''; } $html .= '
' . I18N::number($family->getNumberOfChildren()) . '' . $family->lastChangeTimestamp() . '
'; return $html; } /** * Print a table of sources * * @param Source[] $sources * * @return string */ public static function sourceTable($sources) { global $WT_TREE, $controller; // Count the number of linked records. These numbers include private records. // It is not good to bypass privacy, but many servers do not have the resources // to process privacy for every record in the tree $count_individuals = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##individuals` JOIN `##link` ON l_from = i_id AND l_file = i_file AND l_type = 'SOUR' GROUP BY l_to, l_file" )->fetchAssoc(); $count_families = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##families` JOIN `##link` ON l_from = f_id AND l_file = f_file AND l_type = 'SOUR' GROUP BY l_to, l_file" )->fetchAssoc(); $count_media = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##media` JOIN `##link` ON l_from = m_id AND l_file = m_file AND l_type = 'SOUR' GROUP BY l_to, l_file" )->fetchAssoc(); $count_notes = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##other` JOIN `##link` ON l_from = o_id AND l_file = o_file AND o_type = 'NOTE' AND l_type = 'SOUR' GROUP BY l_to, l_file" )->fetchAssoc(); $html = ''; $table_id = 'table-sour-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable( { dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth: false, processing: true, columns: [ /* Title */ { type: "text" }, /* Author */ { type: "text" }, /* Individuals */ { type: "num" }, /* Families */ { type: "num" }, /* Media objects */ { type: "num" }, /* Notes */ { type: "num" }, /* Last change */ { visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, /* Delete */ { visible: ' . (Auth::isManager($WT_TREE) ? 'true' : 'false') . ', sortable: false } ], displayLength: 20, pagingType: "full_numbers" }); jQuery(".source-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($sources as $source) { if (!$source->canShow()) { continue; } if ($source->isPendingAddtion()) { $class = ' class="new"'; } elseif ($source->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Source name(s) $html .= ''; // Author $auth = $source->getFirstFact('AUTH'); if ($auth) { $author = $auth->getValue(); } else { $author = ''; } $html .= ''; $key = $source->getXref() . '@' . $source->getTree()->getTreeId(); // Count of linked individuals $num = array_key_exists($key, $count_individuals) ? $count_individuals[$key] : 0; $html .= ''; // Count of linked families $num = array_key_exists($key, $count_families) ? $count_families[$key] : 0; $html .= ''; // Count of linked media objects $num = array_key_exists($key, $count_media) ? $count_media[$key] : 0; $html .= ''; // Count of linked notes $num = array_key_exists($key, $count_notes) ? $count_notes[$key] : 0; $html .= ''; // Last change $html .= ''; // Delete $html .= ''; $html .= ''; } $html .= '
' . GedcomTag::getLabel('TITL') . '' . GedcomTag::getLabel('AUTH') . '' . I18N::translate('Individuals') . '' . I18N::translate('Families') . '' . I18N::translate('Media objects') . '' . I18N::translate('Shared notes') . '' . GedcomTag::getLabel('CHAN') . '' . I18N::translate('Delete') . '
'; foreach ($source->getAllNames() as $n => $name) { if ($n) { $html .= '
'; } if ($n == $source->getPrimaryName()) { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . ''; } else { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . ''; } } $html .= '
' . FunctionsPrint::highlightSearchHits($author) . '' . I18N::number($num) . '' . I18N::number($num) . '' . I18N::number($num) . '' . I18N::number($num) . '' . $source->lastChangeTimestamp() . 'getXref() . '\');">' . I18N::translate('Delete') . '
'; return $html; } /** * Print a table of shared notes * * @param Note[] $notes * * @return string */ public static function noteTable($notes) { global $WT_TREE, $controller; // Count the number of linked records. These numbers include private records. // It is not good to bypass privacy, but many servers do not have the resources // to process privacy for every record in the tree $count_individuals = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##individuals` JOIN `##link` ON l_from = i_id AND l_file = i_file AND l_type = 'NOTE' GROUP BY l_to, l_file" )->fetchAssoc(); $count_families = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##families` JOIN `##link` ON l_from = f_id AND l_file = f_file AND l_type = 'NOTE' GROUP BY l_to, l_file" )->fetchAssoc(); $count_media = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##media` JOIN `##link` ON l_from = m_id AND l_file = m_file AND l_type = 'NOTE' GROUP BY l_to, l_file" )->fetchAssoc(); $count_sources = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##sources` JOIN `##link` ON l_from = s_id AND l_file = s_file AND l_type = 'NOTE' GROUP BY l_to, l_file" )->fetchAssoc(); $html = ''; $table_id = 'table-note-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable({ dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth: false, processing: true, columns: [ /* Title */ { type: "text" }, /* Individuals */ { type: "num" }, /* Families */ { type: "num" }, /* Media objects */ { type: "num" }, /* Sources */ { type: "num" }, /* Last change */ { type: "num", visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, /* Delete */ { visible: ' . (Auth::isManager($WT_TREE) ? 'true' : 'false') . ', sortable: false } ], displayLength: 20, pagingType: "full_numbers" }); jQuery(".note-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($notes as $note) { if (!$note->canShow()) { continue; } if ($note->isPendingAddtion()) { $class = ' class="new"'; } elseif ($note->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Count of linked notes $html .= ''; $key = $note->getXref() . '@' . $note->getTree()->getTreeId(); // Count of linked individuals $num = array_key_exists($key, $count_individuals) ? $count_individuals[$key] : 0; $html .= ''; // Count of linked families $num = array_key_exists($key, $count_families) ? $count_families[$key] : 0; $html .= ''; // Count of linked media objects $num = array_key_exists($key, $count_media) ? $count_media[$key] : 0; $html .= ''; // Count of linked sources $num = array_key_exists($key, $count_sources) ? $count_sources[$key] : 0; $html .= ''; // Last change $html .= ''; // Delete $html .= ''; $html .= ''; } $html .= '
' . GedcomTag::getLabel('TITL') . '' . I18N::translate('Individuals') . '' . I18N::translate('Families') . '' . I18N::translate('Media objects') . '' . I18N::translate('Sources') . '' . GedcomTag::getLabel('CHAN') . '' . I18N::translate('Delete') . '
' . FunctionsPrint::highlightSearchHits($note->getFullName()) . '' . I18N::number($num) . '' . I18N::number($num) . '' . I18N::number($num) . '' . I18N::number($num) . '' . $note->lastChangeTimestamp() . 'getXref() . '\');">' . I18N::translate('Delete') . '
'; return $html; } /** * Print a table of repositories * * @param Repository[] $repositories * * @return string */ public static function repositoryTable($repositories) { global $WT_TREE, $controller; // Count the number of linked records. These numbers include private records. // It is not good to bypass privacy, but many servers do not have the resources // to process privacy for every record in the tree $count_sources = Database::prepare( "SELECT CONCAT(l_to, '@', l_file), COUNT(*) FROM `##sources` JOIN `##link` ON l_from = s_id AND l_file = s_file AND l_type = 'REPO' GROUP BY l_to, l_file" )->fetchAssoc(); $html = ''; $table_id = 'table-repo-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable({ dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth: false, processing: true, columns: [ /* Name */ { type: "text" }, /* Sources */ { type: "num" }, /* Last change */ { visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, /* Delete */ { visible: ' . (Auth::isManager($WT_TREE) ? 'true' : 'false') . ', sortable: false } ], displayLength: 20, pagingType: "full_numbers" }); jQuery(".repo-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($repositories as $repository) { if (!$repository->canShow()) { continue; } if ($repository->isPendingAddtion()) { $class = ' class="new"'; } elseif ($repository->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Repository name(s) $html .= ''; $key = $repository->getXref() . '@' . $repository->getTree()->getTreeId(); // Count of linked sources $num = array_key_exists($key, $count_sources) ? $count_sources[$key] : 0; $html .= ''; // Last change $html .= ''; // Delete $html .= ''; $html .= ''; } $html .= '
' . I18N::translate('Repository name') . '' . I18N::translate('Sources') . '' . GedcomTag::getLabel('CHAN') . '' . I18N::translate('Delete') . '
'; foreach ($repository->getAllNames() as $n => $name) { if ($n) { $html .= '
'; } if ($n == $repository->getPrimaryName()) { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . ''; } else { $html .= '' . FunctionsPrint::highlightSearchHits($name['full']) . ''; } } $html .= '
' . I18N::number($num) . '' . $repository->lastChangeTimestamp() . 'getXref() . '\');">' . I18N::translate('Delete') . '
'; return $html; } /** * Print a table of media objects * * @param Media[] $media_objects * * @return string */ public static function mediaTable($media_objects) { global $WT_TREE, $controller; $html = ''; $table_id = 'table-obje-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable({ dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', ' . I18N::datatablesI18N() . ', jQueryUI: true, autoWidth:false, processing: true, columns: [ /* Thumbnail */ { sortable: false }, /* Title */ { type: "text" }, /* Individuals */ { type: "num" }, /* Families */ { type: "num" }, /* Sources */ { type: "num" }, /* Last change */ { visible: ' . ($WT_TREE->getPreference('SHOW_LAST_CHANGE') ? 'true' : 'false') . ' }, ], displayLength: 20, pagingType: "full_numbers" }); jQuery(".media-list").css("visibility", "visible"); jQuery(".loading-image").css("display", "none"); '); $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($media_objects as $media_object) { if ($media_object->canShow()) { $name = $media_object->getFullName(); if ($media_object->isPendingAddtion()) { $class = ' class="new"'; } elseif ($media_object->isPendingDeletion()) { $class = ' class="old"'; } else { $class = ''; } $html .= ''; // Media object thumbnail $html .= ''; // Media object name(s) $html .= ''; // Count of linked individuals $num = count($media_object->linkedIndividuals('OBJE')); $html .= ''; // Count of linked families $num = count($media_object->linkedFamilies('OBJE')); $html .= ''; // Count of linked sources $num = count($media_object->linkedSources('OBJE')); $html .= ''; // Last change $html .= ''; $html .= ''; } } $html .= '
' . I18N::translate('Media') . '' . GedcomTag::getLabel('TITL') . '' . I18N::translate('Individuals') . '' . I18N::translate('Families') . '' . I18N::translate('Sources') . '' . GedcomTag::getLabel('CHAN') . '
' . $media_object->displayImage() . ''; $html .= ''; $html .= FunctionsPrint::highlightSearchHits($name) . ''; if (Auth::isEditor($media_object->getTree())) { $html .= '
' . basename($media_object->getFilename()) . ''; } $html .= '
' . I18N::number($num) . '' . I18N::number($num) . '' . I18N::number($num) . '' . $media_object->lastChangeTimestamp() . '
'; return $html; } /** * Print a table of surnames, for the top surnames block, the indi/fam lists, etc. * * @param string[][] $surnames array (of SURN, of array of SPFX_SURN, of array of PID) * @param string $script "indilist.php" (counts of individuals) or "famlist.php" (counts of spouses) * @param Tree $tree generate links for this tree * * @return string */ public static function surnameTable($surnames, $script, Tree $tree) { global $controller; $html = ''; $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery(".surname-list").dataTable({ dom: "t", jQueryUI: true, autoWidth: false, ' . I18N::datatablesI18N() . ', paging: false, sorting: [[0, "asc"]], columns: [ /* Surname */ { type: "text" }, /* Count */ { type: "num" } ] }); '); if ($script == 'famlist.php') { $col_heading = I18N::translate('Spouses'); } else { $col_heading = I18N::translate('Individuals'); } $html .= '' . '' . '' . '' . '' . '' . ''; $html .= ''; foreach ($surnames as $surn => $surns) { // Each surname links back to the indi/fam surname list if ($surn) { $url = $script . '?surname=' . rawurlencode($surn) . '&ged=' . $tree->getNameUrl(); } else { $url = $script . '?alpha=,&ged=' . $tree->getNameUrl(); } $html .= ''; // Surname $html .= ''; // Surname count $subtotal = 0; foreach ($surns as $indis) { $subtotal += count($indis); } $html .= ''; $html .= ''; } $html .= '
' . GedcomTag::getLabel('SURN') . '' . $col_heading . '
'; // Multiple surname variants, e.g. von Groot, van Groot, van der Groot, etc. foreach ($surns as $spfxsurn => $indis) { if ($spfxsurn) { $html .= '' . Filter::escapeHtml($spfxsurn) . '
'; } else { // No surname, but a value from "2 SURN"? A common workaround for toponyms, etc. $html .= '' . Filter::escapeHtml($surn) . '
'; } } $html .= '
'; foreach ($surns as $indis) { $html .= I18N::number(count($indis)) . '
'; } if (count($surns) > 1) { // More than one surname variant? Show a subtotal $html .= I18N::number($subtotal); } $html .= '
'; return $html; } /** * Print a tagcloud of surnames. * * @param string[][] $surnames array (of SURN, of array of SPFX_SURN, of array of PID) * @param string $script indilist or famlist * @param bool $totals show totals after each name * @param Tree $tree generate links to this tree * * @return string */ public static function surnameTagCloud($surnames, $script, $totals, Tree $tree) { $minimum = PHP_INT_MAX; $maximum = 1; foreach ($surnames as $surn => $surns) { foreach ($surns as $spfxsurn => $indis) { $maximum = max($maximum, count($indis)); $minimum = min($minimum, count($indis)); } } $html = ''; foreach ($surnames as $surn => $surns) { foreach ($surns as $spfxsurn => $indis) { if ($maximum === $minimum) { // All surnames occur the same number of times $size = 150.0; } else { $size = 75.0 + 125.0 * (count($indis) - $minimum) / ($maximum - $minimum); } $html .= ''; if ($totals) { $html .= I18N::translate('%1$s (%2$s)', '' . $spfxsurn . '', I18N::number(count($indis))); } else { $html .= $spfxsurn; } $html .= ' '; } } return '
' . $html . '
'; } /** * Print a list of surnames. * * @param string[][] $surnames array (of SURN, of array of SPFX_SURN, of array of PID) * @param int $style 1=bullet list, 2=semicolon-separated list, 3=tabulated list with up to 4 columns * @param bool $totals show totals after each name * @param string $script indilist or famlist * @param Tree $tree Link back to the individual list in this tree * * @return string */ public static function surnameList($surnames, $style, $totals, $script, Tree $tree) { $html = array(); foreach ($surnames as $surn => $surns) { // Each surname links back to the indilist if ($surn) { $url = $script . '?surname=' . urlencode($surn) . '&ged=' . $tree->getNameUrl(); } else { $url = $script . '?alpha=,&ged=' . $tree->getNameUrl(); } // If all the surnames are just case variants, then merge them into one // Comment out this block if you want SMITH listed separately from Smith $first_spfxsurn = null; foreach ($surns as $spfxsurn => $indis) { if ($first_spfxsurn) { if (I18N::strtoupper($spfxsurn) == I18N::strtoupper($first_spfxsurn)) { $surns[$first_spfxsurn] = array_merge($surns[$first_spfxsurn], $surns[$spfxsurn]); unset($surns[$spfxsurn]); } } else { $first_spfxsurn = $spfxsurn; } } $subhtml = '' . Filter::escapeHtml(implode(I18N::$list_separator, array_keys($surns))) . ''; if ($totals) { $subtotal = 0; foreach ($surns as $indis) { $subtotal += count($indis); } $subhtml .= ' (' . I18N::number($subtotal) . ')'; } $html[] = $subhtml; } switch ($style) { case 1: return ''; case 2: return implode(I18N::$list_separator, $html); case 3: $i = 0; $count = count($html); if ($count > 36) { $col = 4; } elseif ($count > 18) { $col = 3; } elseif ($count > 6) { $col = 2; } else { $col = 1; } $newcol = ceil($count / $col); $html2 = ''; $html2 .= '
'; foreach ($html as $surns) { $html2 .= $surns . '
'; $i++; if ($i == $newcol && $i < $count) { $html2 .= '
'; $newcol = $i + ceil($count / $col); } } $html2 .= '
'; return $html2; } } /** * Print a table of events * * @param int $startjd * @param int $endjd * @param string $events * @param bool $only_living * @param string $sort_by * * @return string */ public static function eventsTable($startjd, $endjd, $events = 'BIRT MARR DEAT', $only_living = false, $sort_by = 'anniv') { global $controller, $WT_TREE; $html = ''; $table_id = 'table-even-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page $controller ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) ->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; jQuery("#' . $table_id . '").dataTable({ dom: "t", ' . I18N::datatablesI18N() . ', autoWidth: false, paging: false, lengthChange: false, filter: false, info: true, jQueryUI: true, sorting: [[ ' . ($sort_by == 'alpha' ? 0 : 1) . ', "asc"]], columns: [ /* Name */ { type: "text" }, /* Date */ { type: "num" }, /* Anniversary */ { type: "num" }, /* Event */ { type: "text" } ] }); '); // Did we have any output? Did we skip anything? $filter = 0; $filtered_events = array(); foreach (FunctionsDb::getEventsList($startjd, $endjd, $events, $WT_TREE) as $fact) { $record = $fact->getParent(); // Only living people ? if ($only_living) { if ($record instanceof Individual && $record->isDead()) { $filter++; continue; } if ($record instanceof Family) { $husb = $record->getHusband(); if (is_null($husb) || $husb->isDead()) { $filter++; continue; } $wife = $record->getWife(); if (is_null($wife) || $wife->isDead()) { $filter++; continue; } } } $filtered_events[] = $fact; } if (!empty($filtered_events)) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($filtered_events as $n => $fact) { $record = $fact->getParent(); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . I18N::translate('Record') . '' . GedcomTag::getLabel('DATE') . '' . GedcomTag::getLabel('EVEN') . '
'; $html .= '' . $record->getFullName() . ''; if ($record instanceof Individual) { $html .= $record->getSexImage(); } $html .= ''; $html .= $fact->getDate()->display(); $html .= ''; $html .= ($fact->anniv ? I18N::number($fact->anniv) : ''); $html .= '' . $fact->getLabel() . '
'; } else { if ($endjd === WT_CLIENT_JD) { // We're dealing with the Today’s Events block if ($filter === 0) { $html .= I18N::translate('No events exist for today.'); } else { $html .= I18N::translate('No events for living individuals exist for today.'); } } else { // We're dealing with the Upcoming Events block if ($filter === 0) { if ($endjd === $startjd) { $html .= I18N::translate('No events exist for tomorrow.'); } else { $html .= /* I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” */ I18N::plural('No events exist for the next %s day.', 'No events exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1)); } } else { if ($endjd === $startjd) { $html .= I18N::translate('No events for living individuals exist for tomorrow.'); } else { // I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” $html .= I18N::plural('No events for living people exist for the next %s day.', 'No events for living people exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1)); } } } } return $html; } /** * Print a list of events * * This performs the same function as print_events_table(), but formats the output differently. * * @param int $startjd * @param int $endjd * @param string $events * @param bool $only_living * @param string $sort_by * * @return string */ public static function eventsList($startjd, $endjd, $events = 'BIRT MARR DEAT', $only_living = false, $sort_by = 'anniv') { global $WT_TREE; // Did we have any output? Did we skip anything? $output = 0; $filter = 0; $filtered_events = array(); $html = ''; foreach (FunctionsDb::getEventsList($startjd, $endjd, $events, $WT_TREE) as $fact) { $record = $fact->getParent(); // only living people ? if ($only_living) { if ($record instanceof Individual && $record->isDead()) { $filter++; continue; } if ($record instanceof Family) { $husb = $record->getHusband(); if (is_null($husb) || $husb->isDead()) { $filter++; continue; } $wife = $record->getWife(); if (is_null($wife) || $wife->isDead()) { $filter++; continue; } } } $output++; $filtered_events[] = $fact; } // Now we've filtered the list, we can sort by event, if required switch ($sort_by) { case 'anniv': // Data is already sorted by anniversary date break; case 'alpha': uasort($filtered_events, function (Fact $x, Fact $y) { return GedcomRecord::compare($x->getParent(), $y->getParent()); }); break; } foreach ($filtered_events as $fact) { $record = $fact->getParent(); $html .= '' . $record->getFullName() . ''; if ($record instanceof Individual) { $html .= $record->getSexImage(); } $html .= '
'; $html .= $fact->getLabel() . ' — ' . $fact->getDate()->display(true); if ($fact->anniv) { $html .= ' (' . I18N::translate('%s year anniversary', I18N::number($fact->anniv)) . ')'; } if (!$fact->getPlace()->isEmpty()) { $html .= ' — ' . $fact->getPlace()->getFullName() . ''; } $html .= '
'; } // Print a final summary message about restricted/filtered facts $summary = ''; if ($endjd == WT_CLIENT_JD) { // We're dealing with the Today’s Events block if ($output == 0) { if ($filter == 0) { $summary = I18N::translate('No events exist for today.'); } else { $summary = I18N::translate('No events for living individuals exist for today.'); } } } else { // We're dealing with the Upcoming Events block if ($output == 0) { if ($filter == 0) { if ($endjd == $startjd) { $summary = I18N::translate('No events exist for tomorrow.'); } else { // I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” $summary = I18N::plural('No events exist for the next %s day.', 'No events exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1)); } } else { if ($endjd == $startjd) { $summary = I18N::translate('No events for living individuals exist for tomorrow.'); } else { // I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” $summary = I18N::plural('No events for living people exist for the next %s day.', 'No events for living people exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1)); } } } } if ($summary) { $html .= '' . $summary . ''; } return $html; } /** * Print a chart by age using Google chart API * * @param int[] $data * @param string $title * * @return string */ public static function chartByAge($data, $title) { $count = 0; $agemax = 0; $vmax = 0; $avg = 0; foreach ($data as $age => $v) { $n = strlen($v); $vmax = max($vmax, $n); $agemax = max($agemax, $age); $count += $n; $avg += $age * $n; } if ($count < 1) { return ''; } $avg = round($avg / $count); $chart_url = "https://chart.googleapis.com/chart?cht=bvs"; // chart type $chart_url .= "&chs=725x150"; // size $chart_url .= "&chbh=3,2,2"; // bvg : 4,1,2 $chart_url .= "&chf=bg,s,FFFFFF99"; //background color $chart_url .= "&chco=0000FF,FFA0CB,FF0000"; // bar color $chart_url .= "&chdl=" . rawurlencode(I18N::translate('Males')) . "|" . rawurlencode(I18N::translate('Females')) . "|" . rawurlencode(I18N::translate('Average age') . ": " . $avg); // legend & average age $chart_url .= "&chtt=" . rawurlencode($title); // title $chart_url .= "&chxt=x,y,r"; // axis labels specification $chart_url .= "&chm=V,FF0000,0," . ($avg - 0.3) . ",1"; // average age line marker $chart_url .= "&chxl=0:|"; // label for ($age = 0; $age <= $agemax; $age += 5) { $chart_url .= $age . "|||||"; // x axis } $chart_url .= "|1:||" . rawurlencode(I18N::percentage($vmax / $count)); // y axis $chart_url .= "|2:||"; $step = $vmax; for ($d = $vmax; $d > 0; $d--) { if ($vmax < ($d * 10 + 1) && ($vmax % $d) == 0) { $step = $d; } } if ($step == $vmax) { for ($d = $vmax - 1; $d > 0; $d--) { if (($vmax - 1) < ($d * 10 + 1) && (($vmax - 1) % $d) == 0) { $step = $d; } } } for ($n = $step; $n < $vmax; $n += $step) { $chart_url .= $n . "|"; } $chart_url .= rawurlencode($vmax . " / " . $count); // r axis $chart_url .= "&chg=100," . round(100 * $step / $vmax, 1) . ",1,5"; // grid $chart_url .= "&chd=s:"; // data : simple encoding from A=0 to 9=61 $CHART_ENCODING61 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for ($age = 0; $age <= $agemax; $age++) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$age], "M") * 61 / $vmax)]; } $chart_url .= ","; for ($age = 0; $age <= $agemax; $age++) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$age], "F") * 61 / $vmax)]; } $html = '' . $title . ''; return $html; } /** * Print a chart by decade using Google chart API * * @param int[] $data * @param string $title * * @return string */ public static function chartByDecade($data, $title) { $count = 0; $vmax = 0; foreach ($data as $v) { $n = strlen($v); $vmax = max($vmax, $n); $count += $n; } if ($count < 1) { return ''; } $chart_url = "https://chart.googleapis.com/chart?cht=bvs"; // chart type $chart_url .= "&chs=360x150"; // size $chart_url .= "&chbh=3,3"; // bvg : 4,1,2 $chart_url .= "&chf=bg,s,FFFFFF99"; //background color $chart_url .= "&chco=0000FF,FFA0CB"; // bar color $chart_url .= "&chtt=" . rawurlencode($title); // title $chart_url .= "&chxt=x,y,r"; // axis labels specification $chart_url .= "&chxl=0:|<|||"; // <1570 for ($y = 1600; $y < 2030; $y += 50) { $chart_url .= $y . "|||||"; // x axis } $chart_url .= "|1:||" . rawurlencode(I18N::percentage($vmax / $count)); // y axis $chart_url .= "|2:||"; $step = $vmax; for ($d = $vmax; $d > 0; $d--) { if ($vmax < ($d * 10 + 1) && ($vmax % $d) == 0) { $step = $d; } } if ($step == $vmax) { for ($d = $vmax - 1; $d > 0; $d--) { if (($vmax - 1) < ($d * 10 + 1) && (($vmax - 1) % $d) == 0) { $step = $d; } } } for ($n = $step; $n < $vmax; $n += $step) { $chart_url .= $n . "|"; } $chart_url .= rawurlencode($vmax . " / " . $count); // r axis $chart_url .= "&chg=100," . round(100 * $step / $vmax, 1) . ",1,5"; // grid $chart_url .= "&chd=s:"; // data : simple encoding from A=0 to 9=61 $CHART_ENCODING61 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for ($y = 1570; $y < 2030; $y += 10) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$y], "M") * 61 / $vmax)]; } $chart_url .= ","; for ($y = 1570; $y < 2030; $y += 10) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$y], "F") * 61 / $vmax)]; } $html = '' . $title . ''; return $html; } }