SF.net SVN: postfixadmin:[1311] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-12-27 18:13:38
|
Revision: 1311 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1311&view=rev Author: christian_boltz Date: 2011-12-27 18:13:32 +0000 (Tue, 27 Dec 2011) Log Message: ----------- AliasHandler now works with edit.php in many cases (TODO: catchall handling, mailbox and vacation aliases) AliasHandler.php - drop unused $username - set $domain_field - initStruct(): - use correct labels - set 'domain' field options to allowed domains - add (virtual) 'localpart' field - add comments for more virtual fields - add webformConfig() (note: modifies $struct on $new - otherwise we couldn't use the domain dropdown in the web interface) - add mergeId to merge localpart and domain to address (called by edit.php _before_ ->init) - add validate_new_id() (doesn't work for catchall yet) - add setmore() to - fill 'domain' based on 'address' - convert $values[goto] from array to comma-separated string - add read_from_db_postprocess to split goto to an array (TODO: handling of mailbox and vacation aliases) - add _field_goto() validator - add empty, commented dummy delete() that will replace the "old" delete function one day - make hasAliasRecord() private (only used internally) - mark all "old" functions as obsolete edit.php: - add handling of txtl field (convert textarea to array) - call $handler->mergeId if $id_field is editable, but not displayed in form (usecase: merge localpart + domain to address) editform.tpl: - add handling of txtl fields (textarea, filled by array) PFAHandler.php: - add setmore() hook function - runs at the end of set() AdminHandler.php: - add a comment for 'txtl' (array of one line texts, like alias goto) Modified Paths: -------------- trunk/edit.php trunk/model/AdminHandler.php trunk/model/AliasHandler.php trunk/model/PFAHandler.php trunk/templates/editform.tpl Modified: trunk/edit.php =================================================================== --- trunk/edit.php 2011-12-26 20:54:40 UTC (rev 1310) +++ trunk/edit.php 2011-12-27 18:13:32 UTC (rev 1311) @@ -85,6 +85,19 @@ } else { if($field['type'] == 'bool') { $values[$key] = safepost($key, 0); # isset() for unchecked checkboxes is always false + } elseif($field['type'] == 'txtl') { + $values[$key] = safepost($key); + $values[$key] = preg_replace ('/\\\r\\\n/', ',', $values[$key]); + $values[$key] = preg_replace ('/\r\n/', ',', $values[$key]); + $values[$key] = preg_replace ('/,[\s]+/i', ',', $values[$key]); + $values[$key] = preg_replace ('/[\s]+,/i', ',', $values[$key]); + $values[$key] = preg_replace ('/,,*/', ',', $values[$key]); + $values[$key] = preg_replace ('/,*$|^,*/', '', $values[$key]); + if ($values[$key] == '') { + $values[$key] = array(); + } else { + $values[$key] = explode(",", $values[$key]); + } } else { $values[$key] = safepost($key); } @@ -99,6 +112,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST" || $active != '') { if ($edit != "") $values[$id_field] = $edit; + if ($new && ($form_fields[$id_field]['display_in_form'] == 0) && ($form_fields[$id_field]['editable'] == 1) ) { # address split to localpart and domain? + $values[$id_field] = $handler->mergeId($values); + } + if (!$handler->init($values[$id_field])) { $error = 1; $errormsg = $handler->errormsg; Modified: trunk/model/AdminHandler.php =================================================================== --- trunk/model/AdminHandler.php 2011-12-26 20:54:40 UTC (rev 1310) +++ trunk/model/AdminHandler.php 2011-12-27 18:13:32 UTC (rev 1311) @@ -30,6 +30,7 @@ # text one line of text # pass password (will be encrypted with pacrypt()) # num number + # txtl text "list" - array of one line texts # vnum "virtual" number, coming from JOINs etc. # bool boolean (converted to 0/1, additional column _$field with yes/no) # ts timestamp (created/modified) Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2011-12-26 20:54:40 UTC (rev 1310) +++ trunk/model/AliasHandler.php 2011-12-27 18:13:32 UTC (rev 1311) @@ -8,7 +8,7 @@ */ class AliasHandler extends PFAHandler { - private $username = null; + protected $domain_field = 'domain'; /** * @@ -21,14 +21,22 @@ $this->id_field = 'address'; $this->struct=array( - # field name allow display in... type $PALANG label $PALANG description default / options / ... + # field name allow display in... type $PALANG label $PALANG description default / ... # editing? form list - 'address' => pacol( $this->new, 1, 1, 'mail', 'pCreate_alias_domain_alias' , 'pCreate_alias_domain_alias_text' ), - 'goto' => pacol( 1, 1, 1, 'mail', 'pCreate_alias_domain_target' , 'pCreate_alias_domain_target_text' ), - 'domain' => pacol( $this->new, 0, 0, 'text', '' , '' ), - 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), - 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), - 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), + 'address' => pacol( $this->new, 1, 1, 'mail', 'pEdit_alias_address' , 'pCreate_alias_catchall_text' ), + 'localpart' => pacol( $this->new, 0, 0, 'text', 'pEdit_alias_address' , 'pCreate_alias_catchall_text' , '', + /*options*/ '', + /*not_in_db*/ 1 ), + 'domain' => pacol( $this->new, 0, 0, 'enum', '' , '' , '', + /*options*/ $this->allowed_domains ), + 'goto' => pacol( 1, 1, 1, 'txtl', 'pEdit_alias_goto' , 'pEdit_alias_help' ), +# target (forwardings) +# is_mailbox (alias belongs to mailbox) +# mailbox_target (is_mailbox and mailbox is (part of the) target +# vacation (active? 0/1) + 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), + 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), + 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), ); } @@ -45,7 +53,98 @@ } + public function webformConfig() { + if ($this->new) { # the webform will display a localpart field + domain dropdown on $new + $this->struct['address']['display_in_form'] = 0; + $this->struct['localpart']['display_in_form'] = 1; + $this->struct['domain']['display_in_form'] = 1; + } + return array( + # $PALANG labels + 'formtitle_create' => 'pCreate_alias_welcome', + 'formtitle_edit' => 'pEdit_alias_welcome', + 'create_button' => 'pCreate_alias_button', + 'successmessage' => 'pCreate_alias_result_success', # TODO: better message for edit + + # various settings + 'required_role' => 'admin', + 'listview' => 'list-virtual.php', + 'early_init' => 0, + ); + } + + protected function validate_new_id() { + $valid = check_email($this->id); # TODO: check_email should return error message instead of using flash_error itsself + # TODO: handle catchall (input: *@domain, write to db: @domain (without *) + return $valid; + } + + /** + * merge localpart and domain to address + * called by edit.php (if id_field is editable and hidden in editform) _before_ ->init + */ + public function mergeId($values) { + if ($this->struct['localpart']['display_in_form'] == 1 && $this->struct['domain']['display_in_form']) { # webform mode - combine to 'address' field + if (empty($values['localpart']) || empty($values['domain']) ) { # localpart or domain not set + return ""; + } + if ($values['localpart'] == '*') $values['localpart'] = ''; # catchall + error_log("merged to: " . $values['localpart'] . '@' . $values['domain']); + return $values['localpart'] . '@' . $values['domain']; + } else { + return $values[$this->id_field]; + } + } + + protected function setmore($values) { + if ($this->new) { + if ($this->struct['address']['display_in_form'] == 1) { # default mode - split off 'domain' field from 'address' # TODO: do this unconditional? + list(/*NULL*/,$domain) = explode('@', $values['address']); + $this->values['domain'] = $domain; + } + } + + $this->values['goto'] = join(',', $values['goto']); # TODO: add mailbox and vacation aliases + } + + protected function read_from_db_postprocess($db_result) { + foreach ($db_result as $key => $value) { + $db_result[$key]['goto'] = explode(',', $db_result[$key]['goto']); + } +#print_r($db_result); exit; + return $db_result; + } + +/* delete is already implemented in the "old functions" section + public function delete() { + $this->errormsg[] = '*** Alias domain deletion not implemented yet ***'; + return false; # XXX function aborts here until TODO below is implemented! XXX + # TODO: move the needed code from delete.php here + } +*/ + + protected function _field_goto($field, $val) { + if (count($val) == 0) { + # TODO: empty is ok for mailboxes - mailbox alias is in a separate field + $this->errormsg[$field] = 'empty goto'; # TODO: better error message + return false; + } + + foreach ($val as $singlegoto) { + if (!check_email($singlegoto)) { + $this->errormsg[$field] .= "invalid: $singlegoto "; # TODO: better error message + } + } + + return false; + } + +/********************************************************************************************************************************************************** + old function from non-PFAHandler times of AliasHandler + They still work, but are deprecated and will be removed. + **********************************************************************************************************************************************************/ + /** * @return bool true if succeed * (may be an empty list, especially if $CONF['alias_control'] is turned off...) @@ -227,7 +326,7 @@ /** * @return boolean true if the user has an alias record (i.e row in alias table); else false. */ - public function hasAliasRecord() { + private function hasAliasRecord() { # only used by update() in this class $username = escape_string($this->id); $table_alias = table_by_key('alias'); $sql = "SELECT * FROM $table_alias WHERE address = '$username'"; Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2011-12-26 20:54:40 UTC (rev 1310) +++ trunk/model/PFAHandler.php 2011-12-27 18:13:32 UTC (rev 1311) @@ -138,6 +138,8 @@ } } + $this->setmore($values); + if (count($this->errormsg) == 0) { $this->values_valid = true; } @@ -145,6 +147,15 @@ } /** + * set more values + * can be used to update additional columns etc. + * hint: modify $this->values and $this->errormsg directly as needed + */ + protected function setmore($values) { + # do nothing + } + + /** * store $this->values in the database * calls $this->storemore() where additional things can be done * @return bool - true if all values are valid, otherwise false Modified: trunk/templates/editform.tpl =================================================================== --- trunk/templates/editform.tpl 2011-12-26 20:54:40 UTC (rev 1310) +++ trunk/templates/editform.tpl 2011-12-27 18:13:32 UTC (rev 1311) @@ -39,6 +39,9 @@ --> {elseif $field.type == 'pass'} <input class="flat" type="password" name="{$key}" /> + {elseif $field.type == 'txtl'} + <textarea class="flat" rows="10" cols="35" name="{$key}">{foreach key=key2 item=field2 from=$value_{$key}}{$field2} +{/foreach}</textarea> {else} <input class="flat" type="text" name="{$key}" value="{$value_{$key}}" /> {/if} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |