You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-09 05:02:44 +03:00
templates/editform.tpl:
- new file - generic edit form template that uses $struct to render the form templates/admin_edit-domain.tpl: - deleted, obsoleted by editform.tpl create-domain.php - use new editform.tpl - use $errormsg array instead of join't $errortext - store/move errors related to a display_in_form field in $fielderror (they will be displayed next to the field) - display remaining error messages (not related to a field) with flash_error() - use "value_$key" instead of "t$Key" as smarty variable name for field values model/DomainHandler.php - store error messages in $this->errormsg[$field] (instead of $this->errormsg[]) - fix label for default_aliases model/PFAHandler.php: - store error messages in $this->errormsg[$field] (instead of $this->errormsg[]) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1252 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
*
|
*
|
||||||
* File: create-domain.php
|
* File: create-domain.php
|
||||||
* Allows administrators to create or edit domains.
|
* Allows administrators to create or edit domains.
|
||||||
* Template File: admin_edit-domain.tpl
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('common.php');
|
require_once('common.php');
|
||||||
@@ -22,7 +21,6 @@ require_once('common.php');
|
|||||||
authentication_require_role('global-admin');
|
authentication_require_role('global-admin');
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$errortext = "";
|
|
||||||
$mode = 'create';
|
$mode = 'create';
|
||||||
|
|
||||||
$edit = safepost('edit', safeget('edit'));
|
$edit = safepost('edit', safeget('edit'));
|
||||||
@@ -75,17 +73,17 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||||||
|
|
||||||
if (!$handler->init($values[$id_field])) {
|
if (!$handler->init($values[$id_field])) {
|
||||||
$error = 1;
|
$error = 1;
|
||||||
$errortext = join("<br />", $handler->errormsg);
|
$errormsg = $handler->errormsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$handler->set($values)) {
|
if (!$handler->set($values)) {
|
||||||
$error = 1;
|
$error = 1;
|
||||||
$errortext = join("<br />", $handler->errormsg);
|
$errormsg = $handler->errormsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error != 1) {
|
if ($error != 1) {
|
||||||
if (!$handler->store()) {
|
if (!$handler->store()) {
|
||||||
$errortext = join("\n", $handler->errormsg);
|
$errormsg = $handler->errormsg;
|
||||||
} else {
|
} else {
|
||||||
flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values[$id_field] . ")");
|
flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values[$id_field] . ")");
|
||||||
# TODO: - use a sprintf string
|
# 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) {
|
foreach($form_fields as $key => $field) {
|
||||||
if($form_fields[$key]['display_in_form']) {
|
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']) {
|
switch ($field['type']) {
|
||||||
case 'bool':
|
case 'bool':
|
||||||
$smarty->assign ($smartykey, ($values[$key] == '1') ? ' checked="checked"' : '');
|
$smarty->assign ("value_$key", ($values[$key] == '1') ? ' checked="checked"' : '');
|
||||||
break;
|
break;
|
||||||
case 'enum':
|
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;
|
break;
|
||||||
default:
|
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') {
|
if ($mode == 'edit') {
|
||||||
$smarty->assign('formtitle', Lang::read('pAdminEdit_domain_welcome'));
|
$smarty->assign('formtitle', Lang::read('pAdminEdit_domain_welcome'));
|
||||||
$smarty->assign('submitbutton', Lang::read('save'));
|
$smarty->assign('submitbutton', Lang::read('save'));
|
||||||
@@ -135,9 +147,11 @@ if ($mode == 'edit') {
|
|||||||
$smarty->assign('submitbutton', Lang::read('pAdminCreate_domain_button'));
|
$smarty->assign('submitbutton', Lang::read('pAdminCreate_domain_button'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$smarty->assign ('struct', $form_fields);
|
||||||
|
$smarty->assign ('fielderror', $fielderror);
|
||||||
$smarty->assign ('mode', $mode);
|
$smarty->assign ('mode', $mode);
|
||||||
$smarty->assign ('errortext', $errortext, false); # non-escaped
|
$smarty->assign ('table', 'domain');
|
||||||
$smarty->assign ('smarty_template', 'admin_edit-domain');
|
$smarty->assign ('smarty_template', 'editform');
|
||||||
$smarty->display ('index.tpl');
|
$smarty->display ('index.tpl');
|
||||||
|
|
||||||
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
||||||
|
@@ -41,7 +41,7 @@ class DomainHandler extends PFAHandler {
|
|||||||
|
|
||||||
if ($this->new) {
|
if ($this->new) {
|
||||||
if ($exists) {
|
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;
|
return false;
|
||||||
} elseif (!$this->validate_id() ) {
|
} elseif (!$this->validate_id() ) {
|
||||||
# errormsg filled by validate_id()
|
# errormsg filled by validate_id()
|
||||||
@@ -51,7 +51,7 @@ class DomainHandler extends PFAHandler {
|
|||||||
}
|
}
|
||||||
} else { # edit mode
|
} else { # edit mode
|
||||||
if (!$exists) {
|
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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@@ -65,7 +65,7 @@ class DomainHandler extends PFAHandler {
|
|||||||
if ($valid) {
|
if ($valid) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,11 +123,12 @@ class DomainHandler extends PFAHandler {
|
|||||||
/*options*/ $this->getTransports() ),
|
/*options*/ $this->getTransports() ),
|
||||||
'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ),
|
'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ),
|
||||||
'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ),
|
'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 */ , '' ),
|
'created' => pacol( 0, 0, 1, 'ts', '' /* TODO: "created" label */ , '' ),
|
||||||
'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ),
|
'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# TODO: hook to modify $this->struct
|
||||||
}
|
}
|
||||||
|
|
||||||
# messages used in various functions.
|
# messages used in various functions.
|
||||||
|
@@ -15,27 +15,27 @@ class PFAHandler {
|
|||||||
function _inp_num($field, $val) {
|
function _inp_num($field, $val) {
|
||||||
$valid = is_numeric($val);
|
$valid = is_numeric($val);
|
||||||
if ($val < -1) $valid = false;
|
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 $valid;
|
||||||
# return (int)($val);
|
# return (int)($val);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _inp_bool($field, $val) {
|
function _inp_bool($field, $val) {
|
||||||
if ($val == "0" || $val == "1") return true;
|
if ($val == "0" || $val == "1") return true;
|
||||||
$this->errormsg[] = "$field must be boolean";
|
$this->errormsg[$field] = "$field must be boolean";
|
||||||
return false;
|
return false;
|
||||||
# return $val ? db_get_boolean(true): db_get_boolean(false);
|
# return $val ? db_get_boolean(true): db_get_boolean(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _inp_enum($field, $val) {
|
function _inp_enum($field, $val) {
|
||||||
if(in_array($val, $this->struct[$field]['options'])) return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _inp_password($field, $val){
|
function _inp_password($field, $val){
|
||||||
# TODO: fetchmail specific. Not suited for mailbox/admin passwords.
|
# 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 false;
|
||||||
# return base64_encode($val);
|
# return base64_encode($val);
|
||||||
}
|
}
|
||||||
|
@@ -1,86 +0,0 @@
|
|||||||
<div id="edit_form">
|
|
||||||
<form name="edit_domain" method="post" action="">
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th colspan="4">{$formtitle}</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_domain}:</label></td>
|
|
||||||
<td>
|
|
||||||
{if $mode == 'edit'}
|
|
||||||
<em>{$tDomain}</em>
|
|
||||||
<input type="hidden" name="edit" value="{$tDomain}" />
|
|
||||||
{else}
|
|
||||||
<input class="flat" type="text" name="domain" value="{$tDomain}" />
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td> </td>
|
|
||||||
<td><span class="error_msg">{$errortext}</span></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_description}:</label></td>
|
|
||||||
<td><input class="flat" type="text" name="description" value="{$tDescription}" /></td>
|
|
||||||
<td colspan="2"> </td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_aliases}:</label></td>
|
|
||||||
<td><input class="flat" type="text" name="aliases" value="{$tAliases}" /></td>
|
|
||||||
<td>{$PALANG.pAdminEdit_domain_aliases_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_mailboxes}:</label></td>
|
|
||||||
<td><input class="flat" type="text" name="mailboxes" value="{$tMailboxes}" /></td>
|
|
||||||
<td>{$PALANG.pAdminEdit_domain_mailboxes_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
{if $CONF.domain_quota===YES}
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_quota}:</label></td>
|
|
||||||
<td><input class="flat" type="text" name="quota" value="{$tQuota}" /></td>
|
|
||||||
<td>{$PALANG.pAdminEdit_domain_maxquota_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
{/if}
|
|
||||||
{if $CONF.quota===YES}
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_maxquota}:</label></td>
|
|
||||||
<td><input class="flat" type="text" name="maxquota" value="{$tMaxquota}" /></td>
|
|
||||||
<td>{$PALANG.pAdminEdit_domain_maxquota_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
{/if}
|
|
||||||
{if $CONF.transport===YES}
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_transport}:</label></td>
|
|
||||||
<td><select class="flat" name="transport">{$tTransport}</select></td>
|
|
||||||
<td>{$PALANG.pAdminEdit_domain_transport_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
{/if}
|
|
||||||
{if $mode == 'create'}
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminCreate_domain_defaultaliases}:</label></td>
|
|
||||||
<td><input class="flat" type="checkbox" value='1' name="default_aliases"{$tDefault_aliases}/></td>
|
|
||||||
<td>{$PALANG.pAdminCreate_domain_defaultaliases_text}</td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
{/if}
|
|
||||||
<tr>
|
|
||||||
<td class="label"><label>{$PALANG.pAdminEdit_domain_backupmx}:</label></td>
|
|
||||||
<td><input class="flat" type="checkbox" value='1' name="backupmx"{$tBackupmx}/></td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
|
||||||
<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>
|
|
||||||
<tr>
|
|
||||||
<td> </td>
|
|
||||||
<td colspan="3"><input class="button" type="submit" name="submit" value="{$submitbutton}" /></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
47
templates/editform.tpl
Normal file
47
templates/editform.tpl
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<div id="edit_form">
|
||||||
|
<form name="edit_{$table}" method="post" action="">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th colspan="4">{$formtitle}</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{foreach key=key item=field from=$struct}
|
||||||
|
{if $field.display_in_form == 1}
|
||||||
|
|
||||||
|
{if $table == 'foo' && $key == 'bar'}
|
||||||
|
<tr><td>Special handling (complete table row) for {$table} / {$key}</td></tr>
|
||||||
|
{else}
|
||||||
|
<tr>
|
||||||
|
<td class="label">{$field.label}</td>
|
||||||
|
<td>
|
||||||
|
{if $field.editable == 0}
|
||||||
|
{$value_{$key}}
|
||||||
|
{else}
|
||||||
|
{if $table == 'foo' && $key == 'bar'}
|
||||||
|
Special handling (td content) for {$table} / {$key}
|
||||||
|
{elseif $field.type == 'bool'}
|
||||||
|
<input class="flat" type="checkbox" value='1' name="{$key}"{$value_{$key}}/>
|
||||||
|
{elseif $field.type == 'enum'}
|
||||||
|
<select class="flat" name="{$key}">{$value_{$key}}</select>
|
||||||
|
{else}
|
||||||
|
<input class="flat" type="text" name="{$key}" value="{$value_{$key}}" />
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td>{$field.desc}</td>
|
||||||
|
<td class="error_msg">{$fielderror.{$key}}</td>
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
<td colspan="3"><input class="button" type="submit" name="submit" value="{$submitbutton}" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
Reference in New Issue
Block a user