. */ namespace Fisharebest\Webtrees; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\Functions; define('WT_SCRIPT_NAME', 'admin_trees_manage.php'); require './includes/session.php'; $controller = new PageController; $controller ->addExternalJavascript(WT_ADMIN_JS_URL) ->restrictAccess(Auth::isAdmin() || Auth::isManager($WT_TREE)) ->setPageTitle(I18N::translate('Manage family trees')); // Show a reduced page when there are more than a certain number of trees $multiple_tree_threshold = Site::getPreference('MULTIPLE_TREE_THRESHOLD') ?: 500; // Note that glob() returns false instead of an empty array when open_basedir_restriction // is in force and no files are found. See PHP bug #47358. if (defined('GLOB_BRACE')) { $gedcom_files = glob(WT_DATA_DIR . '*.{ged,Ged,GED}', GLOB_NOSORT | GLOB_BRACE) ?: array(); } else { $gedcom_files = array_merge( glob(WT_DATA_DIR . '*.ged', GLOB_NOSORT) ?: array(), glob(WT_DATA_DIR . '*.Ged', GLOB_NOSORT) ?: array(), glob(WT_DATA_DIR . '*.GED', GLOB_NOSORT) ?: array() ); } // Process POST actions switch (Filter::post('action')) { case 'delete': $gedcom_id = Filter::postInteger('gedcom_id'); if (Filter::checkCsrf() && $gedcom_id) { $tree = Tree::findById($gedcom_id); FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ I18N::translate('The family tree “%s” has been deleted.', $tree->getTitleHtml()), 'success'); $tree->delete(); } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'setdefault': if (Filter::checkCsrf()) { Site::setPreference('DEFAULT_GEDCOM', Filter::post('ged')); FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ I18N::translate('The family tree “%s” will be shown to visitors when they first arrive at this website.', $WT_TREE->getTitleHtml()), 'success'); } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'new_tree': $basename = basename(Filter::post('tree_name')); $tree_title = Filter::post('tree_title'); if (Filter::checkCsrf() && $basename && $tree_title) { if (Tree::findByName($basename)) { FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ I18N::translate('The family tree “%s” already exists.', Filter::escapeHtml($basename)), 'danger'); } else { Tree::create($basename, $tree_title); FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ I18N::translate('The family tree “%s” has been created.', Filter::escapeHtml($basename)), 'success'); } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME . '?ged=' . Filter::escapeUrl($basename)); return; case 'replace_upload': $gedcom_id = Filter::postInteger('gedcom_id'); $keep_media = Filter::post('keep_media', '1', '0'); $GEDCOM_MEDIA_PATH = Filter::post('GEDCOM_MEDIA_PATH'); $WORD_WRAPPED_NOTES = Filter::post('WORD_WRAPPED_NOTES', '1', '0'); $tree = Tree::findById($gedcom_id); if (Filter::checkCsrf() && $tree) { $tree->setPreference('keep_media', $keep_media); $tree->setPreference('GEDCOM_MEDIA_PATH', $GEDCOM_MEDIA_PATH); $tree->setPreference('WORD_WRAPPED_NOTES', $WORD_WRAPPED_NOTES); if (isset($_FILES['tree_name'])) { if ($_FILES['tree_name']['error'] == 0 && is_readable($_FILES['tree_name']['tmp_name'])) { $tree->importGedcomFile($_FILES['tree_name']['tmp_name'], $_FILES['tree_name']['name']); } else { FlashMessages::addMessage(Functions::fileUploadErrorText($_FILES['tree_name']['error']), 'danger'); } } else { FlashMessages::addMessage(I18N::translate('No GEDCOM file was received.'), 'danger'); } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'replace_import': $basename = basename(Filter::post('tree_name')); $gedcom_id = Filter::postInteger('gedcom_id'); $keep_media = Filter::post('keep_media', '1', '0'); $GEDCOM_MEDIA_PATH = Filter::post('GEDCOM_MEDIA_PATH'); $WORD_WRAPPED_NOTES = Filter::post('WORD_WRAPPED_NOTES', '1', '0'); $tree = Tree::findById($gedcom_id); if (Filter::checkCsrf() && $tree) { $tree->setPreference('keep_media', $keep_media); $tree->setPreference('GEDCOM_MEDIA_PATH', $GEDCOM_MEDIA_PATH); $tree->setPreference('WORD_WRAPPED_NOTES', $WORD_WRAPPED_NOTES); if ($basename) { $tree->importGedcomFile(WT_DATA_DIR . $basename, $basename); } else { FlashMessages::addMessage(I18N::translate('No GEDCOM file was received.'), 'danger'); } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'synchronize': if (Filter::checkCsrf()) { $basenames = array(); foreach ($gedcom_files as $gedcom_file) { $filemtime = filemtime($gedcom_file); // Only import files that have changed $basename = basename($gedcom_file); $basenames[] = $basename; $tree = Tree::findByName($basename); if (!$tree) { $tree = Tree::create($basename, $basename); } if ($tree->getPreference('filemtime') != $filemtime) { $tree->importGedcomFile($gedcom_file, $basename); $tree->setPreference('filemtime', $filemtime); FlashMessages::addMessage(I18N::translate('The GEDCOM file “%s” has been imported.', Filter::escapeHtml($basename)), 'success'); } } foreach (Tree::getAll() as $tree) { if (!in_array($tree->getName(), $basenames)) { FlashMessages::addMessage(I18N::translate('The family tree “%s” has been deleted.', $tree->getTitleHtml()), 'success'); $tree->delete(); } } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; } $default_tree_title = /* I18N: Default name for a new tree */ I18N::translate('My family tree'); $default_tree_name = 'tree'; $default_tree_number = 1; $existing_trees = Tree::getNameList(); while (array_key_exists($default_tree_name . $default_tree_number, $existing_trees)) { $default_tree_number++; } $default_tree_name .= $default_tree_number; // Process GET actions switch (Filter::get('action')) { case 'importform': $controller ->setPageTitle($WT_TREE->getTitleHtml() . ' — ' . I18N::translate('Import a GEDCOM file')) ->pageHeader(); ?>
getTitleHtml()); ?>
pageHeader(); $all_trees = Tree::getAll(); // On sites with hundreds or thousands of trees, this page becomes very large. // Just show the current tree, the default tree, and unimported trees if (count($all_trees) >= $multiple_tree_threshold) { $all_trees = array_filter($all_trees, function (Tree $x) use ($WT_TREE) { return $x->getPreference('imported') === '0' || $WT_TREE->getTreeId() === $x->getTreeId() || $x->getName() === Site::getPreference('DEFAULT_GEDCOM'); }); } // List the gedcoms available to this user ?>