SF.net SVN: postfixadmin:[1276] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-11-13 22:59:28
|
Revision: 1276 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1276&view=rev Author: christian_boltz Date: 2011-11-13 22:59:21 +0000 (Sun, 13 Nov 2011) Log Message: ----------- 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 :-) Modified Paths: -------------- trunk/configs/menu.conf trunk/model/DomainHandler.php trunk/templates/adminlistdomain.tpl trunk/templates/menu.tpl Removed Paths: ------------- trunk/create-domain.php Modified: trunk/configs/menu.conf =================================================================== --- trunk/configs/menu.conf 2011-11-13 22:48:22 UTC (rev 1275) +++ trunk/configs/menu.conf 2011-11-13 22:59:21 UTC (rev 1276) @@ -4,7 +4,6 @@ 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 @@ [adminlistdomain] url_edit_active_domain = edit-active-domain.php -url_edit_domain = create-domain.php +url_edit_domain = edit.php?table=domain Deleted: trunk/create-domain.php =================================================================== --- trunk/create-domain.php 2011-11-13 22:48:22 UTC (rev 1275) +++ trunk/create-domain.php 2011-11-13 22:59:21 UTC (rev 1276) @@ -1,149 +0,0 @@ -<?php -/** - * Postfix Admin - * - * LICENSE - * This source file is subject to the GPL license that is bundled with - * this package in the file LICENSE.TXT. - * - * Further details on the project are available at : - * http://www.postfixadmin.com or http://postfixadmin.sf.net - * - * @version $Id$ - * @license GNU GPL v2 or later. - * - * File: create-domain.php - * Allows administrators to create or edit domains. - */ - -require_once('common.php'); - -authentication_require_role('global-admin'); - -$error = 0; -$mode = 'create'; - -$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("<br />", $handler->errormsg)); - header ("Location: $listview"); - exit; - } - - if ($_SERVER['REQUEST_METHOD'] == "GET") { # read values from database - if (!$handler->view()) { - flash_error(join("<br />", $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("<br />", $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: */ -?> Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2011-11-13 22:48:22 UTC (rev 1275) +++ trunk/model/DomainHandler.php 2011-11-13 22:59:21 UTC (rev 1276) @@ -95,6 +95,24 @@ } } + /* + * 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. Modified: trunk/templates/adminlistdomain.tpl =================================================================== --- trunk/templates/adminlistdomain.tpl 2011-11-13 22:48:22 UTC (rev 1275) +++ trunk/templates/adminlistdomain.tpl 2011-11-13 22:59:21 UTC (rev 1276) @@ -34,10 +34,10 @@ <td>{$domain.backupmx}</td> <td>{$domain.modified}</td> <td><a href="{#url_edit_active_domain#}?domain={$domain.domain|escape:"url"}">{$domain.active}</a></td> - <td><a href="{#url_edit_domain#}?edit={$domain.domain|escape:"url"}">{$PALANG.edit}</a></td> + <td><a href="{#url_edit_domain#}&edit={$domain.domain|escape:"url"}">{$PALANG.edit}</a></td> <td><a href="{#url_delete#}?table=domain&delete={$domain.domain|escape:"url"}" onclick="return confirm ('{$PALANG.confirm_domain}{$PALANG.pAdminList_admin_domain}: {$domain.domain}')">{$PALANG.del}</a></td> </tr> {/foreach} </table> {/if} -<br /><a href="{#url_create_domain#}" class="button">{$PALANG.pAdminMenu_create_domain}</a><br /> +<br /><a href="{#url_edit_domain#}" class="button">{$PALANG.pAdminMenu_create_domain}</a><br /> Modified: trunk/templates/menu.tpl =================================================================== --- trunk/templates/menu.tpl 2011-11-13 22:48:22 UTC (rev 1275) +++ trunk/templates/menu.tpl 2011-11-13 22:59:21 UTC (rev 1276) @@ -27,7 +27,7 @@ <ul> <li><a target="_top" href="{#url_list_domain#}">{$PALANG.pAdminMenu_list_domain}</a></li> {if $authentication_has_role.global_admin} - <li><a target="_top" href="{#url_create_domain#}">{$PALANG.pAdminMenu_create_domain}</a></li> + <li><a target="_top" href="{#url_edit_domain#}">{$PALANG.pAdminMenu_create_domain}</a></li> {/if} </ul> </li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |