diff --git a/create-domain.php b/create-domain.php index b4605c5b..c029d2be 100644 --- a/create-domain.php +++ b/create-domain.php @@ -14,7 +14,6 @@ * * File: create-domain.php * Allows administrators to create or edit domains. - * Template File: admin_edit-domain.tpl */ require_once('common.php'); @@ -22,7 +21,6 @@ require_once('common.php'); authentication_require_role('global-admin'); $error = 0; -$errortext = ""; $mode = 'create'; $edit = safepost('edit', safeget('edit')); @@ -75,17 +73,17 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { if (!$handler->init($values[$id_field])) { $error = 1; - $errortext = join("
", $handler->errormsg); + $errormsg = $handler->errormsg; } if (!$handler->set($values)) { $error = 1; - $errortext = join("
", $handler->errormsg); + $errormsg = $handler->errormsg; } if ($error != 1) { if (!$handler->store()) { - $errortext = join("\n", $handler->errormsg); + $errormsg = $handler->errormsg; } else { flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values[$id_field] . ")"); # TODO: - use a sprintf string @@ -111,22 +109,36 @@ if ($error != 1 && $new) { # no error and not in edit mode - reset fields to def } } +$errormsg = $handler->errormsg; +$fielderror = array(); + foreach($form_fields as $key => $field) { if($form_fields[$key]['display_in_form']) { - $smartykey = "t" . ucfirst($key); # TODO: ugly workaround until I decide on the template variable names + + if (isset($errormsg[$key])) { + $fielderror[$key] = $errormsg[$key]; + unset ($errormsg[$key]); + } else { + $fielderror[$key] = ''; + } + switch ($field['type']) { case 'bool': - $smarty->assign ($smartykey, ($values[$key] == '1') ? ' checked="checked"' : ''); + $smarty->assign ("value_$key", ($values[$key] == '1') ? ' checked="checked"' : ''); break; case 'enum': - $smarty->assign ($smartykey, select_options ($form_fields[$key]['options'], array ($values[$key])),false); + $smarty->assign ("value_$key", select_options ($form_fields[$key]['options'], array ($values[$key])),false); # non-escaped break; default: - $smarty->assign ($smartykey, $values[$key]); + $smarty->assign ("value_$key", $values[$key]); } } } +foreach($errormsg as $msg) { # output the remaining error messages (not related to a field) with flash_error + flash_error($msg); +} + if ($mode == 'edit') { $smarty->assign('formtitle', Lang::read('pAdminEdit_domain_welcome')); $smarty->assign('submitbutton', Lang::read('save')); @@ -135,9 +147,11 @@ if ($mode == 'edit') { $smarty->assign('submitbutton', Lang::read('pAdminCreate_domain_button')); } +$smarty->assign ('struct', $form_fields); +$smarty->assign ('fielderror', $fielderror); $smarty->assign ('mode', $mode); -$smarty->assign ('errortext', $errortext, false); # non-escaped -$smarty->assign ('smarty_template', 'admin_edit-domain'); +$smarty->assign ('table', 'domain'); +$smarty->assign ('smarty_template', 'editform'); $smarty->display ('index.tpl'); /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 433960cd..a7607a48 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -41,7 +41,7 @@ class DomainHandler extends PFAHandler { if ($this->new) { if ($exists) { - $this->errormsg[] = Lang::read($this->msg['error_already_exists']); + $this->errormsg[$this->id_field] = Lang::read($this->msg['error_already_exists']); return false; } elseif (!$this->validate_id() ) { # errormsg filled by validate_id() @@ -51,7 +51,7 @@ class DomainHandler extends PFAHandler { } } else { # edit mode if (!$exists) { - $this->errormsg[] = Lang::read($this->msg['error_does_not_exist']); + $this->errormsg[$this->id_field] = Lang::read($this->msg['error_does_not_exist']); return false; } else { return true; @@ -65,7 +65,7 @@ class DomainHandler extends PFAHandler { if ($valid) { return true; } else { - $this->errormsg[] = Lang::read('pAdminCreate_domain_domain_text_error2'); # TODO: half of the errormsg is currently delivered via flash_error() in check_domain + $this->errormsg[$this->id_field] = Lang::read('pAdminCreate_domain_domain_text_error2'); # TODO: half of the errormsg is currently delivered via flash_error() in check_domain return false; } } @@ -123,11 +123,12 @@ class DomainHandler extends PFAHandler { /*options*/ $this->getTransports() ), 'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ), 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), - 'default_aliases' => pacol( $this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases ', '' , 1,'', /*not in db*/ 1 ), + 'default_aliases' => pacol( $this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '' , 1,'', /*not in db*/ 1 ), 'created' => pacol( 0, 0, 1, 'ts', '' /* TODO: "created" label */ , '' ), '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 45cfe079..1c531b1b 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -15,27 +15,27 @@ class PFAHandler { function _inp_num($field, $val) { $valid = is_numeric($val); if ($val < -1) $valid = false; - if (!$valid) $this->errormsg[] = "$field must be numeric"; + if (!$valid) $this->errormsg[$field] = "$field must be numeric"; return $valid; # return (int)($val); } function _inp_bool($field, $val) { if ($val == "0" || $val == "1") return true; - $this->errormsg[] = "$field must be boolean"; + $this->errormsg[$field] = "$field must be boolean"; return false; # return $val ? db_get_boolean(true): db_get_boolean(false); } function _inp_enum($field, $val) { if(in_array($val, $this->struct[$field]['options'])) return true; - $this->errormsg[] = "Invalid parameter given for $field"; + $this->errormsg[$field] = "Invalid parameter given for $field"; return false; } function _inp_password($field, $val){ # TODO: fetchmail specific. Not suited for mailbox/admin passwords. - $this->errormsg[] = "_inp_password not implemented yet"; + $this->errormsg[$field] = "_inp_password not implemented yet"; return false; # return base64_encode($val); } diff --git a/templates/admin_edit-domain.tpl b/templates/admin_edit-domain.tpl deleted file mode 100644 index 87845f6e..00000000 --- a/templates/admin_edit-domain.tpl +++ /dev/null @@ -1,86 +0,0 @@ -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -{if $CONF.domain_quota===YES} - - - - - - -{/if} -{if $CONF.quota===YES} - - - - - - -{/if} -{if $CONF.transport===YES} - - - - - - -{/if} -{if $mode == 'create'} - - - - - - -{/if} - - - - - - - - - - - - - - - -
{$formtitle}
-{if $mode == 'edit'} - {$tDomain} - -{else} - -{/if} -  {$errortext}
 
{$PALANG.pAdminEdit_domain_aliases_text} 
{$PALANG.pAdminEdit_domain_mailboxes_text} 
{$PALANG.pAdminEdit_domain_maxquota_text} 
{$PALANG.pAdminEdit_domain_maxquota_text} 
{$PALANG.pAdminEdit_domain_transport_text} 
{$PALANG.pAdminCreate_domain_defaultaliases_text} 
  
 
 
-
-
diff --git a/templates/editform.tpl b/templates/editform.tpl new file mode 100644 index 00000000..006c3f8c --- /dev/null +++ b/templates/editform.tpl @@ -0,0 +1,47 @@ +
+
+ + + + + + +{foreach key=key item=field from=$struct} + {if $field.display_in_form == 1} + + {if $table == 'foo' && $key == 'bar'} + + {else} + + + + + + + {/if} + + {/if} +{/foreach} + + + + + +
{$formtitle}
Special handling (complete table row) for {$table} / {$key}
{$field.label} + {if $field.editable == 0} + {$value_{$key}} + {else} + {if $table == 'foo' && $key == 'bar'} + Special handling (td content) for {$table} / {$key} + {elseif $field.type == 'bool'} + + {elseif $field.type == 'enum'} + + {else} + + {/if} + {/if} + {$field.desc}{$fielderror.{$key}}
 
+ +
+