<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

$mobile = $_REQUEST['mobile'];
$mobilecond = '';

if (!empty($_REQUEST['mobile'])) {
    $mobilecond = "AND `mobile` = '$mobile' ";
}


$getredpts = mysqli_query($conn, "SELECT vouchno, mobile, sum(redeemamt) as redeemamt FROM `pointsacn` WHERE `vouchno` != '' $mobilecond group by mobile ")or die(mysqli_error($conn));
$m = mysqli_fetch_array($getredpts);

if ($mobile != "") {
    if ($m['redeemamt'] != '') {
        $it = 1;
        $redeem = 'Total Redeem Points is ' . $m['redeemamt'];
    }
    if ($m['redeemamt'] == '') {
        $it = 1;
        $redeem = 'Total Redeem Points is ' . 0;
    }
}

$rows = array('it' => $it,
    'redeem' => "$redeem",
    'redeemt' => "$m[redeemamt]"
);

header("Content-type: application\json");
echo json_encode($rows);
