add EmailAccounts.add; added wrapper function ApiCommand.getMailTemplate() to reduce code-duplication

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-12 13:44:44 +01:00
parent 2e597ef7d9
commit 6fc8cce8f5
6 changed files with 74 additions and 284 deletions

View File

@@ -589,25 +589,17 @@ class Customers extends ApiCommand implements ResourceEntity
'DOMAINNAME' => $_stdsubdomain
);
// Get mail templates from database; the ones from 'admin' are fetched for fallback
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `language` = :deflang AND `templategroup` = 'mails' AND `varname` = 'createcustomer_subject'");
$result = Database::pexecute_first($result_stmt, array(
// get template for mail subject
$mail_subject = $this->getMailTemplate(array(
'adminid' => $this->getUserDetail('adminid'),
'deflang' => $def_language
), true, true);
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['createcustomer']['subject']), $replace_arr));
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `language` = :deflang AND `templategroup` = 'mails' AND `varname` = 'createcustomer_mailbody'");
$result = Database::pexecute_first($result_stmt, array(
'def_language' => $def_language
), 'mails', 'createcustomer_subject', $replace_arr, $this->lng['mails']['createcustomer']['subject']);
// get template for mail body
$mail_body = $this->getMailTemplate(array(
'adminid' => $this->getUserDetail('adminid'),
'deflang' => $def_language
), true, true);
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['createcustomer']['mailbody']), $replace_arr));
'def_language' => $def_language
), 'mails', 'createcustomer_mailbody', $replace_arr, $this->lng['mails']['createcustomer']['mailbody']);
$_mailerror = false;
try {
$this->mailer()->Subject = $mail_subject;
@@ -665,7 +657,7 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
@@ -921,7 +913,7 @@ class Customers extends ApiCommand implements ResourceEntity
// At last flush the new privileges
$dbm->getManager()->flushPrivileges();
Database::needRoot(false);
// reactivate/deactivate api-keys
$valid_until = $deactivated ? 0 : - 1;
$stmt = Database::prepare("UPDATE `" . TABLE_API_KEYS . "` SET `valid_until` = :vu WHERE `customerid` = :id");
@@ -929,7 +921,7 @@ class Customers extends ApiCommand implements ResourceEntity
'id' => $id,
'vu' => $valid_until
), true, true);
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] " . ($deactivated ? 'deactivated' : 'reactivated') . " user '" . $result['loginname'] . "'");
inserttask('1');
}
@@ -1164,7 +1156,7 @@ class Customers extends ApiCommand implements ResourceEntity
}
}
}
$result = $this->apiCall('Customers.get', array(
'id' => $result['customerid']
));
@@ -1192,7 +1184,7 @@ class Customers extends ApiCommand implements ResourceEntity
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$delete_userfiles = $this->getParam('delete_userfiles', true, 0);
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
@@ -1331,7 +1323,7 @@ class Customers extends ApiCommand implements ResourceEntity
Database::pexecute($stmt, array(
'id' => $id
), true, true);
// Delete all waiting "create user" -tasks for this user, #276
// Note: the WHERE selects part of a serialized array, but it should be safe this way
$del_stmt = Database::prepare("
@@ -1438,7 +1430,7 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
@@ -1482,7 +1474,7 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$c_result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
@@ -1530,7 +1522,7 @@ class Customers extends ApiCommand implements ResourceEntity
updateCounters(false);
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] moved user '" . $c_result['loginname'] . "' from admin/reseller '" . $c_result['adminname'] . " to admin/reseller '" . $a_result['loginname'] . "'");
$result = $this->apiCall('Customers.get', array(
'id' => $c_result['customerid']
));

View File

@@ -332,8 +332,6 @@ class Emails extends ApiCommand implements ResourceEntity
if ($result['destination'] != '') {
$result['destination'] = explode(' ', $result['destination']);
$number_forwarders = count($result['destination']);
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
Admins::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
}
// check whether this address is an account
if ($result['popaccountid'] != 0) {
@@ -357,8 +355,13 @@ class Emails extends ApiCommand implements ResourceEntity
Customers::decreaseUsage($customer['customerid'], 'email_accounts_used');
Admins::decreaseUsage($customer['customerid'], 'email_accounts_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email account '" . $result['email_full'] . "'");
$number_forwarders --;
}
// decrease forwarder counter
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
Admins::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
if ($delete_userfiles) {
inserttask('7', $customer['loginname'], $result['email_full']);
}

View File

@@ -189,36 +189,11 @@ class Ftps extends ApiCommand implements ResourceEntity
'USR_PASS' => $password,
'USR_PATH' => makeCorrectDir(str_replace($customer['documentroot'], "/", $path))
);
$def_language = $customer['def_language'];
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid
AND `language` = :lang
AND `templategroup`='mails'
AND `varname`='new_ftpaccount_by_customer_subject'
");
Database::pexecute($result_stmt, array(
"adminid" => $customer['adminid'],
"lang" => $def_language
));
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['new_ftpaccount_by_customer']['subject']), $replace_arr));
$def_language = $customer['def_language'];
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid
AND `language` = :lang
AND `templategroup`='mails'
AND `varname`='new_ftpaccount_by_customer_mailbody'");
Database::pexecute($result_stmt, array(
"adminid" => $customer['adminid'],
"lang" => $def_language
));
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['new_ftpaccount_by_customer']['mailbody']), $replace_arr));
// get template for mail subject
$mail_subject = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_subject', $replace_arr, $this->lng['mails']['new_ftpaccount_by_customer']['subject']);
// get template for mail body
$mail_body = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_mailbody', $replace_arr, $this->lng['mails']['new_ftpaccount_by_customer']['mailbody']);
$_mailerror = false;
try {
$this->mailer()->Subject = $mail_subject;

View File

@@ -131,34 +131,12 @@ class Mysqls extends ApiCommand implements ResourceEntity
'DB_SRV' => $sql_root['host'],
'PMA_URI' => $pma
);
$def_language = $userinfo['def_language'];
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid
AND `language` = :lang
AND `templategroup`='mails'
AND `varname`='new_database_by_customer_subject'
");
$result = Database::pexecute_first($result_stmt, array(
"adminid" => $userinfo['adminid'],
"lang" => $def_language
), true, true);
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['new_database_by_customer']['subject']), $replace_arr));
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid`= :adminid
AND `language`= :lang
AND `templategroup` = 'mails'
AND `varname` = 'new_database_by_customer_mailbody'
");
$result = Database::pexecute_first($result_stmt, array(
"adminid" => $userinfo['adminid'],
"lang" => $def_language
));
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['new_database_by_customer']['mailbody']), $replace_arr));
// get template for mail subject
$mail_subject = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_subject', $replace_arr, $this->lng['mails']['new_database_by_customer']['subject']);
// get template for mail body
$mail_body = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_mailbody', $replace_arr, $this->lng['mails']['new_database_by_customer']['mailbody']);
$_mailerror = false;
try {
$this->mail->Subject = $mail_subject;