Browse Source

move pacol() into PFAHandler class, I think it makes more sense for it to be there given the dependency between the two

pull/941/head
David Goodwin 6 months ago
parent
commit
0d5edbf099
Failed to extract signature
  1. 49
      functions.inc.php
  2. 26
      model/AdminHandler.php
  3. 8
      model/AdminpasswordHandler.php
  4. 28
      model/AliasHandler.php
  5. 10
      model/AliasdomainHandler.php
  6. 12
      model/DkimHandler.php
  7. 6
      model/DkimsigningHandler.php
  8. 48
      model/DomainHandler.php
  9. 48
      model/FetchmailHandler.php
  10. 36
      model/MailboxHandler.php
  11. 57
      model/PFAHandler.php
  12. 20
      model/VacationHandler.php

49
functions.inc.php

@ -471,54 +471,6 @@ function safesession($param, $default = "")
}
/**
* pacol
* @param int $allow_editing
* @param int $display_in_form
* @param int display_in_list
* @param string $type
* @param string PALANG_label
* @param string PALANG_desc
* @param any optional $default
* @param array $options optional options
* @param int or $not_in_db - if array, can contain the remaining parameters as associated array. Otherwise counts as $not_in_db
* @return array for $struct
*/
function pacol($allow_editing, $display_in_form, $display_in_list, $type, $PALANG_label, $PALANG_desc, $default = "", $options = array(), $multiopt = 0, $dont_write_to_db = 0, $select = "", $extrafrom = "", $linkto = "")
{
if ($PALANG_label != '') {
$PALANG_label = Config::lang($PALANG_label);
}
if ($PALANG_desc != '') {
$PALANG_desc = Config::lang($PALANG_desc);
}
if (is_array($multiopt)) { # remaining parameters provided in named array
$not_in_db = 0; # keep default value
foreach ($multiopt as $key => $value) {
$$key = $value; # extract everything to the matching variable
}
} else {
$not_in_db = $multiopt;
}
return array(
'editable' => $allow_editing,
'display_in_form' => $display_in_form,
'display_in_list' => $display_in_list,
'type' => $type,
'label' => $PALANG_label, # $PALANG field label
'desc' => $PALANG_desc, # $PALANG field description
'default' => $default,
'options' => $options,
'not_in_db' => $not_in_db,
'dont_write_to_db' => $dont_write_to_db,
'select' => $select, # replaces the field name after SELECT
'extrafrom' => $extrafrom, # added after FROM xy - useful for JOINs etc.
'linkto' => $linkto, # make the value a link - %s will be replaced with the ID
);
}
/**
* Action: Get all the properties of a domain.
* @param string $domain
@ -940,7 +892,6 @@ function validate_password(string $password): array
}
/**
* Create/Validate courier authlib style crypt'ed passwords. (md5, md5raw, crypt, sha1)
*

26
model/AdminHandler.php

@ -49,16 +49,16 @@ class AdminHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'username' => pacol($this->new, 1, 1, 'text', 'admin' , 'email_address' , '', array(),
'username' => self::pacol($this->new, 1, 1, 'text', 'admin' , 'email_address' , '', array(),
array('linkto' => 'list.php?table=domain&username=%s')),
'password' => pacol(1, 1, 0, 'pass', 'password' , ''),
'password2' => pacol(1, 1, 0, 'pass', 'password_again' , '' , '', array(),
'password' => self::pacol(1, 1, 0, 'pass', 'password' , ''),
'password2' => self::pacol(1, 1, 0, 'pass', 'password_again' , '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'password as password2'
),
'superadmin' => pacol(1, 1, 0, 'bool', 'super_admin' , 'super_admin_desc' , 0
'superadmin' => self::pacol(1, 1, 0, 'bool', 'super_admin' , 'super_admin_desc' , 0
# TODO: (finally) replace the ALL domain with a column in the admin table
# TODO: current status: 'superadmin' column exists and is written when storing an admin with AdminHandler,
# TODO: but the superadmin status is still (additionally) stored in the domain_admins table ("ALL" dummy domain)
@ -67,14 +67,14 @@ class AdminHandler extends PFAHandler
# TODO: Create them with the trunk version to avoid this problem.
),
'domains' => pacol(1, 1, 0, 'list', 'domain' , '' , array(), list_domains(),
'domains' => self::pacol(1, 1, 0, 'list', 'domain' , '' , array(), list_domains(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ "coalesce(domains,'') as domains"
/*extrafrom set in domain_count*/
),
'domain_count' => pacol(0, 0, 1, 'vnum', 'pAdminList_admin_count', '' , '', array(),
'domain_count' => self::pacol(0, 0, 1, 'vnum', 'pAdminList_admin_count', '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__domain_count,0) as domain_count',
@ -84,13 +84,13 @@ class AdminHandler extends PFAHandler
" WHERE domain != 'ALL' GROUP BY username " .
' ) AS __domain on username = __domain_username'),
'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'phone' => pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''),
'email_other' => pacol(1, $passwordReset, 0, 'mail', 'pCreate_mailbox_email', 'pCreate_mailbox_email_desc', ''),
'token' => pacol(1, 0, 0, 'text', '' , ''),
'token_validity' => pacol(1, 0, 0, 'ts', '' , '', date("Y-m-d H:i:s",time())),
'created' => pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'phone' => self::pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''),
'email_other' => self::pacol(1, $passwordReset, 0, 'mail', 'pCreate_mailbox_email', 'pCreate_mailbox_email_desc', ''),
'token' => self::pacol(1, 0, 0, 'text', '' , ''),
'token_validity' => self::pacol(1, 0, 0, 'ts', '' , '', date("Y-m-d H:i:s",time())),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
);
}

