0) {
$pCreate_mailbox_password_text_error = $validpass[0]; # TODO: honor all error messages, not only the first one
$error = 1;
}
}
if ($CONF['quota'] == "YES")
{
if (!check_quota ($fQuota, $fDomain))
{
$error = 1;
$pCreate_mailbox_quota_text_error = $PALANG['pCreate_mailbox_quota_text_error'];
}
}
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
if ($result['rows'] == 1)
{
$error = 1;
$pCreate_mailbox_username_text_error = $PALANG['pCreate_mailbox_username_text_error2'];
}
if ($error != 0) {
$tUsername = escape_string ($_POST['fUsername']);
$tName = $fName;
$tQuota = $fQuota;
$tDomain = $fDomain;
} else {
$password = escape_string(pacrypt ($fPassword));
if($CONF['maildir_name_hook'] != 'NO' && function_exists($CONF['maildir_name_hook'])) {
$hook_func = $CONF['maildir_name_hook'];
$maildir = $hook_func ($fDomain, $fUsername);
}
else if ($CONF['domain_path'] == "YES")
{
if ($CONF['domain_in_mailbox'] == "YES")
{
$maildir = $fDomain . "/" . $fUsername . "/";
}
else
{
$maildir = $fDomain . "/" . escape_string (strtolower($_POST['fUsername'])) . "/";
}
}
else
{
$maildir = $fUsername . "/";
}
if (!empty ($fQuota))
{
$quota = multiply_quota ($fQuota);
}
else
{
$quota = 0;
}
if ($fActive == "on")
{
$sqlActive = db_get_boolean(True);
}
else
{
$sqlActive = db_get_boolean(False);
}
if ('pgsql'==$CONF['database_type'])
{
db_query('BEGIN');
}
$result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$sqlActive')");
if ($result['rows'] != 1)
{
$tDomain = $fDomain;
flash_error($PALANG['pAlias_result_error'] . "
($fUsername -> $fUsername)");
}
// apparently uppercase usernames really confuse some IMAP clients.
$fUsername = strtolower($fUsername);
$local_part = '';
if(preg_match('/^(.*)@/', $fUsername, $matches)) {
$local_part = $matches[1];
}
$result = db_query ("INSERT INTO $table_mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$local_part','$quota','$fDomain',NOW(),NOW(),'$sqlActive')");
if ($result['rows'] != 1 || !mailbox_postcreation($fUsername,$fDomain,$maildir, $quota))
{
$tDomain = $fDomain;
flash_error($PALANG['pCreate_mailbox_result_error'] . "
($fUsername)");
db_query('ROLLBACK');
}
else
{
db_query('COMMIT');
db_log ($fDomain, 'create_mailbox', "$fUsername");
$tDomain = $fDomain;
$tQuota = allowed_quota($tDomain, 0);
if ($fMail == "on")
{
$fTo = $fUsername;
$fFrom = smtp_get_admin_email();
$fSubject = $PALANG['pSendmail_subject_text'];
$fBody = $CONF['welcome_text'];
if (!smtp_mail ($fTo, $fFrom, $fSubject, $fBody))
{
flash_error($PALANG['pSendmail_result_error']);
}
else
{
flash_info($PALANG['pSendmail_result_success']);
}
}
$tShowpass = "";
if ( $tPassGenerated == 1 || $CONF['show_password'] == "YES") $tShowpass = " / $fPassword";
if (create_mailbox_subfolders($fUsername,$fPassword))
{
flash_info($PALANG['pCreate_mailbox_result_success'] . "
($fUsername$tShowpass)");
} else {
flash_info($PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "
($fUsername$tShowpass)");
}
}
}
}
$smarty->assign ('mode', 'create');
$smarty->assign ('tUsername', $tUsername);
$smarty->assign ('tActive', ' checked="checked" '); # TODO: use form value if POST
$smarty->assign ('select_options', select_options ($list_domains, array ($tDomain)), false);
$smarty->assign ('pCreate_mailbox_username_text_error', $pCreate_mailbox_username_text_error, false);
$smarty->assign ('mailbox_password_text_error', $pCreate_mailbox_password_text_error, false);
$smarty->assign ('tName', $tName, false);
$smarty->assign ('tQuota', $tQuota);
$smarty->assign ('mailbox_quota_text_error', $pCreate_mailbox_quota_text_error, false);
$smarty->assign ('smarty_template', 'edit-mailbox');
$smarty->display ('index.tpl');
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
?>