Ejemplo n.º 1
0
/**
 * Edit Shop Product action by ajax
 */
function editProduct()
{
    $userID = buckys_is_logged_in();
    if (!$userID) {
        return;
    }
    $shopProductIns = new BuckysShopProduct();
    $inputValidFlag = true;
    $requiredFields = ['title', 'subtitle', 'description', 'category', 'return_policy', 'shipping_price', 'price'];
    foreach ($requiredFields as $requiredField) {
        if ($_REQUEST[$requiredField] == '') {
            $inputValidFlag = false;
        }
    }
    $categoryClass = new BuckysShopCategory();
    $category = $categoryClass->getCategoryByID($_REQUEST['category']);
    if (!$category['isDownloadable'] && $_REQUEST['location'] == '') {
        $inputValidFlag = false;
    } else {
        if ($category['isDownloadable'] == 1) {
            $_REQUEST['location'] = 0;
        }
    }
    if (isset($_REQUEST['price']) && (!is_numeric($_REQUEST['price']) || $_REQUEST['price'] <= 0)) {
        $inputValidFlag = false;
    }
    $shippingPriceList = [];
    if (isset($_REQUEST['shipping_price'])) {
        $shippingPriceList = json_decode($_REQUEST['shipping_price'], true);
        if (!is_array($shippingPriceList) || count($shippingPriceList) < 1) {
            $inputValidFlag = false;
        }
    }
    $actionType = get_secure_string($_REQUEST['type']);
    $paramProdID = get_secure_integer($_REQUEST['productID']);
    $listingFeeType = null;
    $data = [];
    $editableFlag = false;
    if ($actionType == 'relist') {
        $shopItemData = $shopProductIns->getProductById($paramProdID, true);
        if (!$shopItemData) {
            echo json_encode(['success' => 0, 'msg' => 'You could not relist this item.']);
            exit;
        }
        $listingFeeType = get_secure_integer($_REQUEST['listing_fee_type']);
        if ($listingFeeType === null) {
            $inputValidFlag = false;
        } else {
            //check if you can relist them
            if ($shopProductIns->hasMoneyToListProduct($userID, $listingFeeType)) {
                //Ok you can relist the product
            } else {
                echo json_encode(['success' => 0, 'msg' => 'You could not relist this item. You have no credits or bitcoin.']);
                exit;
            }
        }
        //you can relist this item
        $data['createdDate'] = date('Y-m-d H:i:s');
        if ($shopItemData['userID'] == $userID) {
            $editableFlag = true;
        } else {
            $editableFlag = false;
        }
    } else {
        $shopItemData = $shopProductIns->getProductById($paramProdID, false);
        if ($shopItemData && $shopItemData['userID'] == $userID) {
            $editableFlag = true;
        }
    }
    if ($inputValidFlag) {
        if ($editableFlag) {
            $data['title'] = get_secure_string($_REQUEST['title']);
            $data['subtitle'] = get_secure_string($_REQUEST['subtitle']);
            $data['description'] = get_secure_string($_REQUEST['description']);
            $data['catID'] = get_secure_string($_REQUEST['category']);
            $data['images'] = get_secure_string($_REQUEST['images']);
            $data['locationID'] = get_secure_string($_REQUEST['location']);
            $data['returnPolicy'] = get_secure_string($_REQUEST['return_policy']);
            $data['price'] = get_secure_string($_REQUEST['price']);
            $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['images'] = moveShopTmpImages($data['images']);
            if ($data['images'] === false) {
                echo json_encode(['success' => 0, 'msg' => 'Something goes wrong, please contact administrator.']);
                exit;
            }
            if ($actionType == 'relist') {
                $flag = $shopProductIns->payListingFee($userID, $paramProdID, $listingFeeType);
                if (!$flag) {
                    echo json_encode(['success' => 0, 'msg' => 'You could not relist this item. You have no credits or bitcoin.']);
                    exit;
                }
            }
            if ($category['isDownloadable'] == 1 && !empty($_REQUEST['filename'])) {
                if (!$_REQUEST['filename'] || file_exists(DIR_FS_SHOP_IMG_TMP . $_REQUEST['filename'])) {
                    echo json_encode(['success' => 0, 'msg' => 'Please select a zip file.']);
                    exit;
                }
                $data['isDownloadable'] = 1;
                $filename = moveShopTmpProduct($_REQUEST['filename']);
                //Remove Old File
                @unlink(DIR_FS_SHOP_PRODUCTS . $shopItemData['fileName']);
                $data['fileName'] = $filename;
            }
            $shopProductIns->updateProduct($paramProdID, $data);
            $shopProductIns->updateShippingPrice($paramProdID, $shippingPriceList);
            echo json_encode(['success' => 1, 'msg' => 'An item has been updated successfully.']);
        } else {
            echo json_encode(['success' => 0, 'msg' => "You don't have permission."]);
        }
    } else {
        //error
        echo json_encode(['success' => 0, 'msg' => 'Please input required field(s).']);
    }
}
 /**
  * Search products
  *
  * @param string $qStr   : Query String
  * @param string $catStr : Category Name/ Category ID
  * @param string $locStr : Location / Location ID
  * @return array
  */
 public function search($qStr, $catStr, $locStr, $userID)
 {
     global $db;
     $catIns = new BuckysShopCategory();
     $locationIns = new BuckysCountry();
     //Get category data
     $catData = null;
     if (is_numeric($catStr)) {
         $catData = $catIns->getCategoryByID($catStr);
     } else {
         $catData = $catIns->getCategoryByName($catStr);
     }
     //Get Location data
     $locationData = null;
     if (is_numeric($locStr)) {
         $locationData = $locationIns->getCountryById($locStr);
     } else {
         $locationData = $locationIns->getCountryByName($locStr);
     }
     //Make Where condition
     $whereCondList = [];
     if (isset($qStr) && $qStr != '') {
         $qStr = addslashes($qStr);
         $whereCondList[] = sprintf(" MATCH (p.title, p.subtitle, p.description) AGAINST ('%s' IN BOOLEAN MODE)", $qStr);
     }
     if (isset($catData)) {
         $whereCondList[] = 'p.catID=' . $catData['catID'];
     } else {
         if ($catStr != '') {
             return null;
         }
     }
     if (isset($locationData)) {
         $whereCondList[] = 'p.locationID=' . $locationData['countryID'];
     }
     if (isset($userID) && is_numeric($userID)) {
         $whereCondList[] = 'p.userID=' . $userID;
     }
     //Valid items
     $avaiableTime = date('Y-m-d H:i:s');
     $whereCondList[] = " (p.expiryDate >='" . $avaiableTime . "' OR p.listingDuration=-1) ";
     $whereCondList[] = 'p.status=' . BuckysShopProduct::STATUS_ACTIVE;
     $whereCond = ' WHERE ' . implode(' AND ', $whereCondList);
     $whereCond .= ' GROUP BY p.productID ';
     $query = sprintf("SELECT p.*, u.firstName, u.lastName, tu.totalRating, tu.positiveRating \n                            FROM %s AS p \n                            LEFT JOIN %s AS tu ON p.userID=tu.userID \n                            LEFT JOIN %s AS u ON p.userID=u.userID \n                            ", TABLE_SHOP_PRODUCTS, TABLE_USERS_RATING, TABLE_USERS);
     $query = $db->prepare($query . $whereCond);
     $data = $db->getResultsArray($query);
     return $data;
 }
