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()



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1426 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 12 years ago
parent fad18fc953
commit 5a8ee27af3

@ -67,9 +67,13 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && $active == '') {
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);

@ -41,22 +41,46 @@ class MailboxHandler extends PFAHandler {
'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() {
@ -258,6 +282,12 @@ class MailboxHandler extends PFAHandler {
}
*/
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

@ -184,6 +184,19 @@ abstract class PFAHandler {
*/
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, ...)

Loading…
Cancel
Save