Guest User

Untitled

a guest
Apr 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?php
  2. $id = $router->requestVar('id', -1);
  3. $admin = level(LEVEL_ADMIN);
  4.  
  5. $router->codeUnless(404, $shopItem = Query::create()
  6.         ->select('i.cost, e.*')
  7.             ->from('ShopItem i')
  8.                 ->leftJoin('i.Effects e')
  9.             ->where('id = ?', $id)
  10.         ->fetchOne());
  11. $return_back = '<br />' . make_link(array('controller' => 'Shop', 'action' => 'index', 'cat' => $shopItem->category_id), lang('back_to_index'));
  12.  
  13. $router->codeUnless(404, $char = $account->getMainChar());
  14. /* @var $char Character */
  15.  
  16. if (!$admin)
  17. {
  18.     if ($shopItem->cost > $account->User->points)
  19.     {
  20.         printf(lang('shop.cannot_buy_but_credit'), $shopItem->name,
  21.          make_link('@vote', lang('acc.vote')), make_link('@credit', lang('acc.credit.add')), $return_back);
  22.         return;
  23.     }
  24.     $this->codeIf(404, $shopItem->is_hidden
  25.      || ($shopItem->is_vip && (empty($config['COST_VIP']) || !$account->vip)));
  26. }
  27.  
  28. if ($shopItem->confirm($_POST))
  29. {
  30.     if ($shopItem->is_lottery)
  31.     {
  32.         list($effect, $hasEffect) = $shopItem->giveTo($char, $_POST);
  33.         if ($hasEffect)
  34.             printf(lang('shop.lottery_bought'), $shopItem['name'], br2nl($effect));
  35.         else //pretty complicated name, huh
  36.             printf(lang('shop.lottery_owned_bought' . ( $admin ? '_admin' : '' )), $shopItem['name'], str_replace(tag('br'), '', $effect));
  37.  
  38.         echo $account->getUser()->decredit($shopItem['cost']);
  39.     }
  40.     else
  41.     {
  42.         if ($shopItem->giveTo($char, $_POST))
  43.             echo sprintf(lang('shop.bought'), $shopItem['name']), $account->getUser()->decredit($shopItem['cost']);
  44.         else
  45.             printf(lang('shop.empty_buy'), $shopItem['name']);
  46.     }
  47.  
  48. }
  49. else
  50. {
  51.     if (empty($errors))
  52.         echo sprintf(lang('shop.buying_confirm'), $shopItem['name']), $shopItem->getConfirmationForm($_POST);
  53.     else
  54.         echo render_errors();
  55. }
  56.  
  57.  
  58.  
  59. echo tag('br') . $return_back;
Add Comment
Please, Sign In to add comment