some code-reduction
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -69,21 +69,8 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
standard_error('destinationalreadyexist', $destination, true);
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the email-address-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customerid');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the mail-forwarder added
|
||||
if ($customer['email_forwarders_used'] >= $customer['email_forwarders'] && $customer['email_forwarders'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
// get needed customer info to reduce the email-forwarder-counter by one
|
||||
$customer = $this->getCustomerData('email_forwarders');
|
||||
|
||||
// add destination to address
|
||||
$result['destination'] .= ' ' . $destination;
|
||||
@@ -93,13 +80,13 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$params = array(
|
||||
"dest" => makeCorrectDestination($result['destination']),
|
||||
"cid" => $customer_id,
|
||||
"cid" => $customer['customerid'],
|
||||
"id" => $id
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer_id, 'email_forwarders_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'email_forwarders_used');
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($customer['adminid'], 'email_forwarders_used');
|
||||
@@ -169,17 +156,8 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
$result['destination'] = explode(' ', $result['destination']);
|
||||
if (isset($result['destination'][$forwarderid]) && $result['email'] != $result['destination'][$forwarderid]) {
|
||||
|
||||
// get needed customer info to reduce the email-address-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
// get needed customer info to reduce the email-forwarder-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
// get specific forwarder
|
||||
$forwarder = $result['destination'][$forwarderid];
|
||||
@@ -207,7 +185,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
|
||||
// update customer usage
|
||||
Customers::decreaseUsage($customer_id, 'email_forwarders_used');
|
||||
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used');
|
||||
|
||||
// update admin usage
|
||||
Admins::decreaseUsage($customer['adminid'], 'email_forwarders_used');
|
||||
|
||||
@@ -85,20 +85,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the email-address-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customerid');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the mail-address added
|
||||
if ($customer['emails_used'] >= $customer['emails'] && $customer['emails'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData('emails');
|
||||
|
||||
// duplicate check
|
||||
$stmt = Database::prepare("
|
||||
@@ -138,7 +125,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
$address_id = Database::lastInsertId();
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer_id, 'emails_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'emails_used');
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($customer['adminid'], 'emails_used');
|
||||
@@ -236,16 +223,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
$iscatchall = $this->getParam('iscatchall', true, $result['iscatchall']);
|
||||
|
||||
// get needed customer info to reduce the email-address-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customerid');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
// check for catchall-flag
|
||||
if ($iscatchall) {
|
||||
@@ -348,16 +326,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
$delete_userfiles = $this->getParam('delete_userfiles', true, 0);
|
||||
|
||||
// get needed customer info to reduce the email-address-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customerid');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
// check for forwarders
|
||||
$number_forwarders = 0;
|
||||
@@ -373,7 +342,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
if (Settings::Get('system.mail_quota_enabled') == 1) {
|
||||
$stmt = Database::prepare("SELECT `quota` FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :customerid AND `id`= :id");
|
||||
$res_quota = Database::pexecute_first($stmt, array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"id" => $result['popaccountid']
|
||||
), true, true);
|
||||
Customers::decreaseUsage($customer['customerid'], 'email_quota_used', '', $res_quota['quota']);
|
||||
@@ -383,7 +352,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
// delete account
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :customerid AND `id`= :id");
|
||||
Database::pexecute($stmt, array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"id" => $result['popaccountid']
|
||||
), true, true);
|
||||
Customers::decreaseUsage($customer['customerid'], 'email_accounts_used');
|
||||
@@ -398,7 +367,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
// delete address
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `id`= :id");
|
||||
Database::pexecute($stmt, array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"id" => $id
|
||||
), true, true);
|
||||
Customers::decreaseUsage($customer['customerid'], 'emails_used');
|
||||
|
||||
@@ -83,20 +83,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
|
||||
$params = array();
|
||||
// get needed customer info to reduce the ftp-user-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the ftp-user added
|
||||
if ($customer['ftps_used'] >= $customer['ftps'] && $customer['ftps'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData('ftps');
|
||||
|
||||
if ($sendinfomail != 1) {
|
||||
$sendinfomail = 0;
|
||||
@@ -114,7 +101,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
AND `customerid` = :customerid");
|
||||
$ftpdomain_check = Database::pexecute_first($ftpdomain_check_stmt, array(
|
||||
"domain" => $ftpdomain,
|
||||
"customerid" => $customer_id
|
||||
"customerid" => $customer['customerid']
|
||||
), true, true);
|
||||
|
||||
if ($ftpdomain_check && $ftpdomain_check['domain'] != $ftpdomain) {
|
||||
@@ -144,7 +131,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
(`customerid`, `username`, `description`, `password`, `homedir`, `login_enabled`, `uid`, `gid`, `shell`)
|
||||
VALUES (:customerid, :username, :description, :password, :homedir, 'y', :guid, :guid, :shell)");
|
||||
$params = array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"username" => $username,
|
||||
"description" => $description,
|
||||
"password" => $cryptPassword,
|
||||
@@ -179,14 +166,14 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$params = array(
|
||||
"username" => $username,
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"guid" => $customer['guid']
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer_id, 'ftps_used');
|
||||
Customers::increaseUsage($customer_id, 'ftp_lastaccountnumber');
|
||||
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'ftp_lastaccountnumber');
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($customer['adminid'], 'ftps_used');
|
||||
@@ -360,16 +347,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the ftp-user-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
// password update?
|
||||
if ($password != '') {
|
||||
|
||||
@@ -68,19 +68,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the database added
|
||||
if ($customer['mysqls_used'] >= $customer['mysqls'] && $customer['mysqls'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
}
|
||||
$customer = $this->getCustomerData('mysqls');
|
||||
|
||||
$newdb_params = array(
|
||||
'loginname' => ($this->isAdmin() ? $customer['loginname'] : $this->getUserDetail('loginname')),
|
||||
@@ -105,7 +93,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
`dbserver` = :dbserver
|
||||
");
|
||||
$params = array(
|
||||
"customerid" => ($this->isAdmin() ? $customer['customerid'] : $this->getUserDetail('customerid')),
|
||||
"customerid" => $customer['customerid'],
|
||||
"databasename" => $username,
|
||||
"description" => $databasedescription,
|
||||
"dbserver" => $dbserver
|
||||
@@ -115,8 +103,8 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$params['id'] = $databaseid;
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage(($this->isAdmin() ? $customer['customerid'] : $this->getUserDetail('customerid')), 'mysqls_used');
|
||||
Customers::increaseUsage(($this->isAdmin() ? $customer['customerid'] : $this->getUserDetail('customerid')), 'mysql_lastaccountnumber');
|
||||
Customers::increaseUsage($customer['customerid'], 'mysqls_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'mysql_lastaccountnumber');
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($this->getUserDetail('adminid'), 'mysqls_used');
|
||||
@@ -132,7 +120,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
Database::needSqlData();
|
||||
$sql_root = Database::getSqlData();
|
||||
Database::needRoot(false);
|
||||
$userinfo = ($this->isAdmin() ? $customer : $this->getUserData());
|
||||
$userinfo = $customer;
|
||||
|
||||
$replace_arr = array(
|
||||
'SALUTATION' => getCorrectUserSalutation($userinfo),
|
||||
@@ -351,19 +339,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the database added
|
||||
if ($customer['mysqls_used'] >= $customer['mysqls'] && $customer['mysqls'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
if ($password != '') {
|
||||
// validate password
|
||||
@@ -398,7 +374,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$params = array(
|
||||
"desc" => $databasedescription,
|
||||
"customerid" => ($this->isAdmin() ? $customer['customerid'] : $this->getUserDetail('customerid')),
|
||||
"customerid" => $customer['customerid'],
|
||||
"id" => $id
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
@@ -519,19 +495,12 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
), true, true);
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $result['customerid']
|
||||
));
|
||||
$mysql_used = $customer['mysqls_used'];
|
||||
$customer_id = $customer['customer_id'];
|
||||
} else {
|
||||
$mysql_used = $this->getUserDetail('mysqls_used');
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
$mysql_used = $customer['mysqls_used'];
|
||||
|
||||
// reduce mysql-usage-counter
|
||||
$resetaccnumber = ($mysql_used == '1') ? " , `mysql_lastaccountnumber` = '0' " : '';
|
||||
Customers::decreaseUsage($customer_id, 'mysqls_used', $resetaccnumber);
|
||||
Customers::decreaseUsage($customer['customerid'], 'mysqls_used', $resetaccnumber);
|
||||
// update admin usage
|
||||
Admins::decreaseUsage(($this->isAdmin() ? $customer['adminid'] : $this->getUserDetail('adminid')), 'mysqls_used');
|
||||
|
||||
|
||||
@@ -78,20 +78,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the subdomain-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the subdomain added
|
||||
if ($customer['subdomains_used'] >= $customer['subdomains'] && $customer['subdomains'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData('subdomains');
|
||||
|
||||
// validation
|
||||
if (substr($subdomain, 0, 4) == 'xn--') {
|
||||
@@ -127,7 +114,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$completedomain_check = Database::pexecute_first($completedomain_stmt, array(
|
||||
"domain" => $completedomain,
|
||||
"customerid" => $customer_id
|
||||
"customerid" => $customer['customerid']
|
||||
), true, true);
|
||||
|
||||
if ($completedomain_check) {
|
||||
@@ -153,7 +140,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$aliasdomain_check = Database::pexecute_first($aliasdomain_stmt, array(
|
||||
"id" => $aliasdomain,
|
||||
"customerid" => $customer_id
|
||||
"customerid" => $customer['customerid']
|
||||
), true, true);
|
||||
if ($aliasdomain_check['id'] != $aliasdomain) {
|
||||
standard_error('domainisaliasorothercustomer', '', true);
|
||||
@@ -461,20 +448,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// get needed customer info to reduce the subdomain-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
// get customer id
|
||||
$customer_id = $this->getParam('customer_id');
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $customer_id
|
||||
));
|
||||
// check whether the customer has enough resources to get the subdomain added
|
||||
if ($customer['subdomains_used'] >= $customer['subdomains'] && $customer['subdomains'] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getUserData();
|
||||
}
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
$alias_stmt = Database::prepare("SELECT COUNT(`id`) AS count FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `aliasdomain`= :aliasdomain");
|
||||
$alias_check = Database::pexecute_first($alias_stmt, array(
|
||||
@@ -494,7 +468,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
$aliasdomain_check = Database::pexecute_first($aliasdomain_stmt, array(
|
||||
"id" => $aliasdomain,
|
||||
"customerid" => $customer_id
|
||||
"customerid" => $customer['customerid']
|
||||
), true, true);
|
||||
if ($aliasdomain_check['id'] != $aliasdomain) {
|
||||
standard_error('domainisaliasorothercustomer', '', true);
|
||||
@@ -743,20 +717,13 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
$id = $result['id'];
|
||||
|
||||
// get needed customer info to reduce the subdomain-usage-counter by one
|
||||
if ($this->isAdmin()) {
|
||||
$customer = $this->apiCall('Customers.get', array(
|
||||
'id' => $result['customerid']
|
||||
));
|
||||
$subdomains_used = $customer['subdomains_used'];
|
||||
$customer_id = $customer['customer_id'];
|
||||
} else {
|
||||
if ($result['caneditdomain'] == 0) {
|
||||
throw new Exception("You cannot edit this resource", 405);
|
||||
}
|
||||
$subdomains_used = $this->getUserDetail('subdomains_used');
|
||||
$customer_id = $this->getUserDetail('customerid');
|
||||
$customer = $this->getCustomerData();
|
||||
$subdomains_used = $customer['subdomains_used'];
|
||||
|
||||
if (!$this->isAdmin() && $result['caneditdomain'] == 0) {
|
||||
throw new Exception("You cannot edit this resource", 405);
|
||||
}
|
||||
|
||||
|
||||
if ($result['isemaildomain'] == '1') {
|
||||
// check for e-mail addresses
|
||||
$emails_stmt = Database::prepare("
|
||||
@@ -764,7 +731,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
WHERE `customerid` = :customerid AND `domainid` = :domainid
|
||||
");
|
||||
$emails = Database::pexecute_first($emails_stmt, array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"domainid" => $id
|
||||
), true, true);
|
||||
|
||||
@@ -780,7 +747,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
DELETE FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `customerid` = :customerid AND `id` = :id
|
||||
");
|
||||
Database::pexecute($stmt, array(
|
||||
"customerid" => $customer_id,
|
||||
"customerid" => $customer['customerid'],
|
||||
"id" => $id
|
||||
), true, true);
|
||||
|
||||
@@ -825,7 +792,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
inserttask('4');
|
||||
|
||||
// reduce subdomain-usage-counter
|
||||
Customers::decreaseUsage($customer_id, 'subdomains_used');
|
||||
Customers::decreaseUsage($customer['customerid'], 'subdomains_used');
|
||||
// update admin usage
|
||||
Admins::decreaseUsage(($this->isAdmin() ? $customer['adminid'] : $this->getUserDetail('adminid')), 'subdomains_used');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user