commit - fcd063fccb050ea361d792942eae3be661e39b3d
commit + 050fa4a19a73bbf4ac4880598638473815c9e5c2
blob - db9b622e6306097906e2d207e02519ce49f4422b
blob + 265baee683b6acdc681460438504478dafd2feee
--- delete.php
+++ delete.php
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
-$list_domains = list_domains($SESSID_USERNAME);
+$ROLE = check_role();
+if ($ROLE == ADMIN_ROLE) {
+ $list_domains = list_domains();
+} else {
+ $list_domains = list_domains($SESSID_USERNAME);
+}
+
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$table = filter_input(INPUT_GET, 'table', FILTER_DEFAULT);
$delete = filter_input(INPUT_GET, 'delete', FILTER_DEFAULT);
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
+ if ($ROLE == ADMIN_ROLE && $domain_exist && $table == "domain") {
+ try {
+ $dbh = pdo_connect();
+ $dbh->beginTransaction();
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM log WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_log = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM log WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_log) {
+ throw new RuntimeException('Unable to delete entries from the logs table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_vacation = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM vacation WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_vacation) {
+ throw new RuntimeException('Unable to delete entries from the vacation table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM alias WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_alias = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM alias WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_alias) {
+ throw new RuntimeException('Unable to delete entries from the alias table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM mailbox WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_mailbox = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM mailbox WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_mailbox) {
+ throw new RuntimeException('Unable to delete entries from the mailbox table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_domain_admins = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM domain_admins WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_domain_admins) {
+ throw new RuntimeException('Unable to delete entries from the domain_admins table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM domain WHERE domain=?");
+ $sth->execute(array($domain));
+ $count_domain = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM domain WHERE domain=?");
+ $sth->execute(array($domain));
+ if ($sth->rowCount() != $count_domain) {
+ throw new RuntimeException('Unable to delete entry from the domain table.');
+ }
+
+ $dbh->commit();
+ header("Location: list-domain.php");
+ } catch (RuntimeException $e) {
+ $message = $e->getMessage();
+ $dbh->rollBack();
+ } catch (PDOException $e) {
+ $message = $e->getMessage();
+ }
+ }
+
+ if ($ROLE == ADMIN_ROLE && $table == "admin") {
+ try {
+ $dbh = pdo_connect();
+ $dbh->beginTransaction();
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM admin WHERE username=?");
+ $sth->execute(array($delete));
+ $count_admin = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM admin WHERE username=?");
+ $sth->execute(array($delete));
+ if ($sth->rowCount() != $count_admin) {
+ throw new RuntimeException('Unable to delete entry from the admin table.');
+ }
+
+ $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE username=?");
+ $sth->execute(array($delete));
+ $count_domain_admins = $sth->fetchColumn();
+
+ $sth = $dbh->prepare("DELETE FROM domain_admins WHERE username=?");
+ $sth->execute(array($delete));
+ if ($sth->rowCount() != $count_domain_admins) {
+ throw new RuntimeException('Unable to delete entries from the domain_admins table.');
+ }
+
+ $dbh->commit();
+ header("Location: list-admin.php");
+ } catch (RuntimeException $e) {
+ $message = $e->getMessage();
+ $dbh->rollBack();
+ } catch (PDOException $e) {
+ $message = $e->getMessage();
+ $dbh->rollBack();
+ }
+ }
+
if ($domain_exist && ($table == 'alias' || $table == 'mailbox')) {
try {
$dbh = pdo_connect();
$sth = $dbh->prepare("DELETE FROM mailbox WHERE username=? AND domain=?");
$sth->bindParam(1, $delete, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
-
-
- $sth = $dbh->prepare("DELETE FROM mailbox WHERE username=? AND domain=?");
- $sth->bindParam(1, $delete, PDO::PARAM_STR);
- $sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
if ($sth->rowCount() != 1) {
throw new RuntimeException('mailbox');
$sth->bindParam(1, $delete, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
-
header("Location: list-virtual.php?domain=$domain");
} catch (RuntimeException $e) {
$message = $LANG['Delete_delete_error'] . "<b>$delete</b> (" . $e->getMessage() . ")!</span>";