From b4823b9e041344b191060fe49efbacb91a250e21 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Tue, 19 Feb 2013 23:08:01 +0000 Subject: [PATCH] Finally replace create-mailbox.php with edit.php?table=mailbox :-) configs/menu.conf: - change url_create_mailbox to edit.php?table=mailbox templates/list-virtual.tpl: - replace hardcoded create-mailbox.php with {#url_create_mailbox#} functions.inc.php: - delete functions that are now part of MailboxHandler: - check_mailbox() - multiply_quota() - add some TODO notes config.inc.php: - rewrite a comment that referenced create-mailbox.php create-mailbox.php: - delete - no longer needed git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1433 a1433add-5e2c-0410-b055-b7f2511e0802 --- config.inc.php | 2 +- configs/menu.conf | 2 +- create-mailbox.php | 260 ------------------------------------- functions.inc.php | 39 +----- templates/list-virtual.tpl | 2 +- 5 files changed, 8 insertions(+), 297 deletions(-) delete mode 100644 create-mailbox.php diff --git a/config.inc.php b/config.inc.php index 9d57f5ff..bba30ae1 100644 --- a/config.inc.php +++ b/config.inc.php @@ -210,7 +210,7 @@ $CONF['maildir_name_hook'] = 'NO'; /* maildir_name_hook example function - Called by create-mailbox.php if $CONF['maildir_name_hook'] == '' + Called when creating a mailbox if $CONF['maildir_name_hook'] == '' - allows for customized maildir paths determined by a custom function - the example below will prepend a single-character directory to the beginning of the maildir, splitting domains more or less evenly over diff --git a/configs/menu.conf b/configs/menu.conf index e6692129..eebdcf49 100644 --- a/configs/menu.conf +++ b/configs/menu.conf @@ -7,7 +7,7 @@ url_list_domain = list-domain.php url_edit_domain = edit.php?table=domain # list-virtual url_list_virtual = list-virtual.php -url_create_mailbox = create-mailbox.php? +url_create_mailbox = edit.php?table=mailbox url_create_alias = edit.php?table=alias url_create_alias_domain = edit.php?table=aliasdomain # fetchmail diff --git a/create-mailbox.php b/create-mailbox.php deleted file mode 100644 index 2a6c3da7..00000000 --- a/create-mailbox.php +++ /dev/null @@ -1,260 +0,0 @@ - 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: */ -?> diff --git a/functions.inc.php b/functions.inc.php index d8d50efe..761d6093 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -581,34 +581,13 @@ function get_mailbox_properties ($username) { -// -// check_mailbox -// Action: Checks if the domain is still able to create mailboxes. -// Call: check_mailbox (string domain) -// -function check_mailbox ($domain) { - $limit = get_domain_properties ($domain); - /* -1 = disable, 0 = unlimited */ - if ($limit['mailboxes'] == 0) { - return true; - } - if ($limit['mailboxes'] < 0) { - return false; - } - if ($limit['mailbox_count'] >= $limit['mailboxes']) { - return false; - } else { - return true; - } -} - - - // // check_quota // Action: Checks if the user is creating a mailbox with the correct quota // Call: check_quota (string domain) // +# TODO: move to MailboxHandler +# TODO: merge with allowed_quota? function check_quota ($quota, $domain, $username="") { global $CONF; $rval = false; @@ -687,17 +666,6 @@ function allowed_quota($domain, $current_user_quota) { } -// -// multiply_quota -// Action: Recalculates the quota from bytes to MBs (multiply, *) -// Call: multiply_quota (string $quota) -// -function multiply_quota ($quota) { - global $CONF; - if ($quota == -1) return $quota; - $value = $quota * $CONF['quota_multiplier']; - return $value; -} @@ -1822,6 +1790,9 @@ function table_by_key ($table_key) { Called after a mailbox has been created in the DBMS. Returns: boolean. */ +# TODO: move to MailboxHandler +# TODO: use Config::read instead of $CONF +# TODO: replace "print" with $this->errormsg (or infomsg?) function mailbox_postcreation($username,$domain,$maildir,$quota) { if (empty($username) || empty($domain) || empty($maildir)) { trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR); diff --git a/templates/list-virtual.tpl b/templates/list-virtual.tpl index 9f318d95..548f3d40 100644 --- a/templates/list-virtual.tpl +++ b/templates/list-virtual.tpl @@ -64,7 +64,7 @@ {/if} {$nav_bar_mailbox.bottom} {if $tCanAddMailbox} -
{$PALANG.pMenu_create_mailbox}
+
{$PALANG.pMenu_create_mailbox}
{/if} {/if} {if $CONF.show_status===YES && $CONF.show_status_key===YES}