summaryrefslogtreecommitdiffstats
path: root/search.php
blob: 11b21d27120527d5eae0fda9116a648f7ceae727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
// 
// Postfix Admin 
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: search.php
//
// Template File: search.tpl
//
// Template Variables:
//
// tAlias
// tMailbox
//
// Form POST \ GET Variables:
//
// fSearch
//
require ("./variables.inc.php");
require ("./config.inc.php");
require ("./functions.inc.php");
include ("./languages/" . check_language () . ".lang");

$SESSID_USERNAME = check_session();

$tAlias = array();
$tMailbox = array();

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
   if (isset ($_GET['search'])) $fSearch = escape_string ($_GET['search']);

   if ($CONF['alias_control'] == "YES")
   {
      $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address";
   }
   else
   {
      $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address";
   }

   $result = db_query ("$query");
   
   if ($result['rows'] > 0)
   {
      while ($row = db_array ($result['result']))
      {
         if (check_owner ($SESSID_USERNAME, $row['domain']))
         {
            $tAlias[] = $row;
         }
      }
   }

   $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username");
   if ($result['rows'] > 0)
   {
      while ($row = db_array ($result['result']))
      {
         if (check_owner ($SESSID_USERNAME, $row['domain']))
         {
            $tMailbox[] = $row;
         }
      }
   }

   include ("./templates/header.tpl");
   include ("./templates/menu.tpl");
   include ("./templates/search.tpl");
   include ("./templates/footer.tpl");
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
   if (isset ($_POST['search'])) $fSearch = escape_string ($_POST['search']);

   if ($CONF['alias_control'] == "YES")
   {
      $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address";
   }
   else
   {
      $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address";
   }

   $result = db_query ("$query");
   
   if ($result['rows'] > 0)
   {
      while ($row = db_array ($result['result']))
      {
         if (check_owner ($SESSID_USERNAME, $row['domain']))
         {
            $tAlias[] = $row;
         }
      }
   }

   $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username");
   if ($result['rows'] > 0)
   {
      while ($row = db_array ($result['result']))
      {
         if (check_owner ($SESSID_USERNAME, $row['domain']))
         {
            $tMailbox[] = $row;
         }
      }
   }

   include ("./templates/header.tpl");
   include ("./templates/menu.tpl");
   include ("./templates/search.tpl");
   include ("./templates/footer.tpl");
}
?>