{ // 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); }
function CreateThumbnails() { $family = LoadFamilyData(); foreach ($family->Elements("Person") as $person) { $PersonID = $person->id; if ($person->ElementExists("Images/Image")) { $picDir = PersonPicsDir($PersonID); $smallFile = "{$picDir}/small.png"; if (!file_exists($smallFile)) { $largePicName = $person->Element("Images/Image[last()]")->InnerText; $large = imagecreatefromjpeg("{$picDir}/{$largePicName}"); $small = imagecreatetruecolor(80, 100); // aspect 1.25 imagecopyresampled($small, $large, 0, 0, 0, 0, 80, 100, imagesx($large), imagesy($large)); imagepng($small, $smallFile); imagedestroy($large); imagedestroy($small); } } } }