
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?

// Start the session
session_start();

date_default_timezone_set('Asia/Riyadh');

//Connection Detail
$dbhost = 'localhost';
$dbuser = 'balubaid_hijaz_ads';
$db = 'balubaid_crmdata';
$dbpass = 'crm963963';
//$id = $_GET['id'];

$link = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
$GLOBALS["link"] = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
$link->set_charset("utf8");
if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}



function create_customer($data){

$name = $data['cname'];
$city = $data['city'];
$email = $data['email'];
$phone = $data['mobile'];
$source = $data['source'];


$codequery = "insert into xx_funland_lucky_wheel_customers (name, city, phone, email, source,creation_date) value ('$name','$city','$phone', '$email','$source',now())";

//echo $codequery;

if ($GLOBALS["link"]->query($codequery) === TRUE) {
return '1';    
}else{
return '0';    
}
    
}

function is_existing_customer($data){

$codequery = "select count(id) as cnt from xx_funland_lucky_wheel_customers
where phone = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$cnt = $row['cnt'];
}

if($cnt >= 1){$is_existing = '1';}else{$is_existing = '0';}    

return $is_existing;
    
}

function get_customer_id($data){

$codequery = "select id from xx_funland_lucky_wheel_customers
where phone = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row['id'];
}


return $id;
    
}

function get_customer_details($data){

$codequery = "select * from xx_funland_lucky_wheel_customers
where id = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row;
}


return $id;
    
}

function get_prize_details($data){

$codequery = "select * from xx_funland_luckywheel_prize
where prize_code = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row;
}


return $id;
    
}

function get_prize_details2($data){

$codequery = "select * from xx_prize_vu
where prize_code = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row;
}


return $id;
    
}

function get_last_win_date($data){

$codequery = "select win_date from xx_funland_luckywheel_prize
where cst_id = '$data'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row['win_date'];
}


return $id;
    
}

function check_unredeem_win($data){

$codequery = "select count(id)cnt from xx_funland_luckywheel_prize
where cst_id = '$data' and is_redeemed <> 'Y'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row['cnt'];
}


return $id;
    
}

function get_daily_redeem_report($uid){

$tdate = date("Y-m-d");

$codequery = "select * from xx_prize_vu where redeem_by_id = '$uid' and date_format(redeem_date,'%Y-%m-%d') = '$tdate'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id[] = $row;
}


return $id;
    
}

function add_winning($cst_id,$prize,$source,$prizeCode){
    
    $wdate = date("Y-m-d h:i:sa");

$codequery = "insert into xx_funland_luckywheel_prize (cst_id, prize, win_date,source,prize_code) value ('$cst_id','$prize','$wdate','$source','$prizeCode')";

//echo $codequery;

if ($GLOBALS["link"]->query($codequery) === TRUE) {
return '1';    
}else{
return '0';    
}
    
}

function redeem_prize($uid,$voucher){
    
    $wdate = date("Y-m-d h:i:sa");

$codequery = "update xx_funland_luckywheel_prize set redeem_by_id = '$uid', is_redeemed = 'Y', redeem_date = '$wdate' where prize_code = '$voucher'";

//echo $codequery;

if ($GLOBALS["link"]->query($codequery) === TRUE) {
return '1';    
}else{
return '0';    
}
    
}



function is_active_session(){

if($_SESSION['active'] == 'Y'){

//ok    
    
}

else{
    
    $newURL = 'https://funlandksa.com/luckywheel/login/';

header('Location: '.$newURL);
}
    
}

function send_sms($data,$message){

$message = urlencode($message);

//echo $message;

$url = "https://www.oursms.net/api/sendsms.php?username=hijazmall&password=123456&message=$message&numbers=$data&sender=FUN%20LAND&unicode=e&Rmduplicated=1&return=json";

//echo $url;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

return $server_output;

}

function send_sms2($data,$message){

$message = urlencode($message);

//echo $message;

$url = "https://www.oursms.net/api/sendsms.php?username=hijazmall&password=123456&message=$message&numbers=$data&sender=FUN%20LAND-AD&unicode=e&Rmduplicated=1&return=json";

//echo $url;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

return $server_output;

}

function get_shorturl($a){

$desturl = $a;


$desturl = urlencode($desturl);    
    
$api_url = "http://1bg.me/api/?api=856d6cdb89543c36c89f998e7dfb8bdcf961adf7&type=1&url=".$desturl;
$result = @json_decode(file_get_contents($api_url),TRUE);
if($result["status"] === 'error') {
return "0";
} else {
return $result["shortenedUrl"];
}
}

function authuser($usr,$pwd){

$codequery = "select * from xx_funland_luckywheel_admin_user where username = '$usr'";

//echo $codequery;

$result = $GLOBALS["link"]->query($codequery);
while($row = $result->fetch_assoc()) {
$id = $row;
}

if($id['password'] == $pwd){

$_SESSION['UID'] = $id['id'];
$_SESSION['USN'] = $id['username'];
$_SESSION['AUTH'] = 'Y';
$_SESSION['ROLE'] = $id['role'];

return 1; 
    
}else{

return 0;    
    
}
    
}


function is_logged_in(){
    
if($_SESSION['AUTH'] == 'Y'){
    
}else{

$newURL = 'https://funlandksa.com/luckywheel/admin/login.php';

header('Location: '.$newURL);

}    
    
} 


?>