Ejemplo n.º 3
0
$catIns = new BuckysShopCategory();
$countryIns = new BuckysCountry();
$userIns = new BuckysUser();
$shippingInfoIns = new BuckysTradeUser();
$view['product'] = $shopProductIns->getProductById($paramShopID);
$view['myID'] = $userID;
if (!isset($view['product']) || $view['product']['status'] == BuckysShopProduct::STATUS_INACTIVE) {
    buckys_redirect('/shop/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Check if the items owner is active one
$userData = $userIns->getUserData($view['product']['userID']);
if ($userData['status'] == BuckysUser::STATUS_USER_BANNED) {
    buckys_redirect('/shop/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Read more info from DB
$catData = $catIns->getCategoryByID($view['product']['catID']);
$view['product']['categoryName'] = isset($catData) ? $catData['name'] : '';
$countryData = $countryIns->getCountryById($view['product']['locationID']);
$view['product']['locationName'] = isset($countryData) ? $countryData['country_title'] : '';
$view['product']['userInfo'] = $userIns->getUserBasicInfo($view['product']['userID']);
if (!isset($view['product']['userInfo'])) {
    buckys_redirect('/shop/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
$view['my_product_flag'] = false;
$view['available_shipping_price'] = null;
$view['my_shipping_info'] = $myShippingData = $shippingInfoIns->getUserByID($userID);
$view['fill_shipping_info'] = false;
$view['my_info'] = $userIns->getUserBasicInfo($userID);
$view['is_purchased'] = $shopProductIns->isPurchased($userID, $paramShopID);
if (!$userID || $userID == $view['product']['userID']) {
    $view['my_product_flag'] = true;