summaryrefslogtreecommitdiff
path: root/delperson.php
diff options
context:
space:
mode:
authorNiklas Olmes <niklas@olmes.de>2026-04-24 19:30:00 +0200
committerNiklas Olmes <niklas@olmes.de>2026-04-24 19:30:00 +0200
commitcdea8caa5617f0cb77bcbc9803759abd2df50644 (patch)
tree2f7f1bd3af3b2396baf5403ad1a7ad00bcb7fae9 /delperson.php
stipcrmHEADmain
Diffstat (limited to 'delperson.php')
-rw-r--r--delperson.php385
1 files changed, 385 insertions, 0 deletions
diff --git a/delperson.php b/delperson.php
new file mode 100644
index 0000000..001ad5e
--- /dev/null
+++ b/delperson.php
@@ -0,0 +1,385 @@
+<?php
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+?>
+<?
+/* vim: set ts=4 sw=4 et : */
+
+require_once __DIR__ . "/check_auth.php";
+require_once __DIR__ . "/../includes/common.php";
+
+$persID = $_GET['id'];
+$prohibit = false;
+
+(function () use ($mysqli, $_title, $persID) {
+ $sql = "SELECT *, DATE(Geburtsdatum) AS Geburtsdatum FROM Personen WHERE id=?;";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param('i', $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ $l = $r->fetch_object();
+
+ $_title = '<span class="pii">' . $l->Nachname . ', ' . $l->Vorname . '</span> (ID ' . $persID . ')';
+ include_once __DIR__ . "/header.php";
+?>
+ <h1 style="display: inline-block;"><span style="color: red; font-weight: bold;">Personendatensatz löschen:</span> <?=$_title?></h1>
+<?
+ if ($l->ID < 1) {
+?>
+ <p><b>Kein Datensatz mit dieser ID gefunden!</b></p>
+ <p>Wenn Sie gerade gelöscht haben, war das Löschen erfolgreich.</p>
+
+<? if (isset($_GET['autodel']) && $_GET['autodel'] == 1) { ?>
+ <script>
+ window.close();
+ </script>
+<? }
+ exit(0);
+ }
+
+ $def = [
+ "Auszug",
+ [6, '_Geschlecht', '_=2Vorname', '_=2Nachname', '_Titel'],
+ [6, '_Geburtsdatum#isodate', '_=2Email', '_PLZ', '_=2Ort']
+ ];
+ include __DIR__ . '/autoform.php';
+ $stmt->reset();
+})();
+?>
+
+<?
+(function () use ($persID) {
+ $globstring = "{" . $persID . "person}_";
+ require_once __DIR__ . "/doc.php";
+})();
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Spenden";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ Spenden.ID AS SpendenID,
+ Spenden.Organisation AS OrgaID,
+ Organisationen.Name AS Organisation,
+ contract AS VertrID,
+ CONCAT(calls.name, ' [', contracts.call, '] - ', ContractOrga.Name) AS Vertrag,
+ Betrag,
+ DATE(Geldeingang) AS Geldeingang
+FROM Spenden
+ LEFT JOIN Organisationen ON Spenden.Organisation = Organisationen.ID
+ LEFT JOIN contracts ON Spenden.contract = contracts.id
+ LEFT JOIN Förderer AS ContractPatron ON contracts.patron = ContractPatron.ID
+ LEFT JOIN Organisationen AS ContractOrga ON ContractPatron.Organisation = ContractOrga.ID
+ LEFT JOIN calls ON contracts.`call` = calls.shorthand
+WHERE Spenden.Person=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Spendendatens&auml;tze, die mit diesem Personendatensatz verknüpft sind. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Stipendien";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ Stipendien.ID AS StipID,
+ Stipendien.Jahr AS Jahr,
+ Förderarten.Name AS Förderart
+FROM Stipendien
+ LEFT JOIN Förderarten ON Stipendien.Förderart = Förderarten.ID
+WHERE Stipendien.Person=? AND Förderbeginn >= '2000-01-01'
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Stipendiendatens&auml;tze, die mit diesem Personendatensatz verknüpft sind. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Notizen";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ id AS NotizID,
+ title AS Titel,
+ solved AS erledigt,
+ changets AS `Letzte Änderung`
+FROM notes
+WHERE persid=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Notizendatensätze, die mit diesem Personendatensatz verknüpft sind. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Organisationen";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ Personen_Organisationen.Organisation AS OrgaID,
+ Organisationen.Name AS Organisation,
+ Abteilung,
+ Funktion
+FROM Personen_Organisationen
+ LEFT JOIN Organisationen ON Personen_Organisationen.Organisation = Organisationen.ID
+WHERE Personen_Organisationen.Person=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Verknüpfungen zu Organisationen. Löschen daher nicht möglich.</p>
+ <button class="medium" onclick="return delOrgas();" style="background: red;"><i class="far fa-trash-alt"></i> Alle Organisationsverknüpfungen löschen</button>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Förderer";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ Förderer.ID AS FoerdID,
+ Organisationen.Name AS Förderer
+FROM Förderer
+ LEFT JOIN Organisationen ON Förderer.Organisation = Organisationen.ID
+WHERE Förderer.zuwendungen=? OR Förderer.`Ansprechpartner Stipendiaten`=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("ii", $persID, $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren Verknüpfungen in <?=$num_rows?> Fördererdatensätzen. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Verträge";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ contracts.id AS VertrID,
+ contracts.`call`,
+ Organisationen.Name AS Förderer
+FROM contracts
+ LEFT JOIN Förderer ON contracts.patron = Förderer.ID
+ LEFT JOIN Organisationen ON Förderer.Organisation = Organisationen.ID
+WHERE contracts.contact=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren Verknüpfungen in <?=$num_rows?> Vertragsdatensätzen. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Kommissionen";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ `call`,
+ Kommissionen.Benutzername AS Shorthand
+FROM commissioners
+LEFT JOIN Kommissionen on commissioners.Kommission = Kommissionen.ID
+WHERE commissioners.Person=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Verknüpfungen zu Kommissionen. Löschen daher nicht möglich.</p>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "Events";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ eventid AS EventID,
+ events.name AS Name
+FROM event_participants
+ LEFT JOIN events ON event_participants.eventid = events.id
+WHERE persid=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> Verknüpfungen zu Events. Löschen daher nicht möglich.</p>
+ <button class="medium" onclick="return delEvents();" style="background: red;"><i class="far fa-trash-alt"></i> Alle Eventverknüpfungen löschen</button>
+<?
+}
+?>
+
+<?
+(function () use ($mysqli, $persID, &$num_rows) {
+ $title = "E-Mails";
+ $nochosen = $nofilter = true;
+ $sql = "
+SELECT
+ mails.id AS EmailID,
+ mails.subject AS Betreff,
+ mails.from AS Absender,
+ mails.ts AS Datum
+FROM mails
+WHERE persid=?
+";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $persID);
+ $stmt->execute();
+ $r = $stmt->get_result();
+ include __DIR__ . '/autotable.php';
+ $stmt->reset();
+})();
+if ($num_rows) {
+ $prohibit = true;
+?>
+ <p class="warning"><i class="fas fa-exclamation-triangle"></i> Es existieren <?=$num_rows?> verknüpfte E-Mails. Löschen daher nicht möglich.</p>
+ <button class="medium" onclick="return delMails();" style="background: red;"><i class="far fa-trash-alt"></i> Alle verknüpften E-Mails löschen</button>
+ <button class="medium" onclick="return rewMails();" style="background: orange;"><i class="fas fa-eraser"></i> E-Mails beibehalten, alle Verknüpfungen entfernen</button>
+<?
+}
+?>
+
+<hr>
+<?
+if (!$prohibit) {
+?>
+ <button class="medium" onclick="return delPerson();" style="background: red;"><i class="far fa-trash-alt"></i> Personendatensatz unwiderruflich löschen</button>
+<?
+} else {
+?>
+<p>Löschen derzeit nicht möglich. Zunächst Datensätze umwidmen bzw. Verknüpfungen entfernen.<p>
+<?
+}
+?>
+<script>
+<? minStart(); ?>
+function doSth(what) {
+ $.ajaxSetup({async:false});
+ $.post('/db/main/delpersondo.php', {
+ 'id': <?=$persID?>,
+ 'what': what
+ });
+ window.location.reload();
+}
+
+function delOrgas() {
+ doSth('orga');
+}
+
+function delEvents() {
+ doSth('event');
+}
+
+function delMails() {
+ doSth('email');
+}
+
+function rewMails() {
+ doSth('emailrewrite');
+}
+
+function delPerson() {
+ doSth('person');
+}
+<? minEnd(); ?>
+</script>
+
+<?
+if (!$prohibit && isset($_GET['autodel']) && $_GET['autodel'] == 1) {
+?>
+<script>
+ delPerson();
+</script>
+<?
+}
+
+require_once __DIR__ . "/jumper.php";
+exit(0);
+?>