Sometimes short commit messages are the best ones - see the message

for create-domain.php...

create-domain.php:
- finally: use DomainHandler :-))

edit-domain.php, create-domain.php, 
templates/admin_edit-domain.tpl:
- use 0/1 instead of off/on for checkboxes



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1217 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 13 years ago
parent 1aeae661af
commit a11d8c3dda

@ -14,7 +14,7 @@
* *
* File: create-domain.php * File: create-domain.php
* Allows administrators to create new domains. * Allows administrators to create new domains.
* Template File: admin_create-domain.tpl * Template File: admin_edit-domain.tpl
* *
* Template Variables: * Template Variables:
* *
@ -48,8 +48,8 @@ $form_fields = array(
'fMaxquota' => array('type' => 'int', 'default' => $CONF['maxquota']), 'fMaxquota' => array('type' => 'int', 'default' => $CONF['maxquota']),
'fDomainquota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']), 'fDomainquota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']),
'fTransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']), 'fTransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']),
'fDefaultaliases' => array('type' => 'bool', 'default' => 'on', 'options' => array('on', 'off')), 'fDefaultaliases' => array('type' => 'bool', 'default' => '1', 'options' => array(1, 0)),
'fBackupmx' => array('type' => 'bool', 'default' => 'off', 'options' => array('on', 'off')) 'fBackupmx' => array('type' => 'bool', 'default' => '0', 'options' => array(1, 0))
); );
$fDefaultaliases = ""; $fDefaultaliases = "";
@ -58,7 +58,7 @@ $tDefaultaliases = "";
# TODO: this foreach block should only be executed for POST # TODO: this foreach block should only be executed for POST
foreach($form_fields as $key => $default) { foreach($form_fields as $key => $default) {
if($default['type'] == 'bool' && $_SERVER['REQUEST_METHOD'] == "POST") { if($default['type'] == 'bool' && $_SERVER['REQUEST_METHOD'] == "POST") {
$$key = escape_string(safepost($key, 'off')); # isset for unchecked checkboxes is always false $$key = escape_string(safepost($key, 0)); # isset for unchecked checkboxes is always false
} }
elseif (isset($_POST[$key]) && (strlen($_POST[$key]) > 0)) { elseif (isset($_POST[$key]) && (strlen($_POST[$key]) > 0)) {
$$key = escape_string($_POST[$key]); $$key = escape_string($_POST[$key]);
@ -79,8 +79,6 @@ foreach($form_fields as $key => $default) {
} }
} }
$fDomain = strtolower($fDomain);
if ($_SERVER['REQUEST_METHOD'] == "GET") if ($_SERVER['REQUEST_METHOD'] == "GET")
{ {
/* default values as set above */ /* default values as set above */
@ -96,8 +94,9 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
if ($_SERVER['REQUEST_METHOD'] == "POST") if ($_SERVER['REQUEST_METHOD'] == "POST")
{ {
$tBackupmx = ""; $tBackupmx = "";
if ($fDomain == null or domain_exist($fDomain) or !check_domain($fDomain))
{ $handler = new DomainHandler($fDomain, 1);
if (!$handler->result()) {
$error = 1; $error = 1;
$tDomain = $fDomain; $tDomain = $fDomain;
$tDescription = $fDescription; $tDescription = $fDescription;
@ -108,8 +107,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if (isset ($_POST['fTransport'])) $tTransport = $fTransport; if (isset ($_POST['fTransport'])) $tTransport = $fTransport;
if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = $fDefaultaliases; if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = $fDefaultaliases;
if (isset ($_POST['fBackupmx'])) $tBackupmx = $fBackupmx; if (isset ($_POST['fBackupmx'])) $tBackupmx = $fBackupmx;
$pAdminCreate_domain_domain_text_error = $PALANG['pAdminCreate_domain_domain_text_error2']; $pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
if (domain_exist ($fDomain)) $pAdminCreate_domain_domain_text_error = $PALANG['pAdminCreate_domain_domain_text_error'];
} }
if ($error != 1) if ($error != 1)
@ -119,38 +117,29 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$tMaxquota = $CONF['maxquota']; $tMaxquota = $CONF['maxquota'];
$tDomainquota = $CONF['domain_quota_default']; $tDomainquota = $CONF['domain_quota_default'];
if ($fBackupmx == "on") $values = array(
{ 'description' => $fDescription,
$fBackupmx = 1; 'aliases' => $fAliases,
$sqlBackupmx = db_get_boolean(true); 'mailboxes' => $fMailboxes,
} 'maxquota' => $fMaxquota,
else 'quota' => $fDomainquota,
{ 'transport' => $fTransport,
$fBackupmx = 0; 'backupmx' => $fBackupmx,
$sqlBackupmx = db_get_boolean(false); 'active' => 1, # hardcoded for now - TODO: change this ;-)
} 'default_aliases' => $fDefaultaliases,
);
$sql_query = "INSERT INTO $table_domain (domain,description,aliases,mailboxes,maxquota,quota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,$fDomainquota,'$fTransport','$sqlBackupmx',NOW(),NOW())"; if (!$handler->set($values)) {
$result = db_query($sql_query); $pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
if ($result['rows'] != 1) } else {
{ if (!$handler->store()) {
$pAdminCreate_domain_domain_text_error = $PALANG['pAdminCreate_domain_result_error'] . "<br />($fDomain)"; # TODO: remove a sprintf string $pAdminCreate_domain_domain_text_error = join("\n", $handler->errormsg);
} } else {
else flash_info($PALANG['pAdminCreate_domain_result_success'] . " ($fDomain)"); # TODO: use a sprintf string
{ if (count($handler->errormsg)) { # might happen if domain_postcreation fails
if ($fDefaultaliases == "on") flash_error(join("<br />", $handler->errormsg));
{
foreach ($CONF['default_aliases'] as $address=>$goto)
{
$address = $address . "@" . $fDomain;
$result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified) VALUES ('$address','$goto','$fDomain',NOW(),NOW())");
} }
} }
flash_info($PALANG['pAdminCreate_domain_result_success'] . "<br />($fDomain)"); # TODO: use a sprintf string
}
if (!domain_postcreation($fDomain))
{
flash_error($PALANG['pAdminCreate_domain_error']);
} }
} }
} }
@ -166,8 +155,8 @@ $smarty->assign ('tMailboxes', $tMailboxes);
$smarty->assign ('tDomainquota', $tDomainquota); $smarty->assign ('tDomainquota', $tDomainquota);
$smarty->assign ('tMaxquota', $tMaxquota,false); # TODO: why is sanitize disabled? Should be just integer... $smarty->assign ('tMaxquota', $tMaxquota,false); # TODO: why is sanitize disabled? Should be just integer...
$smarty->assign ('select_options', select_options ($CONF ['transport_options'], array ($tTransport)),false); $smarty->assign ('select_options', select_options ($CONF ['transport_options'], array ($tTransport)),false);
$smarty->assign ('tDefaultaliases', ($tDefaultaliases == 'on') ? ' checked="checked"' : ''); $smarty->assign ('tDefaultaliases', ($tDefaultaliases == '1') ? ' checked="checked"' : '');
$smarty->assign ('tBackupmx', ($tBackupmx == 'on') ? ' checked="checked"' : ''); $smarty->assign ('tBackupmx', ($tBackupmx == '1') ? ' checked="checked"' : '');
$smarty->assign ('smarty_template', 'admin_edit-domain'); $smarty->assign ('smarty_template', 'admin_edit-domain');
$smarty->display ('index.tpl'); $smarty->display ('index.tpl');

