MOON
Server: Apache
System: Linux ip-208-109-13-31.ip.secureserver.net 3.10.0-1160.119.1.el7.tuxcare.els4.x86_64 #1 SMP Sat Aug 31 06:58:57 UTC 2024 x86_64
User: durgeshpandey215 (1013)
PHP: 8.1.29
Disabled: NONE
Upload Files
File: /home/durgeshpandey215/www/zeeroprice.skilladders.com/ajax_showprice-free.php
<?
require_once "application_top.php"; 
$userid = isset($_SESSION['useridsess'])?$_SESSION['useridsess']:"0";
$id = isset($_REQUEST['id'])? decode($_REQUEST['id']) : "";
$error = "";
if(!$userid){
	$error = "<a href='".HTTP_SERVER."login.php' class='btn'>Login <br/>to View Zeero Price.</a>";
	$objret = array("error"=>$error);
	echo json_encode($objret);
	exit;
}

//Get products details
$db->where('istatus',1);
$db->where('qty',0,'>');
$db->where('pid',$id);
$db->where('tilldate',CURDATE,'>=');
$rowprd = $db->getOne('products');

if(!$rowprd){
	$error = "Product is sold out.";
	$objret = array("error"=>$error);
	echo json_encode($objret);
	exit;
}

$prdCurrency = $rowprd["currency"];
$pointstocut = PointsFromMRP($rowprd["mrp"]);
//Reduce price of products 
$oldreducedprice = floatval(finalcost($rowprd["reducedPrice"]));
$cop = floatval(costofPoints($pointstocut));
$newcollectedprice = floatval($rowprd["collectedprice"]+$cop);


$newreducedPrice = floatval($oldreducedprice - $cop);
if($newreducedPrice <= 0){
	$newreducedPrice = 0;
}

//$objret = array("pid"=>1,"orderid"=>2,"reducedPrice"=>$newreducedPrice,"pointsRemain"=>20);
//echo json_encode($objret);
//exit;
//get user details
$db->where('userid',$_SESSION['useridsess']);
$rowu = $db->getOne('register');

//Check if user have sufficient free balance
if((!$rowu['freePoints'])||($rowu['freePoints'] < $pointstocut) ){
	$error = "You don't have sufficient".POINTS.".<br/><a href='".HTTP_SERVER."wallet.php' class='btn'>Click To Recharge.</a>";
	$objret = array("error"=>$error);
	echo json_encode($objret);exit;
};

//check if user have sufficient Gold points incase he wants to buy Product
$addNote = "";
if($newreducedPrice>$rowu['points']){
	$addNote = "<br/><font style='font-size:12px;'>Note: You have inefficient Gold ".POINTS." to buy this product.Please recharge your walllet.</font>";
}

//cut freePoints from users wallet 
$pointsRemain = $rowu["freePoints"]- $pointstocut;
$updateaArr = array(
'freePoints' => $pointsRemain
);
$db->where('userid',$_SESSION['useridsess']);
if($db->update('register',$updateaArr)){
	//create Session
	$_SESSION['freeCoins'] = $pointsRemain;
}
$objret = array("pid"=>encode($id),"reducedPrice"=>$newreducedPrice,"pointsRemain"=>$pointsRemain,"addNote"=>$addNote);
echo json_encode($objret);
?>