list-virtual.php:

- lots of whitespace fixes to use 4 spaces everywhere
  (which list-virtual.php has in its vim: comment since a long time)


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1053 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 13 years ago
parent 23e3330003
commit 3ffd496587

@ -37,35 +37,32 @@ $fDomain = false;
$SESSID_USERNAME = authentication_get_username();
if (authentication_has_role('global-admin')) {
$list_domains = list_domains ();
$is_superadmin = 1;
$list_domains = list_domains ();
$is_superadmin = 1;
} else {
$list_domains = list_domains_for_admin(authentication_get_username());
$is_superadmin = 0;
$list_domains = list_domains_for_admin(authentication_get_username());
$is_superadmin = 0;
}
$tAlias = array();
$tMailbox = array();
$fDisplay = 0;
$page_size = $CONF['page_size'];
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']);
$search = escape_string(safeget('search'));
}
else
{
if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']);
$search = escape_string(safepost('search'));
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']);
$search = escape_string(safeget('search'));
} else {
if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']);
$search = escape_string(safepost('search'));
}
if (count($list_domains) == 0) {
# die("no domains");
flash_error( $PALANG['invalid_parameter'] );
header("Location: list-domain.php"); # no domains (for this admin at least) - redirect to domain list
exit;
flash_error( $PALANG['invalid_parameter'] );
header("Location: list-domain.php"); # no domains (for this admin at least) - redirect to domain list
exit;
}
if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) {
@ -75,15 +72,15 @@ if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) {
}
if(!in_array($fDomain, $list_domains)) {
flash_error( $PALANG['invalid_parameter'] );
header("Location: list-domain.php"); # invalid domain, or not owned by this admin
exit;
flash_error( $PALANG['invalid_parameter'] );
header("Location: list-domain.php"); # invalid domain, or not owned by this admin
exit;
}
if (!check_owner(authentication_get_username(), $fDomain)) {
flash_error( $PALANG['invalid_parameter'] . " If you see this message, please open a bugreport"); # this check is most probably obsoleted by the in_array() check above
header("Location: list-domain.php"); # domain not owned by this admin
exit(0);
flash_error( $PALANG['invalid_parameter'] . " If you see this message, please open a bugreport"); # this check is most probably obsoleted by the in_array() check above
header("Location: list-domain.php"); # domain not owned by this admin
exit(0);
}
// store fDomain in $_SESSION so after adding/editing aliases/mailboxes we can
@ -102,7 +99,7 @@ if (boolconf('alias_domain')) {
$modified_field = 'modified';
if ('pgsql'==$CONF['database_type']) { # TODO: do we really need the extract(epoch from modified) for pgsql? We ust gmstrftime anyway (see below)
$modified_field = 'extract(epoch from modified) as modified';
}
}
$query = "
SELECT alias_domain,target_domain,$modified_field,active FROM $table_alias_domain
@ -111,35 +108,32 @@ if (boolconf('alias_domain')) {
LIMIT $page_size OFFSET $fDisplay
";
$result = db_query ($query);
$tAliasDomains = array();
$result = db_query ($query);
$tAliasDomains = array();
$can_create_alias_domain = 1;
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
if ('pgsql'==$CONF['database_type'])
{
$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tAliasDomains[] = $row;
if ($result['rows'] > 0) {
while ($row = db_array ($result['result'])) {
if ('pgsql'==$CONF['database_type']) {
$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tAliasDomains[] = $row;
if ($row['target_domain'] == $fDomain) $can_create_alias_domain = 0;
}
}
}
}
# TODO: set $can_create_alias_domain = 0; if all domains (of this admin) are already used as alias domains
}
}
#
# aliases
#
if ($search == "") {
$sql_domain = " $table_alias.domain='$fDomain' ";
$sql_where = "";
$sql_domain = " $table_alias.domain='$fDomain' ";
$sql_where = "";
} else {
$sql_domain = db_in_clause("$table_alias.domain", $list_domains);
$sql_where = " AND ( address LIKE '%$search%' OR goto LIKE '%$search%' ) ";
$sql_domain = db_in_clause("$table_alias.domain", $list_domains);
$sql_where = " AND ( address LIKE '%$search%' OR goto LIKE '%$search%' ) ";
}
$alias_pagebrowser_query = "
@ -155,20 +149,17 @@ $query = "
";
$result = db_query ($query);
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
if ('pgsql'==$CONF['database_type'])
{
//. at least in my database, $row['modified'] already looks like : 2009-04-11 21:38:10.75586+01,
// while gmstrftime expects an integer value. strtotime seems happy though.
//$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tAlias[] = $row;
}
if ($result['rows'] > 0) {
while ($row = db_array ($result['result'])) {
if ('pgsql'==$CONF['database_type']) {
//. at least in my database, $row['modified'] already looks like : 2009-04-11 21:38:10.75586+01,
// while gmstrftime expects an integer value. strtotime seems happy though.
//$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tAlias[] = $row;
}
}
@ -222,11 +213,9 @@ $query = "$sql_select\n$mailbox_pagebrowser_query\n$sql_limit";
$result = db_query ($query);
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
if ($display_mailbox_aliases) {
if ($result['rows'] > 0) {
while ($row = db_array ($result['result'])) {
if ($display_mailbox_aliases) {
$goto_split = explode(",", $row['goto']);
$row['goto_mailbox'] = 0;
$row['goto_other'] = array();
@ -240,20 +229,19 @@ if ($result['rows'] > 0)
$row['goto_other'][] = $goto_single;
}
}
}
if ('pgsql'==$CONF['database_type'])
{
// XXX
$row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
$row['created'] = date('Y-m-d H:i', strtotime($row['created']));
$row['active']=('t'==$row['active']) ? 1 : 0;
if($row['v_active'] == NULL) {
$row['v_active'] = 'f';
}
$row['v_active']=('t'==$row['v_active']) ? 1 : 0;
}
$tMailbox[] = $row;
}
}
if ('pgsql'==$CONF['database_type']) {
// XXX
$row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
$row['created'] = date('Y-m-d H:i', strtotime($row['created']));
$row['active']=('t'==$row['active']) ? 1 : 0;
if($row['v_active'] == NULL) {
$row['v_active'] = 'f';
}
$row['v_active']=('t'==$row['v_active']) ? 1 : 0;
}
$tMailbox[] = $row;
}
}
$tCanAddAlias = false;
@ -261,53 +249,52 @@ $tCanAddMailbox = false;
$limit = get_domain_properties($fDomain);
if (isset ($limit)) {
if ($fDisplay >= $page_size) {
$tDisplay_back_show = 1;
$tDisplay_back = $fDisplay - $page_size;
}
if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) {
$tDisplay_up_show = 1;
}
if ((($fDisplay + $page_size) < $limit['alias_count']) or
(($fDisplay + $page_size) < $limit['mailbox_count']))
{
$tDisplay_next_show = 1;
$tDisplay_next = $fDisplay + $page_size;
}
if($limit['aliases'] == 0) {
$tCanAddAlias = true;
}
elseif($limit['alias_count'] < $limit['aliases']) {
$tCanAddAlias = true;
}
if($limit['mailboxes'] == 0) {
$tCanAddMailbox = true;
}
elseif($limit['mailbox_count'] < $limit['mailboxes']) {
$tCanAddMailbox = true;
}
$limit ['aliases'] = eval_size ($limit ['aliases']);
$limit ['mailboxes'] = eval_size ($limit ['mailboxes']);
$limit ['maxquota'] = eval_size ($limit ['maxquota']);
if ($fDisplay >= $page_size) {
$tDisplay_back_show = 1;
$tDisplay_back = $fDisplay - $page_size;
}
if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) {
$tDisplay_up_show = 1;
}
if (
(($fDisplay + $page_size) < $limit['alias_count']) or
(($fDisplay + $page_size) < $limit['mailbox_count'])
) {
$tDisplay_next_show = 1;
$tDisplay_next = $fDisplay + $page_size;
}
if($limit['aliases'] == 0) {
$tCanAddAlias = true;
}
elseif($limit['alias_count'] < $limit['aliases']) {
$tCanAddAlias = true;
}
if($limit['mailboxes'] == 0) {
$tCanAddMailbox = true;
}
elseif($limit['mailbox_count'] < $limit['mailboxes']) {
$tCanAddMailbox = true;
}
$limit ['aliases'] = eval_size ($limit ['aliases']);
$limit ['mailboxes'] = eval_size ($limit ['mailboxes']);
$limit ['maxquota'] = eval_size ($limit ['maxquota']);
}
$gen_show_status = array ();
$check_alias_owner = array ();
if ((is_array ($tAlias) and sizeof ($tAlias) > 0))
for ($i = 0; $i < sizeof ($tAlias); $i++)
{
$gen_show_status [$i] = gen_show_status($tAlias[$i]['address']);
$check_alias_owner [$i] = check_alias_owner($SESSID_USERNAME, $tAlias[$i]['address']);
}
for ($i = 0; $i < sizeof ($tAlias); $i++) {
$gen_show_status [$i] = gen_show_status($tAlias[$i]['address']);
$check_alias_owner [$i] = check_alias_owner($SESSID_USERNAME, $tAlias[$i]['address']);
}
$gen_show_status_mailbox = array ();
$divide_quota = array ('current' => array(), 'quota' => array());
if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
for ($i = 0; $i < sizeof ($tMailbox); $i++)
{
for ($i = 0; $i < sizeof ($tMailbox); $i++) {
$gen_show_status_mailbox [$i] = gen_show_status($tMailbox[$i]['username']);
if(isset($tMailbox[$i]['current'])) {
$divide_quota ['current'][$i] = divide_quota ($tMailbox[$i]['current']);
@ -315,98 +302,98 @@ if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
if(isset($tMailbox[$i]['quota'])) {
$divide_quota ['quota'][$i] = divide_quota ($tMailbox[$i]['quota']);
}
}
}
class cNav_bar
{
var $count, $title, $limit, $page_size, $pages, $search; //* arguments
var $url; //* manually
var $fInit, $arr_prev, $arr_next, $arr_top; //* internal
var $anchor;
function cNav_bar ($aTitle, $aLimit, $aPage_size, $aPages, $aSearch)
{
$this->count = count($aPages);
$this->title = $aTitle;
$this->limit = $aLimit;
$this->page_size = $aPage_size;
$this->pages = $aPages;
var $count, $title, $limit, $page_size, $pages, $search; //* arguments
var $url; //* manually
var $fInit, $arr_prev, $arr_next, $arr_top; //* internal
var $anchor;
function cNav_bar ($aTitle, $aLimit, $aPage_size, $aPages, $aSearch) {
$this->count = count($aPages);
$this->title = $aTitle;
$this->limit = $aLimit;
$this->page_size = $aPage_size;
$this->pages = $aPages;
if ($aSearch == "") {
$this->search = "";
} else {
$this->search = "&search=" . htmlentities($aSearch);
}
$this->url = '';
$this->fInit = false;
}
function init ()
{
$this->anchor = 'a'.substr ($this->title, 3);
$this->url .= '#'.$this->anchor;
($this->limit >= $this->page_size) ? $this->arr_prev = '&nbsp;<a href="?limit='.($this->limit - $this->page_size).$this->search.$this->url.'"><img border="0" src="images/arrow-l.png" title="'.$GLOBALS ['PALANG']['pOverview_left_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_left_arrow'].'"/></a>&nbsp;' : $this->arr_prev = '';
($this->limit > 0) ? $this->arr_top = '&nbsp;<a href="?limit=0' .$this->search.$this->url.'"><img border="0" src="images/arrow-u.png" title="'.$GLOBALS ['PALANG']['pOverview_up_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_up_arrow'].'"/></a>&nbsp;' : $this->arr_top = '';
(($this->limit + $this->page_size) < ($this->count * $this->page_size)) ? $this->arr_next = '&nbsp;<a href="?limit='.($this->limit + $this->page_size).$this->search.$this->url.'"><img border="0" src="images/arrow-r.png" title="'.$GLOBALS ['PALANG']['pOverview_right_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_right_arrow'].'"/></a>&nbsp;' : $this->arr_next = '';
$this->fInit = true;
}
function display_pre ()
{
$ret_val = '<div class="nav_bar"';
//$ret_val .= ' style="background-color:#ffa;"';
$ret_val .= '>';
$ret_val .= '<table width="730"><colgroup span="1"><col width="550"></col></colgroup> ';
$ret_val .= '<tr><td align="left">';
return $ret_val;
}
function display_post ()
{
$ret_val = '</td></tr></table></div>';
return $ret_val;
}
function display_top ()
{
$ret_val = '';
if ($this->count < 1)
return $ret_val;
if (!$this->fInit)
$this->init ();
$ret_val .= '<a name="'.$this->anchor.'"></a>';
$ret_val .= $this->display_pre ();
$ret_val .= '<b>'.$this->title.'</b>&nbsp;&nbsp;';
($this->limit >= $this->page_size) ? $highlight_at = $this->limit / $this->page_size : $highlight_at = 0;
for ($i = 0; $i < count ($this->pages); $i++)
{
$lPage = $this->pages [$i];
if ($i == $highlight_at)
$lPage = '<b>'.$lPage.'</b>';
$ret_val .= '<a href="?limit='.($i * $this->page_size).$this->search.$this->url.'">'.$lPage.'</a>'."\n";
}
$ret_val .= '</td><td valign="middle" align="right">';
$ret_val .= $this->arr_prev;
$ret_val .= $this->arr_top;
$ret_val .= $this->arr_next;
$ret_val .= $this->display_post ();
return $ret_val;
}
function display_bottom ()
{
$ret_val = '';
if ($this->count < 1)
return $ret_val;
if (!$this->fInit)
$this->init ();
$ret_val .= $this->display_pre ();
$ret_val .= '</td><td valign="middle" align="right">';
$ret_val .= $this->arr_prev;
$ret_val .= $this->arr_top;
$ret_val .= $this->arr_next;
$ret_val .= $this->display_post ();
return $ret_val;
}
$this->url = '';
$this->fInit = false;
}
function init () {
$this->anchor = 'a'.substr ($this->title, 3);
$this->url .= '#'.$this->anchor;
($this->limit >= $this->page_size) ? $this->arr_prev = '&nbsp;<a href="?limit='.($this->limit - $this->page_size).$this->search.$this->url.'"><img border="0" src="images/arrow-l.png" title="'.$GLOBALS ['PALANG']['pOverview_left_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_left_arrow'].'"/></a>&nbsp;' : $this->arr_prev = '';
($this->limit > 0) ? $this->arr_top = '&nbsp;<a href="?limit=0' .$this->search.$this->url.'"><img border="0" src="images/arrow-u.png" title="'.$GLOBALS ['PALANG']['pOverview_up_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_up_arrow'].'"/></a>&nbsp;' : $this->arr_top = '';
(($this->limit + $this->page_size) < ($this->count * $this->page_size)) ? $this->arr_next = '&nbsp;<a href="?limit='.($this->limit + $this->page_size).$this->search.$this->url.'"><img border="0" src="images/arrow-r.png" title="'.$GLOBALS ['PALANG']['pOverview_right_arrow'].'" alt="'.$GLOBALS ['PALANG']['pOverview_right_arrow'].'"/></a>&nbsp;' : $this->arr_next = '';
$this->fInit = true;
}
function display_pre () {
$ret_val = '<div class="nav_bar"';
//$ret_val .= ' style="background-color:#ffa;"';
$ret_val .= '>';
$ret_val .= '<table width="730"><colgroup span="1"><col width="550"></col></colgroup> ';
$ret_val .= '<tr><td align="left">';
return $ret_val;
}
function display_post () {
$ret_val = '</td></tr></table></div>';
return $ret_val;
}
function display_top () {
$ret_val = '';
if ($this->count < 1)
return $ret_val;
if (!$this->fInit)
$this->init ();
$ret_val .= '<a name="'.$this->anchor.'"></a>';
$ret_val .= $this->display_pre ();
$ret_val .= '<b>'.$this->title.'</b>&nbsp;&nbsp;';
($this->limit >= $this->page_size) ? $highlight_at = $this->limit / $this->page_size : $highlight_at = 0;
for ($i = 0; $i < count ($this->pages); $i++)
{
$lPage = $this->pages [$i];
if ($i == $highlight_at)
$lPage = '<b>'.$lPage.'</b>';
$ret_val .= '<a href="?limit='.($i * $this->page_size).$this->search.$this->url.'">'.$lPage.'</a>'."\n";
}
$ret_val .= '</td><td valign="middle" align="right">';
$ret_val .= $this->arr_prev;
$ret_val .= $this->arr_top;
$ret_val .= $this->arr_next;
$ret_val .= $this->display_post ();
return $ret_val;
}
function display_bottom () {
$ret_val = '';
if ($this->count < 1)
return $ret_val;
if (!$this->fInit)
$this->init ();
$ret_val .= $this->display_pre ();
$ret_val .= '</td><td valign="middle" align="right">';
$ret_val .= $this->arr_prev;
$ret_val .= $this->arr_top;
$ret_val .= $this->arr_next;
$ret_val .= $this->display_post ();
return $ret_val;
}
}
$pagebrowser_alias = create_page_browser("$table_alias.address", $alias_pagebrowser_query);
@ -418,7 +405,7 @@ $nav_bar_mailbox = new cNav_bar ($PALANG['pOverview_mailbox_title'], $fDisplay,
$nav_bar_mailbox->url = '&amp;domain='.$fDomain;
//print $nav_bar_alias->display_top ();
// this is why we need a proper template layer.
$fDomain = htmlentities($fDomain, ENT_QUOTES);
@ -442,7 +429,7 @@ $smarty->assign ('tDisplay_next_show', $tDisplay_next_show);
$smarty->assign ('tDisplay_next', $tDisplay_next);
if(sizeof ($tAliasDomains) > 0)
$smarty->assign ('tAliasDomains', $tAliasDomains);
$smarty->assign ('tAliasDomains', $tAliasDomains);
$smarty->assign ('can_create_alias_domain', $can_create_alias_domain);
$smarty->assign ('tAlias', $tAlias);
@ -456,11 +443,11 @@ $smarty->assign ('divide_quota', $divide_quota);
$smarty->assign ('tCanAddMailbox', $tCanAddMailbox);
$smarty->assign ('display_mailbox_aliases', $display_mailbox_aliases);
if (isset ($_GET ['tab']))
$_SESSION ['tab'] = $_GET ['tab'];
$_SESSION ['tab'] = $_GET ['tab'];
//if (empty ($_GET ['tab']))
// unset ($_SESSION ['tab']);
// unset ($_SESSION ['tab']);
if (!isset ($_SESSION ['tab']))
$_SESSION ['tab'] = 'mailbox';
$_SESSION ['tab'] = 'mailbox';
$smarty->assign ('tab', $_SESSION ['tab']);
$smarty->assign ('smarty_template', 'list-virtual');
$smarty->display ('index.tpl');

Loading…
Cancel
Save