// Delete Family pledges $sSQL = "DELETE FROM pledge_plg WHERE plg_PledgeOrPayment = 'Pledge' AND plg_FamID = " . $iFamilyID; RunQuery($sSQL); // Remove family property data $sSQL = "SELECT pro_ID FROM property_pro WHERE pro_Class='f'"; $rsProps = RunQuery($sSQL); while ($aRow = mysql_fetch_row($rsProps)) { $sSQL = "DELETE FROM record2property_r2p WHERE r2p_pro_ID = " . $aRow[0] . " AND r2p_record_ID = " . $iFamilyID; RunQuery($sSQL); } if (isset($_GET["Members"])) { // Delete all persons that were in this family $sSQL = "SELECT per_ID FROM person_per WHERE per_fam_ID = " . $iFamilyID; $rsPersons = RunQuery($sSQL); while ($aRow = mysql_fetch_row($rsPersons)) { DeletePerson($aRow[0]); } } else { // Reset previous members' family ID to 0 (undefined) $sSQL = "UPDATE person_per SET per_fam_ID = 0 WHERE per_fam_ID = " . $iFamilyID; RunQuery($sSQL); } // Delete the specified Family record $sSQL = "DELETE FROM family_fam WHERE fam_ID = " . $iFamilyID; RunQuery($sSQL); // Remove custom field data $sSQL = "DELETE FROM family_custom WHERE fam_ID = " . $iFamilyID; RunQuery($sSQL); // Delete the photo files, if they exist $photoThumbnail = "Images/Family/thumbnails/" . $iFamilyID . ".jpg"; if (file_exists($photoThumbnail)) {
{ // Abort deletion if person is parent in some family with children (must remove the children first) if ($family->ElementExists("Family[ChildID and (ParentID = {$PersonID})]")) { // Actually, we could allow this, but the spouses of the families would have to be deleted also. // Currently this restriction means that we cannot delete root-ancestors. throw new Exception("Person has families with children in database. Cannot delete."); } // Delete the person itself, references to him as child and all empty families he is in $family->RemoveElements("Person[@id = '{$PersonID}']"); $family->RemoveElements("Family/ChildID[. = '{$PersonID}']"); $family->RemoveElements("Family[ParentID = '{$PersonID}']"); } //-------------------------- MAIN -------------------------- try { VerifyPassword(); $family = LoadFamilyData(); $PersonID = $_REQUEST["PersonID"]; if ($family->ElementExists("Family[ChildID = '{$PersonID}']")) { // redirect to first parent when this person has been deleted $parentID = $family->Element("Family[ChildID = '{$PersonID}']/ParentID[1]")->InnerText; } DeletePerson($family, $PersonID); SaveFamilyData($family); if (isset($parentID)) { Redirect("person.php?PersonID={$parentID}"); } else { Redirect("index.php"); } } catch (Exception $e) { ReportException($e); }