opensmtpdadmin/search.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2022-08-18 14:01:52 +02:00
<?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:
//
2022-09-04 20:44:32 +02:00
// list_alias
// list_mailbox
2022-08-18 14:01:52 +02:00
//
2022-09-04 22:43:21 +02:00
// Form POST / GET Variables:
2022-08-18 14:01:52 +02:00
//
2022-09-04 20:44:32 +02:00
// search
2022-08-18 14:01:52 +02:00
//
2022-09-04 20:44:32 +02:00
require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
2022-08-18 14:01:52 +02:00
$SESSID_USERNAME = check_session();
2022-09-04 20:44:32 +02:00
$list_domains = list_domains($SESSID_USERNAME);
2022-09-04 22:43:21 +02:00
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$search = filter_input(INPUT_POST, 'search', FILTER_DEFAULT);
2022-09-04 20:44:32 +02:00
2022-09-04 22:43:21 +02:00
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]);
}
2022-08-18 14:01:52 +02:00
}
2022-09-04 22:43:21 +02:00
$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]);
}
2022-08-18 14:01:52 +02:00
}
2022-09-04 22:43:21 +02:00
} else {
$list_alias = array();
$list_mailbox = array();
2022-08-18 14:01:52 +02:00
}
}
2022-09-04 20:44:32 +02:00
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/search.tpl';
include './templates/footer.tpl';
2022-08-18 14:01:52 +02:00
?>