@@ -239,15 +239,15 @@ function rexshop_payment_page()
239
239
'uid ' => (int ) $ mybb ->user ['uid ' ],
240
240
]));
241
241
242
- $ enddate = (int ) (TIME_NOW + rexshop_remaining_seconds (intval ($ mybb ->user ['uid ' ]), false ));
242
+ $ enddate = (int ) (TIME_NOW + rexshop_remaining_seconds (intval ($ mybb ->user ['uid ' ]), null , false ));
243
243
244
244
if ($ enddate > TIME_NOW ) {
245
245
$ offsetquery = $ db ->simple_select ("users " , "timezone " , "uid=' " . intval ($ mybb ->user ['uid ' ]) . "' " );
246
246
$ offset = (int ) $ db ->fetch_field ($ offsetquery , "timezone " );
247
247
$ enddate += (3600 * $ offset );
248
248
249
249
$ contents .= "Your subscription expires: " . date ('j, M Y H:m ' , $ enddate ) . " GMT " . (strpos ($ offset , '- ' ) !== false ? $ offset : "+ {$ offset }" ) . "<br><br> " ;
250
- } else if ($ enddate <= -1 ) {
250
+ } elseif ($ enddate <= -1 ) {
251
251
$ contents .= "Your subscription will never expire " ;
252
252
}
253
253
@@ -367,12 +367,14 @@ function handleCompletedTransaction($request)
367
367
}
368
368
369
369
//How much seconds the user has remaining & expire old purchases.
370
- $ remainingSeconds = rexshop_remaining_seconds ($ userId );
370
+ $ remainingSeconds = rexshop_remaining_seconds ($ userId, $ request [ ' order ' ][ ' products ' ][ 0 ][ ' sku ' ] );
371
371
372
372
//Figure out how much seconds the user has purchased.
373
373
$ purchasedSeconds = rexshop_purchased_seconds ($ request , $ request ['order ' ]['products ' ][0 ]['sku ' ]);
374
374
375
- $ newEnddate = $ purchasedSeconds < 0 ? -1 : TIME_NOW + $ remainingSeconds + $ purchasedSeconds ;
375
+ $ newEnddate = $ purchasedSeconds < 0
376
+ ? -1
377
+ : TIME_NOW + $ remainingSeconds + $ purchasedSeconds ;
376
378
377
379
rexshop_store_transaction ($ request , $ userId , $ newEnddate , $ request ['order ' ]['products ' ][0 ]['sku ' ]);
378
380
@@ -445,7 +447,7 @@ function handleRefundedTransaction($request)
445
447
$ refundedSeconds = $ refundedAmount * $ pricePerSecond ;
446
448
447
449
//Check how much time the user has left
448
- $ remainingSeconds = rexshop_remaining_seconds ($ userId , false );
450
+ $ remainingSeconds = rexshop_remaining_seconds ($ userId , $ request [ ' order ' ][ ' products ' ][ 0 ][ ' sku ' ], false );
449
451
450
452
//Subtract the time that was refunded.
451
453
$ newEndDate = TIME_NOW + ($ remainingSeconds - $ refundedSeconds );
@@ -570,11 +572,11 @@ function handleDisputedTransaction($request)
570
572
return rexshop_on_failure ();
571
573
}
572
574
573
- //Figure out how much time to suspend
575
+ //Figure out how much time to suspend
574
576
$ secondsToSuspend = rexshop_purchased_seconds ($ request , $ usergroup );
575
577
576
578
//Figure out how much time the user has left.
577
- $ remainingSeconds = rexshop_remaining_seconds ($ userId , false );
579
+ $ remainingSeconds = rexshop_remaining_seconds ($ userId , null , false );
578
580
579
581
$ completed = REXSHOP_STATUS_COMPLETED ;
580
582
@@ -683,7 +685,7 @@ function rexshop_products_usergroup($product)
683
685
break 2 ;
684
686
}
685
687
}
686
- } else if (isset ($ product ['addons ' ])) {
688
+ } elseif (isset ($ product ['addons ' ])) {
687
689
foreach ($ product ['addons ' ] as $ addon ) {
688
690
if (strtolower ($ addon ['name ' ]) !== 'usergroup ' ) {
689
691
continue ;
@@ -715,13 +717,18 @@ function rexshop_products_usergroup($product)
715
717
* @param boolean $expiresExisting
716
718
* @return integer
717
719
*/
718
- function rexshop_remaining_seconds ($ userId , $ expireExisting = true )
720
+ function rexshop_remaining_seconds ($ userId , $ sku = null , $ expireExisting = true )
719
721
{
720
722
global $ db ;
721
723
722
724
$ remainingSeconds = 0 ;
723
725
724
- $ query = $ db ->query ("SELECT * FROM ` " . TABLE_PREFIX . "rexshop_logs` WHERE `uid`=' " . (int ) $ userId . "' AND `expired`='0' " );
726
+ $ queryString = "SELECT * FROM ` " . TABLE_PREFIX . "rexshop_logs` WHERE `uid`=' " . (int ) $ userId . "' AND `expired`='0' " ;
727
+ if (isset ($ sku )) {
728
+ $ queryString .= " AND `product_sku`=' " . rexshop_regex_escape ($ sku , '/[^a-zA-Z0-9]/ ' ) . "' " ;
729
+ }
730
+
731
+ $ query = $ db ->query ($ queryString );
725
732
$ resultCount = $ db ->num_rows ($ query );
726
733
if ($ resultCount <= 0 ) {
727
734
return $ remainingSeconds ;
@@ -1231,7 +1238,7 @@ function rexshop_fetch_products($acp = false)
1231
1238
$ usergroups = explode (', ' , ltrim (rtrim (trim ($ addon ['value ' ], ' ' ), ', ' ), ', ' ));
1232
1239
if (empty ($ usergroups )) {
1233
1240
continue ;
1234
- }
1241
+ }
1235
1242
1236
1243
$ usergroupIds = [];
1237
1244
foreach ($ usergroups as $ usergroup ) {
@@ -1250,7 +1257,7 @@ function rexshop_fetch_products($acp = false)
1250
1257
if (! in_array ((int ) $ mybb ->user ['usergroup ' ], $ usergroupIds )) {
1251
1258
continue 2 ;
1252
1259
}
1253
- } else if (mb_strtolower ($ addon ['name ' ]) === 'excludeusergroups ' || mb_strtolower ($ addon ['name ' ]) === 'excludeusergroup ' ) {
1260
+ } elseif (mb_strtolower ($ addon ['name ' ]) === 'excludeusergroups ' || mb_strtolower ($ addon ['name ' ]) === 'excludeusergroup ' ) {
1254
1261
if (in_array ((int ) $ mybb ->user ['usergroup ' ], $ usergroupIds )) {
1255
1262
continue 2 ;
1256
1263
}
0 commit comments