public function __construct() { global $SCRIPT_NAME, $MEDIA_DIRECTORY, $WT_SESSION; // Our cart is an array of items in the session if (!is_array($WT_SESSION->cart)) { $WT_SESSION->cart = array(); } if (!array_key_exists(WT_GED_ID, $WT_SESSION->cart)) { $WT_SESSION->cart[WT_GED_ID] = array(); } $this->action = WT_Filter::get('action'); $this->id = WT_Filter::get('id'); $convert = WT_Filter::get('convert', 'yes|no', 'no'); $this->Zip = WT_Filter::get('Zip'); $this->IncludeMedia = WT_Filter::get('IncludeMedia'); $this->conv_path = WT_Filter::get('conv_path'); $this->privatize_export = WT_Filter::get('privatize_export', 'none|visitor|user|gedadmin', 'visitor'); $this->level1 = WT_Filter::getInteger('level1'); $this->level2 = WT_Filter::getInteger('level2'); $this->level3 = WT_Filter::getInteger('level3'); $others = WT_Filter::get('others'); $this->type = WT_Filter::get('type'); if (($this->privatize_export == 'none' || $this->privatize_export == 'none') && !WT_USER_GEDCOM_ADMIN) { $this->privatize_export = 'visitor'; } if ($this->privatize_export == 'user' && !WT_USER_CAN_ACCESS) { $this->privatize_export = 'visitor'; } if ($this->action == 'add') { if (empty($this->type) && !empty($this->id)) { $this->type = ""; $obj = WT_GedcomRecord::getInstance($this->id); if (is_null($obj)) { $this->id = ""; $this->action = ""; } else { $this->type = strtolower($obj::RECORD_TYPE); } } else { if (empty($this->id)) { $this->action = ""; } } if (!empty($this->id) && $this->type != 'fam' && $this->type != 'indi' && $this->type != 'sour') { $this->action = 'add1'; } } if ($this->action == 'add1') { $obj = WT_GedcomRecord::getInstance($this->id); $this->addClipping($obj); if ($this->type == 'sour') { if ($others == 'linked') { foreach ($obj->linkedIndividuals('SOUR') as $indi) { $this->addClipping($indi); } foreach ($obj->linkedFamilies('SOUR') as $fam) { $this->addClipping($fam); } } } if ($this->type == 'fam') { if ($others == 'parents') { $this->addClipping($obj->getHusband()); $this->addClipping($obj->getWife()); } elseif ($others == "members") { $this->addFamilyMembers(WT_Family::getInstance($this->id)); } elseif ($others == "descendants") { $this->addFamilyDescendancy(WT_Family::getInstance($this->id)); } } elseif ($this->type == 'indi') { if ($others == 'parents') { foreach (WT_Individual::getInstance($this->id)->getChildFamilies() as $family) { $this->addFamilyMembers($family); } } elseif ($others == 'ancestors') { $this->addAncestorsToCart(WT_Individual::getInstance($this->id), $this->level1); } elseif ($others == 'ancestorsfamilies') { $this->addAncestorsToCartFamilies(WT_Individual::getInstance($this->id), $this->level2); } elseif ($others == 'members') { foreach (WT_Individual::getInstance($this->id)->getSpouseFamilies() as $family) { $this->addFamilyMembers($family); } } elseif ($others == 'descendants') { foreach (WT_Individual::getInstance($this->id)->getSpouseFamilies() as $family) { $this->addClipping($family); $this->addFamilyDescendancy($family, $this->level3); } } uksort($WT_SESSION->cart[WT_GED_ID], array('WT_Controller_Clippings', 'compareClippings')); } } elseif ($this->action == 'remove') { unset($WT_SESSION->cart[WT_GED_ID][$this->id]); } elseif ($this->action == 'empty') { $WT_SESSION->cart[WT_GED_ID] = array(); } elseif ($this->action == 'download') { $media = array(); $mediacount = 0; $filetext = gedcom_header(WT_GEDCOM); // Include SUBM/SUBN records, if they exist $subn = WT_DB::prepare("SELECT o_gedcom FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBN', WT_GED_ID))->fetchOne(); if ($subn) { $filetext .= $subn . "\n"; } $subm = WT_DB::prepare("SELECT o_gedcom FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBM', WT_GED_ID))->fetchOne(); if ($subm) { $filetext .= $subm . "\n"; } if ($convert == "yes") { $filetext = str_replace("UTF-8", "ANSI", $filetext); $filetext = utf8_decode($filetext); } switch ($this->privatize_export) { case 'gedadmin': $access_level = WT_PRIV_NONE; break; case 'user': $access_level = WT_PRIV_USER; break; case 'visitor': $access_level = WT_PRIV_PUBLIC; break; case 'none': $access_level = WT_PRIV_HIDE; break; } foreach (array_keys($WT_SESSION->cart[WT_GED_ID]) as $xref) { $object = WT_GedcomRecord::getInstance($xref); if ($object) { // The object may have been deleted since we added it to the cart.... $record = $object->privatizeGedcom($access_level); // Remove links to objects that aren't in the cart preg_match_all('/\\n1 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[2-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { if (!array_key_exists($match[1], $WT_SESSION->cart[WT_GED_ID])) { $record = str_replace($match[0], '', $record); } } preg_match_all('/\\n2 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[3-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { if (!array_key_exists($match[1], $WT_SESSION->cart[WT_GED_ID])) { $record = str_replace($match[0], '', $record); } } preg_match_all('/\\n3 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[4-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { if (!array_key_exists($match[1], $WT_SESSION->cart[WT_GED_ID])) { $record = str_replace($match[0], '', $record); } } $record = convert_media_path($record, $this->conv_path); $savedRecord = $record; // Save this for the "does this file exist" check if ($convert == 'yes') { $record = utf8_decode($record); } switch ($object::RECORD_TYPE) { case 'INDI': $filetext .= $record . "\n"; $filetext .= "1 SOUR @WEBTREES@\n"; $filetext .= "2 PAGE " . WT_SERVER_NAME . WT_SCRIPT_PATH . $object->getRawUrl() . "\n"; break; case 'FAM': $filetext .= $record . "\n"; $filetext .= "1 SOUR @WEBTREES@\n"; $filetext .= "2 PAGE " . WT_SERVER_NAME . WT_SCRIPT_PATH . $object->getRawUrl() . "\n"; break; case 'SOUR': $filetext .= $record . "\n"; $filetext .= "1 NOTE " . WT_SERVER_NAME . WT_SCRIPT_PATH . $object->getRawUrl() . "\n"; break; default: $ft = preg_match_all("/\n\\d FILE (.+)/", $savedRecord, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { // Skip external files and non-existant files if (file_exists(WT_DATA_DIR . $MEDIA_DIRECTORY . $match[$k][1])) { $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => WT_DATA_DIR . $MEDIA_DIRECTORY . $match[$k][1], PCLZIP_ATT_FILE_NEW_FULL_NAME => $match[$k][1]); $mediacount++; } } $filetext .= trim($record) . "\n"; break; } } } if ($this->IncludeMedia == "yes") { $this->media_list = $media; } $filetext .= "0 @WEBTREES@ SOUR\n1 TITL " . WT_SERVER_NAME . WT_SCRIPT_PATH . "\n"; if ($user_id = get_gedcom_setting(WT_GED_ID, 'CONTACT_EMAIL')) { $user = User::find($user_id); $filetext .= "1 AUTH " . $user->getRealName() . "\n"; } $filetext .= "0 TRLR\n"; //-- make sure the preferred line endings are used $filetext = preg_replace("/[\r\n]+/", WT_EOL, $filetext); $this->download_data = $filetext; $this->downloadClipping(); } }
function init() { global $PRIV_HIDE, $PRIV_PUBLIC, $ENABLE_CLIPPINGS_CART, $SCRIPT_NAME, $pgv_lang, $SERVER_URL, $CONTACT_EMAIL, $HOME_SITE_TEXT, $HOME_SITE_URL, $MEDIA_DIRECTORY; global $GEDCOM, $CHARACTER_SET, $cart; if (!isset($ENABLE_CLIPPINGS_CART)) { $ENABLE_CLIPPINGS_CART = $PRIV_HIDE; } if ($ENABLE_CLIPPINGS_CART === true) { $ENABLE_CLIPPING_CART = $PRIV_PUBLIC; } if ($ENABLE_CLIPPINGS_CART < PGV_USER_ACCESS_LEVEL) { header("Location: index.php"); exit; } if (!isset($_SESSION['exportConvPath'])) { $_SESSION['exportConvPath'] = $MEDIA_DIRECTORY; } if (!isset($_SESSION['exportConvSlashes'])) { $_SESSION['exportConvSlashes'] = 'forward'; } $this->action = safe_GET("action"); $this->id = safe_GET('id'); $remove = safe_GET('remove', "", "no"); $convert = safe_GET('convert', "", "no"); $this->Zip = safe_GET('Zip'); $this->IncludeMedia = safe_GET('IncludeMedia'); $this->conv_path = safe_GET('conv_path', PGV_REGEX_NOSCRIPT, $_SESSION['exportConvPath']); $this->conv_slashes = safe_GET('conv_slashes', array('forward', 'backward'), $_SESSION['exportConvSlashes']); $this->privatize_export = safe_GET('privatize_export', array('none', 'visitor', 'user', 'gedadmin', 'admin')); $this->filetype = safe_GET('filetype'); $this->level1 = safe_GET('level1'); $this->level2 = safe_GET('level2'); $this->level3 = safe_GET('level3'); if (empty($this->filetype)) { $this->filetype = "gedcom"; } $others = safe_GET('others'); $item = safe_GET('item'); if (!isset($cart)) { $cart = $_SESSION['cart']; } $this->type = safe_GET('type'); $this->conv_path = stripLRMRLM($this->conv_path); $_SESSION['exportConvPath'] = $this->conv_path; // remember this for the next Download $_SESSION['exportConvSlashes'] = $this->conv_slashes; if ($this->action == 'add') { if (empty($this->type) && !empty($this->id)) { $this->type = ""; $obj = GedcomRecord::getInstance($this->id); if (is_null($obj)) { $this->id = ""; $this->action = ""; } else { $this->type = strtolower($obj->getType()); } } else { if (empty($this->id)) { $this->action = ""; } } if (!empty($this->id) && $this->type != 'fam' && $this->type != 'indi' && $this->type != 'sour') { $this->action = 'add1'; } } if ($this->action == 'add1') { $clipping = array(); $clipping['type'] = $this->type; $clipping['id'] = $this->id; $clipping['gedcom'] = $GEDCOM; $ret = $this->add_clipping($clipping); if ($ret) { if ($this->type == 'sour') { if ($others == 'linked') { foreach (fetch_linked_indi($this->id, 'SOUR', PGV_GED_ID) as $indi) { if ($indi->canDisplayName()) { $this->add_clipping(array('type' => 'indi', 'id' => $indi->getXref())); } } foreach (fetch_linked_fam($this->id, 'SOUR', PGV_GED_ID) as $fam) { if ($fam->canDisplayName()) { $this->add_clipping(array('type' => 'fam', 'id' => $fam->getXref())); } } } } if ($this->type == 'fam') { if ($others == 'parents') { $parents = find_parents($this->id); if (!empty($parents["HUSB"])) { $clipping = array(); $clipping['type'] = "indi"; $clipping['id'] = $parents["HUSB"]; $ret = $this->add_clipping($clipping); } if (!empty($parents["WIFE"])) { $clipping = array(); $clipping['type'] = "indi"; $clipping['id'] = $parents["WIFE"]; $ret = $this->add_clipping($clipping); } } else { if ($others == "members") { $this->add_family_members($this->id); } else { if ($others == "descendants") { $this->add_family_descendancy($this->id); } } } } else { if ($this->type == 'indi') { if ($others == 'parents') { $famids = find_family_ids($this->id); foreach ($famids as $indexval => $famid) { $clipping = array(); $clipping['type'] = "fam"; $clipping['id'] = $famid; $ret = $this->add_clipping($clipping); if ($ret) { $this->add_family_members($famid); } } } else { if ($others == 'ancestors') { $this->add_ancestors_to_cart($this->id, $this->level1); } else { if ($others == 'ancestorsfamilies') { $this->add_ancestors_to_cart_families($this->id, $this->level2); } else { if ($others == 'members') { $famids = find_sfamily_ids($this->id); foreach ($famids as $indexval => $famid) { $clipping = array(); $clipping['type'] = "fam"; $clipping['id'] = $famid; $ret = $this->add_clipping($clipping); if ($ret) { $this->add_family_members($famid); } } } else { if ($others == 'descendants') { $famids = find_sfamily_ids($this->id); foreach ($famids as $indexval => $famid) { $clipping = array(); $clipping['type'] = "fam"; $clipping['id'] = $famid; $ret = $this->add_clipping($clipping); if ($ret) { $this->add_family_descendancy($famid, $this->level3); } } } } } } } } } } } else { if ($this->action == 'remove') { $ct = count($cart); for ($i = $item + 1; $i < $ct; $i++) { $cart[$i - 1] = $cart[$i]; } unset($cart[$ct - 1]); } else { if ($this->action == 'empty') { $cart = array(); $_SESSION["cart"] = $cart; } else { if ($this->action == 'download') { usort($cart, "same_group"); if ($this->filetype == "gedcom") { $path = substr($SCRIPT_NAME, 0, strrpos($SCRIPT_NAME, "/")); if (empty($path)) { $path = "/"; } if ($path[strlen($path) - 1] != "/") { $path .= "/"; } if ($SERVER_URL[strlen($SERVER_URL) - 1] == "/") { $dSERVER_URL = substr($SERVER_URL, 0, strlen($SERVER_URL) - 1); } else { $dSERVER_URL = $SERVER_URL; } $media = array(); $mediacount = 0; $ct = count($cart); $filetext = "0 HEAD\n1 SOUR " . PGV_PHPGEDVIEW . "\n2 NAME " . PGV_PHPGEDVIEW . "\n2 VERS " . PGV_VERSION_TEXT . "\n1 DEST DISKETTE\n1 DATE " . date("j M Y") . "\n2 TIME " . date("H:i:s") . "\n"; $filetext .= "1 GEDC\n2 VERS 5.5\n2 FORM LINEAGE-LINKED\n1 CHAR {$CHARACTER_SET}\n"; $head = find_gedcom_record("HEAD"); $placeform = trim(get_sub_record(1, "1 PLAC", $head)); if (!empty($placeform)) { $filetext .= $placeform . "\n"; } else { $filetext .= "1 PLAC\n2 FORM " . "City, County, State/Province, Country" . "\n"; } if ($convert == "yes") { $filetext = preg_replace("/UTF-8/", "ANSI", $filetext); $filetext = utf8_decode($filetext); } $tempUserID = '#ExPoRt#'; if ($this->privatize_export != 'none') { // Create a temporary userid $export_user_id = createTempUser($tempUserID, $this->privatize_export, $GEDCOM); // Create a temporary userid // Temporarily become this user $_SESSION["org_user"] = $_SESSION["pgv_user"]; $_SESSION["pgv_user"] = $tempUserID; } for ($i = 0; $i < $ct; $i++) { $clipping = $cart[$i]; if ($clipping['gedcom'] == $GEDCOM) { $record = find_gedcom_record($clipping['id']); $savedRecord = $record; // Save this for the "does this file exist" check if ($clipping['type'] == 'obje') { $record = convert_media_path($record, $this->conv_path, $this->conv_slashes); } $record = privatize_gedcom($record); $record = remove_custom_tags($record, $remove); if ($convert == "yes") { $record = utf8_decode($record); } switch ($clipping['type']) { case 'indi': $ft = preg_match_all("/1 FAMC @(.*)@/", $record, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { if (!id_in_cart($match[$k][1])) { $record = preg_replace("/1 FAMC @" . $match[$k][1] . "@.*/", "", $record); } } $ft = preg_match_all("/1 FAMS @(.*)@/", $record, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { if (!id_in_cart($match[$k][1])) { $record = preg_replace("/1 FAMS @" . $match[$k][1] . "@.*/", "", $record); } } $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1])); if (file_exists($filename)) { $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename); $mediacount++; } // $record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record); } $filetext .= trim($record) . "\n"; $filetext .= "1 SOUR @SPGV1@\n"; $filetext .= "2 PAGE " . $dSERVER_URL . "/individual.php?pid=" . $clipping['id'] . "\n"; $filetext .= "2 DATA\n"; $filetext .= "3 TEXT " . $pgv_lang["indi_downloaded_from"] . "\n"; $filetext .= "4 CONT " . $dSERVER_URL . "/individual.php?pid=" . $clipping['id'] . "\n"; break; case 'fam': $ft = preg_match_all("/1 CHIL @(.*)@/", $record, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { if (!id_in_cart($match[$k][1])) { /* if the child is not in the list delete the record of it */ $record = preg_replace("/1 CHIL @" . $match[$k][1] . "@.*/", "", $record); } } $ft = preg_match_all("/1 HUSB @(.*)@/", $record, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { if (!id_in_cart($match[$k][1])) { /* if the husband is not in the list delete the record of him */ $record = preg_replace("/1 HUSB @" . $match[$k][1] . "@.*/", "", $record); } } $ft = preg_match_all("/1 WIFE @(.*)@/", $record, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { if (!id_in_cart($match[$k][1])) { /* if the wife is not in the list delete the record of her */ $record = preg_replace("/1 WIFE @" . $match[$k][1] . "@.*/", "", $record); } } $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1])); if (file_exists($filename)) { $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename); $mediacount++; } // $record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record); } $filetext .= trim($record) . "\n"; $filetext .= "1 SOUR @SPGV1@\n"; $filetext .= "2 PAGE " . $dSERVER_URL . $path . "family.php?famid=" . $clipping['id'] . "\n"; $filetext .= "2 DATA\n"; $filetext .= "3 TEXT " . $pgv_lang["family_downloaded_from"] . "\n"; $filetext .= "4 CONT " . $dSERVER_URL . "/family.php?famid=" . $clipping['id'] . "\n"; break; case 'source': $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1])); if (file_exists($filename)) { $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename); $mediacount++; } // $record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record); } $filetext .= trim($record) . "\n"; $filetext .= "1 NOTE " . $pgv_lang["source_downloaded_from"] . "\n"; $filetext .= "2 CONT " . $dSERVER_URL . "/source.php?sid=" . $clipping['id'] . "\n"; break; default: $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER); for ($k = 0; $k < $ft; $k++) { $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1])); if (file_exists($filename)) { $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename); $mediacount++; } // $record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record); } $filetext .= trim($record) . "\n"; break; } } } if ($this->privatize_export != 'none') { $_SESSION["pgv_user"] = $_SESSION["org_user"]; delete_user($export_user_id); AddToLog("deleted dummy user -> {$tempUserID} <-"); } if ($this->IncludeMedia == "yes") { $this->media_list = $media; } $filetext .= "0 @SPGV1@ SOUR\n"; if ($user_id = get_user_id($CONTACT_EMAIL)) { $filetext .= "1 AUTH " . getUserFullName($user_id) . "\n"; } $filetext .= "1 TITL " . $HOME_SITE_TEXT . "\n"; $filetext .= "1 ABBR " . $HOME_SITE_TEXT . "\n"; $filetext .= "1 PUBL " . $HOME_SITE_URL . "\n"; $filetext .= "0 TRLR\n"; //-- make sure the preferred line endings are used $filetext = preg_replace("/[\r\n]+/", PGV_EOL, $filetext); $this->download_data = $filetext; $this->download_clipping(); } else { if ($this->filetype == "gramps") { // Sort the clippings cart because the export works better when the cart is sorted usort($cart, "same_group"); require_once "includes/classes/class_geclippings.php"; $gramps_Exp = new GEClippings(); $gramps_Exp->begin_xml(); $ct = count($cart); usort($cart, "same_group"); for ($i = 0; $i < $ct; $i++) { $clipping = $cart[$i]; switch ($clipping['type']) { case 'indi': $rec = find_person_record($clipping['id']); $rec = remove_custom_tags($rec, $remove); if ($this->privatize_export != 'none') { $rec = privatize_gedcom($rec); } $gramps_Exp->create_person($rec, $clipping['id']); break; case 'fam': $rec = find_family_record($clipping['id']); $rec = remove_custom_tags($rec, $remove); if ($this->privatize_export != 'none') { $rec = privatize_gedcom($rec); } $gramps_Exp->create_family($rec, $clipping['id']); break; case 'source': $rec = find_source_record($clipping['id']); $rec = remove_custom_tags($rec, $remove); if ($this->privatize_export != 'none') { $rec = privatize_gedcom($rec); } $gramps_Exp->create_source($rec, $clipping['id']); break; } } $this->download_data = $gramps_Exp->dom->saveXML(); if ($convert) { $this->download_data = utf8_decode($this->download_data); } $this->media_list = $gramps_Exp->get_all_media(); $this->download_clipping(); } } } } } } }
function export_gedcom($gedcom, $gedout, $exportOptions) { global $GEDCOM; // Temporarily switch to the specified GEDCOM $oldGEDCOM = $GEDCOM; $GEDCOM = $gedcom; $ged_id = get_id_from_gedcom($gedcom); switch ($exportOptions['privatize']) { case 'gedadmin': $access_level = WT_PRIV_NONE; break; case 'user': $access_level = WT_PRIV_USER; break; case 'visitor': $access_level = WT_PRIV_PUBLIC; break; case 'none': $access_level = WT_PRIV_HIDE; break; } $head = gedcom_header($gedcom); if ($exportOptions['toANSI'] == 'yes') { $head = str_replace('UTF-8', 'ANSI', $head); $head = utf8_decode($head); } $head = reformat_record_export($head); fwrite($gedout, $head); // Buffer the output. Lots of small fwrite() calls can be very slow when writing large gedcoms. $buffer = ''; // Generate the OBJE/SOUR/REPO/NOTE records first, as their privacy calcualations involve // database queries, and we wish to avoid large gaps between queries due to MySQL connection timeouts. $tmp_gedcom = ''; $rows = WT_DB::prepare("SELECT 'OBJE' AS type, m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media` WHERE m_file=? ORDER BY m_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); $rec = convert_media_path($rec, $exportOptions['path']); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources` WHERE s_file=? ORDER BY s_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT o_type AS type, o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other` WHERE o_file=? AND o_type!='HEAD' AND o_type!='TRLR' ORDER BY o_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { switch ($row->type) { case 'NOTE': $record = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; case 'REPO': $record = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; default: $record = WT_GedcomRecord::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; } $rec = $record->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals` WHERE i_file=? ORDER BY i_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $buffer .= reformat_record_export($rec); if (strlen($buffer) > 65536) { fwrite($gedout, $buffer); $buffer = ''; } } $rows = WT_DB::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom" . " FROM `##families` WHERE f_file=? ORDER BY f_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $buffer .= reformat_record_export($rec); if (strlen($buffer) > 65536) { fwrite($gedout, $buffer); $buffer = ''; } } fwrite($gedout, $buffer); fwrite($gedout, $tmp_gedcom); fwrite($gedout, '0 TRLR' . WT_EOL); $GEDCOM = $oldGEDCOM; }