restrictAccess(Auth::isManager()) ->setPageTitle(WT_I18N::translate('Manage family trees')); $gedcom_files = glob(WT_DATA_DIR . '*.{ged,Ged,GED}', GLOB_NOSORT | GLOB_BRACE); // Process POST actions switch (WT_Filter::post('action')) { case 'delete': $gedcom_id = WT_Filter::postInteger('gedcom_id'); if (WT_Filter::checkCsrf() && $gedcom_id) { $tree = WT_Tree::get($gedcom_id); WT_FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ WT_I18N::translate('The family tree “%s” has been deleted.', $tree->titleHtml()), 'success'); $tree->delete(); } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'setdefault': if (WT_Filter::checkCsrf()) { WT_Site::setPreference('DEFAULT_GEDCOM', WT_Filter::post('ged')); WT_FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ WT_I18N::translate('The family tree “%s” will be shown to visitors when they first arrive at this website.', $WT_TREE->titleHtml()), 'success'); } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'new_tree': $basename = basename(WT_Filter::post('tree_name')); $tree_title = WT_Filter::post('tree_title'); if (WT_Filter::checkCsrf() && $basename && $tree_title) { if (WT_Tree::getIdFromName($basename)) { WT_FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ WT_I18N::translate('The family tree “%s” already exists.', WT_Filter::escapeHtml($basename)), 'danger'); } else { WT_Tree::create($basename, $tree_title); WT_FlashMessages::addMessage(/* I18N: %s is the name of a family tree */ WT_I18N::translate('The family tree “%s” has been created.', WT_Filter::escapeHtml($basename)), 'success'); } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME . '?ged=' . $basename); return; case 'replace_upload': $gedcom_id = WT_Filter::postInteger('gedcom_id'); $keep_media = WT_Filter::postBool('keep_media'); $tree = WT_Tree::get($gedcom_id); if (WT_Filter::checkCsrf() && $tree) { foreach ($_FILES as $FILE) { if ($FILE['error'] == 0 && is_readable($FILE['tmp_name'])) { $tree->importGedcomFile($FILE['tmp_name'], $FILE['name'], $keep_media); } } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'replace_import': $basename = basename(WT_Filter::post('tree_name')); $gedcom_id = WT_Filter::postInteger('gedcom_id'); $keep_media = WT_Filter::postBool('keep_media'); $tree = WT_Tree::get($gedcom_id); if (WT_Filter::checkCsrf() && $tree && $basename) { $tree->importGedcomFile(WT_DATA_DIR . $basename, $basename, $keep_media); } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; case 'bulk-import': if (WT_Filter::checkCsrf()) { $tree_names = WT_Tree::getNameList(); $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 = WT_Tree::create($basename, $basename); if ($tree->getPreference('filemtime') != $filemtime) { $tree->importGedcomFile($gedcom_file, $basename, false); $tree->setPreference('filemtime', $filemtime); WT_FlashMessages::addMessage(WT_I18N::translate('The GEDCOM file “%s” has been imported.', WT_Filter::escapeHtml($basename)), 'success'); } } foreach (WT_Tree::getAll() as $tree) { if (!in_array($tree->name(), $basenames)) { WT_FlashMessages::addMessage(WT_I18N::translate('The family tree “%s” has been deleted.', $tree->titleHtml()), 'success'); $tree->delete(); } } } header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); return; } $default_tree_title = /* I18N: Default name for a new tree */ WT_I18N::translate('My family tree'); $default_tree_name = 'tree'; $default_tree_number = 1; $existing_trees = WT_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 (WT_Filter::get('action')) { case 'uploadform': case 'importform': if (WT_Filter::get('action') === 'uploadform') { $controller->setPageTitle(WT_I18N::translate('Upload family tree')); } else { $controller->setPageTitle(WT_I18N::translate('Import family tree')); } $controller->pageHeader(); ?>