reindent; fix postgres date formatting issue with +01 times

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@630 a1433add-5e2c-0410-b055-b7f2511e0802
postfixadmin-2.3
David Goodwin 15 years ago
parent 05e832ca8c
commit 125130c1dd

@ -36,11 +36,11 @@ authentication_require_role('admin');
$SESSID_USERNAME = authentication_get_username(); $SESSID_USERNAME = authentication_get_username();
if (authentication_has_role('global-admin')) { if (authentication_has_role('global-admin')) {
$list_domains = list_domains (); $list_domains = list_domains ();
$is_superadmin = 1; $is_superadmin = 1;
} else { } else {
$list_domains = list_domains_for_admin(authentication_get_username()); $list_domains = list_domains_for_admin(authentication_get_username());
$is_superadmin = 0; $is_superadmin = 0;
} }
$tAlias = array(); $tAlias = array();
@ -50,153 +50,156 @@ $page_size = $CONF['page_size'];
if ($_SERVER['REQUEST_METHOD'] == "GET") if ($_SERVER['REQUEST_METHOD'] == "GET")
{ {
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']); if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']);
} }
else else
{ {
if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']); if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']); if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']);
} }
if (count($list_domains) == 0) { if (count($list_domains) == 0) {
# die("no domains"); # die("no domains");
header("Location: list-domain.php"); # no domains (for this admin at least) - redirect to domain list header("Location: list-domain.php"); # no domains (for this admin at least) - redirect to domain list
} }
if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[0]; if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[0];
if (!check_owner(authentication_get_username(), $fDomain)) { if (!check_owner(authentication_get_username(), $fDomain)) {
# die($PALANG['invalid_parameter']); # die($PALANG['invalid_parameter']);
header("Location: list-domain.php"); # domain not owned by this admin header("Location: list-domain.php"); # domain not owned by this admin
exit(0); exit(0);
} }
if (boolconf('alias_domain')) { if (boolconf('alias_domain')) {
# Alias-Domains # Alias-Domains
# first try to get a list of other domains pointing # first try to get a list of other domains pointing
# to this currently chosen one (aka. alias domains) # to this currently chosen one (aka. alias domains)
$query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY $table_alias_domain.alias_domain LIMIT $fDisplay, $page_size"; $query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY $table_alias_domain.alias_domain LIMIT $fDisplay, $page_size";
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY alias_domain LIMIT $page_size OFFSET $fDisplay"; $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY alias_domain LIMIT $page_size OFFSET $fDisplay";
} }
$result = db_query ($query); $result = db_query ($query);
$tAliasDomains = array(); $tAliasDomains = array();
if ($result['rows'] > 0) if ($result['rows'] > 0)
{ {
while ($row = db_array ($result['result'])) while ($row = db_array ($result['result']))
{ {
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$row['modified']=gmstrftime('%c %Z',$row['modified']); $row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['active']=('t'==$row['active']) ? 1 : 0; $row['active']=('t'==$row['active']) ? 1 : 0;
} }
$tAliasDomains[] = $row; $tAliasDomains[] = $row;
} }
} }
# now let's see if the current domain itself is an alias for another domain # now let's see if the current domain itself is an alias for another domain
$query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; $query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE alias_domain='$fDomain'";
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE alias_domain='$fDomain'";
} }
$result = db_query ($query); $result = db_query ($query);
$tTargetDomain = ""; $tTargetDomain = "";
if ($result['rows'] > 0) if ($result['rows'] > 0)
{ {
if($row = db_array ($result['result'])) if($row = db_array ($result['result']))
{ {
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$row['modified']=gmstrftime('%c %Z',$row['modified']); $row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['active']=('t'==$row['active']) ? 1 : 0; $row['active']=('t'==$row['active']) ? 1 : 0;
} }
$tTargetDomain = $row; $tTargetDomain = $row;
} }
} }
} }
$query = "SELECT $table_alias.address, $query = "SELECT $table_alias.address,
$table_alias.goto, $table_alias.goto,
$table_alias.modified, $table_alias.modified,
$table_alias.active $table_alias.active
FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username
WHERE ($table_alias.domain='$fDomain' AND $table_mailbox.maildir IS NULL) WHERE ($table_alias.domain='$fDomain' AND $table_mailbox.maildir IS NULL)
OR OR
($table_alias.domain='$fDomain' ($table_alias.domain='$fDomain'
AND $table_alias.goto LIKE '%,%' AND $table_alias.goto LIKE '%,%'
AND $table_mailbox.maildir IS NOT NULL) AND $table_mailbox.maildir IS NOT NULL)
ORDER BY $table_alias.address LIMIT $fDisplay, $page_size"; ORDER BY $table_alias.address LIMIT $fDisplay, $page_size";
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$query = "SELECT address, $query = "SELECT address,
goto, goto,
modified, modified,
active active
FROM $table_alias WHERE domain='$fDomain' FROM $table_alias WHERE domain='$fDomain'
AND NOT EXISTS(SELECT 1 FROM $table_mailbox AND NOT EXISTS(SELECT 1 FROM $table_mailbox
WHERE username=$table_alias.address WHERE username=$table_alias.address
AND $table_alias.goto NOT LIKE '%,%') AND $table_alias.goto NOT LIKE '%,%')
ORDER BY address LIMIT $page_size OFFSET $fDisplay"; ORDER BY address LIMIT $page_size OFFSET $fDisplay";
} }
$result = db_query ($query); $result = db_query ($query);
if ($result['rows'] > 0) if ($result['rows'] > 0)
{ {
while ($row = db_array ($result['result'])) while ($row = db_array ($result['result']))
{ {
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$row['modified']=gmstrftime('%c %Z',$row['modified']); //. at least in my database, $row['modified'] already looks like : 2009-04-11 21:38:10.75586+01,
$row['active']=('t'==$row['active']) ? 1 : 0; // 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']));
/* Has a real mailbox as well? Remove the address from $row['goto'] in order to edit just the real aliases */ $row['active']=('t'==$row['active']) ? 1 : 0;
if (strstr ($row['goto'], ',') != FALSE) }
{
$row['goto'] = preg_replace ('/\s*,*\s*' . $row['address'] . '\s*,*\s*/', '', $row['goto']); /* Has a real mailbox as well? Remove the address from $row['goto'] in order to edit just the real aliases */
} if (strstr ($row['goto'], ',') != FALSE)
{
$tAlias[] = $row; $row['goto'] = preg_replace ('/\s*,*\s*' . $row['address'] . '\s*,*\s*/', '', $row['goto']);
} }
$tAlias[] = $row;
}
} }
if ($CONF['vacation_control_admin'] == 'YES') if ($CONF['vacation_control_admin'] == 'YES')
{ {
if (boolconf('used_quotas')) if (boolconf('used_quotas'))
$query = "SELECT $table_mailbox.*, $table_vacation.active AS v_active, $table_quota.current FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email LEFT JOIN $table_quota ON $table_mailbox.username=$table_quota.username WHERE $table_mailbox.domain='$fDomain' AND $table_quota.path='quota/storage' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay"; $query = "SELECT $table_mailbox.*, $table_vacation.active AS v_active, $table_quota.current FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email LEFT JOIN $table_quota ON $table_mailbox.username=$table_quota.username WHERE $table_mailbox.domain='$fDomain' AND $table_quota.path='quota/storage' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay";
else else
$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.domain='$fDomain' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay"; $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.domain='$fDomain' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay";
} }
else else
{ {
$query = "SELECT * FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"; $query = "SELECT * FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size";
if ('pgsql'==$CONF['database_type']) 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 domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay"; $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay";
} }
} }
$result = db_query ($query); $result = db_query ($query);
if ($result['rows'] > 0) if ($result['rows'] > 0)
{ {
while ($row = db_array ($result['result'])) while ($row = db_array ($result['result']))
{ {
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
//var_dump($row); // XXX
$row['created']=gmstrftime('%c %Z',strtotime($row['created'])); $row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
$row['modified']=gmstrftime('%c %Z',strtotime($row['modified'])); $row['created'] = date('Y-m-d H:i', strtotime($row['created']));
$row['active']=('t'==$row['active']) ? 1 : 0; $row['active']=('t'==$row['active']) ? 1 : 0;
if($row['v_active'] == NULL) { if($row['v_active'] == NULL) {
$row['v_active'] = 'f'; $row['v_active'] = 'f';
} }
$row['v_active']=('t'==$row['v_active']) ? 1 : 0; $row['v_active']=('t'==$row['v_active']) ? 1 : 0;
} }
$tMailbox[] = $row; $tMailbox[] = $row;
} }
} }
$tCanAddAlias = false; $tCanAddAlias = false;
@ -204,32 +207,32 @@ $tCanAddMailbox = false;
$limit = get_domain_properties($fDomain); $limit = get_domain_properties($fDomain);
if (isset ($limit)) { if (isset ($limit)) {
if ($fDisplay >= $page_size) { if ($fDisplay >= $page_size) {
$tDisplay_back_show = 1; $tDisplay_back_show = 1;
$tDisplay_back = $fDisplay - $page_size; $tDisplay_back = $fDisplay - $page_size;
} }
if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) {
$tDisplay_up_show = 1; $tDisplay_up_show = 1;
} }
if ((($fDisplay + $page_size) < $limit['alias_count']) or if ((($fDisplay + $page_size) < $limit['alias_count']) or
(($fDisplay + $page_size) < $limit['mailbox_count'])) (($fDisplay + $page_size) < $limit['mailbox_count']))
{ {
$tDisplay_next_show = 1; $tDisplay_next_show = 1;
$tDisplay_next = $fDisplay + $page_size; $tDisplay_next = $fDisplay + $page_size;
} }
if($limit['aliases'] == 0) { if($limit['aliases'] == 0) {
$tCanAddAlias = true; $tCanAddAlias = true;
} }
elseif($limit['alias_count'] < $limit['aliases']) { elseif($limit['alias_count'] < $limit['aliases']) {
$tCanAddAlias = true; $tCanAddAlias = true;
} }
if($limit['mailboxes'] == 0) { if($limit['mailboxes'] == 0) {
$tCanAddMailbox = true; $tCanAddMailbox = true;
} }
elseif($limit['mailbox_count'] < $limit['mailboxes']) { elseif($limit['mailbox_count'] < $limit['mailboxes']) {
$tCanAddMailbox = true; $tCanAddMailbox = true;
} }
} }
// this is why we need a proper template layer. // this is why we need a proper template layer.

Loading…
Cancel
Save