Exemplo n.º 1
0
 protected function initStruct()
 {
     # NOTE: There are dependencies between domains and domain_count
     # NOTE: If you disable "display in list" for domain_count, the SQL query for domains might break.
     # NOTE: (Disabling both shouldn't be a problem.)
     # TODO: move to a db_group_concat() function?
     if (db_pgsql()) {
         $domains_grouped = "array_to_string(array_agg(domain), ',')";
     } else {
         # mysql
         $domains_grouped = 'group_concat(domain)';
     }
     $this->struct = array('username' => pacol($this->new, 1, 1, 'text', 'admin', 'email_address', '', '', array('linkto' => 'list.php?table=domain&username=%s')), 'password' => pacol(1, 1, 0, 'pass', 'password', ''), 'password2' => pacol(1, 1, 0, 'pass', 'password_again', '', '', '', 0, 1, 'password as password2'), 'superadmin' => pacol(1, 1, 0, 'bool', 'super_admin', 'super_admin_desc', 0), 'domains' => pacol(1, 1, 0, 'list', 'domain', '', array(), list_domains(), 0, 1, "coalesce(domains,'') as domains"), 'domain_count' => pacol(0, 0, 1, 'vnum', 'pAdminList_admin_count', '', '', '', 0, 1, 'coalesce(__domain_count,0) as domain_count', 'LEFT JOIN ( ' . ' SELECT count(*) AS __domain_count, ' . $domains_grouped . ' AS domains, username AS __domain_username ' . ' FROM ' . table_by_key('domain_admins') . " WHERE domain != 'ALL' GROUP BY username " . ' ) AS __domain on username = __domain_username'), 'active' => pacol(1, 1, 1, 'bool', 'active', '', 1), 'created' => pacol(0, 0, 0, 'ts', 'created', ''), 'modified' => pacol(0, 0, 1, 'ts', 'last_modified', ''));
 }
Exemplo n.º 2
0
 /**
  * build_select_query
  *
  * helper function to build the inner part of the select query
  * can be used by read_from_db() and for generating the pagebrowser
  *
  * @param array or string - condition (an array will be AND'ed using db_where_clause, a string will be directly used)
  *                          (if you use a string, make sure it is correctly escaped!)
  *                        - WARNING: will be changed to array only in the future, with an option to include a raw string inside the array
  * @param array searchmode - operators to use (=, <, >) if $condition is an array. Defaults to = if not specified for a field.
  * @return array - contains query parts
  */
 protected function build_select_query($condition, $searchmode)
 {
     $select_cols = array();
     $yes = escape_string(Config::lang('YES'));
     $no = escape_string(Config::lang('NO'));
     if (db_pgsql()) {
         $formatted_date = "TO_DATE(text(###KEY###), '" . escape_string(Config::Lang('dateformat_pgsql')) . "')";
         $base64_decode = "DECODE(###KEY###, 'base64')";
     } elseif (db_sqlite()) {
         $formatted_date = "strftime(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')";
         $base64_decode = "base64_decode(###KEY###)";
     } else {
         $formatted_date = "DATE_FORMAT(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')";
         $base64_decode = "FROM_BASE64(###KEY###)";
     }
     $colformat = array('ts' => "{$formatted_date} AS ###KEY###, ###KEY### AS _###KEY###", 'bool' => "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '1'    WHEN '" . db_get_boolean(false) . "' THEN '0'   END as ###KEY###," . "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '{$yes}' WHEN '" . db_get_boolean(false) . "' THEN '{$no}' END as _###KEY###", 'b64p' => "{$base64_decode} AS ###KEY###");
     # get list of fields to display
     $extrafrom = "";
     foreach ($this->struct as $key => $row) {
         if (($row['display_in_list'] != 0 || $row['display_in_form'] != 0) && $row['not_in_db'] == 0) {
             if ($row['select'] != '') {
                 $key = $row['select'];
             }
             if ($row['extrafrom'] != '') {
                 $extrafrom = $extrafrom . " " . $row['extrafrom'] . "\n";
             }
             if (isset($colformat[$row['type']])) {
                 $select_cols[] = str_replace('###KEY###', $key, $colformat[$row['type']]);
             } else {
                 $select_cols[] = $key;
             }
         }
     }
     $cols = join(',', $select_cols);
     $table = table_by_key($this->db_table);
     $additional_where = '';
     if ($this->domain_field != "") {
         $additional_where .= " AND " . db_in_clause($this->domain_field, $this->allowed_domains);
     }
     # if logged in as user, restrict to the items the user is allowed to see
     if (!$this->is_admin && $this->user_field != '') {
         $additional_where .= " AND " . $this->user_field . " = '" . escape_string($this->username) . "' ";
     }
     if (is_array($condition)) {
         if (isset($condition['_']) && count($this->searchfields) > 0) {
             $simple_search = array();
             foreach ($this->searchfields as $field) {
                 $simple_search[] = "{$field} LIKE '%" . escape_string($condition['_']) . "%'";
             }
             $additional_where .= " AND ( " . join(" OR ", $simple_search) . " ) ";
             unset($condition['_']);
         }
         $where = db_where_clause($condition, $this->struct, $additional_where, $searchmode);
     } else {
         if ($condition == "") {
             $condition = '1=1';
         }
         $where = " WHERE ( {$condition} ) {$additional_where}";
     }
     return array('select_cols' => " SELECT {$cols} ", 'from_where_order' => " FROM {$table} {$extrafrom} {$where} ORDER BY " . $this->order_by);
 }
Exemplo n.º 3
0
                if (!empty($CONF['recipient_delimiter'])) {
                    $goto_single_rec_del = preg_replace('/' . $delimiter . '[^' . $delimiter . '@]*@/', "@", $goto_single);
                }
                if ($goto_single == $row['username'] || $goto_single_rec_del == $row['username']) {
                    # delivers to mailbox
                    $row['goto_mailbox'] = 1;
                } elseif (Config::bool('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 (db_pgsql()) {
            // 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;
    }
}
$alias_data['msg']['can_create'] = false;
$tCanAddMailbox = false;
$tDisplay_back = "";
Exemplo n.º 4
0
function db_rollback()
{
    if (db_pgsql()) {
        db_query('ROLLBACK');
    }
}