@ -74,10 +74,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
} }
} }
if (isset ($_POST['fBackupmx'])) $fBackupmx = escape_string ($_POST['fBackupmx']); if (isset ($_POST['fBackupmx'])) $fBackupmx = (int) escape_string ($_POST['fBackupmx']);
if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']); if (isset ($_POST['fActive'])) $fActive = (int) escape_string ($_POST['fActive']);
if ($fBackupmx == "on") if ($fBackupmx == 1)
{ {
$fBackupmx = 1; $fBackupmx = 1;
$sqlBackupmx = db_get_boolean(True); $sqlBackupmx = db_get_boolean(True);
@ -88,7 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$sqlBackupmx = db_get_boolean(False); $sqlBackupmx = db_get_boolean(False);
} }
if ($fActive == "on") { if ($fActive == 1) {
$sqlActive = db_get_boolean(True); $sqlActive = db_get_boolean(True);
} }
else { else {

@ -66,14 +66,14 @@
{if $mode == 'create'} {if $mode == 'create'}
<tr> <tr>
<td class="label"><label>{$PALANG.pAdminCreate_domain_defaultaliases}:</label></td> <td class="label"><label>{$PALANG.pAdminCreate_domain_defaultaliases}:</label></td>
<td><input class="flat" type="checkbox" value='on' name="fDefaultaliases"{$tDefaultaliases}/></td> <td><input class="flat" type="checkbox" value='1' name="fDefaultaliases"{$tDefaultaliases}/></td>
<td>{$PALANG.pAdminCreate_domain_defaultaliases_text}</td> <td>{$PALANG.pAdminCreate_domain_defaultaliases_text}</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
{/if} {/if}
<tr> <tr>
<td class="label"><label>{$PALANG.pAdminEdit_domain_backupmx}:</label></td> <td class="label"><label>{$PALANG.pAdminEdit_domain_backupmx}:</label></td>
<td><input class="flat" type="checkbox" value='on' name="fBackupmx"{$tBackupmx}/></td> <td><input class="flat" type="checkbox" value='1' name="fBackupmx"{$tBackupmx}/></td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
@ -81,7 +81,7 @@
<!-- TODO: create should also offer the 'active' option --> <!-- TODO: create should also offer the 'active' option -->
<tr> <tr>
<td class="label"><label>{$PALANG.pAdminEdit_domain_active}:</label></td> <td class="label"><label>{$PALANG.pAdminEdit_domain_active}:</label></td>
<td><input class="flat" type="checkbox" name="fActive"{$tActive}/></td> <td><input class="flat" type="checkbox" value='1' name="fActive"{$tActive}/></td>
<td colspan="2">&nbsp;</td> <td colspan="2">&nbsp;</td>
</tr> </tr>
{/if} {/if}

Loading…
Cancel
Save