Esempio n. 1
0
 /**
  * check whether or not this fact can be edited
  *
  * @return boolean
  */
 function canEdit()
 {
     if (!$this->canShowDetails()) {
         return false;
     }
     if (is_null($this->canEdit)) {
         if (!is_null($this->parentObject)) {
             $this->canEdit = !FactEditRestricted($this->parentObject->getXref(), $this->gedcomRecord);
         } else {
             $this->canEdit = true;
         }
     }
     return $this->canEdit;
 }
 function check_updated_facts($i, &$famrec, $TAGS, $prefix)
 {
     global $typefacts, $pid, $pgv_lang, $factarray;
     $famrec = trim($famrec);
     $famupdate = false;
     $repeat_tags = array();
     $var = $prefix . $i . "DESCS";
     if (!empty($_POST[$var])) {
         $DESCS = $_POST[$var];
     } else {
         $DESCS = array();
     }
     $var = $prefix . $i . "DATES";
     if (!empty($_POST[$var])) {
         $DATES = $_POST[$var];
     } else {
         $DATES = array();
     }
     $var = $prefix . $i . "PLACS";
     if (!empty($_POST[$var])) {
         $PLACS = $_POST[$var];
     } else {
         $PLACS = array();
     }
     $var = $prefix . $i . "TEMPS";
     if (!empty($_POST[$var])) {
         $TEMPS = $_POST[$var];
     } else {
         $TEMPS = array();
     }
     $var = $prefix . $i . "RESNS";
     if (!empty($_POST[$var])) {
         $RESNS = $_POST[$var];
     } else {
         $RESNS = array();
     }
     $var = $prefix . $i . "REMS";
     if (!empty($_POST[$var])) {
         $REMS = $_POST[$var];
     } else {
         $REMS = array();
     }
     $var = "F" . $i . "MARRY";
     if (!empty($_REQUEST[$var])) {
         $FMARRY = $_REQUEST[$var];
     } else {
         $FMARRY = "";
     }
     $var = "F" . $i . "DIVY";
     if (!empty($_REQUEST[$var])) {
         $FDIVY = $_REQUEST[$var];
     } else {
         $FDIVY = "";
     }
     for ($j = 0; $j < count($TAGS); $j++) {
         if (!empty($TAGS[$j])) {
             $fact = $TAGS[$j];
             if (!isset($repeat_tags[$fact])) {
                 $repeat_tags[$fact] = 1;
             } else {
                 $repeat_tags[$fact]++;
             }
             $DATES[$j] = check_input_date($DATES[$j]);
             if (!isset($REMS[$j])) {
                 $REMS[$j] = 0;
             }
             if ($REMS[$j] == 1) {
                 $DESCS[$j] = "";
                 $DATES[$j] = "";
                 $PLACS[$j] = "";
                 $TEMPS[$j] = "";
                 $RESNS[$j] = "";
             }
             if (empty($DATES[$j]) && empty($PLACS[$j]) && empty($TEMPS[$j]) && empty($RESNS[$j])) {
                 if (!in_array($fact, $typefacts)) {
                     $factrec = "1 {$fact}";
                 } else {
                     $factrec = "1 EVEN\n2 TYPE {$fact}";
                 }
                 if (!empty($DESCS[$j])) {
                     $factrec .= " {$DESCS[$j]}\n";
                 } elseif (!empty($FMARRY)) {
                     $factrec = "1 MARR Y\n";
                 } elseif (!empty($FDIVY)) {
                     $factrec = "1 DIV Y\n";
                 } else {
                     $factrec = "";
                 }
             } else {
                 if (!in_array($fact, $typefacts)) {
                     $factrec = "1 {$fact}";
                 } else {
                     $factrec = "1 EVEN\n2 TYPE {$fact}";
                 }
                 if (!empty($DESCS[$j])) {
                     $factrec .= " {$DESCS[$j]}\n";
                 } else {
                     $factrec .= "\n";
                 }
                 if (!empty($DATES[$j])) {
                     $factrec .= "2 DATE {$DATES[$j]}\n";
                 }
                 if (!empty($PLACS[$j])) {
                     $factrec .= "2 PLAC {$PLACS[$j]}\n";
                 }
                 if (!empty($TEMPS[$j])) {
                     $factrec .= "2 TEMP {$TEMPS[$j]}\n";
                 }
                 if (!empty($RESNS[$j])) {
                     $factrec .= "2 RESN {$RESNS[$j]}\n";
                 }
             }
             if (!in_array($fact, $typefacts)) {
                 $lookup = "1 {$fact}";
             } else {
                 $lookup = "1 EVEN\n2 TYPE {$fact}\n";
             }
             $pos1 = strpos($famrec, $lookup);
             $k = 1;
             //-- make sure we are working with the correct fact
             while ($k < $repeat_tags[$fact]) {
                 $pos1 = strpos($famrec, $lookup, $pos1 + 5);
                 $k++;
                 if ($pos1 === false) {
                     break;
                 }
             }
             $noupdfact = false;
             if ($pos1 !== false) {
                 $pos2 = strpos($famrec, "\n1 ", $pos1 + 5);
                 if ($pos2 === false) {
                     $pos2 = strlen($famrec);
                 }
                 $oldfac = trim(substr($famrec, $pos1, $pos2 - $pos1));
                 $noupdfact = FactEditRestricted($pid, $oldfac);
                 if ($noupdfact) {
                     echo "<br />", $pgv_lang["update_fact_restricted"], " ", $factarray[$fact], "<br /><br />";
                 } else {
                     //-- delete the fact
                     if ($REMS[$j] == 1) {
                         $famupdate = true;
                         $famrec = substr($famrec, 0, $pos1) . "\n" . substr($famrec, $pos2);
                     } else {
                         if (!empty($oldfac) && !empty($factrec)) {
                             $factrec = $oldfac;
                             if (!empty($DESCS[$j])) {
                                 if (strstr($factrec, "1 {$fact}")) {
                                     $factrec = preg_replace("/1 {$fact}.*/", "1 {$fact} {$DESCS[$j]}", $factrec);
                                 } else {
                                     $factrec = $factrec . "\n1 {$fact} {$DESCS[$j]}";
                                 }
                             }
                             if (!empty($DATES[$j])) {
                                 if (strstr($factrec, "\n2 DATE")) {
                                     $factrec = preg_replace("/2 DATE.*/", "2 DATE {$DATES[$j]}", $factrec);
                                 } else {
                                     $factrec = $factrec . "\n2 DATE {$DATES[$j]}";
                                 }
                             }
                             if (!empty($PLACS[$j])) {
                                 if (strstr($factrec, "\n2 PLAC")) {
                                     $factrec = preg_replace("/2 PLAC.*/", "2 PLAC {$PLACS[$j]}", $factrec);
                                 } else {
                                     $factrec = $factrec . "\n2 PLAC {$PLACS[$j]}";
                                 }
                             }
                             if (!empty($TEMPS[$j])) {
                                 if (strstr($factrec, "\n2 TEMP")) {
                                     $factrec = preg_replace("/2 TEMP.*/", "2 TEMP {$TEMPS[$j]}", $factrec);
                                 } else {
                                     $factrec = $factrec . "\n2 TEMP {$TEMPS[$j]}";
                                 }
                             }
                             if (!empty($RESNS[$j])) {
                                 if (strstr($factrec, "\n2 RESN")) {
                                     $factrec = preg_replace("/2 RESN.*/", "2 RESN {$RESNS[$j]}", $factrec);
                                 } else {
                                     $factrec = $factrec . "\n2 RESN {$RESNS[$j]}";
                                 }
                             }
                             $factrec = preg_replace("/[\r\n]+/", "\n", $factrec);
                             $oldfac = preg_replace("/[\r\n]+/", "\n", $oldfac);
                             if (trim($factrec) != trim($oldfac)) {
                                 $famupdate = true;
                                 $famrec = substr($famrec, 0, $pos1) . trim($factrec) . "\n" . substr($famrec, $pos2);
                             }
                         }
                     }
                 }
             } else {
                 if (!empty($factrec)) {
                     $famrec .= "\n" . $factrec;
                     $famupdate = true;
                 }
             }
         }
     }
     return $famupdate;
 }