8
model/AdminpasswordHandler.php

@ -28,11 +28,11 @@ class AdminpasswordHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'username' => pacol(0, 1, 1, 'text', 'admin' , ''),
'oldpass' => pacol(1, 1, 0, 'pass', 'pPassword_password_current' , '', '', array(),
'username' => self::pacol(0, 1, 1, 'text', 'admin' , ''),
'oldpass' => self::pacol(1, 1, 0, 'pass', 'pPassword_password_current' , '', '', array(),
/*not_in_db*/ 1),
'password' => pacol(1, 1, 0, 'pass', 'pPassword_password' , ''),
'password2' => pacol(1, 1, 0, 'pass', 'pPassword_password2' , '' , '', array(),
'password' => self::pacol(1, 1, 0, 'pass', 'pPassword_password' , ''),
'password2' => self::pacol(1, 1, 0, 'pass', 'pPassword_password2' , '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'password as password2'

28
model/AliasHandler.php

@ -27,16 +27,16 @@ class AliasHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / ...
# editing? form list
'status' => pacol(0, 0, 0, 'html', '' , '' , '', array(),
'status' => self::pacol(0, 0, 0, 'html', '' , '' , '', array(),
array('not_in_db' => 1)),
'address' => pacol($this->new, 1, 1, 'mail', 'alias' , 'pCreate_alias_catchall_text'),
'localpart' => pacol($this->new, 0, 0, 'text', 'alias' , 'pCreate_alias_catchall_text' , '',
'address' => self::pacol($this->new, 1, 1, 'mail', 'alias' , 'pCreate_alias_catchall_text'),
'localpart' => self::pacol($this->new, 0, 0, 'text', 'alias' , 'pCreate_alias_catchall_text' , '',
/*options*/ array(),
/*not_in_db*/ 1),
'domain' => pacol($this->new, 0, 1, 'enum', '' , '' , '',
'domain' => self::pacol($this->new, 0, 1, 'enum', '' , '' , '',
/*options*/ $this->allowed_domains),
'goto' => pacol(1, 1, 1, 'txtl', 'to' , 'pEdit_alias_help' , array()),
'is_mailbox' => pacol(0, 0, 1, 'int', '' , '' , 0 ,
'goto' => self::pacol(1, 1, 1, 'txtl', 'to' , 'pEdit_alias_help' , array()),
'is_mailbox' => self::pacol(0, 0, 1, 'int', '' , '' , 0 ,
# technically 'is_mailbox' is bool, but the automatic bool conversion breaks the query. Flagging it as int avoids this problem.
# Maybe having a vbool type (without the automatic conversion) would be cleaner - we'll see if we need it.
/*options*/ array(),
@ -44,19 +44,19 @@ class AliasHandler extends PFAHandler
/*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__is_mailbox,0) as is_mailbox'),
/*extrafrom set via set_is_mailbox_extrafrom() */
'__mailbox_username' => pacol(0, 0, 1, 'vtxt', '' , '' , 0), # filled via is_mailbox
'goto_mailbox' => pacol($mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0,
'__mailbox_username' => self::pacol(0, 0, 1, 'vtxt', '' , '' , 0), # filled via is_mailbox
'goto_mailbox' => self::pacol($mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0,
/*options*/ array(),
/*not_in_db*/ 1), # read_from_db_postprocess() sets the value
'on_vacation' => pacol(1, 0, 1, 'bool', 'pUsersMenu_vacation' , '' , 0 ,
'on_vacation' => self::pacol(1, 0, 1, 'bool', 'pUsersMenu_vacation' , '' , 0 ,
/*options*/ array(),
/*not_in_db*/ 1), # read_from_db_postprocess() sets the value - TODO: read active flag from vacation table instead?
'created' => pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'_can_edit' => pacol(0, 0, 1, 'vnum', '' , '' , 0 , array(),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'_can_edit' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0 , array(),
array('select' => '1 as _can_edit')),
'_can_delete' => pacol(0, 0, 1, 'vnum', '' , '' , 0 , array(),
'_can_delete' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0 , array(),
array('select' => '1 as _can_delete')), # read_from_db_postprocess() updates the value
# aliases listed in $CONF[default_aliases] are read-only for domain admins if $CONF[special_alias_control] is NO.
);

10
model/AliasdomainHandler.php

@ -17,14 +17,14 @@ class AliasdomainHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'alias_domain' => pacol($this->new, 1, 1, 'enum', 'pCreate_alias_domain_alias' , 'pCreate_alias_domain_alias_text' , '',
'alias_domain' => self::pacol($this->new, 1, 1, 'enum', 'pCreate_alias_domain_alias' , 'pCreate_alias_domain_alias_text' , '',
/*options, filled below*/ array(),
/* multiopt */ array('linkto' => 'list-virtual.php?domain=%s')),
'target_domain' => pacol(1, 1, 1, 'enum', 'pCreate_alias_domain_target' , 'pCreate_alias_domain_target_text', '',
'target_domain' => self::pacol(1, 1, 1, 'enum', 'pCreate_alias_domain_target' , 'pCreate_alias_domain_target_text', '',
/*options*/ array() /* filled below */),
'created' => pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
);

12
model/DkimHandler.php

@ -19,12 +19,12 @@ class DkimHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'id' => pacol(0, 0, 1, 'num' , 'pFetchmail_field_id' , '' , '', array(), array('dont_write_to_db' => 1)),
'description' => pacol(1, 1, 1, 'text', 'description' , ''),
'selector' => pacol(1, 1, 1, 'text', 'pDkim_field_selector', 'pDkim_field_selector_desc'),
'domain_name' => pacol(1, 1, 1, 'enum', 'domain' , 'pDkim_field_domain_desc' , '', $this->allowed_domains),
'private_key' => pacol(1, 1, 0, 'txta', 'pDkim_field_pkey' , 'pDkim_field_pkey_desc'),
'public_key' => pacol(1, 1, 0, 'txta', 'pDkim_field_pub' , 'pDkim_field_pub_desc'),
'id' => self::pacol(0, 0, 1, 'num' , 'pFetchmail_field_id' , '' , '', array(), array('dont_write_to_db' => 1)),
'description' => self::pacol(1, 1, 1, 'text', 'description' , ''),
'selector' => self::pacol(1, 1, 1, 'text', 'pDkim_field_selector', 'pDkim_field_selector_desc'),
'domain_name' => self::pacol(1, 1, 1, 'enum', 'domain' , 'pDkim_field_domain_desc' , '', $this->allowed_domains),
'private_key' => self::pacol(1, 1, 0, 'txta', 'pDkim_field_pkey' , 'pDkim_field_pkey_desc'),
'public_key' => self::pacol(1, 1, 0, 'txta', 'pDkim_field_pub' , 'pDkim_field_pub_desc'),
);
}

6
model/DkimsigningHandler.php

@ -34,9 +34,9 @@ class DkimsigningHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'id' => pacol(0, 0, 1, 'num' , 'pFetchmail_field_id' , '' , '', array(), array('dont_write_to_db' => 1)),
'dkim_id' => pacol(1, 1, 1, 'enum' , 'pDkim_field_dkim_id' , 'pDkim_field_dkim_id_desc' , '', array_keys($dkim_handler->result)),
'author' => pacol(1, 1, 1, 'enum' , 'pDkim_field_author' , 'pDkim_field_author_desc' , '', $authors),
'id' => self::pacol(0, 0, 1, 'num' , 'pFetchmail_field_id' , '' , '', array(), array('dont_write_to_db' => 1)),
'dkim_id' => self::pacol(1, 1, 1, 'enum' , 'pDkim_field_dkim_id' , 'pDkim_field_dkim_id_desc' , '', array_keys($dkim_handler->result)),
'author' => self::pacol(1, 1, 1, 'enum' , 'pDkim_field_author' , 'pDkim_field_author_desc' , '', $authors),
);
}

48
model/DomainHandler.php

@ -58,61 +58,61 @@ class DomainHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'domain' => pacol($this->new, 1, 1, 'text', 'domain' , '' , '', array(),
'domain' => self::pacol($this->new, 1, 1, 'text', 'domain' , '' , '', array(),
array('linkto' => 'list-virtual.php?domain=%s')),
'description' => pacol($super, $super, $super, 'text', 'description' , ''),
'description' => self::pacol($super, $super, $super, 'text', 'description' , ''),
# Aliases
'aliases' => pacol($super, $super, 0, 'num' , 'aliases' , 'pAdminEdit_domain_aliases_text' , Config::read('aliases')),
'alias_count' => pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
'aliases' => self::pacol($super, $super, 0, 'num' , 'aliases' , 'pAdminEdit_domain_aliases_text' , Config::read('aliases')),
'alias_count' => self::pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__alias_count,0) - coalesce(__mailbox_count,0) as alias_count',
/*extrafrom*/ 'left join ( select count(*) as __alias_count, domain as __alias_domain from ' . table_by_key('alias') .
' group by domain) as __alias on domain = __alias_domain'),
'aliases_quot' => pacol(0, 0, 1, 'quot', 'aliases' , '' , 0, array(),
'aliases_quot' => self::pacol(0, 0, 1, 'quot', 'aliases' , '' , 0, array(),
array('select' => db_quota_text('__alias_count - coalesce(__mailbox_count,0)', 'aliases', 'aliases_quot'))),
'_aliases_quot_percent' => pacol(0, 0, 1, 'vnum', '' ,'' , 0, array(),
'_aliases_quot_percent' => self::pacol(0, 0, 1, 'vnum', '' ,'' , 0, array(),
array('select' => db_quota_percent('__alias_count - coalesce(__mailbox_count,0)', 'aliases', '_aliases_quot_percent'))),
# Mailboxes
'mailboxes' => pacol($super, $super, 0, 'num' , 'mailboxes' , 'pAdminEdit_domain_aliases_text' , Config::read('mailboxes')),
'mailbox_count' => pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
'mailboxes' => self::pacol($super, $super, 0, 'num' , 'mailboxes' , 'pAdminEdit_domain_aliases_text' , Config::read('mailboxes')),
'mailbox_count' => self::pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__mailbox_count,0) as mailbox_count',
/*extrafrom*/ 'left join ( select count(*) as __mailbox_count, sum(quota) as __total_quota, domain as __mailbox_domain from ' . table_by_key('mailbox') .
' group by domain) as __mailbox on domain = __mailbox_domain'),
'mailboxes_quot' => pacol(0, 0, 1, 'quot', 'mailboxes' , '' , 0, array(),
'mailboxes_quot' => self::pacol(0, 0, 1, 'quot', 'mailboxes' , '' , 0, array(),
array('select' => db_quota_text('__mailbox_count', 'mailboxes', 'mailboxes_quot'))),
'_mailboxes_quot_percent' => pacol(0, 0, 1, 'vnum', '' , '' , 0, array(),
'_mailboxes_quot_percent' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0, array(),
array('select' => db_quota_percent('__mailbox_count', 'mailboxes', '_mailboxes_quot_percent'))),
'maxquota' => pacol($editquota,$editquota,$quota, 'num', 'pOverview_get_quota' , 'pAdminEdit_domain_maxquota_text' , Config::read('maxquota')),
'maxquota' => self::pacol($editquota,$editquota,$quota, 'num', 'pOverview_get_quota' , 'pAdminEdit_domain_maxquota_text' , Config::read('maxquota')),
# Domain quota
'quota' => pacol($edit_dom_q,$edit_dom_q, 0, 'num', 'pAdminEdit_domain_quota' , 'pAdminEdit_domain_maxquota_text' , $domain_quota_default),
'total_quota' => pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
'quota' => self::pacol($edit_dom_q,$edit_dom_q, 0, 'num', 'pAdminEdit_domain_quota' , 'pAdminEdit_domain_maxquota_text' , $domain_quota_default),
'total_quota' => self::pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
array('select' => "$query_used_domainquota AS total_quota") /*extrafrom*//* already in mailbox_count */),
'total_quot' => pacol(0, 0, $dom_q, 'quot', 'pAdminEdit_domain_quota' , '' , 0, array(),
'total_quot' => self::pacol(0, 0, $dom_q, 'quot', 'pAdminEdit_domain_quota' , '' , 0, array(),
array('select' => db_quota_text($query_used_domainquota, 'quota', 'total_quot'))),
'_total_quot_percent' => pacol(0, 0, $dom_q, 'vnum', '' , '' , 0, array(),
'_total_quot_percent' => self::pacol(0, 0, $dom_q, 'vnum', '' , '' , 0, array(),
array('select' => db_quota_percent($query_used_domainquota, 'quota', '_total_quot_percent'))),
'transport' => pacol($transp, $transp,$transp,'enum', 'transport' , 'pAdminEdit_domain_transport_text' , Config::read('transport_default') ,
'transport' => self::pacol($transp, $transp,$transp,'enum', 'transport' , 'pAdminEdit_domain_transport_text' , Config::read('transport_default') ,
/*options*/ Config::read_array('transport_options')),
'backupmx' => pacol($super, $super, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' , 0),
'active' => pacol($super, $super, 1, 'bool', 'active' , '' , 1),
'default_aliases' => pacol($this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '' , 1,array(), /*not in db*/ 1),
'created' => pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => pacol(0, 0, $super, 'ts', 'last_modified' , ''),
'password_expiry' => pacol($super, $pwexp, $pwexp, 'num', 'password_expiration' , 'password_expiration_desc' , 365),
'_can_edit' => pacol(0, 0, 1, 'int', '' , '' , 0 ,
'backupmx' => self::pacol($super, $super, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' , 0),
'active' => self::pacol($super, $super, 1, 'bool', 'active' , '' , 1),
'default_aliases' => self::pacol($this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '' , 1,array(), /*not in db*/ 1),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, $super, 'ts', 'last_modified' , ''),
'password_expiry' => self::pacol($super, $pwexp, $pwexp, 'num', 'password_expiration' , 'password_expiration_desc' , 365),
'_can_edit' => self::pacol(0, 0, 1, 'int', '' , '' , 0 ,
/*options*/ array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ $this->is_superadmin . ' as _can_edit'),
'_can_delete' => pacol(0, 0, 1, 'int', '' , '' , 0 ,
'_can_delete' => self::pacol(0, 0, 1, 'int', '' , '' , 0 ,
/*options*/ array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,

48
model/FetchmailHandler.php

@ -23,31 +23,31 @@ class FetchmailHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'id' => pacol(0, 0, 1, 'num' , '' , '' , '', array(),
'id' => self::pacol(0, 0, 1, 'num' , '' , '' , '', array(),
array('dont_write_to_db' => 1)),
'domain' => pacol(0, 0, 1, 'text', '' , ''),
'mailbox' => pacol(1, 1, 1, 'enum', 'pFetchmail_field_mailbox' , 'pFetchmail_desc_mailbox'), # mailbox list
'src_server' => pacol(1, 1, 1, 'text', 'pFetchmail_field_src_server' , 'pFetchmail_desc_src_server'),
'src_port' => pacol(1, 1, 1, 'num', 'pFetchmail_field_src_port' , 'pFetchmail_desc_src_port' , 0),
'src_auth' => pacol(1, 1, 1, 'enum', 'pFetchmail_field_src_auth' , 'pFetchmail_desc_src_auth' , '', $src_auth_options),
'src_user' => pacol(1, 1, 1, 'text', 'pFetchmail_field_src_user' , 'pFetchmail_desc_src_user'),
'src_password' => pacol(1, 1, 0, 'b64p', 'pFetchmail_field_src_password' , 'pFetchmail_desc_src_password'),
'src_folder' => pacol(1, 1, 1, 'text', 'pFetchmail_field_src_folder' , 'pFetchmail_desc_src_folder'),
'poll_time' => pacol(1, 1, 1, 'num' , 'pFetchmail_field_poll_time' , 'pFetchmail_desc_poll_time' , 10),
'fetchall' => pacol(1, 1, 1, 'bool', 'pFetchmail_field_fetchall' , 'pFetchmail_desc_fetchall'),
'keep' => pacol(1, 1, 1, 'bool', 'pFetchmail_field_keep' , 'pFetchmail_desc_keep'),
'protocol' => pacol(1, 1, 1, 'enum', 'pFetchmail_field_protocol' , 'pFetchmail_desc_protocol' , '', $src_protocol_options),
'usessl' => pacol(1, 1, 1, 'bool', 'pFetchmail_field_usessl' , 'pFetchmail_desc_usessl'),
'sslcertck' => pacol(1, 1, 1, 'bool', 'pFetchmail_field_sslcertck' , ''),
'sslcertpath' => pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslcertpath' , ''),
'sslfingerprint' => pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslfingerprint',''),
'extra_options' => pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_extra_options', 'pFetchmail_desc_extra_options'),
'mda' => pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_mda' , 'pFetchmail_desc_mda'),
'date' => pacol(0, 0, 1, 'text', 'pFetchmail_field_date' , 'pFetchmail_desc_date' , '2000-01-01'),
'returned_text' => pacol(0, 0, 1, 'text', 'pFetchmail_field_returned_text', 'pFetchmail_desc_returned_text'),
'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'domain' => self::pacol(0, 0, 1, 'text', '' , ''),
'mailbox' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_mailbox' , 'pFetchmail_desc_mailbox'), # mailbox list
'src_server' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_server' , 'pFetchmail_desc_src_server'),
'src_port' => self::pacol(1, 1, 1, 'num', 'pFetchmail_field_src_port' , 'pFetchmail_desc_src_port' , 0),
'src_auth' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_src_auth' , 'pFetchmail_desc_src_auth' , '', $src_auth_options),
'src_user' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_user' , 'pFetchmail_desc_src_user'),
'src_password' => self::pacol(1, 1, 0, 'b64p', 'pFetchmail_field_src_password' , 'pFetchmail_desc_src_password'),
'src_folder' => self::pacol(1, 1, 1, 'text', 'pFetchmail_field_src_folder' , 'pFetchmail_desc_src_folder'),
'poll_time' => self::pacol(1, 1, 1, 'num' , 'pFetchmail_field_poll_time' , 'pFetchmail_desc_poll_time' , 10),
'fetchall' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_fetchall' , 'pFetchmail_desc_fetchall'),
'keep' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_keep' , 'pFetchmail_desc_keep'),
'protocol' => self::pacol(1, 1, 1, 'enum', 'pFetchmail_field_protocol' , 'pFetchmail_desc_protocol' , '', $src_protocol_options),
'usessl' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_usessl' , 'pFetchmail_desc_usessl'),
'sslcertck' => self::pacol(1, 1, 1, 'bool', 'pFetchmail_field_sslcertck' , ''),
'sslcertpath' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslcertpath' , ''),
'sslfingerprint' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_sslfingerprint',''),
'extra_options' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_extra_options', 'pFetchmail_desc_extra_options'),
'mda' => self::pacol($extra, $extra, $extra, 'text', 'pFetchmail_field_mda' , 'pFetchmail_desc_mda'),
'date' => self::pacol(0, 0, 1, 'text', 'pFetchmail_field_date' , 'pFetchmail_desc_date' , '2000-01-01'),
'returned_text' => self::pacol(0, 0, 1, 'text', 'pFetchmail_field_returned_text', 'pFetchmail_desc_returned_text'),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
);
# get list of mailboxes (for currently logged in user)

36
model/MailboxHandler.php

@ -30,38 +30,38 @@ class MailboxHandler extends PFAHandler
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'username' => pacol($this->new, 1, 1, 'mail', 'pEdit_mailbox_username', '', ''),
'local_part' => pacol($this->new, 0, 0, 'text', 'pEdit_mailbox_username', '', '',
'username' => self::pacol($this->new, 1, 1, 'mail', 'pEdit_mailbox_username', '', ''),
'local_part' => self::pacol($this->new, 0, 0, 'text', 'pEdit_mailbox_username', '', '',
/*options*/ array('legal_chars' => Config::read('username_legal_chars'), 'legal_char_warning' => Config::lang('pLegal_char_warning'))
),
'domain' => pacol($this->new, 0, 1, 'enum', '', '', '',
'domain' => self::pacol($this->new, 0, 1, 'enum', '', '', '',
/*options*/ $this->allowed_domains),
# TODO: maildir: display in list is needed to include maildir in SQL result (for post_edit hook)
# TODO: (not a perfect solution, but works for now - maybe we need a separate "include in SELECT query" field?)
'maildir' => pacol($this->new, 0, 1, 'text', '', '', ''),
'password' => pacol($editPw, $editPw, 0, 'pass', 'password', 'pCreate_mailbox_password_text', ''),
'password2' => pacol($editPw, $editPw, 0, 'pass', 'password_again', '', '',
'maildir' => self::pacol($this->new, 0, 1, 'text', '', '', ''),
'password' => self::pacol($editPw, $editPw, 0, 'pass', 'password', 'pCreate_mailbox_password_text', ''),
'password2' => self::pacol($editPw, $editPw, 0, 'pass', 'password_again', '', '',
/*options*/ array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ 'password as password2'
),
'name' => pacol(1, 1, 1, 'text', 'name', 'pCreate_mailbox_name_text', ''),
'quota' => pacol(1, 1, 1, 'int', 'pEdit_mailbox_quota', 'pEdit_mailbox_quota_text', ''), # in MB
'name' => self::pacol(1, 1, 1, 'text', 'name', 'pCreate_mailbox_name_text', ''),
'quota' => self::pacol(1, 1, 1, 'int', 'pEdit_mailbox_quota', 'pEdit_mailbox_quota_text', ''), # in MB
# read_from_db_postprocess() also sets 'quotabytes' for use in init()
# TODO: read used quota from quota/quota2 table
'active' => pacol(1, 1, 1, 'bool', 'active', '', 1),
'smtp_active' => pacol($smtpActiveFlag, $smtpActiveFlag, 0, 'bool', 'smtp_active', '', 1),
'welcome_mail' => pacol($this->new, $this->new, 0, 'bool', 'pCreate_mailbox_mail', '', 1,
'active' => self::pacol(1, 1, 1, 'bool', 'active', '', 1),
'smtp_active' => self::pacol($smtpActiveFlag, $smtpActiveFlag, 0, 'bool', 'smtp_active', '', 1),
'welcome_mail' => self::pacol($this->new, $this->new, 0, 'bool', 'pCreate_mailbox_mail', '', 1,
/*options*/ array(),
/*not_in_db*/ 1),
'phone' => pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''),
'email_other' => pacol(1, $passwordReset, 0, 'mail', 'pCreate_mailbox_email', 'pCreate_mailbox_email_desc', ''),
'token' => pacol(1, 0, 0, 'text', '', ''),
'token_validity' => pacol(1, 0, 0, 'ts', '', '', date("Y-m-d H:i:s", time())),
'created' => pacol(0, 0, 1, 'ts', 'created', ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified', ''),
'password_expiry' => pacol(0, 0, 1, 'ts', 'password_expiration', ''),
'phone' => self::pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''),
'email_other' => self::pacol(1, $passwordReset, 0, 'mail', 'pCreate_mailbox_email', 'pCreate_mailbox_email_desc', ''),
'token' => self::pacol(1, 0, 0, 'text', '', ''),
'token_validity' => self::pacol(1, 0, 0, 'ts', '', '', date("Y-m-d H:i:s", time())),
'created' => self::pacol(0, 0, 1, 'ts', 'created', ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified', ''),
'password_expiry' => self::pacol(0, 0, 1, 'ts', 'password_expiration', ''),
# TODO: add virtual 'notified' column and allow to display who received a vacation response?
);

57
model/PFAHandler.php

@ -221,7 +221,7 @@ abstract class PFAHandler
* @psalm-suppress InvalidArrayOffset
*/
if (!isset($this->struct['_can_edit'])) {
$this->struct['_can_edit'] = pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
$this->struct['_can_edit'] = self::pacol(0, 0, 1, 'vnum', '', '', '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ '1 as _can_edit'
@ -232,7 +232,7 @@ abstract class PFAHandler
* @psalm-suppress InvalidArrayOffset
*/
if (!isset($this->struct['_can_delete'])) {
$this->struct['_can_delete'] = pacol(0, 0, 1, 'vnum', '' , '' , '', array(),
$this->struct['_can_delete'] = self::pacol(0, 0, 1, 'vnum', '', '', '', array(),
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*select*/ '1 as _can_delete'
@ -273,8 +273,6 @@ abstract class PFAHandler
}
}
/**
* init $this->struct (an array of pacol() results)
* see pacol() in functions.inc.php for all available parameters
@ -926,6 +924,57 @@ abstract class PFAHandler
return $this->result;
}
/**
* Define a db column, also used to control rendering/editing behaviour.
*
* @param int $allow_editing
* @param int $display_in_form
* @param int display_in_list
* @param string $type e.g. text|pass|bool|list|vnum|mail|ts - see PFAHandler::initStruct()
* @param string PALANG_label
* @param string PALANG_desc
* @param any optional $default
* @param array $options optional options
* @param array|int or $multiopt - if array, can contain the remaining parameters as associated array. Otherwise counts as $not_in_db
* @return array for $struct
*
* @see PFAHandler::initStruct() for a list of possible types.
*/
public static function pacol(int $allow_editing, int $display_in_form, int $display_in_list, string $type, string $PALANG_label, string $PALANG_desc, $default = "", array $options = array(), $multiopt = 0, int $dont_write_to_db = 0, string $select = "", string $extrafrom = "", string $linkto = ""): array
{
if ($PALANG_label != '') {
$PALANG_label = Config::lang($PALANG_label);
}
if ($PALANG_desc != '') {
$PALANG_desc = Config::lang($PALANG_desc);
}
if (is_array($multiopt)) { # remaining parameters provided in named array
$not_in_db = 0; # keep default value
foreach ($multiopt as $key => $value) {
$$key = $value; # extract everything to the matching variable
}
} else {
$not_in_db = $multiopt;
}
return array(
'editable' => $allow_editing,
'display_in_form' => $display_in_form,
'display_in_list' => $display_in_list,
'type' => $type,
'label' => $PALANG_label, # $PALANG field label
'desc' => $PALANG_desc, # $PALANG field description
'default' => $default,
'options' => $options,
'not_in_db' => $not_in_db,
'dont_write_to_db' => $dont_write_to_db,
'select' => $select, # replaces the field name after SELECT
'extrafrom' => $extrafrom, # added after FROM xy - useful for JOINs etc.
'linkto' => $linkto, # make the value a link - %s will be replaced with the ID
);
}
/**
* compare two password fields

20
model/VacationHandler.php

@ -32,20 +32,20 @@ class VacationHandler extends PFAHandler
$this->struct = array(
# field name allow display in... type $PALANG label $PALANG description default / options / ...
# editing? form list
'email' => pacol($this->new, 1, 1, 'text', 'pLogin_username' , '' , ''),
'domain' => pacol(1, 0, 0, 'text', '' , '' , ''),
'subject' => pacol(1, 1, 0, 'text', 'pUsersVacation_subject' , '' , ''),
'body' => pacol(1, 1, 0, 'text', 'pUsersVacation_body' , '' , ''),
'activefrom' => pacol(1, 1, 1, 'text', 'pUsersVacation_activefrom' , '' , ''),
'activeuntil' => pacol(1, 1, 1, 'text', 'pUsersVacation_activeuntil' , '' , ''),
'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => pacol(0, 0, 1, 'ts', 'created' , ''),
'modified' => pacol(0, 0, 1, 'ts', 'last_modified' , ''),
'email' => self::pacol($this->new, 1, 1, 'text', 'pLogin_username' , '' , ''),
'domain' => self::pacol(1, 0, 0, 'text', '' , '' , ''),
'subject' => self::pacol(1, 1, 0, 'text', 'pUsersVacation_subject' , '' , ''),
'body' => self::pacol(1, 1, 0, 'text', 'pUsersVacation_body' , '' , ''),
'activefrom' => self::pacol(1, 1, 1, 'text', 'pUsersVacation_activefrom' , '' , ''),
'activeuntil' => self::pacol(1, 1, 1, 'text', 'pUsersVacation_activeuntil' , '' , ''),
'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1),
'created' => self::pacol(0, 0, 1, 'ts', 'created' , ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
# TODO: add virtual 'notified' column and allow to display who received a vacation response?
);
if (! db_pgsql()) {
$this->struct['cache'] = pacol(0, 0, 0, 'text', '' , '' , ''); # leftover from 2.2
$this->struct['cache'] = self::pacol(0, 0, 0, 'text', '' , '' , ''); # leftover from 2.2
}
}

Loading…
Cancel
Save