File: search.php

package info (click to toggle)
postfixadmin 2.3.5-2+deb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,200 kB
  • sloc: php: 25,767; xml: 14,485; perl: 964; sh: 664; python: 169; makefile: 84
file content (133 lines) | stat: -rw-r--r-- 4,205 bytes parent folder | download | duplicates (2)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/** 
 * Postfix Admin 
 * 
 * LICENSE 
 * This source file is subject to the GPL license that is bundled with  
 * this package in the file LICENSE.TXT. 
 * 
 * Further details on the project are available at : 
 *     http://www.postfixadmin.com or http://postfixadmin.sf.net 
 * 
 * @version $Id: search.php 566 2009-02-15 15:02:26Z christian_boltz $ 
 * @license GNU GPL v2 or later. 
 * 
 * File: search.php
 * Provides a method for searching for a user/mailbox
 * Template File: search.php
 *
 * Template Variables:
 *
 * tAlias
 * tMailbox
 *
 * Form POST \ GET Variables:
 *
 * fSearch
 * fGo
 * fDomain
 */

require_once('common.php');

authentication_require_role('admin');
$SESSID_USERNAME = authentication_get_username();
if(authentication_has_role('global-admin')) {
    $list_domains = list_domains ();
}
else { 
    $list_domains = list_domains_for_admin ($SESSID_USERNAME);
}


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

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

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

if (empty ($fSearch) /* && !empty ($fGo) */)
{
    header("Location: list-virtual.php?domain=" . $fDomain ) && exit;
}

if ($CONF['alias_control_admin'] == "YES")
{
    $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto, 
        $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active 
        FROM $table_alias 
        WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address";
}
else
{
    // find all aliases which don't have a matching entry in table_mailbox
    $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
        $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active 
        FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username 
        WHERE address LIKE '%$fSearch%' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address";

}

$result = db_query ($query);
if ($result['rows'] > 0)
{
    while ($row = db_array ($result['result']))
    {
        if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
        {
            if ('pgsql'==$CONF['database_type'])
            {
                $row['modified']=gmstrftime('%c %Z',$row['modified']);
                $row['active']=('t'==$row['active']) ? 1 : 0;
            }
            $tAlias[] = $row;
        }
    }
}


if ($CONF['vacation_control_admin'] == 'YES' && $CONF['vacation'] == 'YES')
{
    $query = ("SELECT $table_mailbox.*, $table_vacation.active AS v_active FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email WHERE $table_mailbox.username LIKE '%$fSearch%' OR $table_mailbox.name LIKE '%$fSearch%' ORDER BY $table_mailbox.username");
}
else
{
    $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username";
}

$result = db_query ($query);
if ($result['rows'] > 0)
{
    while ($row = db_array ($result['result']))
    {
        if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
        {
            if ('pgsql'==$CONF['database_type'])
            {
                $row['created']=gmstrftime('%c %Z',strtotime($row['created']));
                $row['modified']=gmstrftime('%c %Z',strtotime($row['modified']));
                $row['active']=('t'==$row['active']) ? 1 : 0;
            }         	
            $tMailbox[] = $row;
        }
    }
}

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

/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
?>