0)) { if (empty ($fDomain)) { $fDomain = $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; } 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); } // store fDomain in $_SESSION so after adding/editing aliases/mailboxes we can // take the user back to the appropriate domain listing. (see templates/menu.tpl) if($fDomain) { $_SESSION['list_virtual_sticky_domain'] = $fDomain; } # # alias domain # # TODO: add search support for alias domains if (boolconf('alias_domain')) { # Alias-Domains # first try to get a list of other domains pointing # 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"; 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"; } $result = db_query ($query); $tAliasDomains = array(); 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; } } # 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'"; 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'"; } $result = db_query ($query); $tTargetDomain = ""; if ($result['rows'] > 0) { if($row = db_array ($result['result'])) { if ('pgsql'==$CONF['database_type']) { $row['modified']=gmstrftime('%c %Z',$row['modified']); $row['active']=('t'==$row['active']) ? 1 : 0; } $tTargetDomain = $row; } } } # # aliases # if ($search == "") { $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%' ) "; } $query = "SELECT address, goto, modified, active FROM $table_alias WHERE $sql_domain AND NOT EXISTS(SELECT 1 FROM $table_mailbox WHERE username=$table_alias.address) $sql_where ORDER BY address LIMIT $page_size OFFSET $fDisplay"; $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; } } # # mailboxes # $display_mailbox_aliases = boolconf('alias_control_admin'); # build the sql query $sql_select = "SELECT $table_mailbox.* "; $sql_from = " FROM $table_mailbox "; $sql_join = ""; $sql_where = " WHERE "; $sql_order = " ORDER BY $table_mailbox.username "; $sql_limit = " LIMIT $page_size OFFSET $fDisplay"; if ($search == "") { $sql_where .= " $table_mailbox.domain='$fDomain' "; } else { $sql_where .= db_in_clause("$table_mailbox.domain", $list_domains) . " "; $sql_where .= " AND ( $table_mailbox.username LIKE '%$search%' OR $table_mailbox.name LIKE '%$search%' "; if ($display_mailbox_aliases) { $sql_where .= " OR $table_alias.goto LIKE '%$search%' "; } $sql_where .= " ) "; # $search is already escaped } if ($display_mailbox_aliases) { $sql_select .= ", $table_alias.goto "; $sql_join .= " LEFT JOIN $table_alias ON $table_mailbox.username=$table_alias.address "; } if (boolconf('vacation_control_admin')) { $sql_select .= ", $table_vacation.active AS v_active "; $sql_join .= " LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email "; } if (boolconf('used_quotas') && boolconf('new_quota_table')) { $sql_select .= ", $table_quota2.bytes as current "; $sql_join .= " LEFT JOIN $table_quota2 ON $table_mailbox.username=$table_quota2.username "; } if (boolconf('used_quotas') && ( ! boolconf('new_quota_table') ) ) { $sql_select .= ", $table_quota.current "; $sql_join .= " LEFT JOIN $table_quota ON $table_mailbox.username=$table_quota.username "; $sql_where .= " AND ( $table_quota.path='quota/storage' OR $table_quota.path IS NULL ) "; } $query = "$sql_select\n$sql_from\n$sql_join\n$sql_where\n$sql_order\n$sql_limit"; $result = db_query ($query); 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(); foreach ($goto_split as $goto_single) { if ($goto_single == $row['username']) { # delivers to mailbox $row['goto_mailbox'] = 1; } elseif (boolconf('vacation') && strstr($goto_single, '@' . $CONF['vacation_domain']) ) { # vacation alias - TODO: check for full vacation alias # skip the vacation alias, vacation status is detected otherwise } else { # forwarding to other alias $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; } } $tCanAddAlias = false; $tCanAddMailbox = false; # TODO: needs reworking for $search... # TODO: (= bug: no page browser displayed in search mode!) - https://sourceforge.net/tracker/?func=detail&aid=2782818&group_id=191583&atid=937964 # for non-search mode, get_domain_properties counts the aliases and mailboxes # Options: # a) # if ($search == "") -> get_domain_properties # else -> "manual count" # b) # "manual count" for all cases (not really more work, queries are similar) # # Note: get_domain_properties also creates the page browser (which needs performance tuning anyway...) $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']); } $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']); } $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++) { $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']); } 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 ($aCount, $aTitle, $aLimit, $aPage_size, $aPages, $aSearch) { $this->count = $aCount; $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 = ' ' : $this->arr_prev = ''; ($this->limit > 0) ? $this->arr_top = ' ' : $this->arr_top = ''; (($this->limit + $this->page_size) < ($this->count * $this->page_size)) ? $this->arr_next = ' ' : $this->arr_next = ''; $this->fInit = true; } function display_pre () { $ret_val = '
'; return $ret_val; } function display_top () { $ret_val = ''; if ($this->count < 1) return $ret_val; if (!$this->fInit) $this->init (); $ret_val .= ''; $ret_val .= $this->display_pre (); $ret_val .= ''.$this->title.' '; ($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 = ''.$lPage.''; $ret_val .= ''.$lPage.''."\n"; } $ret_val .= '