. */ namespace Fisharebest\Webtrees; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\FunctionsPrintLists; define('WT_SCRIPT_NAME', 'placelist.php'); require './includes/session.php'; $controller = new PageController; $action = Filter::get('action', 'find|show', 'find'); $display = Filter::get('display', 'hierarchy|list', 'hierarchy'); $parent = Filter::getArray('parent'); $level = count($parent); if ($display == 'hierarchy') { if ($level) { $controller->setPageTitle(I18N::translate('Place hierarchy') . ' - ' . Filter::escapeHtml(end($parent)) . ''); } else { $controller->setPageTitle(I18N::translate('Place hierarchy')); } } else { $controller->setPageTitle(I18N::translate('Place list')); } $controller->pageHeader(); echo '
'; switch ($display) { case 'list': echo '

', $controller->getPageTitle(), '

'; $list_places = Place::allPlaces($WT_TREE); $numfound = count($list_places); $divisor = $numfound > 20 ? 3 : 2; if ($numfound === 0) { echo '', I18N::translate('No results found.'), '
'; } else { $columns = array_chunk($list_places, ceil($numfound / $divisor)); $html = ''; $html .= ''; $html .= ''; foreach ($columns as $column) { $html .= ''; } $html .= '
'; $html .= ' ' . I18N::translate('Place list'); $html .= '
'; echo $html; } echo '

', I18N::translate('Show places in hierarchy'), '

'; break; case 'hierarchy': $gm_module = Module::getModuleByName('googlemap'); // Find this place and its ID $place = new Place(implode(', ', array_reverse($parent)), $WT_TREE); $place_id = $place->getPlaceId(); $child_places = $place->getChildPlaces(); $numfound = count($child_places); //-- if the number of places found is 0 then automatically redirect to search page if ($numfound === 0) { $action = 'show'; } echo '

', $controller->getPageTitle(); // Breadcrumbs if ($place_id) { $parent_place = $place->getParentPlace(); while ($parent_place->getPlaceId()) { echo ', ', $parent_place->getPlaceName(), ''; $parent_place = $parent_place->getParentPlace(); } echo ', ', I18N::translate('Top level'), ''; } echo '

'; if ($gm_module && $gm_module->getSetting('GM_PLACE_HIERARCHY')) { $linklevels = ''; $place_names = array(); for ($j = 0; $j < $level; $j++) { $linklevels .= '&parent[' . $j . ']=' . rawurlencode($parent[$j]); } $gm_module->createMap(); } elseif (Module::getModuleByName('places_assistant')) { // Places Assistant is a custom/add-on module that was once part of the core code. \PlacesAssistantModule::display_map($level, $parent); } if ($numfound > 0) { if ($numfound > 20) { $divisor = 3; } elseif ($numfound > 4) { $divisor = 2; } else { $divisor = 1; } $columns = array_chunk($child_places, ceil($numfound / $divisor)); $html = ''; $html .= ''; foreach ($columns as $column) { $html .= ''; } $html .= ''; if ($numfound > 0 && $action == 'find' && $place_id) { $html .= ''; } $html .= '
'; $html .= ' '; if ($place_id) { $html .= I18N::translate('Places in %s', $place->getPlaceName()); } else { $html .= I18N::translate('Place hierarchy'); } $html .= '
    '; foreach ($column as $item) { $html .= '
  • ' . $item->getPlaceName() . '
  • '; if ($gm_module && $gm_module->getSetting('GM_PLACE_HIERARCHY')) { list($tmp) = explode(', ', $item->getGedcomName(), 2); $place_names[] = $tmp; } } $html .= '
'; $html .= I18N::translate('View all records found in this place'); $html .= '
'; $html .= '' . $place->getPlaceName() . ''; $html .= '
'; // -- echo the array echo $html; } if ($place_id && $action == 'show') { // -- array of names $myindilist = array(); $myfamlist = array(); $positions = Database::prepare("SELECT DISTINCT pl_gid FROM `##placelinks` WHERE pl_p_id=? AND pl_file=?") ->execute(array($place_id, $WT_TREE->getTreeId())) ->fetchOneColumn(); foreach ($positions as $position) { $record = GedcomRecord::getInstance($position, $WT_TREE); if ($record && $record->canShow()) { if ($record instanceof Individual) { $myindilist[] = $record; } if ($record instanceof Family) { $myfamlist[] = $record; } } } echo '
'; //-- display results $controller ->addInlineJavascript('jQuery("#places-tabs").tabs();') ->addInlineJavascript('jQuery("#places-tabs").css("visibility", "visible");') ->addInlineJavascript('jQuery(".loading-image").css("display", "none");'); echo '
'; echo '
'; if (!empty($myindilist)) { echo '
', FunctionsPrintLists::individualTable($myindilist), '
'; } if (!empty($myfamlist)) { echo '
', FunctionsPrintLists::familyTable($myfamlist), '
'; } echo '
'; //
} echo '

', I18N::translate('Show all places in a list'), '

'; if ($gm_module && $gm_module->getSetting('GM_PLACE_HIERARCHY')) { $gm_module->mapScripts($numfound, $level, $parent, $linklevels, $place_names); } break; } echo '
'; //