Skip to content

Commit 5a93b73

Browse files
committed
updategs
1 parent e53d18c commit 5a93b73

1 file changed

Lines changed: 26 additions & 28 deletions

File tree

src/api.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ function api_get_license_types()
2626
}
2727

2828
/**
29-
* Cancels one of your Software Licenses of type $type on the given IP $ip
29+
* Cancels one of your Software Licenses of type $service_type on the given IP $ip
3030
*
3131
* @param string $sid Session ID
3232
* @param string $ip IP Address to cancel
33-
* @param int $type Package ID. use [get_license_types](#get-license-types) to get a list of possible types.
33+
* @param int $service_type Package ID. use [get_license_types](#get-license-types) to get a list of possible types.
3434
* @return array
3535
* @throws \Exception
3636
*/
37-
function api_cancel_license_ip($sid, $ip, $type)
37+
function api_cancel_license_ip($sid, $ip, $service_type)
3838
{
39-
$type = (int)$type;
40-
myadmin_log('api', 'info', "api_cancel_license_ip('{$sid}', '{$ip}', {$type}) called", __LINE__, __FILE__);
39+
$service_type = (int)$service_type;
40+
myadmin_log('api', 'info', "api_cancel_license_ip('{$sid}', '{$ip}', {$service_type}) called", __LINE__, __FILE__);
4141
$module = 'licenses';
4242
$GLOBALS['tf']->accounts->set_db_module($module);
4343
$GLOBALS['tf']->history->set_db_module($module);
@@ -76,7 +76,7 @@ function api_cancel_license_ip($sid, $ip, $type)
7676
$return['status_text'] = 'Multiple Matches, Specify Type. ';
7777
while ($db->next_record(MYSQL_ASSOC)) {
7878
$return['status_text'] .= "License ID {$db->Record[$settings['PREFIX'] . '_id']} Type {$db->Record[$settings['PREFIX'] . '_type']} ({$service_types[$db->Record[$settings['PREFIX'] . '_type']]['services_name']}) ";
79-
if ($type != '' && $type == $db->Record[$settings['PREFIX'] . '_type']) {
79+
if ($service_type != '' && $service_type == $db->Record[$settings['PREFIX'] . '_type']) {
8080
// reused code block from below start
8181
$id = $db->Record[$settings['PREFIX'] . '_id'];
8282
function_requirements('cancel_service');
@@ -147,35 +147,35 @@ function_requirements('cancel_service');
147147
}
148148

149149
/**
150-
* Places an order in our system for a software license of type $type on the IP $ip
150+
* Places an order in our system for a software license of type $service_type on the IP $ip
151151
*
152152
* @param string $sid the session id
153153
* @param string $ip ip address you wish to license some software on
154-
* @param int $type the package id of the license type you want. use [get_license_types](#get-license-types) to get a list of possible types.
154+
* @param int $service_type the package id of the license type you want. use [get_license_types](#get-license-types) to get a list of possible types.
155155
* @param string $coupon an optional coupon
156156
* @param null|bool $use_prepay optional, whether or not to use a prepay, if specified as true will return an error if not enough prepay
157157
* @return array
158158
* @throws \Exception
159159
* @throws \SmartyException
160160
*/
161-
function api_buy_license_prepay($sid, $ip, $type, $coupon = '', $use_prepay = null)
161+
function api_buy_license_prepay($sid, $ip, $service_type, $coupon = '', $use_prepay = null)
162162
{
163-
return api_buy_license($sid, $ip, $type, $coupon, $use_prepay);
163+
return api_buy_license($sid, $ip, $service_type, $coupon, $use_prepay);
164164
}
165165

166166
/**
167-
* Places an order in our system for a software license of type $type on the IP $ip
167+
* Places an order in our system for a software license of type $service_type on the IP $ip
168168
*
169169
* @param string $sid the session id
170170
* @param string $ip ip address you wish to license some software on
171-
* @param int $type the package id of the license type you want. use [get_license_types](#get-license-types) to get a list of possible types.
171+
* @param int $service_type the package id of the license type you want. use [get_license_types](#get-license-types) to get a list of possible types.
172172
* @param string $coupon an optional coupon
173173
* @param null|bool $use_prepay optional, whether or not to use a prepay, if specified as true will return an error if not enough prepay
174174
* @return array
175175
* @throws \Exception
176176
* @throws \SmartyException
177177
*/
178-
function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
178+
function api_buy_license($sid, $ip, $service_type, $coupon = '', $use_prepay = null)
179179
{
180180
if (null === $use_prepay) {
181181
$use_prepay = true;
@@ -185,12 +185,12 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
185185
}
186186
$module = 'licenses';
187187
$settings = get_module_settings($module);
188-
$type = (int)$type;
188+
$service_type = (int)$service_type;
189189
$db = get_module_db($module);
190190
$ip = $db->real_escape($ip);
191191
$coupon = $db->real_escape($coupon);
192192
$service_types = run_event('get_service_types', false, $module);
193-
$service_cost = $service_types[$type]['services_cost'];
193+
$service_cost = $service_types[$service_type]['services_cost'];
194194
$service_extra = '';
195195
$frequency = 1;
196196
$return = [];
@@ -233,28 +233,26 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
233233
$return['status_text'] .= "Locked Account.\n";
234234
$continue = false;
235235
}
236-
if (in_array($type, array_keys($int_map)) && in_array($ip_owner, get_internal_ip_owners())) {
236+
if (in_array($service_type, array_keys($int_map)) && in_array($ip_owner, get_internal_ip_owners())) {
237237
$return['status'] = 'error';
238-
$return['status_text'] .= "Your IP appears to be within the {$ip_owner} Network. Because of this your license should be changed to a {$service_types[$int_map[$type]]['services_name']} License. Please submit the updated order form to place the order.\n";
238+
$return['status_text'] .= "Your IP appears to be within the {$ip_owner} Network. Because of this your license should be changed to a {$service_types[$int_map[$service_type]]['services_name']} License. Please submit the updated order form to place the order.\n";
239239
$continue = false;
240240
}
241-
if ($service_types[$type]['services_field2'] != '') {
242-
$valid_blocks = explode(',', $service_types[$type]['services_field2']);
241+
if ($service_types[$service_type]['services_field2'] != '') {
242+
$valid_blocks = explode(',', $service_types[$service_type]['services_field2']);
243243
if (!in_array($ip_owner, $valid_blocks)) {
244244
$return['status'] = 'error';
245-
$return['status_text'] .= "This IP does not appear to be a {$service_types[$type]['services_field2']} IP\n";
245+
$return['status_text'] .= "This IP does not appear to be a {$service_types[$service_type]['services_field2']} IP\n";
246246
$continue = false;
247247
}
248248
}
249249
// coupon code
250250
if ($coupon != '') {
251-
$couponquery = <<<SQL
252-
select * from coupons where (customer=-1 or customer={$custid}) and (usable != 0) and module='{$module}' and (applies=-1 or applies like '%,{$type},%' or applies='{$type}' or applies like '{$type},%' or applies like '%,{$type}') and (name='{$coupon}')
253-
SQL;
251+
$couponquery = "select * from coupons where (customer=-1 or customer={$custid}) and (usable != 0) and module='{$module}' and (applies=-1 or find_in_set('{$service_type}', applies) != 0) and (name='{$coupon}')";
254252
$db->query($couponquery, __LINE__, __FILE__);
255253
if ($db->num_rows() == 0) {
256254
$return['status'] = 'error';
257-
$return['status_text'] .= "Invalid {$module} Coupon '{$coupon}' Specified for type '{$type}'\n";
255+
$return['status_text'] .= "Invalid {$module} Coupon '{$coupon}' Specified for type '{$service_type}'\n";
258256
$continue = false;
259257
} else {
260258
$db->next_record(MYSQL_ASSOC);
@@ -286,7 +284,7 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
286284
}
287285
// previously licensed code
288286
if ($continue) {
289-
if ($service_types[$type]['services_type'] == get_service_define('CPANEL')) {
287+
if ($service_types[$service_type]['services_type'] == get_service_define('CPANEL')) {
290288
$db->query("SELECT services_id FROM services LEFT JOIN service_categories ON category_id=services_category WHERE services_module = 'licenses' AND category_module = 'licenses' and category_tag = 'cpanel'");
291289
if ($db->num_rows() > 0) {
292290
while ($db->next_record(MYSQL_ASSOC)) {
@@ -327,7 +325,7 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
327325
}
328326
}
329327
} else {
330-
$db->query("select * from {$settings['TABLE']} where {$settings['PREFIX']}_ip='{$ip}' and {$settings['PREFIX']}_type=$type", __LINE__, __FILE__);
328+
$db->query("select * from {$settings['TABLE']} where {$settings['PREFIX']}_ip='{$ip}' and {$settings['PREFIX']}_type=$service_type", __LINE__, __FILE__);
331329
}
332330
if ($db->num_rows() > 0) {
333331
$db->next_record(MYSQL_ASSOC);
@@ -343,7 +341,7 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
343341
$now = mysql_now();
344342
$repeat_invoice = new \MyAdmin\Orm\Repeat_Invoice($db);
345343
$repeat_invoice->setId(null)
346-
->setDescription($service_types[$type]['services_name'])
344+
->setDescription($service_types[$service_type]['services_name'])
347345
->setType(1)
348346
->setCost($service_cost)
349347
->setCustid($custid)
@@ -360,7 +358,7 @@ function api_buy_license($sid, $ip, $type, $coupon = '', $use_prepay = null)
360358
$iid = $invoice->get_id();
361359
$db->query(make_insert_query($settings['TABLE'], [
362360
$settings['PREFIX'] . '_id' => null,
363-
$settings['PREFIX'] . '_type' => $type,
361+
$settings['PREFIX'] . '_type' => $service_type,
364362
$settings['PREFIX'] . '_cost' => $service_cost,
365363
$settings['PREFIX'] . '_frequency' => $frequency,
366364
$settings['PREFIX'] . '_order_date' => mysql_now(),

0 commit comments

Comments
 (0)