fix bug where list source was not updated on change

This commit is contained in:
Paul 2021-11-10 15:13:53 +01:00
parent a04893aed9
commit 649990eeef
3 changed files with 27 additions and 21 deletions

View File

@ -50,13 +50,27 @@ if ($_SESSION['log'] == 1) {
$sth = $dbh->prepare($eintrag);
$sth->execute(array(':aliasid' => $_POST['editlistid'], ':owner_username' => $maillistownerex[0], ':owner_domain' => $maillistownerex[1]));
}
if ($_SESSION['admin']) {
$newlistsource = explode('@', $_POST['newlistsource']);
} else {
$abfrage = "SELECT `source_username`, `source_domain` FROM `aliases` WHERE `alias_id` LIKE :alias_id";
$abfrage = "SELECT `source` FROM `alias_details` WHERE `id` LIKE :alias_id";
$result = $dbh->prepare($abfrage);
$result->execute(array(':alias_id' => $_POST['editlistid']));
$newlistsource = $result->fetch(); //bei fetch() werden im Array ['spaltenname'] und [#Nummer der Spalte] angelegt also ['source_username'] und [0] praktische Sache
$oldlistsource = $result->fetch()['source']; //bei fetch() werden im Array ['spaltenname'] und [#Nummer der Spalte] angelegt also ['source_username'] und [0] praktische Sache
if ($_SESSION['admin']) {
$newlistsource = $_POST['newlistsource'];
$newlistsourceexp = explode('@', $newlistsource);
if ($newlistsource != $oldlistsource) {
$abfrage = "UPDATE `alias_details` SET `source` = :source WHERE `id` LIKE :alias_id";
$result = $dbh->prepare($abfrage);
$result->execute(array(':source' => $newlistsource, ':alias_id' => $_POST['editlistid']));
$abfrage = "UPDATE `aliases` SET `source_username` = :source_username, `source_domain` = :source_domain WHERE `alias_id` LIKE :alias_id";
$result = $dbh->prepare($abfrage);
$result->execute(array(':source_username' => $newlistsourceexp[0], ':source_domain' => $newlistsourceexp[1], ':alias_id' => $_POST['editlistid']));
}
}
else {
$newlistsource = $oldlistsource;
$newlistsourceexp = explode('@', $newlistsource);
}
$abfrage = "SELECT `id`, `destination_username`, `destination_domain` FROM `aliases` WHERE `alias_id` LIKE :alias_id";
@ -98,7 +112,7 @@ if ($_SESSION['log'] == 1) {
foreach ($addlistdestinations as $addlistdestination) {
$eintrag = "INSERT INTO `aliases` (`alias_id`, `source_username`, `source_domain`, `destination_username`, `destination_domain`) VALUES (:aliasid, :source_username, :source_domain, :destination_username, :destination_domain)"; // Aliasdaten in MailServer DB eintragen
$sth = $dbh->prepare($eintrag);
$sth->execute(array(':aliasid' => $_POST['editlistid'], ':source_username' => $newlistsource[0], ':source_domain' => $newlistsource[1], ':destination_username' => $addlistdestination[0], ':destination_domain' => $addlistdestination[1]));
$sth->execute(array(':aliasid' => $_POST['editlistid'], ':source_username' => $newlistsourceexp[0], ':source_domain' => $newlistsourceexp[1], ':destination_username' => $addlistdestination[0], ':destination_domain' => $addlistdestination[1]));
}
header("Location: maillistsettings.php");
exit;

View File

@ -38,20 +38,16 @@ if ($_SESSION['log']) {
</head>
<body>
<a href="maillistsettings.php"><h3>Zurück zur Maillistoberfläche (Editieren abbrechen)</h3></a><br>';
$abfrage = "SELECT `name`, `owners`, `security`, `islist` FROM `alias_details` WHERE `id` LIKE :editlistid";
$abfrage = "SELECT `name`, `owners`, `source`, `security`, `islist` FROM `alias_details` WHERE `id` LIKE :editlistid";
$result = $dbh->prepare($abfrage);
$result->execute(array(':editlistid' => $_GET['editlistid']));
while ($lists = $result->fetch()) {
$abfrage2 = "SELECT `source_username`, `source_domain` FROM `aliases` WHERE `alias_id` LIKE :aliasid";
$result2 = $dbh->prepare($abfrage2);
$result2->execute(array(':aliasid' => $_GET['editlistid']));
$listdetails = $result2->fetch();
echo'
<form name="editlist" method=POST action="editlist.php">
<label>Listenname: <input name="newlistname" type="text" placeholder="Listenname" value="' . $lists['name'] . '"/></label>
<label>Listenadresse: ';
if ($_SESSION['admin']) echo '<input name="newlistsource" type="text" placeholder="Listenadresse" value="' . $listdetails['source_username'] . '@' . $listdetails['source_domain'] . '"/></label>';
else echo $listdetails['source_username'] . '@' . $listdetails['source_domain'] . '</label> ';
if ($_SESSION['admin']) echo '<input name="newlistsource" type="text" placeholder="Listenadresse" value="' . $lists['name'] . '"/></label>';
else echo $lists['source'] . '</label> ';
echo '<label>Listenbesitzer: <textarea rows="1" cols="50" name="newlistowners">' . $lists['owners'] . '</textarea></label><br>
<label>Listenempfänger (durch Leerzeichen getrennt):<br><textarea rows="4" cols="50" name="newlistdestinations">';
$abfrage3 = "SELECT `destination_username`, `destination_domain` FROM `aliases` WHERE `alias_id` LIKE :aliasid";

View File

@ -69,21 +69,17 @@ if ($_SESSION['log'] == 1) {
echo '<a href="../settings.php"><h3>Zurück</h3></a><br><h3>Meine bestehenden Listen:</h3>';
}
if ($_SESSION['admin']) {
$abfrage = "SELECT `id`, `name`, `owners`, `destinations`, `security`, `islist` FROM `alias_details`";
$abfrage = "SELECT `id`, `name`, `owners`, `source`, `destinations`, `security`, `islist` FROM `alias_details`";
$result = $dbh->query($abfrage);
}
else {
$abfrage = "SELECT `id`, `name`, `owners`, `destinations`, `security`, `islist` FROM `alias_details` WHERE `id` REGEXP :aliasid";
$abfrage = "SELECT `id`, `name`, `owners`, `source`, `destinations`, `security`, `islist` FROM `alias_details` WHERE `id` REGEXP :aliasid";
$result = $dbh->prepare($abfrage);
$result->execute(array(':aliasid' => substr($aliasids, 0, -1)));
}
echo '<table border="1" style="text-align: center; vertical-align: middle;"><tr><th>Listenname</th><th>Listenadresse</th><th>Listenempfänger</th><th>Listenbesitzer</th><th>Listensicherheit</th><th>Ist Maillingliste</th></ht><th>Optionen</th></tr>';
while ($lists = $result->fetch()) {
$abfrage2 = "SELECT `source_username`, `source_domain` FROM `aliases` WHERE `alias_id` LIKE :aliasid";
$result2 = $dbh->prepare($abfrage2);
$result2->execute(array(':aliasid' => $lists['id']));
$listdetails = $result2->fetch();
echo '<tr><td>' . $lists['name'] . '</td><td>' . $listdetails['source_username'] . '@' . $listdetails['source_domain'] . '</td><td>';
echo '<tr><td>' . $lists['name'] . '</td><td>' . $lists['source'] . '</td><td>';
foreach (explode(' ', $lists['destinations']) as $destination) {
echo $destination . '<br>';
}