@ -15,24 +15,6 @@
* File: create-domain.php
* Allows administrators to create new domains.
* Template File: admin_edit-domain.tpl
*
* Template Variables:
*
* tDomain
* tDescription
* tAliases
* tMailboxes
* tMaxquota
* tDefaultaliases
*
* Form POST \ GET Variables:
*
* fDomain
* fDescription
* fAliases
* fMailboxes
* fMaxquota
* fDefaultaliases
*/
require_once('common.php');
@ -40,123 +22,86 @@ require_once('common.php');
authentication_require_role('global-admin');
$error = 0;
$form_fields = array(
'fDomain' => array('type' => 'str', 'default' => null),
'fD escription' => array('type' => 'str', 'default' =>''),
'fA liases' => array('type' => 'int', 'default' => $CONF['aliases']),
'fM ailboxes' => array('type' => 'int', 'default' => $CONF['mailboxes']),
'fM axquota' => array('type' => 'int', 'default' => $CONF['maxquota']),
'fDomain quota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']),
'fT ransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']),
'fDefaultaliases' => array('type' => 'bool', 'default' => '1', 'options' => array(1, 0)),
'fB ackupmx' => array('type' => 'bool', 'default' => '0', 'options' => array(1, 0))
'd omain' => array('type' => 'str', 'default' => null),
'd escription' => array('type' => 'str', 'default' =>''),
'a liases' => array('type' => 'int', 'default' => $CONF['aliases']),
'm ailboxes' => array('type' => 'int', 'default' => $CONF['mailboxes']),
'm axquota' => array('type' => 'int', 'default' => $CONF['maxquota']),
'quota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']),
't ransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']),
'default_aliases' => array('type' => 'bool', 'default' => '1', 'options' => array(1, 0)),
'b ackupmx' => array('type' => 'bool', 'default' => '0', 'options' => array(1, 0))
);
$fDefaultaliases = "";
$tDefaultaliases = "";
# TODO: this foreach block should only be executed for POST
foreach($form_fields as $key => $default ) {
if($default ['type'] == 'bool' & & $_SERVER['REQUEST_METHOD'] == "POST") {
$$key = escape_string( safepost($key, 0) ); # isset for unchecked checkboxes is always false
foreach($form_fields as $key => $field) {
if($field['type'] == 'bool' & & $_SERVER['REQUEST_METHOD'] == "POST") {
$values[ $key] = safepost($key, 0); # isset for unchecked checkboxes is always false
}
elseif (isset($_POST[$key]) & & (strlen($_POST[$key]) > 0)) {
$$key = escape_string($_POST[$key] );
$values[$key] = safepost($key );
}
else {
$$key = $default['default'];
}
if($default['type'] == 'int') {
$$key = intval($$key);
}
if($default['type'] == 'str') {
$$key = strip_tags($$key); /* should we even bother? */
$values[$key] = $field['default'];
}
if(isset($default['options'])) {
if(!in_array($$key, $default['options'])) {
# TODO: check via _inp_enum in *Handler
if(isset($field['options'])) {
if(!in_array($values[$key], $field['options'])) {
die("Invalid parameter given for $key");
}
}
}
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
/* default values as set above */
$tTransport = $fTransport;
$tAliases = $fAliases;
$tMaxquota = $fMaxquota;
$tDomainquota = $fDomainquota;
$tMailboxes = $fMailboxes;
$tDefaultaliases = $fDefaultaliases;
$tBackupmx = $fBackupmx;
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$tBackupmx = "";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$handler = new DomainHandler($fDomain , 1);
$handler = new DomainHandler($values['domain'], 1);
if (!$handler->result()) {
$error = 1;
$tDomain = $fDomain;
$tDescription = $fDescription;
$tAliases = $fAliases;
$tMailboxes = $fMailboxes;
if (isset ($_POST['fMaxquota'])) $tMaxquota = $fMaxquota;
if (isset ($_POST['fDomainquota'])) $tDomainquota = $fDomainquota;
if (isset ($_POST['fTransport'])) $tTransport = $fTransport;
if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = $fDefaultaliases;
if (isset ($_POST['fBackupmx'])) $tBackupmx = $fBackupmx;
$pAdminCreate_domain_domain_text_error = join("< br / > ", $handler->errormsg);
}
if ($error != 1)
{
$tAliases = $CONF['aliases'];
$tMailboxes = $CONF['mailboxes'];
$tMaxquota = $CONF['maxquota'];
$tDomainquota = $CONF['domain_quota_default'];
$values = array(
'description' => $fDescription,
'aliases' => $fAliases,
'mailboxes' => $fMailboxes,
'maxquota' => $fMaxquota,
'quota' => $fDomainquota,
'transport' => $fTransport,
'backupmx' => $fBackupmx,
'active' => 1, # hardcoded for now - TODO: change this ;-)
'default_aliases' => $fDefaultaliases,
);
if (!$handler->set($values)) {
$values['active'] = 1; # hardcoded for now - TODO: change this ;-)
if (!$handler->set($values)) {
$error = 1;
$pAdminCreate_domain_domain_text_error = join("< br / > ", $handler->errormsg);
}
if ($error != 1) {
if (!$handler->store()) {
$pAdminCreate_domain_domain_text_error = join("\n", $handler->errormsg);
} else {
if (!$handler->store()) {
$pAdminCreate_domain_domain_text_error = join("\n", $handler->errormsg);
} else {
flash_info($PALANG['pAdminCreate_domain_result_success'] . " ($fDomain)"); # TODO: use a sprintf string
if (count($handler->errormsg)) { # might happen if domain_postcreation fails
flash_error(join("< br / > ", $handler->errormsg));
}
flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values['domain'] . ")"); # TODO: use a sprintf string
if (count($handler->errormsg)) { # might happen if domain_postcreation fails
flash_error(join("< br / > ", $handler->errormsg));
}
}
}
}
if ($error != 1) {
$values = array();
foreach (array_keys($form_fields) as $key) {
$values[$key] = $form_fields[$key]['default'];
}
}
$smarty->assign ('mode', 'create');
$smarty->assign ('tDomain', $tDomain);
$smarty->assign ('pAdminCreate_domain_domain_text', $pAdminCreate_domain_domain_text, false);
$smarty->assign ('pAdminCreate_domain_domain_text_error', $pAdminCreate_domain_domain_text_error, false);
$smarty->assign ('tDescription', $tDescription, false);
$smarty->assign ('tAliases', $tAliases);
$smarty->assign ('tMailboxes', $tMailboxes);
$smarty->assign ('tDomainquota', $tDomainquota);
$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 ('tDefaultaliases', ($tDefaultaliases == '1') ? ' checked="checked"' : '');
$smarty->assign ('tBackupmx', ($tBackupmx == '1') ? ' checked="checked"' : '');
$smarty->assign ('tDomain', $values['domain']);
$smarty->assign ('tDescription', $values['description']);
$smarty->assign ('tAliases', $values['aliases']);
$smarty->assign ('tMailboxes', $values['mailboxes']);
$smarty->assign ('tDomainquota', $values['quota']);
$smarty->assign ('tMaxquota', $values['maxquota']);
$smarty->assign ('select_options', select_options ($form_fields['transport']['options'], array ($values['transport'])),false);
$smarty->assign ('tDefaultaliases', ($values['default_aliases'] == '1') ? ' checked="checked"' : '');
$smarty->assign ('tBackupmx', ($values['backupmx'] == '1') ? ' checked="checked"' : '');
$smarty->assign ('smarty_template', 'admin_edit-domain');
$smarty->display ('index.tpl');