// Copyright (c) 2022 High5! // License Info: LICENSE.TXT // // File: domain.php // // Template File: admin_domain.tpl // // Template Variables: // // action // message // domain // description // aliases // mailboxes // // Form POST / GET Variables: // // domain // description // aliases // mailboxes // require_once '../functions.inc.php'; include '../languages/' . check_language() . '.lang'; $list_domains = list_domains(); if ($_SERVER['REQUEST_METHOD'] == "GET") { $action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'add'; if ($action == 'edit') { $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN); $domain_key = array_search($domain, array_column($list_domains, 'domain')); $description = $list_domains[$domain_key]['description']; $aliases = $list_domains[$domain_key]['aliases']; $mailboxes = $list_domains[$domain_key]['mailboxes']; } } if ($_SERVER['REQUEST_METHOD'] == "POST") { $action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'add'; $domain = strtolower(filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN)); $description = filter_input(INPUT_POST, 'description', FILTER_CALLBACK, array('options' => 'htmlspecialchars')); $aliases = filter_input(INPUT_POST, 'aliases', FILTER_VALIDATE_INT); $mailboxes = filter_input(INPUT_POST, 'mailboxes', FILTER_VALIDATE_INT); if (!in_array($domain, array_column($list_domains, 'domain'))) { try { $dbh = pdo_connect(); $sth = $dbh->prepare("INSERT INTO domain (domain,description,aliases,mailboxes,created,modified) VALUES (?,?,?,?,NOW(),NOW())"); $sth->bindParam(1, $domain, PDO::PARAM_STR); $sth->bindParam(2, $description, PDO::PARAM_STR); $sth->bindParam(3, $aliases, PDO::PARAM_INT); $sth->bindParam(4, $mailboxes, PDO::PARAM_INT); $sth->execute(); $message = $LANG['AdminAdd_domain_result_succes'] . "
($domain)
"; } catch(PDOException $e) { $message = $LANG['AdminAdd_domain_result_error'] . "
($domain)
"; } } else { $message = $LANG['AdminAdd_domain_domain_text_error']; } if (in_array($domain, array_column($list_domains, 'domain')) && $action == 'edit') { try { $dbh = pdo_connect(); $sth = $dbh->prepare("UPDATE domain SET description=?,aliases=?,mailboxes=?,modified=NOW() WHERE domain=?"); $sth->bindParam(1, $description, PDO::PARAM_STR); $sth->bindParam(2, $aliases, PDO::PARAM_INT); $sth->bindParam(3, $mailboxes, PDO::PARAM_INT); $sth->bindParam(4, $domain, PDO::PARAM_STR); $sth->execute(); header("Location: list-domain.php"); } catch(PDOException $e) { $message = $LANG['AdminEdit_domain_result_error']; } } } include '../templates/header.tpl'; include '../templates/admin_menu.tpl'; include '../templates/admin_domain.tpl'; include '../templates/footer.tpl'; ?>