From 24836cf3ade34138d03ec8832735ca9fc9cfa6e4 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Wed, 19 Oct 2011 21:09:54 +0000 Subject: [PATCH] Add edit mode to create-domain.php create-domain.php: - add edit mode (use ?edit=example.com) - use $id_field instead of hardcoded 'domain' - redirect to list-domain after saving in edit mode - rename some variables edit-domain.php: - rename some smarty variables templates/admin_edit-domain.tpl: - rename some smarty variables - add two hidden fields "edit" and "domain", both contain $tDomain (only in edit mode) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1225 a1433add-5e2c-0410-b055-b7f2511e0802 --- create-domain.php | 61 +++++++++++++++++++++++++++------ edit-domain.php | 4 +-- templates/admin_edit-domain.tpl | 5 +-- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/create-domain.php b/create-domain.php index 1409558a..15fd29c0 100644 --- a/create-domain.php +++ b/create-domain.php @@ -22,9 +22,41 @@ require_once('common.php'); authentication_require_role('global-admin'); $error = 0; +$errortext = ""; +$mode = 'create'; -$handler = new DomainHandler(1); +$edit = safepost('edit', safeget('edit')); +$new = 0; +if ($edit == "") $new = 1; + +$listview = 'list-domain.php'; + +$handler = new DomainHandler($new); $form_fields = $handler->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") { @@ -39,31 +71,40 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { } } } + if ($edit != "") $field[$id_field] = $edit; - if (!$handler->init($values['domain'])) { + if (!$handler->init($values[$id_field])) { $error = 1; - $pAdminCreate_domain_domain_text_error = join("
", $handler->errormsg); + $errortext = join("
", $handler->errormsg); } if (!$handler->set($values)) { $error = 1; - $pAdminCreate_domain_domain_text_error = join("
", $handler->errormsg); + $errortext = join("
", $handler->errormsg); } if ($error != 1) { if (!$handler->store()) { - $pAdminCreate_domain_domain_text_error = join("\n", $handler->errormsg); + $errortext = join("\n", $handler->errormsg); } else { - flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values['domain'] . ")"); # TODO: use a sprintf string + 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) { +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']; @@ -84,8 +125,8 @@ foreach($form_fields as $key => $field) { } } -$smarty->assign ('mode', 'create'); -$smarty->assign ('pAdminCreate_domain_domain_text_error', $pAdminCreate_domain_domain_text_error, false); +$smarty->assign ('mode', $mode); +$smarty->assign ('errortext', $errortext, false); # non-escaped $smarty->assign ('smarty_template', 'admin_edit-domain'); $smarty->display ('index.tpl'); diff --git a/edit-domain.php b/edit-domain.php index 6f2ddfa2..d990458e 100644 --- a/edit-domain.php +++ b/edit-domain.php @@ -120,8 +120,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") } $smarty->assign ('mode', 'edit'); -$smarty->assign ('pAdminCreate_domain_domain_text_error', ''); -$smarty->assign ('domain', $domain); +$smarty->assign ('errortext', ''); +$smarty->assign ('tDomain', $domain); $smarty->assign ('tDescription', $tDescription); $smarty->assign ('tAliases', $tAliases); $smarty->assign ('tMailboxes', $tMailboxes); diff --git a/templates/admin_edit-domain.tpl b/templates/admin_edit-domain.tpl index 863dd7c4..ebc0e1e2 100644 --- a/templates/admin_edit-domain.tpl +++ b/templates/admin_edit-domain.tpl @@ -14,13 +14,14 @@ {if $mode == 'edit'} - {$domain} + {$tDomain} + {else} {/if}   - {$pAdminCreate_domain_domain_text_error} + {$errortext}