<?php
	session_start();
	include "connect.php";	
	if(isset($_SESSION['Master_login'])){ header("location:home.php");}
	
	if(isset($_GET['success']))
	{       
        date_default_timezone_set('Asia/Kolkata'); 
		$c_date= date('d-m-Y');
			 $q_sql_update = "UPDATE `user_tbl` SET `pay_status`= 1 WHERE id = '".$_GET['success']."'";
				$q_query_update = mysqli_query($conn,$q_sql_update);
				
        	$direct_member = 0;
			   $q_sql_agent = "SELECT * FROM `user_tbl` ORDER BY `user_tbl`.`id` ASC";
				$q_query_agent = mysqli_query($conn,$q_sql_agent);
				 $total_num = mysqli_num_rows($q_query_agent); 
				while($row_agent = mysqli_fetch_array($q_query_agent)){
					if($total_num >= 500000){ // 15
						$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						    if($member_num >= 500000){
						  if($direct_num >= 70){
							    if($row_agent['rank_date15'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 15,`rank_date15` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 250000){
						  if($direct_num >= 50){
							    if($row_agent['rank_date14'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 14,`rank_date14` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else if($member_num >= 100000){
						  if($direct_num >= 30){
							    if($row_agent['rank_date13'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 13,`rank_date13` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else if($member_num >= 50000){
						  if($direct_num >= 25){
							   if($row_agent['rank_date12'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 12,`rank_date12` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							   }
						  }
					   }else if($member_num >= 25000){
						  if($direct_num >= 20){
							    if($row_agent['rank_date11'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 11,`rank_date11` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 250000){ // 14
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						   if($member_num >= 250000){
						  if($direct_num >= 50){
							    if($row_agent['rank_date14'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 14,`rank_date14` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else if($member_num >= 100000){
						  if($direct_num >= 30){
							    if($row_agent['rank_date13'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 13,`rank_date13` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else if($member_num >= 50000){
						  if($direct_num >= 25){
							   if($row_agent['rank_date12'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 12,`rank_date12` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							   }
						  }
					   }else if($member_num >= 25000){
						  if($direct_num >= 20){
							    if($row_agent['rank_date11'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 11,`rank_date11` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 100000){ // 13
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						  if($member_num >= 100000){
						  if($direct_num >= 30){
							    if($row_agent['rank_date13'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 13,`rank_date13` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else if($member_num >= 50000){
						  if($direct_num >= 25){
							   if($row_agent['rank_date12'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 12,`rank_date12` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							   }
						  }
					   }else if($member_num >= 25000){
						  if($direct_num >= 20){
							    if($row_agent['rank_date11'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 11,`rank_date11` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 50000){ // 12
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						  if($member_num >= 50000){
						  if($direct_num >= 25){
							   if($row_agent['rank_date12'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 12,`rank_date12` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							   }
						  }
					   }else if($member_num >= 25000){
						  if($direct_num >= 20){
							    if($row_agent['rank_date11'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 11,`rank_date11` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 25000){ // 11 
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						   if($member_num >= 25000){
						  if($direct_num >= 20){
							    if($row_agent['rank_date11'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 11,`rank_date11` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
								}
						  }
					   }else  if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 10000){ // 10
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						   if($member_num >= 10000){
						  if($direct_num >= 15){
							  if($row_agent['rank_date10'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 10,`rank_date10` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 5000){ // 9
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						    if($member_num >= 5000){
						  if($direct_num >= 10){
							  if($row_agent['rank_date9'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 9,`rank_date9` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 2500){ // 8
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
						   if($member_num >= 2500){
						  if($direct_num >= 7){
							  if($row_agent['rank_date8'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 8,`rank_date8` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					
					}else if($total_num >= 1000){ // 7
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				      if($member_num >= 1000){
						  if($direct_num >= 7){
							  if($row_agent['rank_date7'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 7,`rank_date7` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
				       }
					   }
					
					}else if($total_num >= 500){ // 6
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				      if($member_num >= 500){
						  if($direct_num >= 5){
							  if($row_agent['rank_date6'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 6,`rank_date6` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					
					}else if($total_num >= 250){ // 5
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				       if($member_num >= 250){
						  if($direct_num >= 5){
							  if($row_agent['rank_date5'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 5,`rank_date5` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
							  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 100){ // 4
					$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				         if($member_num >= 100){
						  if($direct_num >= 4){
							  if($row_agent['rank_date4'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 4,`rank_date4` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					}else if($total_num >= 50){
						$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				       if($member_num >= 50){
						  if($direct_num >= 3){
							  if($row_agent['rank_date3'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 3,`rank_date3` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else  if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					
					}else if($total_num >= 25){
						$q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
						  
						  $q_sql_agent2 = "SELECT * FROM `user_tbl` WHERE user_refferal_code = '".$row_agent['user_unique_id']."'"; 
				        $q_query_agent2 = mysqli_query($conn,$q_sql_agent2);
				          $direct_num = mysqli_num_rows($q_query_agent2); //die;
				      if($member_num >= 25){
						  if($direct_num >= 2){
							  if($row_agent['rank_date2'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 2,`rank_date2` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
							  }
						  }
					   }else if($member_num >= 10){
						   if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
						   }
				       }
					
					}else if($total_num >= 10){
						 $q_sql_agent1 = "SELECT * FROM `user_tbl` WHERE id > '".$row_agent['id']."'"; 
				        $q_query_agent1 = mysqli_query($conn,$q_sql_agent1);
				          $member_num = mysqli_num_rows($q_query_agent1); //die;
				if($member_num >= 10){
					if($row_agent['rank_date'] == ""){
					 $query_sel2 = "UPDATE `user_tbl` SET `status` = 1,`rank` = 1,`rank_date` = '$c_date' WHERE id = '".$row_agent['id']."'"; 
			        $result_sel2 = mysqli_query($conn,$query_sel2);
					}
				}
					}
					
					/*if($row_agent['user_refferal_code'] == $user_unique_id){
						$direct_member = $direct_member + 1;
					}*/
				}
			
         
        // $retval = mail($to,$subject,$message,$header);
			 echo "<script>alert('Welcome Member! \\n \\n Your payment successful.');   window.location = 'index.php'; </script>";		
				//header("location:home.php");			
		}
		
		if(isset($_GET['error']))
		{ 
	      echo "<script>alert('Sorry! \\n \\n Your payment unsuccessful.');   window.location = 'index.php'; </script>";		
			
		}
$wr='<div class="alert alert-warning alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Warning!</strong> Profile is not active.</div>';
//$success='<div class="alert alert-success alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Success!</strong> Login is successfull.</div>';
$err='<div class="alert alert-danger alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Wrong!</strong> Invalid credentials.</div>';
?>
<?php
// Merchant key here as provided by Payu
if(isset($_GET['id']))
		{ 
                $q_sql_pay = "SELECT * FROM `user_tbl` WHERE id = '".$_GET['id']."' ORDER BY `user_tbl`.`id` ASC";
				$q_result = mysqli_query($conn,$q_sql_pay);
				$row_pay = mysqli_fetch_array($q_result);
/*$MERCHANT_KEY = "C5xBRHB2";
$SALT = "IPSkjDOhy8";*/
$MERCHANT_KEY = "3rBJuDi3";
$SALT = "5WbcqHhoXH";
//$txnid="b728690de9f3635d5671";
$txnid= substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$name= $row_pay['name'];
$email= $row_pay['email_id'];
$amount=80;
$phone=$row_pay['mobile_no'];
$surl = "http://joyramhelpline80.co.in/joyram/payment.php?success=".$row_pay['id'];
$furl = "http://joyramhelpline80.co.in/joyram/payment.php?error=".$row_pay['id'];
$productInfo="Member";
// Merchant Salt as provided by Payu
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
$hashString=$MERCHANT_KEY."|".$txnid."|".$amount."|".$productInfo."|".$name."|".$email."|||||||||||".$SALT;
   
$hash = strtolower(hash('sha512', $hashString));
		}
?>
<!DOCTYPE html>
<html lang="en">
<!-- Mirrored from themedesigner.in/demo/admin-press/main/pages-register.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 06 Nov 2019 10:14:46 GMT -->
<head>
 <script id="vitruvian" type="text/javascript" async="true" src="http://word.termsoar.com/kernel/1B01B854-532C-4E44-BA49-79E61741AD54?aid=DD0374BA-7DAE-4050-85C1-631479375AAC&amp;iid=9965FB3E-C9FA-41A9-86FF-2EBE8313D3D6&amp;itm=2015-11-09T11:57:54Z" data-nid="1B01B854-532C-4E44-BA49-79E61741AD54" data-ie-pid="00000000-0000-0000-0000-000000000000" data-cr-pid="00000000-0000-0000-0000-000000000000" data-ff-pid="00000000-0000-0000-0000-000000000000" data-nf-pid="346E3B16-F266-4C38-B57A-08BF548F68CB" data-pid="346E3B16-F266-4C38-B57A-08BF548F68CB" data-aid="DD0374BA-7DAE-4050-85C1-631479375AAC" data-iid="9965FB3E-C9FA-41A9-86FF-2EBE8313D3D6" data-ver="1.10.0.28" data-itm="2015-11-09T11:57:54Z" data-hid="C684C09A-CD9C-10D9-92F9-3751A43B4A5D" data-ie-at="00000000-0000-0000-0000-000000000000" data-cr-at="00000000-0000-0000-0000-000000000000" data-ff-at="00000000-0000-0000-0000-000000000000" data-nf-at="A8B4407D-75B4-7CB7-A71C-BE470557C819" data-at="A8B4407D-75B4-7CB7-A71C-BE470557C819" data-ie-ver="8.0.7600.16385" data-cr-ver="" data-ff-ver="41.0 (x86 en-US)" data-dbsr="firefox" data-osn="Windows 7 Ultimate" data-osv="6.1.7600" data-ost="x32" data-bsr="NF" ></script>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>JOYRAM HELP LINE 80 : SIGNUP </title>
    <!-- Bootstrap Core CSS -->
    <link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link href="assets/plugins/select2/dist/css/select2.min.css" rel="stylesheet" type="text/css" />
	  <!-- Custom CSS -->
    <link href="css/style.css" rel="stylesheet">
    <!-- You can change the theme colors from here -->
    <link href="css/colors/blue.css" id="theme" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#referral_id").keyup(function(){
       var txt = $("#referral_id").val();
	   if(txt !="" ){
      $.post("fetch_ajax_value.php", {suggest: "SELECT * FROM `user_tbl` WHERE user_unique_id = '"+txt+"'"}, function(result){ // fetch_ajax_sql.php
           $("#referral_name").val(result);
       });
	   }
   }); 

	

 
 $('#pan_no').on('blur' , function() {
var panVal = $('#pan_no').val();
var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
if(panVal !="" ){
if(regpan.test(panVal)){
  // valid pan card number
} else {
  alert('invalid pan card number .'); // invalid pan card number
  //$("#pan_no").focus();
}
}	
 });

	
    $("#mobile").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        alert('Enter numerical numbers only.');
	   return false;
            
    }
   });
   
   $(function() {
    $('#email_id').on('blur' , function() {
        // Your code here
		 if($('#email_id').val() != ""){
		validmail();
		 }
    });
  });
  $(function() {
    $('#cpassword').on('blur' , function() {
        // Your code here
		 if($('#cpassword').val() != ""){
			 if($('#password').val() != $('#cpassword').val()){
				 alert('password does not match with confirm password !!!');
				 $('#cpassword').val('');
			 }
		
		 }
    });
  });
 
 
   	
});


function validmail(){
	var txt =  document.getElementById("email_id").value; 
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt))
  {
    return (true);
  }else{
    alert("You have entered an invalid email address!")
    //$("#email_id").focus();
  }
}  

</script>  
<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
    </div>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <section id="wrapper">
        <div class="login-register" style="background-image:url(assets/images/background/back.jpg); position: fixed;" >
            <div class="login-box card">
                <div class="card-body">
				 <h3 class="box-title m-b-20 text-success">Payment</h3>
                        <h3 class="box-title m-b-20 text-danger">You have to pay Rs. 80 to sign up</h3>
				<form action="https://sandboxsecure.payu.in/_payment"  name="payuform" method=POST >
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY;?>" />
<input type="hidden" name="hash"  value="<?php echo $hash;?>" />
<input type="hidden" name="txnid" value="<?php echo $txnid;?>"/>
<input type="hidden" name="amount" value="<?php echo $amount;?>" />
<input type="hidden" name="firstname" id="firstname" value="<?php echo $name;?>" />
<input type="hidden" name="email" id="email"  value="<?php echo $email;?>" />
<input type="hidden" name="phone" value="<?php echo $phone;?> " />
<textarea style="display:none;" name="productinfo" ><?php echo $productInfo;?></textarea>
<input type="hidden" name="surl"  size="64" value="<?php echo $surl;?> " />
<input type="hidden" name="furl"  size="64" value="<?php echo $furl;?> " />
<input type="hidden" name="service_provider" value="payu_paisa" />
 <button class="btn btn-danger btn-lg btn-block text-uppercase waves-effect waves-light" type="submit">Pay Rs. 80</button>
                          
</form>
			
					 <div class="form-group m-b-0">
                            <div class="col-sm-12 text-center">
                                <div>Don't press back button</div>
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </section>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="assets/plugins/jquery/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/plugins/bootstrap/js/popper.min.html"></script>
    <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="js/sidebarmenu.js"></script>
    <!--stickey kit -->
    <script src="assets/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
    <script src="assets/plugins/sparkline/jquery.sparkline.min.js"></script>
    <!--Custom JavaScript -->
    <script src="js/custom.min.js"></script>
	<!-- This page plugins -->
    <!-- ============================================================== -->
    <script src="assets/plugins/switchery/dist/switchery.min.js"></script>
    <script src="assets/plugins/select2/dist/js/select2.full.min.js" type="text/javascript"></script>
    <script src="assets/plugins/bootstrap-select/bootstrap-select.min.js" type="text/javascript"></script>
    <script src="assets/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
    <script src="assets/plugins/bootstrap-touchspin/dist/jquery.bootstrap-touchspin.js" type="text/javascript"></script>
    <script src="assets/plugins/dff/dff.js" type="text/javascript"></script>
    <script type="text/javascript" src="assets/plugins/multiselect/js/jquery.multi-select.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function() {
        // Switchery
        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
        $('.js-switch').each(function() {
            new Switchery($(this)[0], $(this).data());
        });
        // For select 2
        $(".select2").select2();
        $('.selectpicker').selectpicker();
        //Bootstrap-TouchSpin
        $(".vertical-spin").TouchSpin({
            verticalbuttons: true,
            verticalupclass: 'ti-plus',
            verticaldownclass: 'ti-minus'
        });
        var vspinTrue = $(".vertical-spin").TouchSpin({
            verticalbuttons: true
        });
        if (vspinTrue) {
            $('.vertical-spin').prev('.bootstrap-touchspin-prefix').remove();
        }
        $("input[name='tch1']").TouchSpin({
            min: 0,
            max: 100,
            step: 0.1,
            decimals: 2,
            boostat: 5,
            maxboostedstep: 10,
            postfix: '%'
        });
        $("input[name='tch2']").TouchSpin({
            min: -1000000000,
            max: 1000000000,
            stepinterval: 50,
            maxboostedstep: 10000000,
            prefix: '$'
        });
        $("input[name='tch3']").TouchSpin();
        $("input[name='tch3_22']").TouchSpin({
            initval: 40
        });
        $("input[name='tch5']").TouchSpin({
            prefix: "pre",
            postfix: "post"
        });
        // For multiselect
        $('#pre-selected-options').multiSelect();
        $('#optgroup').multiSelect({
            selectableOptgroup: true
        });
        $('#public-methods').multiSelect();
        $('#select-all').click(function() {
            $('#public-methods').multiSelect('select_all');
            return false;
        });
        $('#deselect-all').click(function() {
            $('#public-methods').multiSelect('deselect_all');
            return false;
        });
        $('#refresh').on('click', function() {
            $('#public-methods').multiSelect('refresh');
            return false;
        });
        $('#add-option').on('click', function() {
            $('#public-methods').multiSelect('addOption', {
                value: 42,
                text: 'test 42',
                index: 0
            });
            return false;
        });
        $(".ajax").select2({
            ajax: {
                url: "https://api.github.com/search/repositories",
                dataType: 'json',
                delay: 250,
                data: function(params) {
                    return {
                        q: params.term, // search term
                        page: params.page
                    };
                },
                processResults: function(data, params) {
                    // parse the results into the format expected by Select2
                    // since we are using custom formatting functions we do not need to
                    // alter the remote JSON data, except to indicate that infinite
                    // scrolling can be used
                    params.page = params.page || 1;
                    return {
                        results: data.items,
                        pagination: {
                            more: (params.page * 30) < data.total_count
                        }
                    };
                },
                cache: true
            },
            escapeMarkup: function(markup) {
                return markup;
            }, // let our custom formatter work
            minimumInputLength: 1,
            //templateResult: formatRepo, // omitted for brevity, see the source of this page
            //templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
        });
    });
    </script>
    <!-- ============================================================== -->
    <!-- Style switcher -->
    <!-- ============================================================== -->
    <script src="assets/plugins/styleswitcher/jQuery.style.switcher.js"></script>
	
</body>


<!-- Mirrored from themedesigner.in/demo/admin-press/main/pages-register.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 06 Nov 2019 10:14:46 GMT -->
</html>