/** * Add trade Item action by Ajax * */ function addTradeItem() { $inputValidFlag = true; $requiredFields = array('title', 'subtitle', 'description', 'category'); foreach ($requiredFields as $requiredField) { if ($_REQUEST[$requiredField] == '') { $inputValidFlag = false; } } $userID = buckys_is_logged_in(); if ($inputValidFlag && $userID !== false) { $tradeItemIns = new BuckysTradeItem(); $data['userID'] = $userID; $data['title'] = get_secure_string($_REQUEST['title']); $data['subtitle'] = get_secure_string($_REQUEST['subtitle']); $data['description'] = get_secure_string($_REQUEST['description']); $data['itemWanted'] = get_secure_string($_REQUEST['items_wanted']); $data['images'] = get_secure_string($_REQUEST['images']); $data['catID'] = get_secure_string($_REQUEST['category']); $data['locationID'] = get_secure_string($_REQUEST['location']); $data['createdDate'] = date('Y-m-d H:i:s'); $data['images'] = moveTradeTmpImages($data['images']); if ($data['images'] === false) { echo json_encode(array('success' => 0, 'msg' => 'Something goes wrong, please contact administrator.')); } if ($newItemID = $tradeItemIns->addItem($data)) { echo json_encode(array('success' => 1, 'msg' => 'Your item has been added successfully.')); } else { echo json_encode(array('success' => 0, 'msg' => 'You do not have enough credits for that.')); } } else { //error echo json_encode(array('success' => 0, 'msg' => 'Please input required field(s).')); } }
/** * Add trade Item action by Ajax */ function addTradeItem() { $inputValidFlag = true; $requiredFields = ['title', 'subtitle', 'description', 'category']; foreach ($requiredFields as $requiredField) { if ($_REQUEST[$requiredField] == '') { $inputValidFlag = false; } } // $listingFeeType = get_secure_integer($_REQUEST['listing_fee_type']); $listingFeeType = 0; // FreeTradeListings - delete this and uncomment above to enable listing fees if ($listingFeeType === null) { $inputValidFlag = false; } $userID = buckys_is_logged_in(); if (!$userID) { return; } if ($inputValidFlag) { $tradeItemIns = new BuckysTradeItem(); $data['userID'] = $userID; $data['title'] = get_secure_string($_REQUEST['title']); $data['subtitle'] = get_secure_string($_REQUEST['subtitle']); $data['description'] = get_secure_string($_REQUEST['description']); $data['itemWanted'] = get_secure_string($_REQUEST['items_wanted']); $data['images'] = get_secure_string($_REQUEST['images']); $data['catID'] = get_secure_string($_REQUEST['category']); $data['locationID'] = get_secure_string($_REQUEST['location']); $data['listingDuration'] = get_secure_string($_REQUEST['listing_duration']); $data['expiryDate'] = $data['listingDuration'] == -1 ? '0000-00-00 00:00:00' : date('Y-m-d H:i:s', time() + 3600 * 24 * $data['listingDuration']); $data['createdDate'] = date('Y-m-d H:i:s'); $data['images'] = moveTradeTmpImages($data['images']); if ($data['images'] === false) { echo json_encode(['success' => 0, 'msg' => 'Something goes wrong, please contact administrator.']); exit; } if ($newItemID = $tradeItemIns->addItem($data, $listingFeeType)) { echo json_encode(['success' => 1, 'msg' => 'Your item has been added successfully.']); } else { echo json_encode(['success' => 0, 'msg' => 'You do not have enough credits for that.']); } } else { //error echo json_encode(['success' => 0, 'msg' => 'Please input required field(s).']); } }