exit; //sleep(3); //die; //echo "Site Updating. Please wait...";die; //echo "Server 174";die; session_start(); date_default_timezone_set('Asia/Calcutta'); //error_reporting(0); if(isset($_REQUEST['debug'])){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); } /* if(date("H")==15 && date("i")>30 && date("i")<58){ sleep(10); } if(date("H")==13 && date("i")>30 && date("i")<58){ sleep(8); } */ $conn = mysqli_connect('localhost','rajeshri10dbusernew', 'Phoenix@6055','rajeshri10_com') or die("Connection Error"); $black_dates = array('-08-15','-01-26','-10-02'); $totNames=73; $gameTimeGap = 10; $rate=array(0,5,10,20,50,100); $rate_loose=array(0,1,1,2,5,10); $win=array(0,90,90,180,450,900); // defined once again inside the update win function define('BASEPATH','/home/w6jxrxq7l98w/www/rajeshri10.com'); $baseurl = "http://rajeshri10.com/"; define('USERBALANCE_LOG','userbalance_log'); define('DOMAIN_NAME','rajeshri10.com'); function __autoload($className) { $ext = '.php'; $paths = array(BASEPATH.'/extended',BASEPATH.'/core'); foreach ($paths as $path) { $filename = $path . DIRECTORY_SEPARATOR . $className; if (is_readable($filename . $ext)) { require_once($filename . $ext); break; } } } ?> function insert_result($date, $name_id, $entry_type) { //var_dump($entry_type);die; if ($entry_type=='Manual'){ insert_result_manual($date, $name_id); } else { insert_result_auto($date, $name_id); } } function my_date_format($dt){ return implode("-",array_reverse(explode("-",$dt))); } function get_site_config() { $siteConfigArray = mysqli_fetch_assoc(exe_query("select * from site_config where id=1")); return $siteConfigArray; } function get_last_result(){ $getLastResult="select * from results inner join names using(name_id) where status=1 order by results.result_id DESC LIMIT 1"; $resLastResult=exe_query($getLastResult); $rowLastResult=mysqli_fetch_assoc($resLastResult); return $rowLastResult; } function get_time_gap_in_min($startTime, $endTime) { $timeDiffSec=strtotime($endTime)-strtotime($startTime); return ($timeDiffSec/60); } function get_rand_user_result($date, $name_id){ //die; //echo "
";
$resultValue = array(
get_rand_result()
);
$get_users = exe_query("SELECT * FROM `users` where priority=1 LIMIT 1");
$res_users = mysqli_fetch_assoc($get_users);
//print_r($res_users);
if($res_users['user_id']){
$get_tickets = exe_query("SELECT alpha_id, num_id,num_name, SUM(quantity) AS total_quantity FROM ticket_master INNER JOIN ticket_details USING (ticket_id) INNER JOIN numbers USING (num_id) where user_id='".$res_users['user_id']."' AND date='$date' AND name_id='$name_id' GROUP BY alpha_id, num_id ORDER BY total_quantity");
// AND alpha_id IN (1,2,3,4,5,6)
$processed = 0;
while($res_tickets = mysqli_fetch_assoc($get_tickets)){
//print_r($res_tickets);
//$ran = explode(",", $res_tickets['num_name']);
//$resultValue[$res_tickets['alpha_id']-1] = $ran[array_rand($ran, 1)];
$resultValue[$res_tickets['alpha_id']-1] = $res_tickets['num_name'];
exe_query("UPDATE `users` SET priority=0 where user_id = '".$res_users['user_id']."'");
$processed = 1;
}
}
return ['status'=>$processed,'result'=>$resultValue];
}
function insert_result_auto($date, $name_id) {
$siteConfig=get_site_config();
$count = 1;
if (strstr($date,'-08-15') || strstr($date,'-01-26') || strstr($date,'-10-02') ) {
$resultValue = array('**');
}
else {
while(1){
//$resultValue = array(get_rand_result());
$resultValues = get_rand_user_result($date, $name_id);
$resultValue = $resultValues['result'];
//var_dump($resultValue);die;
if($siteConfig['entry_type']=='Auto'){
foreach($resultValue as $key=>$result) {
$alpha_id=$key+1;
update_coupon_winning($date, $name_id, $alpha_id, $result, 'Y');
}
$winPercentage = calculate_win_percentage($date, $name_id);
if($resultValues['status']==1){
$winPercentage=-1;
}
//echo $count.". Win : ".$winPercentage."
";
}else{
$winPercentage=-1;
}
if($winPercentage==-1 || (($winPercentage>$siteConfig['min_win_percent'] || $count>10) && $winPercentage<$siteConfig['max_win_percent'])) {
//echo "Final Win - : ".$winPercentage."
";
break;
}
$count++;
}
}
foreach($resultValue as $key=>$result) {
$alpha_id=$key+1;
$insertResult="INSERT INTO `results` (`date` ,`name_id` ,`alpha_id` ,`result`, `entry_date_time`,`entry_type`, `status`) VALUES ('".$date."' , '".$name_id."' , '".$alpha_id."' , '".$result."', '".date("Y-m-d H:i:s")."','".$siteConfig['entry_type']."','1')";
exe_query($insertResult);
update_coupon_winning($date, $name_id, $alpha_id, $result);
}
update_user_balance($date, $name_id); // auto result
}
function update_coupon_winning($date, $name_id, $alpha_id, $resultValue, $temp='N') {
global $win;
$tableNamePrefix="";
if($temp=='Y') {
$tableNamePrefix = "temp_";
exe_query("UPDATE ticket_details INNER JOIN ticket_master USING (ticket_id) SET ticket_details.temp_win_amount=0 WHERE ticket_master.status=1 and ticket_master.date='".$date."' AND ticket_master.name_id='".$name_id."' AND alpha_id='".$alpha_id."'");
}
$checkTicketDetails="SELECT ticket_details.*, numbers.* FROM `ticket_details` INNER JOIN `ticket_master` USING (`ticket_id`) INNER JOIN numbers USING (`num_id`) WHERE ticket_master.status=1 and DATE='".$date."' AND name_id ='".$name_id."' AND alpha_id ='".$alpha_id."' AND num_name LIKE '%".$resultValue."%'";
//echo "
";
$resTicketDetails=exe_query($checkTicketDetails);
if(mysqli_num_rows($resTicketDetails)>0) {
while($rowTicketDetails=mysqli_fetch_assoc($resTicketDetails)){
$win_amount = $rowTicketDetails['quantity']*$win[$alpha_id];
//echo "
";
$updateWinAmount="update ticket_details set ".$tableNamePrefix."win_amount='".$win_amount."' where id=".$rowTicketDetails['id'];
//echo "
";
exe_query($updateWinAmount);
}
}
}
function update_user_balance($date, $name_id, $option='') {
$calProfit="select user_id, sum(amount) as total_amount, sum(win_amount) as total_win_amount,ticket_master.status from ticket_details inner join ticket_master using (ticket_id) where date='".$date."' and name_id='$name_id' group by user_id, ticket_master.status having total_win_amount>0";
$resCalProfit=exe_query($calProfit);
if(mysqli_num_rows($resCalProfit)>0) {
while($rowCalProfit=mysqli_fetch_assoc($resCalProfit)){
extract($rowCalProfit);
if ($option=="reverse") {
$updateBalance="update users set user_balance=user_balance-'".$total_win_amount."' where user_id='".$user_id."'";
exe_query("insert into userbalance_log (user_id, txn_type, amount, txn_detail, datetime) values ('".$user_id."','+', '".$total_win_amount."', 'Winning Reverse','".date("Y-m-d H:i:s")."')");
}
else {
if($rowCalProfit['status']==1) {
$updateBalance="update users set user_balance=user_balance+'".$total_win_amount."' where user_id='".$user_id."'";
exe_query("insert into userbalance_log (user_id, txn_type, amount, txn_detail, datetime) values ('".$user_id."','+', '".$total_win_amount."', 'Ticket Winning','".date("Y-m-d H:i:s")."')");
}
}
//echo "
";
exe_query($updateBalance);
}
}
}
function get_rand_result(){
$res = str_pad(rand(0,99), 2, "0", STR_PAD_LEFT);
return $res;
}
function calculate_win_percentage($date, $name_id){
$getSumRow = mysqli_fetch_assoc(exe_query("SELECT SUM(amount) AS sum_amount, SUM(temp_win_amount) AS sum_temp_win_amount FROM ticket_details inner JOIN ticket_master USING (ticket_id) WHERE ticket_master.status=1 and date='".$date."' AND name_id='".$name_id."'"));
if($getSumRow['sum_amount']==0) {
$returnVar=-1;
}else{
$returnVar=$getSumRow['sum_temp_win_amount']/$getSumRow['sum_amount']*100;
}
return $returnVar;
}
function get_next_result_date_time_id() {
global $totNames;
$tempLastResult=get_last_result();
if($tempLastResult['name_id'] == $totNames) {
$date= date("Y-m-d",strtotime(date("Y-m-d", strtotime($tempLastResult['date'])) . " +1 day"));
$name_id = 1;
} else {
$date = $tempLastResult['date'];
$name_id = $tempLastResult['name_id'] + 1;
}
$getTimeFromId=mysqli_fetch_assoc(exe_query("SELECT `time`,`name` FROM `names` WHERE `name_id`='".$name_id."'"));
return array('date'=>$date, 'name_id'=>$name_id, 'time'=>$getTimeFromId['time'], 'name'=>$getTimeFromId['name']);
}
function scroll($a, $color){
if(strstr($_SERVER['HTTP_USER_AGENT'],'MSIE')){
echo ''.$a.'';
}else{
echo '';
}
}
function get_time_remaining(){
$currentTime = time();
$today = date("Y-m-d");
$timesRemaing = array();
$allTimes = "select time from names";
$resultAllTimes = exe_query($allTimes);
while ($resultRow = mysqli_fetch_array($resultAllTimes)){
$time = $today." ".$resultRow['time'];
if($currentTime < strtotime($time)){
$timesRemaing[] = $resultRow['time'];
}
}
if(sizeof($timesRemaing) == 0){
$resultAllTimes = exe_query($allTimes);
$resultRow = mysqli_fetch_array($resultAllTimes);
$timesRemaing[] = $resultRow['time'];
}
$timeDiff = strtotime($today." ".$timesRemaing[0])-time();
if ($timeDiff<0){
$timeDiff+=(24*3600);
}
return $timeDiff;
}
function insert_result_manual($date, $name_id) {
$resultValue = array();
$getManualRes = exe_query("select * from results where date='$date' and $name_id = '$name_id' and status=0");
while($getManualRow = mysqli_fetch_array($getManualRes)) {
$insertResult="update `results` set status = '1' where result_id='".$getManualRow['result_id']."'";
exe_query($insertResult);
update_coupon_winning($date, $name_id, $getManualRow['alpha_id'], $getManualRow['result']);
}
update_user_balance($date, $name_id);
}
function get_site_status(){
return (int)file_exists(dirname(__DIR__)."/up.htaccess");
}
function set_site_status($status){
if($status==1 && file_exists(dirname(__DIR__)."/.htaccess")){
rename(dirname(__DIR__)."/.htaccess",dirname(__DIR__)."/up.htaccess");
}
else if($status==0 && file_exists(dirname(__DIR__)."/up.htaccess")){
rename(dirname(__DIR__)."/up.htaccess",dirname(__DIR__)."/.htaccess");
}
}
function exe_query($query){
global $conn;
//echo "
".$query;
//exe_query("INSERT INTO query_log (ipaddress, date_time, page_url,query) VALUES('".$_SERVER['REMOTE_ADDR']."','".date("Y-m-d H:i:s")."','".$_SERVER['REQUEST_URI']."','$query')");
$res = mysqli_query($conn, $query) or die(mysqli_error($conn));
//var_dump($qry);die;
return $res;
}
?>
ini_set('max_execution_time', 0);
require_once("includes/config.php");
require_once("includes/functions.php");
$siteConfig = get_site_config();
exe_query("LOCK TABLES site_config WRITE, results WRITE, names WRITE, ticket_details WRITE, ticket_master WRITE, users WRITE, numbers WRITE, userbalance_log WRITE");
$next_result = get_next_result_date_time_id(get_last_result());
if(strtotime($next_result['date'].' '.$next_result['time'])<=time()) {
insert_result($next_result['date'], $next_result['name_id'], $siteConfig['entry_type']);
}
exe_query("UNLOCK TABLES");
?>