<?php
require_once 'config.php';
//$error=false;
$errors=array();
$cities=array();
$cities1=array();
$smsflag=1;
if (isset($_POST['smsbanner_id']) && isset($_POST['user_id']))
{	

$sbid=$_POST['smsbanner_id'];
$uid=$_POST['user_id'];
$query='SELECT * FROM settings ';
$row = mysqli_query($con,$query);
$r=mysqli_fetch_array($row)	;
$credit=$r['credit_value'];
$t=date('Y-m-d');
$today=mysqli_query($con,"SELECT id FROM smsbanner_view_log WHERE user_id='".$uid."' AND smsbanner_id=".$sbid." AND DATE(created_at)='".$t."'" );
if(mysqli_num_rows($today)==0){
//mysqli_query($con,"UPDATE users SET credits=".$credit." WHERE id=".$uid);
$fromuser=mysqli_fetch_array(mysqli_query($con,"SELECT id,point_wallet FROM users WHERE id='".$uid."'"));
$customer=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM settings WHERE id=1"));
   $updatefrompoints=$fromuser['point_wallet']+$customer['refer_commission'];
		
		$createitem= mysqli_query($con,"UPDATE users SET point_wallet=".$updatefrompoints." WHERE id=".$fromuser['id']);
}
mysqli_query($con,"UPDATE smsbanners SET views=views+1 WHERE id=".$sbid);
mysqli_query($con,"INSERT INTO smsbanner_view_log (user_id,smsbanner_id,credit) VALUES('".$uid."','".$sbid."',".$customer['refer_commission'].")");

		$errors['success']='SMS Banner view count updated';

    } else {
		$errors['success']='User or Banner details not given';
	}
	 
	echo json_encode($errors);
	
?>