SF.net SVN: postfixadmin:[1220] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-10-18 22:56:39
|
Revision: 1220 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1220&view=rev Author: christian_boltz Date: 2011-10-18 22:56:33 +0000 (Tue, 18 Oct 2011) Log Message: ----------- 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 Modified Paths: -------------- trunk/create-domain.php trunk/model/DomainHandler.php trunk/model/PFAHandler.php trunk/templates/admin_edit-domain.tpl Modified: trunk/create-domain.php =================================================================== --- trunk/create-domain.php 2011-10-18 22:11:22 UTC (rev 1219) +++ trunk/create-domain.php 2011-10-18 22:56:33 UTC (rev 1220) @@ -21,54 +21,33 @@ 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)) -); +$handler = new DomainHandler(1); +$form_fields = $handler->getStruct(); -# 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']; - } +if ($_SERVER['REQUEST_METHOD'] == "POST") { -# TODO: check via _inp_enum in *Handler - if(isset($field['options'])) { - if(!in_array($values[$key], $field['options'])) { - die("Invalid parameter given for $key"); + 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 ($_SERVER['REQUEST_METHOD'] == "POST") { - - $handler = new DomainHandler(1); 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 ('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'); Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2011-10-18 22:11:22 UTC (rev 1219) +++ trunk/model/DomainHandler.php 2011-10-18 22:56:33 UTC (rev 1220) @@ -92,8 +92,8 @@ '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' , '' ), ); Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2011-10-18 22:11:22 UTC (rev 1219) +++ trunk/model/PFAHandler.php 2011-10-18 22:56:33 UTC (rev 1220) @@ -27,8 +27,15 @@ # 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); } Modified: trunk/templates/admin_edit-domain.tpl =================================================================== --- trunk/templates/admin_edit-domain.tpl 2011-10-18 22:11:22 UTC (rev 1219) +++ trunk/templates/admin_edit-domain.tpl 2011-10-18 22:56:33 UTC (rev 1220) @@ -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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |