function adjustStock($userid, $mode)
{
    global $tableprefix;
    $sql = "SELECT * FROM " . $tableprefix . "cart WHERE user_id = '" . addslashes($userid) . "' ";
    $result = mysql_query($sql);
    $parr = array();
    $itemcount = 0;
    if (mysql_num_rows($result) != 0) {
        while ($row = mysql_fetch_array($result)) {
            $parr[$itemcount]["cartid"] = $row["cart_id"];
            $parr[$itemcount]["productid"] = $row["product_id"];
            $parr[$itemcount]["product_option_id"] = $row["product_option_id"];
            $parr[$itemcount]["quantity"] = $row["quantity"];
            $itemcount++;
        }
    }
    $stockadjusted = false;
    for ($i = 0; $i < $itemcount; $i++) {
        $cartid = $parr[$i]["cartid"];
        $productid = $parr[$i]["productid"];
        $product_option_id = $parr[$i]["product_option_id"];
        $value = $parr[$i]["quantity"];
        $qtyavailable = getProductStock($product_option_id);
        if ($mode == "+") {
            $newstock = $qtyavailable + $value;
            $sqlstatus = "UPDATE  " . $tableprefix . "product_options SET product_stock='" . $newstock . "' WHERE product_option_id = '" . addslashes($product_option_id) . "' ";
        } else {
            if ($mode == "-") {
                $newstock = $qtyavailable - $value;
                $sqlstatus = "UPDATE  " . $tableprefix . "product_options SET product_stock='" . $newstock . "' WHERE product_option_id = '" . addslashes($product_option_id) . "' ";
            }
        }
        mysql_query($sqlstatus);
        // make archive
        makeProductArchive($productid);
    }
    return $stockadjusted;
}
    $qty = intval($_GET['qty']);
    //echo "<pre>";print_r($_POST['txtQuantity_'.$cartId]);exit;
    //print_r($row =  mysql_fetch_array($result));
    //exit;
    $parr = array();
    $poarr = array();
    while ($row = mysql_fetch_array($result)) {
        //echo "<pre>";     print_r($row);exit;
        $cid = $row["cart_id"];
        $parr[$cid] = $row["product_id"];
        $poarr[$cid] = $row["product_option_id"];
        //akhil Modified starts
        $product_option_id = $poarr[$cid];
        $quantity = getWholesaleProductCount($product_option_id);
        if ($qty % $quantity == 0) {
            $qtyavailable = getProductStock($product_option_id);
            if ($qty > $qtyavailable) {
                $qty = $qtyavailable;
                $qtyadjusted = true;
            }
            //akhil Modified ends
            $sql = "UPDATE " . $tableprefix . "cart SET quantity = '" . addslashes($qty) . "' WHERE cart_id='" . addslashes($cartId) . "' ";
            //echo $sql;exit;
            mysql_query($sql);
            $message = "Quantity updated successfully!";
        } else {
            $message .= "<br>Whole sale product, quantity should be  {$quantity} or multiple of  {$quantity}.";
        }
    }
    //exit;
}
} else {
    if (isset($_POST["productid"]) and $_POST["productid"] != "") {
        $productid = $_POST["productid"];
    }
}
if (isset($_GET["product_option_id"]) and $_GET["product_option_id"] != "") {
    $product_option_id = $_GET["product_option_id"];
} else {
    if (isset($_POST["product_option_id"]) and $_POST["product_option_id"] != "") {
        $product_option_id = $_POST["product_option_id"];
    }
}
/*-----------Multicart 2.0 Upgradation------------*/
$check_shipping_enable = checkShippingEnable();
/*-----------Multicart 2.0 Upgradation------------*/
$currentProductStock = getProductStock($product_option_id);
if ($currentProductStock == 0) {
    header("Location:productdetails.php?msg=stock&productid=" . $productid);
    exit;
}
if (isset($_POST['txtQty']) && $_POST['txtQty'] != '') {
    if ($currentProductStock < $_POST['txtQty']) {
        $qty = $currentProductStock;
    } else {
        $qty = $_POST['txtQty'];
    }
} else {
    $qty = 1;
}
// checking producr quantity for whole sale products
$quantity = getWholesaleProductCount($product_option_id);