opensmtpdadmin/search.php

67 lines
1.8 KiB
PHP

<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: search.php
//
// Template File: search.tpl
//
// Template Variables:
//
// list_alias
// list_mailbox
//
// POST / GET Variables:
//
// search
//
require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$ROLE = check_role($SESSID_USERNAME);
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
} else {
$list_domains = list_domains($SESSID_USERNAME);
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$search = filter_input(INPUT_POST, 'search', FILTER_DEFAULT);
if (isset($search)) {
$dbh = pdo_connect();
$sth = $dbh->prepare("SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE ? AND mailbox.maildir IS NULL ORDER BY alias.address");
$sth->bindValue(1, '%'.$search.'%', PDO::PARAM_STR);
$sth->execute();
$list_alias = $sth->fetchAll();
foreach ($list_alias as $key => $value) {
if (!in_array($value['domain'], array_column($list_domains, 'domain'))) {
unset($list_alias[$key]);
}
}
$sth = $dbh->prepare("SELECT * FROM mailbox WHERE username LIKE ? ORDER BY username");
$sth->bindValue(1, '%'.$search.'%', PDO::PARAM_STR);
$sth->execute();
$list_mailbox = $sth->fetchAll();
foreach ($list_mailbox as $key => $value) {
if (!in_array($value['domain'], array_column($list_domains, 'domain'))) {
unset($list_mailbox[$key]);
}
}
} else {
$list_alias = array();
$list_mailbox = array();
}
}
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/search.tpl';
include './templates/footer.tpl';
?>