restrictAccess(Auth::isAdmin()) ->setPageTitle(WT_I18N::translate('Family trees')); // Don’t allow the user to cancel the request. We do not want to be left // with an incomplete transaction. ignore_user_abort(true); /** * @param integer $gedcom_id * @param string $path the full path to the (possibly temporary) file. * @param string $filename the actual filename (no folder). * * @throws Exception */ function import_gedcom_file($gedcom_id, $path, $filename) { // Read the file in blocks of roughly 64K. Ensure that each block // contains complete gedcom records. This will ensure we don’t split // multi-byte characters, as well as simplifying the code to import // each block. $file_data=''; $fp=fopen($path, 'rb'); WT_DB::exec("START TRANSACTION"); WT_DB::prepare("DELETE FROM `##gedcom_chunk` WHERE gedcom_id=?")->execute(array($gedcom_id)); while (!feof($fp)) { $file_data.=fread($fp, 65536); // There is no strrpos() function that searches for substrings :-( for ($pos=strlen($file_data)-1; $pos>0; --$pos) { if ($file_data[$pos]=='0' && ($file_data[$pos-1]=="\n" || $file_data[$pos-1]=="\r")) { // We’ve found the last record boundary in this chunk of data break; } } if ($pos) { WT_DB::prepare( "INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)" )->execute(array($gedcom_id, substr($file_data, 0, $pos))); $file_data=substr($file_data, $pos); } } WT_DB::prepare( "INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)" )->execute(array($gedcom_id, $file_data)); WT_Tree::get($gedcom_id)->setPreference('gedcom_filename', $filename); WT_DB::exec("COMMIT"); fclose($fp); } // Process POST actions switch (WT_Filter::post('action')) { case 'delete': $gedcom_id = WT_Filter::postInteger('gedcom_id'); if (WT_Filter::checkCsrf() && $gedcom_id) { WT_Tree::get($gedcom_id)->delete(); } header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME); break; case 'setdefault': if (WT_Filter::checkCsrf()) { WT_Site::setPreference('DEFAULT_GEDCOM', WT_Filter::post('default_ged')); } header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME); exit; case 'new_tree': $ged_name=basename(WT_Filter::post('ged_name')); if (WT_Filter::checkCsrf() && $ged_name) { WT_Tree::create($ged_name); } header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME); exit; case 'replace_upload': $gedcom_id = WT_Filter::postInteger('gedcom_id'); // Make sure the gedcom still exists if (WT_Filter::checkCsrf() && WT_Tree::get($gedcom_id)) { foreach ($_FILES as $FILE) { if ($FILE['error'] == 0 && is_readable($FILE['tmp_name'])) { import_gedcom_file($gedcom_id, $FILE['tmp_name'], $FILE['name']); } } } header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?keep_media' . $gedcom_id . '=' . WT_Filter::postBool('keep_media' . $gedcom_id)); exit; case 'replace_import': $gedcom_id = WT_Filter::postInteger('gedcom_id'); // Make sure the gedcom still exists if (WT_Filter::checkCsrf() && WT_Tree::get($gedcom_id)) { $ged_name = basename(WT_Filter::post('ged_name')); import_gedcom_file($gedcom_id, WT_DATA_DIR.$ged_name, $ged_name); } header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?keep_media' . $gedcom_id . '=' . WT_Filter::postBool('keep_media' . $gedcom_id)); exit; } $controller->pageHeader(); // Process GET actions switch (WT_Filter::get('action')) { case 'uploadform': case 'importform': $tree=WT_Tree::get(WT_Filter::getInteger('gedcom_id')); // Check it exists if (!$tree) { break; } echo '

', WT_I18N::translate('This will delete all the genealogical data from %s and replace it with data from another GEDCOM.', $tree->tree_name_html), '

'; // the javascript in the next line strips any path associated with the file before comparing it to the current GEDCOM name (both Chrome and IE8 include c:\fakepath\ in the filename). $previous_gedcom_filename = $tree->getPreference('gedcom_filename'); echo '
'; echo ''; echo WT_Filter::getCsrf(); if (WT_Filter::get('action')=='uploadform') { echo ''; echo ''; } else { echo ''; $d=opendir(WT_DATA_DIR); $files=array(); while (($f=readdir($d))!==false) { if (!is_dir(WT_DATA_DIR.$f) && is_readable(WT_DATA_DIR.$f)) { $fp=fopen(WT_DATA_DIR.$f, 'rb'); $header=fread($fp, 64); fclose($fp); if (preg_match('/^('.WT_UTF8_BOM.')?0 *HEAD/', $header)) { $files[]=$f; } } } if ($files) { sort($files); echo WT_DATA_DIR, ''; } else { echo '

', WT_I18N::translate('No GEDCOM files found. You need to copy files to the %s directory on your server.', WT_DATA_DIR); echo '

'; exit; } } echo '

'; echo WT_I18N::translate('If you have created media objects in webtrees, and have edited your gedcom off-line using a program that deletes media objects, then check this box to merge the current media objects with the new GEDCOM file.'); echo '

'; echo ''; exit; } // List the gedcoms available to this user foreach (WT_Tree::GetAll() as $tree) { if (Auth::isManager($tree)) { echo '', '
', WT_I18N::translate('Family tree'), '', $tree->tree_title_html, '', '
', $tree->tree_name_html, ''; // The third row shows an optional progress bar and a list of maintenance options $importing = WT_DB::prepare( "SELECT 1 FROM `##gedcom_chunk` WHERE gedcom_id = ? AND imported = '0' LIMIT 1" )->execute(array($tree->tree_id))->fetchOne(); if ($importing) { $in_progress = WT_DB::prepare( "SELECT 1 FROM `##gedcom_chunk` WHERE gedcom_id = ? AND imported = '1' LIMIT 1" )->execute(array($tree->tree_id))->fetchOne(); if (!$in_progress) { echo '
', WT_I18N::translate('Deleting old genealogy data…'), '
'; $controller->addInlineJavascript( 'jQuery("#progressbar'.$tree->tree_id.'").progressbar({value: 0});' ); } else { echo '
'; } $controller->addInlineJavascript( 'jQuery("#import'.$tree->tree_id.'").load("import.php?gedcom_id='.$tree->tree_id.'&keep_media'.$tree->tree_id.'='.WT_Filter::get('keep_media'.$tree->tree_id).'");' ); echo ''; } else { echo ''; } echo '', // export '', // import '', // download '', // upload '', // delete '
', WT_I18N::translate('Export'), '', help_link('export_gedcom'), '', WT_I18N::translate('Import'), '', help_link('import_gedcom'), '', WT_I18N::translate('Download'), '', help_link('download_gedcom'), '', WT_I18N::translate('Upload'), '', help_link('upload_gedcom'), '', '', WT_I18N::translate('Delete'), '', '
', '', '', WT_Filter::getCsrf(), '
', '

'; } } ?> 1): ?> 1): ?>

', '', WT_I18N::translate('Click here for PhpGedView to webtrees transfer wizard'), '', help_link('PGV_WIZARD'), ''; }