4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
8 // File: edit-alias.php
10 // Template File: edit-alias.tpl
12 // Template Variables:
17 // POST / GET Variables:
23 require_once './functions.inc.php';
24 include './languages/' . check_language() . '.lang';
26 $SESSID_USERNAME = check_session();
27 $ROLE = check_role($SESSID_USERNAME);
29 if ($ROLE == ADMIN_ROLE) {
30 $list_domains = list_domains();
31 $list_admins = list_admins();
33 $list_domains = list_domains($SESSID_USERNAME);
36 if ($_SERVER['REQUEST_METHOD'] == "GET") {
37 $address = filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL);
38 $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
39 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
41 if (in_array($domain, array_column($list_domains, 'domain'))) {
44 $sth = $dbh->prepare("SELECT goto FROM alias WHERE address=? AND domain=?");
45 $sth->bindParam(1, $address, PDO::PARAM_STR);
46 $sth->bindParam(2, $domain, PDO::PARAM_STR);
48 $goto = $sth->fetch(PDO::FETCH_COLUMN);
49 $goto = explode(',', $goto);
50 } catch(PDOException $e) {
51 $message = $LANG['Edit_alias_address_error'];
56 if ($_SERVER['REQUEST_METHOD'] == "POST") {
57 $address = strtolower(filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL));
58 $domain = strtolower(filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN));
59 $goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
60 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
64 $message = $LANG['Edit_alias_goto_text_error1'];
66 $goto = preg_replace('/\\\r\\\n/', ',', $goto);
67 $goto = preg_replace('/\r\n/', ',', $goto);
68 $goto = preg_replace('/[\s]+/i', '', $goto);
69 $goto = preg_replace('/\,*$/', '', $goto);
70 $validate_goto = explode(',', $goto);
71 foreach ($validate_goto as $row) {
72 if (!filter_var($row, FILTER_VALIDATE_EMAIL)) {
73 $goto = explode(',', $goto);
74 $message = $LANG['Edit_alias_goto_text_error2'] . "$row</div>";
79 if (empty($message) && in_array($domain, array_column($list_domains, 'domain'))) {
82 $sth = $dbh->prepare("UPDATE alias SET goto=?,modified=NOW() WHERE address=? AND domain=?");
83 $sth->bindParam(1, $goto, PDO::PARAM_STR);
84 $sth->bindParam(2, $address, PDO::PARAM_STR);
85 $sth->bindParam(3, $domain, PDO::PARAM_STR);
87 logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
88 header("Location: list-virtual.php?domain=$domain");
89 } catch(PDOException $e) {
90 $message = $LANG['Edit_alias_result_error'];
94 include './templates/header.tpl';
95 include './templates/menu.tpl';
96 include './templates/edit-alias.tpl';
97 include './templates/footer.tpl';