diff options
Diffstat (limited to 'delorga.php')
| -rw-r--r-- | delorga.php | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/delorga.php b/delorga.php new file mode 100644 index 0000000..4dfd95c --- /dev/null +++ b/delorga.php @@ -0,0 +1,284 @@ +<?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"; + +$orgaID = $_GET['id']; +$prohibit = false; + +(function () use ($mysqli, $_title, $orgaID) { + $sql = "SELECT * FROM Organisationen WHERE id=?;"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param('i', $orgaID); + $stmt->execute(); + $r = $stmt->get_result(); + $l = $r->fetch_object(); + + $_title = '<span class="pii">' . $l->Name . '</span> (ID ' . $orgaID . ')'; + include_once __DIR__ . "/header.php"; +?> + <h1 style="display: inline-block;"><span style="color: red; font-weight: bold;">Orgadatensatz 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, '_=3Name', '_PLZ', '_=2Ort'] + ]; + include __DIR__ . '/autoform.php'; + $stmt->reset(); +})(); + +(function () use ($orgaID) { + $globstring = "{" . $orgaID . "orga}_"; + require_once __DIR__ . "/doc.php"; +})(); + +(function () use ($mysqli, $orgaID, &$num_rows) { + $title = "Spenden"; + $nochosen = $nofilter = true; + $sql = " +SELECT + Spenden.ID AS SpendenID, + contract AS VertrID, + CONCAT(calls.name, ' [', contracts.call, '] - ', ContractOrga.Name) AS Vertrag, + Betrag, + DATE(Geldeingang) AS Geldeingang +FROM Spenden + 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.Organisation=? OR ContractOrga.ID = ? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("ii", $orgaID, $orgaID); + $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ätze, die direkt oder indirekt mit diesem Orgadatensatz verknüpft sind. Löschen daher nicht möglich.</p> +<? +} + +(function () use ($mysqli, $orgaID, &$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 + LEFT JOIN Förderer ON Stipendien.Förderer = Förderer.ID +WHERE Förderer.Organisation=? AND Förderbeginn >= '2000-01-01' +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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ätze, die über den Fördererdatensatz mit diesem Orgadatensatz verknüpft sind. Löschen daher nicht möglich.</p> +<? +} + +(function () use ($mysqli, $orgaID, &$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 orgaid=? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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 Orgadatensatz verknüpft sind. Löschen daher nicht möglich.</p> +<? +} + +(function () use ($mysqli, $orgaID, &$num_rows) { + $title = "Organisationen"; + $nochosen = $nofilter = true; + $sql = " +SELECT + ID AS OrgaID, + Name AS Organisation +FROM Organisationen +WHERE Superorganisation=? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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, bei der dieser diese Orga die übergeordnete Orga ist. Löschen daher nicht möglich.</p> +<? +} + +(function () use ($mysqli, $orgaID, &$num_rows) { + $title = "Förderer"; + $nochosen = $nofilter = true; + $sql = " +SELECT + Förderer.ID AS FoerdID +FROM Förderer +WHERE Förderer.Organisation=? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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> Dieser Orga ist ein Fördererdatensatz zugeordnet. Löschen daher nicht möglich. Bitte zunächst den Fördererdatensatz löschen.</p> +<? +} + +(function () use ($mysqli, $orgaID, &$num_rows) { + $title = "Verträge"; + $nochosen = $nofilter = true; + $sql = " +SELECT + contracts.id AS VertrID, + contracts.`call` +FROM contracts + LEFT JOIN Förderer ON contracts.patron = Förderer.ID +WHERE Förderer.Organisation=? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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, $orgaID, &$num_rows) { + $title = "Events"; + $nochosen = $nofilter = true; + $sql = " +SELECT + id AS EventID, + name AS Name, + DATE(date) AS Datum +FROM events +WHERE host=? +"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $orgaID); + $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> +<? +} +?> + +<hr> +<? +if (!$prohibit) { +?> + <button class="medium" onclick="return delOrga();" style="background: red;"><i class="far fa-trash-alt"></i> Orgadatensatz 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/delorgado.php', { + 'id': <?=$orgaID?>, + 'what': what + }); + window.location.reload(); +} + +function delOrga() { + doSth('orga'); +} +<? minEnd(); ?> +</script> + +<? +if (!$prohibit && isset($_GET['autodel']) && $_GET['autodel'] == 1) { +?> +<script> + delOrga(); +</script> +<? +} + +require_once __DIR__ . "/jumper.php"; +exit(0); |
