<?php
    include'connection.php';
    date_default_timezone_set("asia/Kolkata");
     $date=Date("d-M-Y");
     $time=Date("h:i:s A");
    if(isset($_POST['submit']))
    {
        $userid=$_POST['userid'];
        $sub=substr($userid,"0","2");
        if($sub==50)
		{
            $quGetUser="select * from retailer where Userid='$userid'";
			$reGetUser=mysqli_query($con,$quGetUser);
			$foundUser=mysqli_num_rows($reGetUser);
			if($foundUser>=1)
			{
			    $data=mysqli_fetch_array($reGetUser);
			    $Mobile=$data['Mobile'];
			    $pwd=$data['Password'];
			    $name=$data['Name'];
			    $status=$data['Active'];
			}
			else
			{
			    echo "<h1 align='center'><font color='#ff0000'> &#x2716; Invalid Userid !</font></h1>";
			}
								
								
		}
		elseif($sub==20)
		{						
			$quGetUser="select * from distributer where Userid='$userid'";
			$reGetUser=mysqli_query($con,$quGetUser);
			$foundUser=mysqli_num_rows($reGetUser);
			if($foundUser>=1)
			{
			    $data=mysqli_fetch_array($reGetUser);
			    $Mobile=$data['Mobile'];
			    $pwd=$data['Password'];
			    $name=$data['Name'];
			    $status=$data['Active'];
			}
			else
			{
			    echo "<h1 align='center'><font color='#ff0000'> &#x2716; Invalid Userid !</font></h1>";
			}
		}
		elseif($sub==30)
		{						
			$quGetUser="select * from masterdis where Userid='$userid'";
			$reGetUser=mysqli_query($con,$quGetUser);
			$foundUser=mysqli_num_rows($reGetUser);
			if($foundUser>=1)
			{
			    $data=mysqli_fetch_array($reGetUser);
			    $Mobile=$data['Mobile'];
			    $pwd=$data['Password'];
			    $name=$data['Name'];
			    $status=$data['Active'];
			}
			else
			{
			    echo "<h1 align='center'><font color='#ff0000'> &#x2716; Invalid Userid !</font></h1>";
			}
		}
		else
		{
		    echo "<h1 align='center'><font color='#ff0000'> &#x2716; Invalid Userid !</font></h1>";
		}
		
		
		if($foundUser>=1)
		{
		    $quGetBal="select * from wallet where Userid='$userid' order by Id desc";
		    $reGetBal=mysqli_query($con,$quGetBal);
		    $dataGetBal=mysqli_fetch_array($reGetBal);
		    $balance=$dataGetBal['Balance'];
		    
            if($status=='1')
            {
                echo "<h1 align='center'><font color='#ff0000'> &#x2716; Userid Deactivated ! Please Contact To Your Distributer!</font></h1>";
            }
            elseif($balance<=0)
            {
                echo "<h1 align='center'><font color='#ff0000'> &#x2716; Insufficient Balance ! Please Update Your Wallet !</font></h1>";
            }
		    else
		    {
    		    $quGetBal="select * from wallet where Userid='$userid' order by Id desc";
	        	$reGetBal=mysqli_query($con,$quGetBal);
	        	$dataGetBal=mysqli_fetch_array($reGetBal);
	    	    $oldBal=$dataGetBal['Balance'];
    	    	$newBal=$oldBal-1;
	    			
	        	$quInsertBal="insert into wallet(Userid,Openingbalance,Debit,Remarks,Balance,Date,Time,Transactiontype)values('$userid','$oldBal','1','Message Charge for Get password','$newBal','$date','$time','Deduction')";
                if(mysqli_query($con,$quInsertBal))
                {
                    $newEwalletId=mysqli_insert_id($con);
                    $quUpdateEwallet="update wallet set Paynrechid='$newEwalletId' where Id='$newEwalletId'";
                    mysqli_query($con,$quUpdateEwallet);
		            $msg="Dear ".$name." Your Userid = ".$userid." and Password Is = ".$pwd." Please Delete This Message After Login. Thanks !";
		    
		            $curl = curl_init();
                    curl_setopt_array($curl, array(
                    CURLOPT_URL => "http://sms2.kwikapi.com/sendSMS?username=sameermansuri111&message=".urlencode($msg)."&sendername=LLPRCH&smstype=TRANS&numbers=$Mobile&apikey=dc086ecd-1a22-4928-9e4e-69703230fd4e",
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => "",
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => false,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => "GET",
                                                ));
                    $response = curl_exec($curl);
                    $err = curl_error($curl);

                    curl_close($curl);

                    if ($err)
                    {
                         echo "cURL Error #:" . $err;
                    }
            	    else
		    	    {
			             $response;	$data2=json_decode($response);
	    			        echo "<h1 align='center'><font color='#008000'> &#x2714; Password Has Been Sent To Your Registerd Mobile Number !</font></h1><br>";
		    	    }
                }
            }
		}
        
    }
    else
    {
        echo "<center><h3 style='color:red;'>Note: It Will Be Chargeable As 1 Rs. Per SMS.</h3></center>";
    }
    
?>
<html>
<head>
<style>
body{background-color:#aedbf4;}
.content{ width:300px; height:300px; margin:50 100px; padding:0;}
#t1{width:300px; height:300px; border-collapse:collapse; text-align:center;  margin:0; padding:0; background:#fbebd5;}
#t1 td{width:200px;}
#llp{background:#996420; color:white; font-size:25px;}
#inp{width:280px; height:50px; font-size:20px; padding:5 10px;}
#btn{width:280px; height:50px; font-size:20px; border-radius:10px; background:#5c0e52; color:white;}
#btn:hover{cursor:pointer; background:#fcd5f7; color:black; }
</style>
</head>
<body >
    <div class="content">
        <form method="post">
            <table border="1" cellpadding="10" id="t1">
                <tr id="llp">
                    <td>LLP RECHARGE</td>
                </tr>
                <tr>
                    <td><input type="text" name="userid" id="inp" placeholder="Enter Your Userid .."></td>
                </tr>
                <tr>
                    <td><input type="submit" name="submit" value="Forget Password" id="btn"></td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>