/**
 * Make an offer
 */
function makeAnOffer()
{
    $successFlag = true;
    $userID = buckys_is_logged_in();
    if (!$userID) {
        return;
    } else {
        //Read Param
        $targetItemID = buckys_escape_query_integer($_REQUEST['targetItemID']);
        $offerItemID = buckys_escape_query_integer($_REQUEST['offerItemID']);
        $tradeItemIns = new BuckysTradeItem();
        $itemData = $tradeItemIns->getItemById($offerItemID, false);
        $targetItemData = $tradeItemIns->getItemById($targetItemID, false);
        if (isset($itemData) && $itemData['status'] == BuckysTradeItem::STATUS_ITEM_ACTIVE && $itemData['userID'] == $userID && isset($targetItemData) && $targetItemData['status'] == BuckysTradeItem::STATUS_ITEM_ACTIVE) {
            //Add offer
            $tradeOfferIns = new BuckysTradeOffer();
            $result = $tradeOfferIns->addOffer($targetItemID, $offerItemID);
            if ($result) {
                echo json_encode(['success' => 1, 'msg' => "You've made an offer successfully."]);
            } else {
                echo json_encode(['success' => 0, 'msg' => "You could not make an offer."]);
            }
        } else {
            echo json_encode(['success' => 0, 'msg' => "You could not make an offer."]);
        }
    }
}
$view['action_name'] = 'editTradeItem';
$paramItemID = get_secure_integer($_REQUEST['id']);
$paramType = get_secure_string($_REQUEST['type']);
$view['item'] = null;
switch ($paramType) {
    case 'relist':
        /*
        $view['no_credits'] = false;
        if (!$tradeUserIns->hasCredits($userID)) {
            $view['no_credits'] = true;
        }
        */
        // Relist trade items with bitcoin or credits - now matches Shop code
        $userInfo = BuckysUser::getUserBasicInfo($userID);
        $view['my_bitcoin_balance'] = BuckysBitcoin::getUserWalletBalance($userID);
        $view['my_credit_balance'] = $userInfo['credits'];
        $view['item'] = $tradeItemIns->getItemById($paramItemID, true);
        $view['type'] = 'relist';
        $view['page_title'] = 'Relist an Item';
        break;
    default:
        $view['item'] = $tradeItemIns->getItemById($paramItemID, false);
        $view['type'] = 'edit';
        $view['page_title'] = 'Edit an Item';
        break;
}
if ($view['item'] == null || $view['item']['userID'] != $userID || $view['item']['status'] != BuckysTradeItem::STATUS_ITEM_ACTIVE) {
    buckys_redirect('/trade/available.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
$TNB_GLOBALS['title'] = 'Edit an Item - BuckysRoomTrade';
require DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php";
Example #3
0
<?php

require dirname(dirname(__FILE__)) . '/includes/bootstrap.php';
$userID = buckys_is_logged_in();
buckys_enqueue_stylesheet('trade.css');
buckys_enqueue_javascript('trade.js');
$BUCKYS_GLOBALS['content'] = 'trade/view';
$BUCKYS_GLOBALS['headerType'] = 'trade';
$paramItemID = get_secure_integer($_REQUEST['id']);
$view = array();
$tradeItemIns = new BuckysTradeItem();
$tradeCatIns = new BuckysTradeCategory();
$countryIns = new BuckysCountry();
$userIns = new BuckysUser();
$tradeOfferIns = new BuckysTradeOffer();
$view['item'] = $tradeItemIns->getItemById($paramItemID);
$view['myID'] = $userID;
if (!isset($view['item']) || $view['item']['status'] == BuckysTradeItem::STATUS_ITEM_INACTIVE) {
    buckys_redirect('/trade/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Check if the items owner is active one
$userData = $userIns->getUserData($view['item']['userID']);
if ($userData['status'] == BuckysUser::STATUS_USER_BANNED) {
    buckys_redirect('/trade/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Read more info from DB
$catData = $tradeCatIns->getCategoryByID($view['item']['catID']);
$view['item']['categoryName'] = isset($catData) ? $catData['name'] : '';
$countryData = $countryIns->getCountryById($view['item']['locationID']);
$view['item']['locationName'] = isset($countryData) ? $countryData['country_title'] : '';
$view['item']['userInfo'] = $userIns->getUserBasicInfo($view['item']['userID']);
 /**
  * Decline offer
  *
  * @param integer $offerID
  */
 public function declineOffer($offerID)
 {
     global $db;
     if (!is_numeric($offerID)) {
         return;
     }
     $dateTimeStamp = date('Y-m-d H:i:s');
     $query = sprintf("UPDATE %s SET STATUS=%d, lastUpdateDate='%s' WHERE offerID=%d", TABLE_TRADE_OFFERS, BuckysTradeOffer::STATUS_OFFER_DECLINED, $dateTimeStamp, $offerID);
     $db->query($query);
     //Notification
     $tradeItemIns = new BuckysTradeItem();
     $offerData = $this->getOfferByID($offerID);
     if ($offerData) {
         $buyerItemData = $tradeItemIns->getItemById($offerData['offeredItemID']);
         $sellerItemData = $tradeItemIns->getItemById($offerData['targetItemID']);
         if ($buyerItemData) {
             //Create notification
             $tradeNotificationIns = new BuckysTradeNotification();
             $tradeNotificationIns->createNotification($buyerItemData['userID'], $sellerItemData['userID'], BuckysTradeNotification::ACTION_TYPE_OFFER_DECLINED, $offerID);
         }
     }
 }