/** * Save Tracking number */ function saveTrackingNumber() { $userID = buckys_is_logged_in(); if (!$userID) { //You should be logged in return; } else { $tradeIns = new BuckysTrade(); $tradeID = buckys_escape_query_integer($_REQUEST['tradeID']); $trackingNo = buckys_escape_query_string($_REQUEST['trackingNo']); $tradeData = $tradeIns->getTradeByID($tradeID); if (empty($tradeData) || $tradeData['sellerID'] != $userID && $tradeData['buyerID'] != $userID) { //error, no permission echo json_encode(['success' => 0, 'msg' => "You do not have permission."]); } else { if ($tradeData['sellerID'] == $userID) { $tradeIns->updateTrade($tradeID, ['sellerTrackingNo' => $trackingNo]); } else { $tradeIns->updateTrade($tradeID, ['buyerTrackingNo' => $trackingNo]); } echo json_encode(['success' => 1, 'msg' => "You have saved tracking number successfully."]); } } }
/** * Update shipping Info * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info. * * @param integer $userID * @param array $data * @return bool */ public function updateShippingInfo($userID, $data) { if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) { return false; } //Update my shipping info global $db; $db->updateFromArray(TABLE_TRADE_USERS, $data, ['userID' => $userID]); //Update trade table which has no shipping info with this info. //It will check trade table, and create records in trade_shipping_info $tradeIns = new BuckysTrade(); $tradeShippingInfoIns = new BuckysTradeShippingInfo(); //---------------- Update for seller ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], ['sellerShippingID' => $shippingRecID]); } } } //---------------- Update for buyer ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], ['buyerShippingID' => $shippingRecID]); } } } //-------------------- Update Buyer Shipping Info -----------------------// $tradeShippingInfoIns->updateTradeShippingInfo($userID, $data); return true; }
/** * Update shipping Info * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info. * * @param integer $userID * @param array $data */ public function updateShippingInfo($userID, $data) { if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) { return false; } //Update my shipping info global $db; $query = sprintf('UPDATE %s SET ', TABLE_TRADE_USERS); $query = $db->prepare($query . 'shippingAddress=%s, shippingCity=%s, shippingState=%s, shippingZip=%s, shippingCountryID=%d WHERE userID=' . $userID, $data['shippingAddress'], $data['shippingCity'], $data['shippingState'], $data['shippingZip'], $data['shippingCountryID']); $db->query($query); //Update trade table which has no shipping info with this info. //It will check trade table, and create records in trade_shipping_info $tradeIns = new BuckysTrade(); $tradeShippingInfoIns = new BuckysTradeShippingInfo(); //---------------- Update for seller ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], array('sellerShippingID' => $shippingRecID)); } } } //---------------- Update for buyer ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], array('buyerShippingID' => $shippingRecID)); } } } return true; }
/** * Save Tracking number * */ function saveTrackingNumber() { $userID = buckys_is_logged_in(); if (!$userID) { //You should be logged in echo json_encode(array('success' => 0, 'msg' => "Please sign in to save tracking number.")); } else { $tradeIns = new BuckysTrade(); $tradeID = get_secure_integer($_REQUEST['tradeID']); $trackingNo = get_secure_string($_REQUEST['trackingNo']); $tradeData = $tradeIns->getTradeByID($tradeID); if (empty($tradeData) || $tradeData['sellerID'] != $userID && $tradeData['buyerID'] != $userID) { //error, no permission echo json_encode(array('success' => 0, 'msg' => "You do not have permission.")); } else { if ($tradeData['sellerID'] == $userID) { $tradeIns->updateTrade($tradeID, array('sellerTrackingNo' => $trackingNo)); } else { $tradeIns->updateTrade($tradeID, array('buyerTrackingNo' => $trackingNo)); } echo json_encode(array('success' => 1, 'msg' => "You have saved tracking number successfully.")); } } }