function append_gedrec($gedrec, $chan = true, $linkpid = '') { global $fcontents, $GEDCOM, $pgv_changes, $manual_save; if (($gedrec = check_gedcom($gedrec, $chan)) !== false) { $ct = preg_match("/0 @(" . PGV_REGEX_XREF . ")@ (" . PGV_REGEX_TAG . ")/", $gedrec, $match); $gid = $match[1]; $type = trim($match[2]); if (preg_match("/\\d+/", $gid) == 0) { $xref = get_new_xref($type); } else { $xref = $gid; } $gedrec = preg_replace("/0 @(.*)@/", "0 @{$xref}@", $gedrec); $change = array(); $change["gid"] = $xref; $change["gedcom"] = $GEDCOM; $change["type"] = "append"; $change["status"] = "submitted"; $change["user"] = PGV_USER_NAME; $change["time"] = time(); if (!empty($linkpid)) { $change["linkpid"] = $linkpid; } $change["undo"] = reformat_record_import($gedrec); if (!isset($pgv_changes[$xref . "_" . $GEDCOM])) { $pgv_changes[$xref . "_" . $GEDCOM] = array(); } $pgv_changes[$xref . "_" . $GEDCOM][] = $change; if (PGV_USER_AUTO_ACCEPT) { accept_changes($xref . "_" . $GEDCOM); } else { write_changes(); } $backtrace = debug_backtrace(); $temp = ""; if (isset($backtrace[2])) { $temp .= basename($backtrace[2]["file"]) . " (" . $backtrace[2]["line"] . ")"; } if (isset($backtrace[1])) { $temp .= basename($backtrace[1]["file"]) . " (" . $backtrace[1]["line"] . ")"; } if (isset($backtrace[0])) { $temp .= basename($backtrace[0]["file"]) . " (" . $backtrace[0]["line"] . ")"; } $action = basename($_SERVER["SCRIPT_NAME"]); if (!empty($_REQUEST['action'])) { $action .= " " . $_REQUEST['action']; } AddToChangeLog($action . " " . $temp . " Appending new {$type} record {$xref} ->" . PGV_USER_NAME . "<-"); return $xref; } return false; }
unset($GLOBALS["newThumbFolder"]); } } // Insert the 1 FILE xxx record into the arrays used by function handle_updates() $glevels = array_merge(array("1"), $glevels); $tag = array_merge(array("FILE"), $tag); $islink = array_merge(array(0), $islink); $text = array_merge(array($folder . $filename), $text); $mediaFile = $filename; $folderName = $folder; } } if ($finalResult && $mediaFile != "") { // NOTE: Build the gedcom record // NOTE: Level 0 $media_id = get_new_xref("OBJE"); $newged = "0 @" . $media_id . "@ OBJE\n"; //-- set the FILE text to the correct file location in the standard media directory if (PGV_USER_GEDCOM_ADMIN) { $text[0] = $folderName . $mediaFile; } else { $newged .= "1 FILE " . $folderName . $mediaFile . "\n"; } $newged = handle_updates($newged); require_once 'includes/classes/class_media.php'; $media_obje = new Media($newged); $mediaid = Media::in_obje_list($media_obje); if (!$mediaid) { $mediaid = append_gedrec($newged, $linktoid); } if ($mediaid) {
// You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA use WT\Auth; define('WT_SCRIPT_NAME', 'admin_trees_renumber.php'); require './includes/session.php'; $controller = new WT_Controller_Page(); $controller->restrictAccess(Auth::isManager())->setPageTitle(WT_I18N::translate('Renumber family tree'))->pageHeader(); // Every XREF used by this tree and also used by some other tree $xrefs = WT_DB::prepare("SELECT xref, type FROM (" . " SELECT i_id AS xref, 'INDI' AS type FROM `##individuals` WHERE i_file = ?" . " UNION " . " SELECT f_id AS xref, 'FAM' AS type FROM `##families` WHERE f_file = ?" . " UNION " . " SELECT s_id AS xref, 'SOUR' AS type FROM `##sources` WHERE s_file = ?" . " UNION " . " SELECT m_id AS xref, 'OBJE' AS type FROM `##media` WHERE m_file = ?" . " UNION " . " SELECT o_id AS xref, o_type AS type FROM `##other` WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" . ") AS this_tree JOIN (" . " SELECT xref FROM `##change` WHERE gedcom_id <> ?" . " UNION " . " SELECT i_id AS xref FROM `##individuals` WHERE i_file <> ?" . " UNION " . " SELECT f_id AS xref FROM `##families` WHERE f_file <> ?" . " UNION " . " SELECT s_id AS xref FROM `##sources` WHERE s_file <> ?" . " UNION " . " SELECT m_id AS xref FROM `##media` WHERE m_file <> ?" . " UNION " . " SELECT o_id AS xref FROM `##other` WHERE o_file <> ? AND o_type NOT IN ('HEAD', 'TRLR')" . ") AS other_trees USING (xref)")->execute(array(WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID, WT_GED_ID))->fetchAssoc(); echo '<h2>', $controller->getPageTitle(), ' — ', $WT_TREE->tree_title_html, '</h2>'; if (WT_Filter::get('go')) { foreach ($xrefs as $old_xref => $type) { WT_DB::exec("START TRANSACTION"); WT_DB::exec("LOCK TABLE `##individuals` WRITE," . " `##families` WRITE," . " `##sources` WRITE," . " `##media` WRITE," . " `##other` WRITE," . " `##name` WRITE," . " `##placelinks` WRITE," . " `##change` WRITE," . " `##next_id` WRITE," . " `##dates` WRITE," . " `##default_resn` WRITE," . " `##hit_counter` WRITE," . " `##link` WRITE," . " `##user_gedcom_setting` WRITE"); $new_xref = get_new_xref($type); switch ($type) { case 'INDI': WT_DB::prepare("UPDATE `##individuals` SET i_id = ?, i_gedcom = REPLACE(i_gedcom, ?, ?) WHERE i_id = ? AND i_file = ?")->execute(array($new_xref, "0 @{$old_xref}@ INDI\n", "0 @{$new_xref}@ INDI\n", $old_xref, WT_GED_ID)); WT_DB::prepare("UPDATE `##families` JOIN `##link` ON (l_file = f_file AND l_to = ? AND l_type = 'HUSB') SET f_gedcom = REPLACE(f_gedcom, ?, ?) WHERE f_file = ?")->execute(array($old_xref, " HUSB @{$old_xref}@", " HUSB @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##families` JOIN `##link` ON (l_file = f_file AND l_to = ? AND l_type = 'WIFE') SET f_gedcom = REPLACE(f_gedcom, ?, ?) WHERE f_file = ?")->execute(array($old_xref, " WIFE @{$old_xref}@", " WIFE @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##families` JOIN `##link` ON (l_file = f_file AND l_to = ? AND l_type = 'CHIL') SET f_gedcom = REPLACE(f_gedcom, ?, ?) WHERE f_file = ?")->execute(array($old_xref, " CHIL @{$old_xref}@", " CHIL @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##families` JOIN `##link` ON (l_file = f_file AND l_to = ? AND l_type = 'ASSO') SET f_gedcom = REPLACE(f_gedcom, ?, ?) WHERE f_file = ?")->execute(array($old_xref, " ASSO @{$old_xref}@", " ASSO @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##families` JOIN `##link` ON (l_file = f_file AND l_to = ? AND l_type = '_ASSO') SET f_gedcom = REPLACE(f_gedcom, ?, ?) WHERE f_file = ?")->execute(array($old_xref, " _ASSO @{$old_xref}@", " _ASSO @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##individuals` JOIN `##link` ON (l_file = i_file AND l_to = ? AND l_type = 'ASSO') SET i_gedcom = REPLACE(i_gedcom, ?, ?) WHERE i_file = ?")->execute(array($old_xref, " ASSO @{$old_xref}@", " ASSO @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##individuals` JOIN `##link` ON (l_file = i_file AND l_to = ? AND l_type = '_ASSO') SET i_gedcom = REPLACE(i_gedcom, ?, ?) WHERE i_file = ?")->execute(array($old_xref, " _ASSO @{$old_xref}@", " _ASSO @{$new_xref}@", WT_GED_ID)); WT_DB::prepare("UPDATE `##placelinks` SET pl_gid = ? WHERE pl_gid = ? AND pl_file = ?")->execute(array($new_xref, $old_xref, WT_GED_ID)); WT_DB::prepare("UPDATE `##dates` SET d_gid = ? WHERE d_gid = ? AND d_file = ?")->execute(array($new_xref, $old_xref, WT_GED_ID)); WT_DB::prepare("UPDATE `##user_gedcom_setting` SET setting_value = ? WHERE setting_value = ? AND gedcom_id = ? AND setting_name IN ('gedcomid', 'rootid')")->execute(array($new_xref, $old_xref, WT_GED_ID)); break; case 'FAM':
public static function createRecord($gedcom, $gedcom_id) { if (preg_match('/^0 @(' . WT_REGEX_XREF . ')@ (' . WT_REGEX_TAG . ')/', $gedcom, $match)) { $xref = $match[1]; $type = $match[2]; } else { throw new Exception('Invalid argument to WT_GedcomRecord::createRecord(' . $gedcom . ')'); } if (strpos("\r", $gedcom) !== false) { // MSDOS line endings will break things in horrible ways throw new Exception('Evil line endings found in WT_GedcomRecord::createRecord(' . $gedcom . ')'); } // webtrees creates XREFs containing digits. Anything else (e.g. “new”) is just a placeholder. if (!preg_match('/\\d/', $xref)) { $xref = get_new_xref($type); $gedcom = preg_replace('/^0 @(' . WT_REGEX_XREF . ')@/', '0 @' . $xref . '@', $gedcom); } // Create a change record, if not already present if (!preg_match('/\\n1 CHAN/', $gedcom)) { $gedcom .= "\n1 CHAN\n2 DATE " . date('d M Y') . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . WT_USER_NAME; } // Create a pending change WT_DB::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, '', ?, ?)")->execute(array($gedcom_id, $xref, $gedcom, WT_USER_ID)); // Accept this pending change if (Auth::user()->getSetting('auto_accept')) { accept_all_changes($xref, $gedcom_id); } // Clear this record from the cache self::$pending_record_cache = null; Log::addEditLog('Create: ' . $type . ' ' . $xref); // Return the newly created record return WT_GedcomRecord::getInstance($xref); }
function create_media_object($level, $gedrec, $ged_id) { static $sql_insert_media = null; static $sql_select_media = null; if (!$sql_insert_media) { $sql_insert_media = WT_DB::prepare("INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom) VALUES (?, ?, ?, ?, ?, ?, ?)"); $sql_select_media = WT_DB::prepare("SELECT m_id FROM `##media` WHERE m_filename=? AND m_titl=? AND m_file=?"); } if (preg_match('/\\n\\d FILE (.+)/', $gedrec, $file_match)) { $file = $file_match[1]; } else { $file = ''; } if (preg_match('/\\n\\d TITL (.+)/', $gedrec, $file_match)) { $titl = $file_match[1]; } else { $titl = $file; } // Have we already created a media object with the same title/filename? $xref = $sql_select_media->execute(array($file, $titl, $ged_id))->fetchOne(); if (!$xref) { $xref = get_new_xref("OBJE", $ged_id); // renumber the lines $gedrec = preg_replace_callback('/\\n(\\d+)/', function ($m) use($level) { return "\n" . ($m[1] - $level); }, $gedrec); // convert to an object $gedrec = str_replace("\n0 OBJE\n", '0 @' . $xref . "@ OBJE\n", $gedrec); // Fix Legacy GEDCOMS $gedrec = preg_replace('/\\n1 FORM (.+)\\n1 FILE (.+)\\n1 TITL (.+)/', "\n1 FILE \$2\n2 FORM \$1\n2 TITL \$3", $gedrec); // Create new record $record = new WT_Media($xref, $gedrec, null, $ged_id); $sql_insert_media->execute(array($xref, $record->extension(), $record->getMediaType(), $record->title, $record->file, $ged_id, $gedrec)); } return "\n" . $level . ' OBJE @' . $xref . '@'; }
/** * Insert media items into the database * This method is used in conjuction with the gedcom import/update routines * @param string $objrec The OBJE subrecord * @param int $objlevel The original level of this OBJE * @param boolean $update Whether or not this is an update or an import * @param string $gid The XREF ID of the record this OBJE is related to * @param int $count The count of OBJE records in the parent record */ function insert_media($objrec, $objlevel, $update, $gid, $count) { global $TBLPREFIX, $media_count, $GEDCOMS, $FILE, $found_ids, $fpnewged, $gBitDb; //-- check for linked OBJE records //-- linked records don't need to insert to media table $ct = preg_match("/OBJE @(.*)@/", $objrec, $match); if ($ct > 0) { //-- get the old id $old_m_media = $match[1]; $objref = $objrec; $new_m_media = $old_m_media; $m_media = $new_m_media; if ($m_media != $old_m_media) { $objref = preg_replace("/@{$old_m_media}@/", "@{$m_media}@", $objref); } } else { $m_media = get_new_xref("OBJE", true); $objref = subrecord_createobjectref($objrec, $objlevel, $m_media); //-- restructure the record to be a linked record $objrec = preg_replace("/ OBJE/", " @" . $m_media . "@ OBJE", $objrec); //-- renumber the lines $objrec = preg_replace("/^(\\d+) /me", "(\$1-{$objlevel}).' '", $objrec); //-- check if another picture with the same file and title was previously imported $media = new Media($objrec); $new_media = Media::in_obje_list($media); if (!$new_media) { //-- add it to the media database table $gBitDb->query("INSERT INTO {$TBLPREFIX}media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)", array(get_next_id('media', 'm_id'), $m_media, $media->ext, $media->title, $media->file, $GEDCOMS[$FILE]["id"], $objrec)); $media_count++; //-- if this is not an update then write it to the new gedcom file if (!$update && !empty($fpnewged)) { fwrite($fpnewged, reformat_record_export($objrec)); } } else { //-- already added so update the local id $objref = preg_replace("/@{$m_media}@/", "@{$new_media}@", $objref); $m_media = $new_media; } } if (isset($m_media)) { //-- add the entry to the media_mapping table $gBitDb->query("INSERT INTO {$TBLPREFIX}media_mapping (mm_id, mm_media, mm_gid, mm_order, mm_gedfile, mm_gedrec) VALUES (?, ?, ?, ?, ?, ?)", array(get_next_id('media_mapping', 'mm_id'), $m_media, $gid, $count, $GEDCOMS[$FILE]['id'], $objref)); return $objref; } else { print "Media reference error " . $objrec; return ""; } }
} replace_gedrec($pid, $indirec, $update_CHAN); } } } break; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ case 'addopfchildaction': if (PGV_DEBUG) { phpinfo(INFO_VARIABLES); } splitSOUR(); // separate SOUR record from the rest $newindixref = get_new_xref('INDI'); $newfamxref = get_new_xref('FAM'); $gedrec = "0 @{$newindixref}@ INDI\n1 FAMC @{$newfamxref}@\n" . addNewName() . addNewSex(); if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) { foreach ($matches[1] as $match) { $gedrec .= addNewFact($match); } } if (safe_POST_bool('SOUR_INDI')) { $gedrec = handle_updates($gedrec); } else { $gedrec = updateRest($gedrec); } $famrec = "0 @{$newfamxref}@ FAM\n1 CHIL @{$newindixref}@"; $person = Person::getInstance($pid); if ($person->getSex() == 'F') { $famrec .= "\n1 WIFE @{$pid}@";