~ubuntu-branches/ubuntu/quantal/postfixadmin/quantal-updates

« back to all changes in this revision

Viewing changes to search.php

  • Committer: Package Import Robot
  • Author(s): Norman Messtorff
  • Date: 2012-01-15 12:27:28 UTC
  • Revision ID: package-import@ubuntu.com-20120115122728-kfoqpd4ewb4nf300
Tags: upstream-2.3.5
ImportĀ upstreamĀ versionĀ 2.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/** 
 
3
 * Postfix Admin 
 
4
 * 
 
5
 * LICENSE 
 
6
 * This source file is subject to the GPL license that is bundled with  
 
7
 * this package in the file LICENSE.TXT. 
 
8
 * 
 
9
 * Further details on the project are available at : 
 
10
 *     http://www.postfixadmin.com or http://postfixadmin.sf.net 
 
11
 * 
 
12
 * @version $Id: search.php 566 2009-02-15 15:02:26Z christian_boltz $ 
 
13
 * @license GNU GPL v2 or later. 
 
14
 * 
 
15
 * File: search.php
 
16
 * Provides a method for searching for a user/mailbox
 
17
 * Template File: search.php
 
18
 *
 
19
 * Template Variables:
 
20
 *
 
21
 * tAlias
 
22
 * tMailbox
 
23
 *
 
24
 * Form POST \ GET Variables:
 
25
 *
 
26
 * fSearch
 
27
 * fGo
 
28
 * fDomain
 
29
 */
 
30
 
 
31
require_once('common.php');
 
32
 
 
33
authentication_require_role('admin');
 
34
$SESSID_USERNAME = authentication_get_username();
 
35
if(authentication_has_role('global-admin')) {
 
36
    $list_domains = list_domains ();
 
37
}
 
38
else { 
 
39
    $list_domains = list_domains_for_admin ($SESSID_USERNAME);
 
40
}
 
41
 
 
42
 
 
43
$tAlias = array();
 
44
$tMailbox = array();
 
45
 
 
46
if ($_SERVER['REQUEST_METHOD'] == "GET")
 
47
{
 
48
    if (isset ($_GET['search'])) $fSearch = escape_string ($_GET['search']);
 
49
    if (isset ($_GET['fGo'])) $fGo = escape_string ($_GET['fGo']);
 
50
    if (isset ($_GET['fDomain'])) $fDomain = escape_string ($_GET['domain']);
 
51
}
 
52
 
 
53
if ($_SERVER['REQUEST_METHOD'] == "POST")
 
54
{
 
55
    if (isset ($_POST['search'])) $fSearch = escape_string ($_POST['search']);
 
56
    if (isset ($_POST['fGo'])) $fGo = escape_string ($_POST['fGo']);
 
57
    if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
 
58
}
 
59
 
 
60
if (empty ($fSearch) /* && !empty ($fGo) */)
 
61
{
 
62
    header("Location: list-virtual.php?domain=" . $fDomain ) && exit;
 
63
}
 
64
 
 
65
if ($CONF['alias_control_admin'] == "YES")
 
66
{
 
67
    $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto, 
 
68
        $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active 
 
69
        FROM $table_alias 
 
70
        WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address";
 
71
}
 
72
else
 
73
{
 
74
    // find all aliases which don't have a matching entry in table_mailbox
 
75
    $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
 
76
        $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active 
 
77
        FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username 
 
78
        WHERE address LIKE '%$fSearch%' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address";
 
79
 
 
80
}
 
81
 
 
82
$result = db_query ($query);
 
83
if ($result['rows'] > 0)
 
84
{
 
85
    while ($row = db_array ($result['result']))
 
86
    {
 
87
        if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
 
88
        {
 
89
            if ('pgsql'==$CONF['database_type'])
 
90
            {
 
91
                $row['modified']=gmstrftime('%c %Z',$row['modified']);
 
92
                $row['active']=('t'==$row['active']) ? 1 : 0;
 
93
            }
 
94
            $tAlias[] = $row;
 
95
        }
 
96
    }
 
97
}
 
98
 
 
99
 
 
100
if ($CONF['vacation_control_admin'] == 'YES' && $CONF['vacation'] == 'YES')
 
101
{
 
102
    $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");
 
103
}
 
104
else
 
105
{
 
106
    $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username";
 
107
}
 
108
 
 
109
$result = db_query ($query);
 
110
if ($result['rows'] > 0)
 
111
{
 
112
    while ($row = db_array ($result['result']))
 
113
    {
 
114
        if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
 
115
        {
 
116
            if ('pgsql'==$CONF['database_type'])
 
117
            {
 
118
                $row['created']=gmstrftime('%c %Z',strtotime($row['created']));
 
119
                $row['modified']=gmstrftime('%c %Z',strtotime($row['modified']));
 
120
                $row['active']=('t'==$row['active']) ? 1 : 0;
 
121
            }           
 
122
            $tMailbox[] = $row;
 
123
        }
 
124
    }
 
125
}
 
126
 
 
127
include ("templates/header.php");
 
128
include ("templates/menu.php");
 
129
include ("templates/search.php");
 
130
include ("templates/footer.php");
 
131
 
 
132
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
 
133
?>