diff --git a/config.inc.php b/config.inc.php index 96841a6f..98c9ea57 100644 --- a/config.inc.php +++ b/config.inc.php @@ -230,6 +230,44 @@ function maildir_name_hook($domain, $user) { } */ +/* + *_struct_hook - change, add or remove fields + + If you need additional fields or want to change or remove existing fields, + you can write a hook function to modify $struct in the *Handler classes. + + The edit form will automatically be updated according to the modified + $struct. The list page is not yet updated automatically. + + You can define one hook function per class, named like the primary database + table of that class. + The hook function is called with $struct as parameter and must return the + modified $struct. + + Note: Adding a field to $struct adds the handling of this field in + PostfixAdmin, but it does not create it in the database. You have to do + that yourself. + Please follow the naming policy for custom database fields and tables on + http://sourceforge.net/apps/mediawiki/postfixadmin/index.php?title=Custom_fields + to avoid clashes with future versions of PostfixAdmin. + + See initStruct() in the *Handler class for the default $struct. + See pacol() in functions.inc.php for the available flags on each column. + + Example: + + function x_struct_admin_modify($struct) { + $struct['superadmin']['editable'] = 0; # make the 'superadmin' flag read-only + $struct['superadmin']['display_in_form'] = 0; # don't display the 'superadmin' flag in edit form + $struct['x_newfield'] = pacol( [...] ); # additional field 'x_newfield' + return $struct; # important! + } + $CONF['admin_struct_hook'] = 'x_struct_admin_modify'; +*/ +$CONF['admin_struct_hook'] = ''; +$CONF['domain_struct_hook'] = ''; +$CONF['alias_domain_struct_hook'] = ''; + // Default Domain Values // Specify your default values below. Quota in MB. diff --git a/model/AdminHandler.php b/model/AdminHandler.php index 123f0944..0ddacaeb 100644 --- a/model/AdminHandler.php +++ b/model/AdminHandler.php @@ -81,8 +81,6 @@ class AdminHandler extends PFAHandler { 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), # obsoletes pAdminList_admin_modified ); - - # TODO: hook to modify $this->struct } # messages used in various functions. diff --git a/model/AliasdomainHandler.php b/model/AliasdomainHandler.php index aec84eeb..1ede1c6f 100644 --- a/model/AliasdomainHandler.php +++ b/model/AliasdomainHandler.php @@ -49,8 +49,6 @@ class AliasdomainHandler extends PFAHandler { $keys = array_keys($this->struct['alias_domain']['options']); unset ($this->struct['target_domain']['options'][$keys[0]]); } - - # TODO: hook to modify $this->struct } public function init($id) { diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 2816d9d4..81d7cbbc 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -76,8 +76,6 @@ class DomainHandler extends PFAHandler { 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), ); - - # TODO: hook to modify $this->struct } # messages used in various functions. diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 1afd57aa..32ec8ae0 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -40,6 +40,12 @@ class PFAHandler { } $this->initStruct(); + + $struct_hook = Config::read($this->db_table . '_struct_hook'); + if ( $struct_hook != 'NO' && function_exists($struct_hook) ) { + $this->struct = $struct_hook($this->struct); + } + $this->initMsg(); }