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)); set_gedcom_setting($gedcom_id, 'gedcom_filename', basename($filename)); WT_DB::exec("COMMIT"); fclose($fp); } // Process GET actions switch (safe_GET('action')) { case 'delete': $ged=safe_GET('ged'); delete_gedcom(get_id_from_gedcom($ged)); break; } // Process POST actions switch (safe_POST('action')) { case 'setdefault': set_site_setting('DEFAULT_GEDCOM', safe_POST('default_ged')); break; case 'new_ged': $ged_name=basename(safe_POST('ged_name')); if ($ged_name) { $gedcom_id=get_id_from_gedcom($ged_name); // check it doesn't already exist before we create it if (!$gedcom_id) { $gedcom_id=get_id_from_gedcom($ged_name, true); // I18N: This should be a common/default/placeholder name of a person. Put slashes around the surname. $john_doe=WT_I18N::translate('John /DOE/'); $note=WT_I18N::translate('Edit this individual and replace their details with your own'); WT_DB::prepare("DELETE FROM `##gedcom_chunk` WHERE gedcom_id=?")->execute(array($gedcom_id)); WT_DB::prepare( "INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)" )->execute(array( $gedcom_id, "0 HEAD\n0 @I1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 01 JAN 1850\n2 NOTE {$note}\n0 TRLR\n" )); } } break; case 'replace_upload': $gedcom_id=safe_POST('gedcom_id'); // Make sure the gedcom still exists if (get_gedcom_from_id($gedcom_id)) { foreach ($_FILES as $FILE) { if ($FILE['error']==0 && is_readable($FILE['tmp_name'])) { import_gedcom_file($gedcom_id, $FILE['tmp_name']); } } } header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.WT_SCRIPT_NAME); exit; case 'replace_import': $gedcom_id=safe_POST('gedcom_id'); // Make sure the gedcom still exists if (get_gedcom_from_id($gedcom_id)) { $ged_name=basename(safe_POST('ged_name')); import_gedcom_file($gedcom_id, WT_DATA_DIR.$ged_name); } header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.WT_SCRIPT_NAME); exit; } $gedcoms=get_all_gedcoms(); print_header(WT_I18N::translate('Family trees')); // "Help for this page" link echo '
', help_link('gedcom_administration'), '
'; // Process GET actions switch (safe_GET('action')) { case 'uploadform': case 'importform': $gedcom_id=safe_GET('gedcom_id'); $gedcom_name=get_gedcom_from_id($gedcom_id); // Check it exists if (!$gedcom_name) { break; } echo '

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

'; // 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=get_gedcom_setting($gedcom_id, 'gedcom_filename'); echo '
'; echo ''; if (safe_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) { 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 '

'; echo '

'; echo '
'; print_footer(); 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.'); echo '

'; echo ''; echo '
'; print_footer(); exit; } // List the gedcoms available to this user foreach ($gedcoms as $gedcom_id=>$gedcom_name) { if (userGedcomAdmin(WT_USER_ID, $gedcom_id)) { echo '', '
', WT_I18N::translate('Family tree'), '', WT_I18N::translate('%s', get_gedcom_setting($gedcom_id, 'title')), '', '
', htmlspecialchars($gedcom_name), ''; // 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($gedcom_id))->fetchOne(); if ($importing) { echo '
', WT_JS_START, 'jQuery("#import', $gedcom_id, '").load("import.php?gedcom_id=', $gedcom_id, '&keep_media=', safe_POST('keep_media'.$gedcom_id), '");', WT_JS_END, ''; } 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'), '', help_link('delete_gedcom'), '

'; } } // Options for creating new gedcoms and setting defaults if (WT_USER_IS_ADMIN) { echo ''; if (count($gedcoms)>1) { echo ''; } echo ''; if (count($gedcoms)>1) { echo ''; } echo '', '
', WT_I18N::translate('Default family tree'), help_link('default_gedcom'), '', WT_I18N::translate('Create a new family tree'), help_link('add_new_gedcom'), '
', '', '
', '
', '', '', ' ', '
', '

'; // display link to PGV-WT transfer wizard on first visit to this page, before any GEDCOM is loaded if (count($gedcoms)==0 && get_user_count()==1) { echo '
', '', WT_I18N::translate('Click here for PhpGedView to webtrees transfer wizard'), '', help_link('PGV_WIZARD'), '
'; } } print_footer();