2007-03-24 08:27:00 +01:00
< ? php
2007-09-30 17:53:54 +02:00
/**
* 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 $
* @ license GNU GPL v2 or later .
*
* File : search . php
* Provides a method for searching for a user / mailbox
* Template File : search . tpl
*
* Template Variables :
*
* tAlias
* tMailbox
*
* Form POST \ GET Variables :
*
* fSearch
* fGo
* fDomain
*/
2007-03-24 08:27:00 +01:00
2007-09-22 12:59:41 +02:00
require_once ( 'common.php' );
authentication_require_role ( 'admin' );
$SESSID_USERNAME = authentication_get_username ();
if ( authentication_has_role ( 'global-admin' )) {
2007-09-30 17:53:54 +02:00
$list_domains = list_domains ();
2007-06-21 00:45:35 +02:00
}
2007-09-22 12:59:41 +02:00
else {
2007-09-30 17:53:54 +02:00
$list_domains = list_domains_for_admin ( $SESSID_USERNAME );
2007-09-22 12:59:41 +02:00
}
2007-06-21 00:45:35 +02:00
2007-03-24 08:27:00 +01:00
$tAlias = array ();
$tMailbox = array ();
if ( $_SERVER [ 'REQUEST_METHOD' ] == " GET " )
{
2007-09-30 17:53:54 +02:00
if ( isset ( $_GET [ 'search' ])) $fSearch = escape_string ( $_GET [ 'search' ]);
2007-10-04 02:01:07 +02:00
if ( isset ( $_GET [ 'fGo' ])) $fGo = escape_string ( $_GET [ 'fGo' ]);
if ( isset ( $_GET [ 'fDomain' ])) $fDomain = escape_string ( $_GET [ 'domain' ]);
2007-03-24 08:27:00 +01:00
}
if ( $_SERVER [ 'REQUEST_METHOD' ] == " POST " )
{
2007-09-30 17:53:54 +02:00
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' ]);
2007-10-04 02:01:07 +02:00
}
2007-09-30 17:53:54 +02:00
2007-10-04 02:01:07 +02:00
if ( empty ( $fSearch ) /* && !empty ($fGo) */ )
2007-09-30 17:53:54 +02:00
{
if ( authentication_has_role ( 'global-admin' ))
{
header ( " Location: list-virtual.php?domain= " . $fDomain ) && exit ;
}
else
{
header ( " Location: overview.php?domain= " . $fDomain ) && exit ;
}
}
if ( $CONF [ 'alias_control_admin' ] == " YES " )
{
$query = " SELECT $table_alias .address, $table_alias .goto, $table_alias .modified, $table_alias .domain, $table_alias .active FROM $table_alias WHERE $table_alias .address LIKE '% $fSearch %' OR $table_alias .goto LIKE '% $fSearch %' ORDER BY $table_alias .address " ;
}
else
{
$query = " SELECT $table_alias .address, $table_alias .goto, $table_alias .modified, $table_alias .domain, $table_alias .active FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias .address= $table_mailbox .username WHERE $table_alias .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' ]))
{
2007-10-04 02:01:07 +02:00
if ( check_owner ( $SESSID_USERNAME , $row [ 'domain' ]) || authentication_has_role ( 'global-admin' ))
2007-06-21 00:45:35 +02:00
{
2007-09-30 17:53:54 +02:00
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$row [ 'modified' ] = gmstrftime ( '%c %Z' , $row [ 'modified' ]);
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
2007-10-04 02:01:07 +02:00
}
2007-09-30 17:53:54 +02:00
$tAlias [] = $row ;
2007-06-21 00:45:35 +02:00
}
2007-09-30 17:53:54 +02:00
}
}
2007-10-04 02:01:07 +02:00
/*
*/
2007-09-30 17:53:54 +02:00
if ( $CONF [ 'vacation_control_admin' ] == '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 " );
2007-10-04 02:01:07 +02:00
# TODO: special query for pgsql needed?
2007-09-30 17:53:54 +02:00
}
else
{
$query = " SELECT * FROM $table_mailbox WHERE username LIKE '% $fSearch %' OR name LIKE '% $fSearch %' ORDER BY username " ;
2007-10-04 02:01:07 +02:00
/* TODO : special query for pgsql really needed ?
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$query = " SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE username LIKE '% $fSearch %' OR name LIKE '% $fSearch %' ORDER BY username " ;
}
*/
2007-09-30 17:53:54 +02:00
}
2007-10-04 02:01:07 +02:00
$result = db_query ( $query );
2007-09-30 17:53:54 +02:00
if ( $result [ 'rows' ] > 0 )
{
while ( $row = db_array ( $result [ 'result' ]))
{
2007-10-04 02:01:07 +02:00
if ( check_owner ( $SESSID_USERNAME , $row [ 'domain' ]) || authentication_has_role ( 'global-admin' ))
2007-06-21 00:45:35 +02:00
{
2007-09-30 17:53:54 +02:00
if ( 'pgsql' == $CONF [ 'database_type' ])
{
2007-10-04 02:01:07 +02:00
$row [ 'created' ] = gmstrftime ( '%c %Z' , $row [ 'created' ]);
2007-09-30 17:53:54 +02:00
$row [ 'modified' ] = gmstrftime ( '%c %Z' , $row [ 'modified' ]);
2007-10-04 02:01:07 +02:00
# TODO: code from admin/search.php
# $row['created']=gmstrftime('%c %Z',$row['uts_created']);
# $row['modified']=gmstrftime('%c %Z',$row['uts_modified']);
2007-09-30 17:53:54 +02:00
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
2007-10-04 02:01:07 +02:00
# TODO: code from admin/search.php
# unset($row['uts_created']);
# unset($row['uts_modified']);
}
2007-09-30 17:53:54 +02:00
$tMailbox [] = $row ;
}
}
}
2007-10-04 02:01:07 +02:00
include ( " $incpath /templates/header.tpl " );
if ( authentication_has_role ( 'global-admin' )) {
include ( " $incpath /templates/admin_menu.tpl " );
} else {
include ( " $incpath /templates/menu.tpl " );
2007-03-24 08:27:00 +01:00
}
2007-10-04 02:01:07 +02:00
include ( " $incpath /templates/search.tpl " );
include ( " $incpath /templates/footer.tpl " );
2007-03-24 08:27:00 +01:00
?>