From 8f267c1b7f83fd479b7aa8b2e06b9c0cafaa43ff Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 13 Nov 2011 22:59:21 +0000 Subject: [PATCH] Use edit.php to create/edit domains model/DomainHandler.php: - add webformConfig() configs/menu.conf: - change url_edit_domain to edit.php?table=domain - drop url_create_domain (use url_edit_domain instead) templates/*: - replace #url_create_domain# with #url_edit_domain# - replace ? with & create-domain.php: - deleted :-) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1276 a1433add-5e2c-0410-b055-b7f2511e0802 --- configs/menu.conf | 3 +- create-domain.php | 149 ---------------------------------- model/DomainHandler.php | 18 ++++ templates/adminlistdomain.tpl | 4 +- templates/menu.tpl | 2 +- 5 files changed, 22 insertions(+), 154 deletions(-) delete mode 100644 create-domain.php diff --git a/configs/menu.conf b/configs/menu.conf index c61b8243..742ccd55 100644 --- a/configs/menu.conf +++ b/configs/menu.conf @@ -4,7 +4,6 @@ url_list_admin = list-admin.php url_create_admin = create-admin.php # list-domain url_list_domain = list-domain.php -url_create_domain = create-domain.php # list-virtual url_list_virtual = list-virtual.php url_create_mailbox = create-mailbox.php @@ -51,4 +50,4 @@ url_edit_admin = edit-admin.php [adminlistdomain] url_edit_active_domain = edit-active-domain.php -url_edit_domain = create-domain.php +url_edit_domain = edit.php?table=domain diff --git a/create-domain.php b/create-domain.php deleted file mode 100644 index 5fa6e3e2..00000000 --- a/create-domain.php +++ /dev/null @@ -1,149 +0,0 @@ -getStruct(); -$id_field = $handler->getId_field(); - - -if ($edit != "") { - $mode = 'edit'; - - if (!$handler->init($edit)) { - flash_error(join("
", $handler->errormsg)); - header ("Location: $listview"); - exit; - } - - if ($_SERVER['REQUEST_METHOD'] == "GET") { # read values from database - if (!$handler->view()) { - flash_error(join("
", $handler->errormsg)); - header ("Location: $listview"); - exit; - } else { - $values = $handler->return; - $values[$id_field] = $edit; - } - } -} - - -if ($_SERVER['REQUEST_METHOD'] == "POST") { - - 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 ($edit != "") $values[$id_field] = $edit; - - if (!$handler->init($values[$id_field])) { - $error = 1; - $errormsg = $handler->errormsg; - } - - if (!$handler->set($values)) { - $error = 1; - $errormsg = $handler->errormsg; - } - - if ($error != 1) { - if (!$handler->store()) { - $errormsg = $handler->errormsg; - } else { - flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values[$id_field] . ")"); - # TODO: - use a sprintf string - # TODO: - get the success message from DomainHandler - # TODO: - use a different success message for create and edit - - if (count($handler->errormsg)) { # might happen if domain_postcreation fails - flash_error(join("
", $handler->errormsg)); - } - - if ($edit != "") { - header ("Location: $listview"); - exit; - } - } - } -} - -if ($error != 1 && $new) { # no error and not in edit mode - reset fields to default for new item - $values = array(); - foreach (array_keys($form_fields) as $key) { - $values[$key] = $form_fields[$key]['default']; - } -} - -$errormsg = $handler->errormsg; -$fielderror = array(); - -foreach($form_fields as $key => $field) { - if($form_fields[$key]['display_in_form']) { - - if (isset($errormsg[$key])) { - $fielderror[$key] = $errormsg[$key]; - unset ($errormsg[$key]); - } else { - $fielderror[$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')); -} else { - $smarty->assign('formtitle', Lang::read('pAdminCreate_domain_welcome')); - $smarty->assign('submitbutton', Lang::read('pAdminCreate_domain_button')); -} - -$smarty->assign ('struct', $form_fields); -$smarty->assign ('fielderror', $fielderror); -$smarty->assign ('mode', $mode); -$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 05ae7e0a..2816d9d4 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -95,6 +95,24 @@ class DomainHandler extends PFAHandler { } } + /* + * Configuration for the web interface + */ + public function webformConfig() { + return array( + # $PALANG labels + 'formtitle_create' => 'pAdminCreate_domain_welcome', + 'formtitle_edit' => 'pAdminEdit_domain_welcome', + 'create_button' => 'pAdminCreate_domain_button', + 'successmessage' => 'pAdminCreate_domain_result_success', + + # various settings + 'required_role' => 'global-admin', + 'listview' => 'list-domain.php', + 'early_init' => 0, + ); + } + /** * called by $this->store() after storing $this->values in the database * can be used to update additional tables, call scripts etc. diff --git a/templates/adminlistdomain.tpl b/templates/adminlistdomain.tpl index 75e2ba90..ee390f47 100644 --- a/templates/adminlistdomain.tpl +++ b/templates/adminlistdomain.tpl @@ -34,10 +34,10 @@ {$domain.backupmx} {$domain.modified} {$domain.active} - {$PALANG.edit} + {$PALANG.edit} {$PALANG.del} {/foreach} {/if} -
{$PALANG.pAdminMenu_create_domain}
+
{$PALANG.pAdminMenu_create_domain}
diff --git a/templates/menu.tpl b/templates/menu.tpl index c8ee7f23..fcde9b04 100644 --- a/templates/menu.tpl +++ b/templates/menu.tpl @@ -27,7 +27,7 @@