<?php
error_reporting(0);
include "../datacon.php";
if (isset($_POST['submit'])){
$pnumber = $_POST['pnumber'];
$idno = $_POST['idno'];
$mpesa = $_POST['mpesa'];
$amount= $_POST['amount'];
$runder= $_POST['runder'];


$query = @mysql_query("select * from gold where   phonenumber= '$pnumber' AND idno='$idno' ")or die(mysql_error());
$count = mysql_num_rows($query);

if ($count >0){ ?>
<script>
alert('You are already a Gold club member ');
window.location = "index";
</script>

<?php
}else{
$queryclub = @mysql_query("select * from gold where   phonenumber= '$runder'")or die(mysql_error());
$countclub = mysql_num_rows($queryclub);
if ($countclub > 0){
 $counto=mysql_query("select * from gold WHERE reg_under='$runder' ");
	 $countq = mysql_num_rows($counto);
	if ($countq <3){  
mysql_query("insert into gold (phonenumber,reg_under,amount,Mpesa,idno,status,date,level) 
values('$pnumber','$runder','$amount','$mpesa','$idno','pending',NOW(),'1')")or die(mysql_error());

mysql_query("insert into mpesa (code,sentby,paymentfor) values('$mpesa','$pnumber','Join club')")or die(mysql_error());

mysql_query("insert into activity_log (date,username,action) values(NOW(),'$pnumber','Joined Club')")or die(mysql_error());
	$phonen=$pnumber;		
$messag= "Congrats%20".$fname."%20You're%20Now%20a%20Club%20Member%20.%20RegisteredUnder%20".$runder."%20.%20with%20Regards%20.%20";
$sendsms ='http://sms.clarity.co.ke/sendsms.jsp?user=wealthmark&password=w@mark&mobiles='. $phonen .'&sms=' . $messag . ' &unicode=1&clientsmsid=10002&senderid=Wealthmark&version=3';
@$homepage = file_get_contents($sendsms);

?>
<script>
alert('You Have Successifuly registered as  a Gold club member.Sponsor your first 3 downlines and train them to do the same so as to achieve more in the club. Thank you');
window.location = "index";
</script>

<?php

} else if($runder=='0772220320'){
mysql_query("insert into gold (phonenumber,reg_under,amount,Mpesa,idno,status,level) 
values('$pnumber','$runder','$amount','$mpesa','$idno','pending','1')")or die(mysql_error());

mysql_query("insert into mpesa (code,sentby,paymentfor) values('$mpesa','$pnumber','Join club')")or die(mysql_error());

mysql_query("insert into activity_log (date,username,action) values(NOW(),'$pnumber','Joined Club')")or die(mysql_error());

	$phonen=$pnumber;		
$messag= "Congrats%20".$fname."%20You're%20Now%20a%20Club%20Member%20.%20RegisteredUnder%20".$runder."%20.%20with%20Regards%20.%20";
$sendsms ='http://sms.clarity.co.ke/sendsms.jsp?user=wealthmark&password=w@mark&mobiles='. $phonen .'&sms=' . $messag . ' &unicode=1&clientsmsid=10002&senderid=Wealthmark&version=3';
@$homepage = file_get_contents($sendsms);
?>
<script>
alert('You are successfuly registered as a Gold club member. please log in to your account using the details sent to your phone. ');
window.location = "index";
</script>

<?php
}else{?>
<script>
alert('The Number You are Registering Under Has reachead the limit of 3 . Register under another number or contact us for more information on 0772220320 ');
window.location = "goldclub";
</script>
<?php
}
}else{?>
<script>
alert('The Number You are Registering Under is not yet a club member. Please ask Him/Her to join the club or contact us on 0772220320 for more information ');
window.location = "goldclub";
</script>
<?php
}
}
}
?>