SF.net SVN: postfixadmin:[1426] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2013-02-09 23:52:06
|
Revision: 1426 http://sourceforge.net/p/postfixadmin/code/1426 Author: christian_boltz Date: 2013-02-09 23:52:03 +0000 (Sat, 09 Feb 2013) Log Message: ----------- displaying the available quota on $new is harder than it looks... edit.php: - call $handler->prefill for all prefill fields - refresh $form_fields after handling prefill fields model/PFAHandler.php: - add prefill() to handle prefill fields. If $this->_prefill_$field() exists, it will be called model/MailboxHandler.php: - init(): error out early if parent::init fails (no need to check the available quota if $this->id is invalid ;-) - move updating the allowed quota to updateMaxquota() - update the available quota based on the prefill domain. If no prefill domain is given, default to the first domain. - new method _prefill_domain() Modified Paths: -------------- trunk/edit.php trunk/model/MailboxHandler.php trunk/model/PFAHandler.php Modified: trunk/edit.php =================================================================== --- trunk/edit.php 2013-02-04 23:18:01 UTC (rev 1425) +++ trunk/edit.php 2013-02-09 23:52:03 UTC (rev 1426) @@ -67,9 +67,13 @@ if ($edit == '') { # new - prefill fields from URL parameters if allowed in $formconf['prefill'] if ( isset($formconf['prefill']) ) { foreach ($formconf['prefill'] as $field) { - if (isset ($_GET[$field])) $form_fields[$field]['default'] = safeget($field); + if (isset ($_GET[$field])) { + $form_fields[$field]['default'] = safeget($field); + $handler->prefill($field, safeget($field)); + } } } + $form_fields = $handler->getStruct(); # refresh $form_fields - a prefill field might have changed something } else { # edit mode - read values from database if (!$handler->view()) { flash_error($handler->errormsg); Modified: trunk/model/MailboxHandler.php =================================================================== --- trunk/model/MailboxHandler.php 2013-02-04 23:18:01 UTC (rev 1425) +++ trunk/model/MailboxHandler.php 2013-02-09 23:52:03 UTC (rev 1426) @@ -41,24 +41,48 @@ 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), # TODO: add virtual 'notified' column and allow to display who received a vacation response? ); + + # update allowed quota + if (count($this->struct['domain']['options']) > 0) $this->prefill('domain', $this->struct['domain']['options'][0]); } public function init($id) { - $retval = parent::init($id); + if (!parent::init($id)) { + return false; + } if ($this->new) { - # handled in validate_new_id() + $domain = $this->struct['domain']['default']; + $currentquota = 0; } else { - # show max allowed quota in quota field description list(/*NULL*/,$domain) = explode('@', $this->id); $currentquota = $this->return['quotabytes']; # parent::init called ->view() - $maxquota = allowed_quota($domain, $currentquota); - $this->struct['quota']['desc'] = sprintf(Lang::Read('mb_max'), $maxquota); } - return $retval; + $this->updateMaxquota($domain, $currentquota); + + return true; # still here? good. } + /** + * show max allowed quota in quota field description + * @param string - domain + * @param int - current quota + */ + protected function updateMaxquota ($domain, $currentquota) { + if ($domain == '') return false; + + $maxquota = allowed_quota($domain, $currentquota); + + if ($maxquota == 0) { + # TODO: show 'unlimited' + # } elseif ($maxquota < 0) { + # TODO: show 'disabled' - at the moment, just shows '-1' + } else { + $this->struct['quota']['desc'] = sprintf(Lang::Read('mb_max'), $maxquota); + } + } + protected function initMsg() { $this->msg['error_already_exists'] = 'pCreate_mailbox_username_text_error2'; $this->msg['error_does_not_exist'] = 'pCreate_mailbox_username_text_error1'; @@ -258,6 +282,12 @@ } */ + protected function _prefill_domain($field, $val) { + if (in_array($val, $this->struct[$field]['options'])) { + $this->struct[$field]['default'] = $val; + $this->updateMaxquota($val, 0); + } + } /** * check if quota is allowed Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2013-02-04 23:18:01 UTC (rev 1425) +++ trunk/model/PFAHandler.php 2013-02-09 23:52:03 UTC (rev 1426) @@ -185,6 +185,19 @@ abstract protected function validate_new_id(); /** + * web interface can prefill some fields + * if a _prefill_$field method exists, call it (it can for example modify $struct) + * @param string - field + * @param string - prefill value + */ + public function prefill($field, $val) { + $func="_prefill_".$field; + if (method_exists($this, $func) ) { + $this->{$func}($field, $val); # call _missing_$fieldname() + } + } + + /** * set and verify values * @param array values - associative array with ($field1 => $value1, $field2 => $value2, ...) * @return bool - true if all values are valid, otherwise false This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |