mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
Make create-domain.php even shorter (109 -> 89 lines) ;-)
create-domain.php - replace old $form_fields with $handler->getStruct() - rewrite handling POST data to make it easier to understand - move reading POST input to the section handling POST - remove condition on POST (we are in the POST block now) - check if editing of a field is allowed (use default value if not) - move validation of 'enum' fields to PFAHandler - allow changing the "active" state (instead of hardcoding it) model/PFAHandler.php: - add check for 'enum' fields model/DomainHandler.php: - change default for "active" and "default_aliases" to 1 templates/admin_edit-domain.tpl: - don't hide the "Active" checkbox on new git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1220 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
parent
f8fb724dcf
commit
95bf0161c6
@ -21,54 +21,33 @@ require_once('common.php');
|
||||
|
||||
authentication_require_role('global-admin');
|
||||
|
||||
|
||||
$error = 0;
|
||||
|
||||
$form_fields = array(
|
||||
'domain' => array('type' => 'str', 'default' => null),
|
||||
'description' => array('type' => 'str', 'default' =>''),
|
||||
'aliases' => array('type' => 'int', 'default' => $CONF['aliases']),
|
||||
'mailboxes' => array('type' => 'int', 'default' => $CONF['mailboxes']),
|
||||
'maxquota' => array('type' => 'int', 'default' => $CONF['maxquota']),
|
||||
'quota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']),
|
||||
'transport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']),
|
||||
'default_aliases'=> array('type' => 'bool', 'default' => '1', 'options' => array(1, 0)),
|
||||
'backupmx' => array('type' => 'bool', 'default' => '0', 'options' => array(1, 0))
|
||||
);
|
||||
|
||||
# TODO: this foreach block should only be executed for POST
|
||||
foreach($form_fields as $key => $field) {
|
||||
if($field['type'] == 'bool' && $_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$values[$key] = safepost($key, 0); # isset for unchecked checkboxes is always false
|
||||
}
|
||||
elseif (isset($_POST[$key]) && (strlen($_POST[$key]) > 0)) {
|
||||
$values[$key] = safepost($key);
|
||||
}
|
||||
else {
|
||||
$values[$key] = $field['default'];
|
||||
}
|
||||
|
||||
# TODO: check via _inp_enum in *Handler
|
||||
if(isset($field['options'])) {
|
||||
if(!in_array($values[$key], $field['options'])) {
|
||||
die("Invalid parameter given for $key");
|
||||
}
|
||||
}
|
||||
}
|
||||
$handler = new DomainHandler(1);
|
||||
$form_fields = $handler->getStruct();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
|
||||
$handler = new DomainHandler(1);
|
||||
foreach($form_fields as $key => $field) {
|
||||
if ($field['editable'] == 0) {
|
||||
$values[$key] = $field['default'];
|
||||
} else {
|
||||
if($field['type'] == 'bool') {
|
||||
$values[$key] = safepost($key, 0); # isset() for unchecked checkboxes is always false
|
||||
} else {
|
||||
$values[$key] = safepost($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$handler->init($values['domain'])) {
|
||||
$error = 1;
|
||||
$pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
|
||||
}
|
||||
|
||||
$values['active'] = 1; # hardcoded for now - TODO: change this ;-)
|
||||
|
||||
if (!$handler->set($values)) {
|
||||
$error = 1;
|
||||
$pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
|
||||
$error = 1;
|
||||
$pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
|
||||
}
|
||||
|
||||
if ($error != 1) {
|
||||
@ -102,6 +81,7 @@ $smarty->assign ('tMaxquota', $values['maxquota']);
|
||||
$smarty->assign ('select_options', select_options ($form_fields['transport']['options'], array ($values['transport'])),false);
|
||||
$smarty->assign ('tDefaultaliases', ($values['default_aliases'] == '1') ? ' checked="checked"' : '');
|
||||
$smarty->assign ('tBackupmx', ($values['backupmx'] == '1') ? ' checked="checked"' : '');
|
||||
$smarty->assign ('tActive', ($values['active'] == '1') ? ' checked="checked"' : '');
|
||||
$smarty->assign ('smarty_template', 'admin_edit-domain');
|
||||
$smarty->display ('index.tpl');
|
||||
|
||||
|
@ -92,8 +92,8 @@ class DomainHandler extends PFAHandler {
|
||||
'transport' => pacol( $transp, $transp,$transp,'enum', 'pAdminEdit_domain_transport' , 'pAdminEdit_domain_transport_text' , Config::read('transport_default') ,
|
||||
/*options*/ $this->getTransports() ),
|
||||
'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ),
|
||||
'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' ),
|
||||
'default_aliases' => pacol( $this->new, 1, 0, 'bool', 'pAdminCreate_domain_defaultaliases ', '' , '','', /*not in db*/ 1 ),
|
||||
'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ),
|
||||
'default_aliases' => pacol( $this->new, 1, 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' , '' ),
|
||||
);
|
||||
|
@ -27,8 +27,15 @@ class PFAHandler {
|
||||
# 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";
|
||||
return false;
|
||||
}
|
||||
|
||||
function _inp_password($field, $val){
|
||||
# TODO: fetchmail specific. Not suited for mailbox/admin passwords.
|
||||
$this->errormsg[] = "_inp_password not implemented yet";
|
||||
return false;
|
||||
# return base64_encode($val);
|
||||
}
|
||||
|
@ -77,14 +77,11 @@
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
{if $mode == 'edit'}
|
||||
<!-- TODO: create should also offer the 'active' option -->
|
||||
<tr>
|
||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_active}:</label></td>
|
||||
<td><input class="flat" type="checkbox" value='1' name="active"{$tActive}/></td>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
{/if}
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td colspan="3"><input class="button" type="submit" name="submit" value="{if $mode == 'edit'}{$PALANG.save}{else}{$PALANG.pAdminCreate_domain_button}{/if}" /></td>
|
||||
|
Loading…
Reference in New Issue
Block a user