Blob


1 <?php
2 //
3 // OpenSMTPD Admin
4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
7 //
8 // File: search.php
9 //
10 // Template File: search.tpl
11 //
12 // Template Variables:
13 //
14 // list_alias
15 // list_mailbox
16 //
17 // POST / GET Variables:
18 //
19 // search
20 //
21 require_once './functions.inc.php';
22 include './languages/' . check_language() . '.lang';
24 $SESSID_USERNAME = check_session();
25 $ROLE = check_role($SESSID_USERNAME);
27 if ($ROLE == ADMIN_ROLE) {
28 $list_domains = list_domains();
29 } else {
30 $list_domains = list_domains($SESSID_USERNAME);
31 }
33 if ($_SERVER['REQUEST_METHOD'] == "POST") {
34 $search = filter_input(INPUT_POST, 'search', FILTER_DEFAULT);
36 if (isset($search)) {
37 $dbh = pdo_connect();
38 $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");
39 $sth->bindValue(1, '%'.$search.'%', PDO::PARAM_STR);
40 $sth->execute();
41 $list_alias = $sth->fetchAll();
42 foreach ($list_alias as $key => $value) {
43 if (!in_array($value['domain'], array_column($list_domains, 'domain'))) {
44 unset($list_alias[$key]);
45 }
46 }
48 $sth = $dbh->prepare("SELECT * FROM mailbox WHERE username LIKE ? ORDER BY username");
49 $sth->bindValue(1, '%'.$search.'%', PDO::PARAM_STR);
50 $sth->execute();
51 $list_mailbox = $sth->fetchAll();
52 foreach ($list_mailbox as $key => $value) {
53 if (!in_array($value['domain'], array_column($list_domains, 'domain'))) {
54 unset($list_mailbox[$key]);
55 }
56 }
57 } else {
58 $list_alias = array();
59 $list_mailbox = array();
60 }
61 }
62 include './templates/header.tpl';
63 include './templates/menu.tpl';
64 include './templates/search.tpl';
65 include './templates/footer.tpl';
66 ?>