Example #1
0
 /**
  * Accept any edit changes into the database
  * Also update the indirec we will use to generate the page
  */
 function acceptChanges()
 {
     global $GEDCOM;
     if (!PGV_USER_CAN_ACCEPT) {
         return;
     }
     if (accept_changes($this->nid . "_" . $GEDCOM)) {
         $this->show_changes = false;
         $this->accept_success = true;
         $indirec = find_other_record($this->nid);
         //-- check if we just deleted the record and redirect to index
         if (empty($indirec)) {
             header("Location: index.php?ctype=gedcom");
             exit;
         }
         $this->note = new Note($indirec);
     }
 }
Example #2
0
        $manual_save = true;
        foreach ($pgv_changes as $cid => $changes) {
            if ($changes[0]['gedcom'] == $ged) {
                undo_change($cid, 0);
            }
        }
        write_changes();
        $manual_save = false;
        echo '<b>', $pgv_lang['undo_successful'], '</b>';
        break;
    case 'acceptall':
        //-- only save the file and changes once
        $manual_save = true;
        foreach ($pgv_changes as $cid => $changes) {
            if ($changes[0]['gedcom'] == $ged) {
                accept_changes($cid);
            }
        }
        write_changes();
        $manual_save = false;
        if ($SYNC_GEDCOM_FILE) {
            write_file();
        }
        echo '<b>', $pgv_lang['accept_successful'], '</b>';
        break;
}
if (empty($pgv_changes)) {
    echo '<br /><br /><b>', $pgv_lang['no_changes'], '</b>';
} else {
    $output = '<br /><br /><table class="list_table"><tr><td class="list_value ' . $TEXT_DIRECTION . '">';
    $changedgedcoms = array();
Example #3
0
 /**
  * Accept any edit changes into the database
  * Also update the indirec we will use to generate the page
  */
 function acceptChanges()
 {
     global $GEDCOM;
     if (!PGV_USER_CAN_ACCEPT) {
         return;
     }
     if (accept_changes($this->pid . "_" . $GEDCOM)) {
         $this->show_changes = false;
         $this->accept_success = true;
         //-- delete the record from the cache and refresh it
         $indirec = find_person_record($this->pid);
         //-- check if we just deleted the record and redirect to index
         if (empty($indirec)) {
             header("Location: index.php?ctype=gedcom");
             exit;
         }
         $this->indi = new Person($indirec);
     }
 }
Example #4
0
function delete_gedrec($gid, $linkpid = '')
{
    global $fcontents, $GEDCOM, $pgv_changes, $manual_save;
    //-- first check if the record is not already deleted
    if (isset($pgv_changes[$gid . "_" . $GEDCOM])) {
        $change = end($pgv_changes[$gid . "_" . $GEDCOM]);
        if ($change["type"] == "delete") {
            return true;
        }
    }
    $undo = find_gedcom_record($gid);
    if (empty($undo)) {
        return false;
    }
    $change = array();
    $change["gid"] = $gid;
    $change["gedcom"] = $GEDCOM;
    $change["type"] = "delete";
    $change["status"] = "submitted";
    $change["user"] = PGV_USER_NAME;
    $change["time"] = time();
    if (!empty($linkpid)) {
        $change["linkpid"] = $linkpid;
    }
    $change["undo"] = "";
    if (!isset($pgv_changes[$gid . "_" . $GEDCOM])) {
        $pgv_changes[$gid . "_" . $GEDCOM] = array();
    }
    $pgv_changes[$gid . "_" . $GEDCOM][] = $change;
    if (PGV_USER_AUTO_ACCEPT) {
        accept_changes($gid . "_" . $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 . " Deleting gedcom record {$gid} ->" . PGV_USER_NAME . "<-");
    return true;
}
Example #5
0
 function init()
 {
     global $Dbwidth, $bwidth, $pbwidth, $pbheight, $bheight, $GEDCOM, $pgv_lang, $CONTACT_EMAIL, $show_famlink, $pgv_changes;
     $bwidth = $Dbwidth;
     $pbwidth = $bwidth + 12;
     $pbheight = $bheight + 14;
     $show_famlink = $this->view != 'preview';
     $this->famid = safe_GET_xref('famid');
     $this->family = Family::getInstance($this->famid);
     if (empty($this->famrec)) {
         $ct = preg_match("/(\\w+):(.+)/", $this->famid, $match);
         if ($ct > 0) {
             $servid = trim($match[1]);
             $remoteid = trim($match[2]);
             include_once 'includes/classes/class_serviceclient.php';
             $service = ServiceClient::getInstance($servid);
             if (!is_null($service)) {
                 $newrec = $service->mergeGedcomRecord($remoteid, "0 @" . $this->famid . "@ FAM\n1 RFN " . $this->famid, false);
                 $this->famrec = $newrec;
             }
         }
         //-- if no record was found create a default empty one
         if (isset($pgv_changes[$this->famid . "_" . $GEDCOM])) {
             $this->famrec = "0 @" . $this->famid . "@ FAM\n";
             $this->family = new Family($this->famrec);
         } else {
             if (empty($this->family)) {
                 return false;
             }
         }
     }
     $this->famrec = $this->family->getGedcomRecord();
     $this->display = displayDetailsById($this->famid, 'FAM');
     //-- if the user can edit and there are changes then get the new changes
     if ($this->show_changes && PGV_USER_CAN_EDIT && isset($pgv_changes[$this->famid . "_" . $GEDCOM])) {
         $newrec = find_updated_record($this->famid);
         if (empty($newrec)) {
             $newrec = find_family_record($this->famid);
         }
         $this->difffam = new Family($newrec);
         $this->difffam->setChanged(true);
         $this->family->diffMerge($this->difffam);
         //$this->famrec = $newrec;
         //$this->family = new Family($this->famrec);
     }
     $this->parents = array('HUSB' => $this->family->getHusbId(), 'WIFE' => $this->family->getWifeId());
     //-- check if we can display both parents
     if ($this->display == false) {
         $this->showLivingHusb = showLivingNameById($this->parents['HUSB']);
         $this->showLivingWife = showLivingNameById($this->parents['WIFE']);
     }
     //-- add favorites action
     if ($this->action == 'addfav' && !empty($_REQUEST['gid']) && PGV_USER_NAME) {
         $_REQUEST['gid'] = strtoupper($_REQUEST['gid']);
         $indirec = find_family_record($_REQUEST['gid']);
         if ($indirec) {
             $favorite = array('username' => PGV_USER_NAME, 'gid' => $_REQUEST['gid'], 'type' => 'FAM', 'file' => $GEDCOM, 'url' => '', 'note' => '', 'title' => '');
             addFavorite($favorite);
         }
     }
     if (PGV_USER_CAN_ACCEPT) {
         if ($this->action == 'accept') {
             if (accept_changes($_REQUEST['famid'] . '_' . $GEDCOM)) {
                 $this->show_changes = false;
                 $this->accept_success = true;
                 //-- check if we just deleted the record and redirect to index
                 $famrec = find_family_record($_REQUEST['famid']);
                 if (empty($famrec)) {
                     header("Location: index.php?ctype=gedcom");
                     exit;
                 }
                 $this->family = new Family($famrec);
                 $this->parents = find_parents($_REQUEST['famid']);
             }
         }
         if ($this->action == 'undo') {
             $this->family->undoChange();
             $this->parents = find_parents($_REQUEST['famid']);
         }
     }
     //-- make sure we have the true id from the record
     $ct = preg_match("/0 @(.*)@/", $this->famrec, $match);
     if ($ct > 0) {
         $this->famid = trim($match[1]);
     }
     if ($this->showLivingHusb == false && $this->showLivingWife == false) {
         print_header($pgv_lang['private'] . " " . $pgv_lang['family_info']);
         print_privacy_error($CONTACT_EMAIL);
         print_footer();
         exit;
     }
     $this->title = $this->family->getFullName();
     if (empty($this->parents['HUSB']) || empty($this->parents['WIFE'])) {
         $this->link_relation = 0;
     } else {
         $this->link_relation = 1;
     }
 }
Example #6
0
 /**
  * Accept any edit changes into the database
  * Also update the mediarec we will use to generate the page
  */
 function acceptChanges()
 {
     global $GEDCOM;
     if (!PGV_USER_CAN_ACCEPT) {
         return;
     }
     if (accept_changes($this->pid . "_" . $GEDCOM)) {
         $this->show_changes = false;
         $this->accept_success = true;
         $mediarec = find_media_record($this->pid);
         //-- check if we just deleted the record and redirect to index
         if (empty($mediarec)) {
             header("Location: index.php?ctype=gedcom");
             exit;
         }
         //$this->mediaobject = Media::getInstance($this->pid);
         $this->mediaobject = new Media($mediarec);
     }
     //This sets the controller ID to be the Media ID
     if (is_null($this->mediaobject)) {
         $this->mediaobject = new Media("0 @" . $this->pid . "@ OBJE");
     }
 }
/**
* Accpet changed gedcom record into database
*
* This function gets an updated record from the gedcom file and replaces it in the database
* @author John Finlay
* @param string $cid The change id of the record to accept
*/
function accept_changes($cid)
{
    global $pgv_changes, $GEDCOM, $TBLPREFIX, $FILE, $GEDCOMS;
    global $INDEX_DIRECTORY, $SYNC_GEDCOM_FILE, $fcontents, $manual_save;
    if (isset($pgv_changes[$cid])) {
        $changes = $pgv_changes[$cid];
        $change = $changes[count($changes) - 1];
        if ($GEDCOM != $change["gedcom"]) {
            $GEDCOM = $change["gedcom"];
        }
        $FILE = $GEDCOM;
        $gid = $change["gid"];
        $gedrec = $change["undo"];
        if (empty($gedrec)) {
            $gedrec = find_gedcom_record($gid);
        }
        update_record($gedrec, $change["type"] == "delete");
        //-- write the changes back to the gedcom file
        if ($SYNC_GEDCOM_FILE) {
            // TODO: We merge CONC lines on import, so need to add them back on export
            if (!isset($manual_save) || $manual_save == false) {
                //-- only allow one thread to accept changes at a time
                //				$mutex = new Mutex("accept_changes");
                //				$mutex->Wait();
            }
            if (empty($fcontents)) {
                read_gedcom_file();
            }
            if ($change["type"] == "delete") {
                $pos1 = find_newline_string($fcontents, "0 @{$gid}@");
                if ($pos1 !== false) {
                    $pos2 = find_newline_string($fcontents, "0", $pos1 + 5);
                    if ($pos2 === false) {
                        $fcontents = substr($fcontents, 0, $pos1) . '0 TRLR' . PGV_EOL;
                        AddToLog("Corruption found in GEDCOM {$GEDCOM} Attempted to correct");
                    } else {
                        $fcontents = substr($fcontents, 0, $pos1) . substr($fcontents, $pos2);
                    }
                } else {
                    AddToLog("Corruption found in GEDCOM {$GEDCOM} Attempted to correct.  Deleted gedcom record {$gid} was not found in the gedcom file.");
                }
            } elseif ($change["type"] == "append") {
                $pos1 = find_newline_string($fcontents, "0 TRLR");
                $fcontents = substr($fcontents, 0, $pos1) . reformat_record_export($gedrec) . '0 TRLR' . PGV_EOL;
            } elseif ($change["type"] == "replace") {
                $pos1 = find_newline_string($fcontents, "0 @{$gid}@");
                if ($pos1 !== false) {
                    $pos2 = find_newline_string($fcontents, "0", $pos1 + 5);
                    if ($pos2 === false) {
                        $fcontents = substr($fcontents, 0, $pos1) . '0 TRLR' . PGV_EOL;
                        AddToLog("Corruption found in GEDCOM {$GEDCOM} Attempted to correct");
                    } else {
                        $fcontents = substr($fcontents, 0, $pos1) . reformat_record_export($gedrec) . substr($fcontents, $pos2);
                    }
                } else {
                    //-- attempted to replace a record that doesn't exist
                    AddToLog("Corruption found in GEDCOM {$GEDCOM} Attempted to correct.  Replaced gedcom record {$gid} was not found in the gedcom file.");
                    $pos1 = find_newline_string($fcontents, "0 TRLR");
                    $fcontents = substr($fcontents, 0, $pos1) . reformat_record_export($gedrec) . '0 TRLR' . PGV_EOL;
                    AddToLog("Gedcom record {$gid} was appended back to the GEDCOM file.");
                }
            }
            if (!isset($manual_save) || $manual_save == false) {
                write_file();
                //				$mutex->Release();
            }
        }
        if ($change["type"] != "delete") {
            //-- synchronize the gedcom record with any user account
            $username = get_user_from_gedcom_xref($GEDCOM, $gid);
            if ($username && get_user_setting($username, 'sync_gedcom') == 'Y') {
                $firstname = get_gedcom_value("GIVN", 2, $gedrec);
                $lastname = get_gedcom_value("SURN", 2, $gedrec);
                if (empty($lastname)) {
                    $fullname = get_gedcom_value("NAME", 1, $gedrec, "", false);
                    $ct = preg_match("~(.*)/(.*)/~", $fullname, $match);
                    if ($ct > 0) {
                        $firstname = $match[1];
                        $lastname = $match[2];
                    } else {
                        $firstname = $fullname;
                    }
                }
                //-- SEE [ 1753047 ] Email/sync with account
                $email = get_gedcom_value("EMAIL", 1, $gedrec);
                if (empty($email)) {
                    $email = get_gedcom_value("_EMAIL", 1, $gedrec);
                }
                if (!empty($email)) {
                    set_user_setting($username, 'email', $email);
                }
                set_user_setting($username, 'firstname', $firstname);
                set_user_setting($username, 'lastname', $lastname);
            }
        }
        unset($pgv_changes[$cid]);
        if (!isset($manual_save) || $manual_save == false) {
            write_changes();
        }
        $logline = AddToLog("Accepted change {$cid} " . $change["type"] . " into database");
        check_in($logline, $GEDCOM, dirname($GEDCOMS[$GEDCOM]['path']));
        if (isset($change["linkpid"])) {
            accept_changes($change["linkpid"] . "_" . $GEDCOM);
        }
        return true;
    }
    return false;
}