<?php
//function autoload
spl_autoload_register(function($class) {
include("../admin_login/classess/".$class.".php");
});
$sqlfun = new sqlfunction();
$admin = new admin_login();
date_default_timezone_set("Asia/Kolkata");
$cur_date = date("Y-m-d");
//refer_id_exists
if(isset($_POST['pin']) && $_POST['pin'] == "CA:DB:17:C3:E1:45:15:FA:D1:54:DD:56:EE:41:B4:E9:86:83:C9:95"){
if(isset($_POST['ref_id']))
{
$ref_id = $_POST['ref_id'];
$cnd = "code='$ref_id'";
$check = $sqlfun->fetchdata("player",$cnd);
if($check->rowCount() > 0)
{
$row = $check->fetch(PDO::FETCH_OBJ);
$data5 = array("res"=>"success" ,"msg" =>"valid","parent_id"=>$row->p_id);
}
else
{
$data5 = array("res"=>"failure","msg"=>"invalid","parent_id"=>"null");
}
//echo json_encode($data);
}
//register_player
if(isset($_POST['ref_idi']) && isset($_POST['f_name']) && isset($_POST['mobile']) && isset($_POST['login_device']) && isset($_POST['pwdd']) && isset($_POST['token']))
{
$ref_idi = $_POST['ref_idi'];
$f_name = $_POST['f_name'];
$mobile = $_POST['mobile'];
$login_device = $_POST['login_device'];
$pwdd = $_POST['pwdd'];
$fcm = $_POST['token'];
$cnd15 = "p_mobile='$mobile'";
$check15 = $sqlfun->fetchdata("player",$cnd15);
if($check15->rowCount()>0)
{
$data5 = array("res"=>"failure","msg"=>"phone number already exists","data"=>array());
}
else
{
if($ref_idi != "")
{
//find parent_id
$cnd1 = "code='$ref_idi'";
$check1 = $sqlfun->fetchdata("player",$cnd1);
$row1 = $check1->fetch(PDO::FETCH_OBJ);
$parent_id = $row1->p_id;
}
else
{
$parent_id = "";
}
$my_code = "";
//player rate find
$check_rate = $sqlfun->query("select default_rate,default_haruf_rate from message where id = '1'");
$row_rate = $check_rate->fetch(PDO::FETCH_OBJ);
$default_rate = $row_rate->default_rate;
$default_haruf_rate = $row_rate->default_haruf_rate;
//player rate end
$datas = array(
"parent_id"=>$parent_id,
"code"=>$my_code,
"p_f_name"=>$f_name,
"p_mobile"=>$mobile,
"wallet"=>"0",
"winwallet"=>"0",
"pwdd"=>$pwdd,
"status"=>"1",
"reg_date"=>$cur_date,
"photo"=>"",
"device_token"=>$fcm,
"rate"=>$default_rate,
"haruf_rate"=>$default_haruf_rate,
"login_device"=>$login_device
);
if($sqlfun->ins_data("player",$datas))
{
$last_inserted_id = $sqlfun->last_id();
$array_update_refer = array("code"=>$last_inserted_id);
$cnd_refer_update = "p_id = '$last_inserted_id'";
$sqlfun->updated("player",$array_update_refer,$cnd_refer_update);
$data2[] = array(
"p_id"=>$last_inserted_id,
"parent_id"=>$parent_id,
"code"=>$last_inserted_id,
"p_f_name"=>$f_name,
"p_mobile"=>$mobile,
"wallet"=>"0",
"winwallet"=>"0",
"status"=>"1",
"rate"=>$default_rate,
"haruf_rate"=>$default_haruf_rate,
"login_device"=>$login_device);
$data5 = array("res"=>"success","msg"=>"register successful","data"=>$data2);
}
else
{
$data5 = array("res"=>"failure","msg"=>"register unsuccessful","data"=>array());
}
}
}
}
else
{
$data5 = array("res"=>"failure","msg"=>"not valid","data"=>array());
}
echo json_encode($data5);
?>