
<?php 
session_start();
require "connection.php";
$email = "";
$name = "";
$errors = array();

//if user signup button
if(isset($_POST['signup'])){
    $fullname = mysqli_real_escape_string($conn, $_POST['fullname']);
    $emailorphone = mysqli_real_escape_string($conn, $_POST['emailorphone']);
    $phonenumber = mysqli_real_escape_string($conn, $_POST['phonenumber']);
    $country = mysqli_real_escape_string($conn, $_POST['country']);
    $accounttype = mysqli_real_escape_string($conn, $_POST['accounttype']);
    $currency = mysqli_real_escape_string($conn, $_POST['currency']);
    $password = mysqli_real_escape_string($conn, $_POST['password']);
    $cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);
    
    if($password !== $cpassword){
        $errors['password'] = "Confirm password not matched!";
    }
    $email_check = "SELECT * FROM crytobaseusers WHERE emailaddress = '$emailorphone'";
    $res = mysqli_query($conn, $email_check);
    if(mysqli_num_rows($res) > 0){
        $errors['email'] = "Email that you have entered is already exist!";
    }
    if(count($errors) === 0){
        $encpass = password_hash($password, PASSWORD_BCRYPT);
        //$encpass = $password;
       
        //$status = "Verified";
        $insert_data = "INSERT INTO crytobaseusers (fullname, emailaddress, country, phonenumber, password, accounttype, currency)
                        values('$fullname', '$emailorphone', '$country','$phonenumber', '$encpass', '$accounttype', '$currency')";
        $data_check = mysqli_query($conn, $insert_data);
        $_SESSION['fullname'] = $fullname;
        $_SESSION['success'] = "You are now logged in";
        header('location: login.php');
       
     }

}
    //if user click verification code submit button
   

    //if user click login button
    if(isset($_POST['login'])){
        $emailorphone = mysqli_real_escape_string($conn, $_POST['emailorphone']);

        $password = mysqli_real_escape_string($conn, $_POST['password']);
        // $encpass = $password;
        $check_email = "SELECT * FROM crytobaseusers WHERE emailaddress = '$emailorphone'";
        $res = mysqli_query($conn, $check_email);
        if(mysqli_num_rows($res) > 0){
            $fetch = mysqli_fetch_assoc($res);
            $fetch_pass = $fetch['password'];
            if(password_verify($password, $fetch_pass)){
                $_SESSION['emailaddress'] = $emailorphone;
                $status = $fetch['status'];
                if($status == 'Verified'){
                  $_SESSION['emailaddress'] = $emailorphone;
                  $_SESSION['password'] = $password;

                    header('location: ../dashboard');
                }else{
                    $info = "It's look like you haven't still verify your email - $email";
                    $_SESSION['info'] = $info;
                    header('location: ../dashboard');
                }
            }else{
                $errors['email'] = "Incorrect email or password!";
            }
        }else{
            $errors['email'] = "It's look like you're not yet a member! Click on the bottom link to signup.";
        }
    }

    //if user click continue button in forgot password form
    if(isset($_POST['check-email'])){
        $email = mysqli_real_escape_string($con, $_POST['email']);
        $check_email = "SELECT * FROM usertable WHERE email='$email'";
        $run_sql = mysqli_query($con, $check_email);
        if(mysqli_num_rows($run_sql) > 0){
            $code = rand(999999, 111111);
            $insert_code = "UPDATE usertable SET code = $code WHERE email = '$email'";
            $run_query =  mysqli_query($con, $insert_code);
            if($run_query){
                $subject = "Password Reset Code";
                $message = "Your password reset code is $code";
                $sender = "From: shahiprem7890@gmail.com";
                if(mail($email, $subject, $message, $sender)){
                    $info = "We've sent a passwrod reset otp to your email - $email";
                    $_SESSION['info'] = $info;
                    $_SESSION['email'] = $email;
                    header('location: reset-code.php');
                    exit();
                }else{
                    $errors['otp-error'] = "Failed while sending code!";
                }
            }else{
                $errors['db-error'] = "Something went wrong!";
            }
        }else{
            $errors['email'] = "This email address does not exist!";
        }
    }

    //if user click check reset otp button
    if(isset($_POST['check-reset-otp'])){
        $_SESSION['info'] = "";
        $otp_code = mysqli_real_escape_string($con, $_POST['otp']);
        $check_code = "SELECT * FROM usertable WHERE code = $otp_code";
        $code_res = mysqli_query($con, $check_code);
        if(mysqli_num_rows($code_res) > 0){
            $fetch_data = mysqli_fetch_assoc($code_res);
            $email = $fetch_data['email'];
            $_SESSION['email'] = $email;
            $info = "Please create a new password that you don't use on any other site.";
            $_SESSION['info'] = $info;
            header('location: new-password.php');
            exit();
        }else{
            $errors['otp-error'] = "You've entered incorrect code!";
        }
    }

    //if user click change password button
    if(isset($_POST['change-password'])){
        $_SESSION['info'] = "";
        $password = mysqli_real_escape_string($con, $_POST['password']);
        $cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
        if($password !== $cpassword){
            $errors['password'] = "Confirm password not matched!";
        }else{
            $code = 0;
            $email = $_SESSION['email']; //getting this email using session
            $encpass = password_hash($password, PASSWORD_BCRYPT);
            $update_pass = "UPDATE usertable SET code = $code, password = '$encpass' WHERE email = '$email'";
            $run_query = mysqli_query($con, $update_pass);
            if($run_query){
                $info = "Your password changed. Now you can login with your new password.";
                $_SESSION['info'] = $info;
                header('Location: password-changed.php');
            }else{
                $errors['db-error'] = "Failed to change your password!";
            }
        }
    }
    
   //if login now button click
    if(isset($_POST['login-now'])){
        header('Location: login-user.php');
    }
?>





















































<?php
        
                $payment_method_typeerror='';
                $amounterror='';
    
        
                if(isset($_POST['deposit'])){
                    
                    
                
                    $method=mysqli_real_escape_string($conn, $_POST['method']);
                    $amount=mysqli_real_escape_string($conn, $_POST['amount']);
                    $emailaddress=mysqli_real_escape_string($conn, $_POST['emailaddress']);
                    $status=mysqli_real_escape_string($conn, $_POST['status']);
                    
                    $id = strtoupper(substr(md5($emailaddress), 0,14).time()."UID");
                
                
                
            
            
            
                            
                            if(empty($amount)==false  and  empty($emailaddress)==false){
                            
                            $query="insert into deposit(method, amount, emailaddress, status, transactionid)values('$method', '$amount', '$emailaddress', '$status', '$id')";
                             mysqli_query($conn, $query);
                             
                        if($conn){
                
                         echo '<script>window.location="funding.php"</script>';
                        
                         
                         
                     }
             
                            }
                     
                }
    
    ?>




<?php
            if(isset($_POST['sub']))
            {
                $ssn = mysqli_real_escape_string($conn, $_POST['ssn']);
                $dob = mysqli_real_escape_string($conn, $_POST['dob']);
                $houseadd = mysqli_real_escape_string($conn, $_POST['houseadd']);
                $phone = mysqli_real_escape_string($conn, $_POST['phone']);
               

                $filename = $_FILES['image']['name'];
                $tempname = $_FILES['image']['tmp_name'];
                $folder = 'kycimages/'.$filename;
                
                $query = mysqli_query($conn, "insert into kyc (ssn, dob, houseadd, phone, file) values('$ssn', '$dob', '$houseadd', '$phone', '$filename')");
                if(move_uploaded_file($tempname, $folder)){
                    echo  "<h2>File uploaded successfully</h2>";

                }
                else{
                    echo  "<h2>File not uploaded</h2> ";
                }
            }






?>



    <!-- withdrawing  -->

    <?php

                $payment_method_typeerror='';
                $amounterror='';
	
		
				if(isset($_POST['bankwithdraw'])){
					
					
				
					$accountnum=mysqli_real_escape_string($conn, $_POST['accountnum']);
					$accountname=mysqli_real_escape_string($conn, $_POST['accountname']);
					$bankname=mysqli_real_escape_string($conn, $_POST['bankname']);
					$routin	=mysqli_real_escape_string($conn, $_POST['routin']);
					$amat=mysqli_real_escape_string($conn, $_POST['amat']);
                    $emailorphone=mysqli_real_escape_string($conn, $_POST['emailorphone']);
                    $id = strtoupper(substr(md5($emailorphone), 0,14).time()."UID");

                    $query = mysqli_query($conn, "insert into withdrawal (accountnum, accountname, bankname, routin, amat, emailaddress, transactionid) values('$accountnum', '$accountname', '$bankname', '$routin', '$amat', '$emailorphone', '$id')");
                    mysqli_query($conn, $query);

                    


                   
					
				
                }


    
    
    ?>
    <!--    FOR COPY TRADING -->
    <?php
   
                 
        if(isset($_POST['linkone']))
        {
           
             $name = mysqli_real_escape_string($conn, $_POST['name']);
            $fee = mysqli_real_escape_string($conn, $_POST['fee']);
            $profit = mysqli_real_escape_string($conn, $_POST['profit']);
             $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
             $query = "INSERT INTO trade (name, fee, profit, emailaddres)
                        values('$name', '$fee', '$profit', '$emailorphon')";
            $data = mysqli_query($conn, $query);
            if( mysqli_num_rows($data) > 1){
		     header('location: success.php');
		}else{
		    header('location: copy_trader.php');
		    
		}
        }
        
    ?>




     <?php
   
                 
        if(isset($_POST['linktwo']))
        {
           
             $name = mysqli_real_escape_string($conn, $_POST['name']);
            $fee = mysqli_real_escape_string($conn, $_POST['fee']);
            $profit = mysqli_real_escape_string($conn, $_POST['profit']);
             $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
             $query = "INSERT INTO trade (name, fee, profit, emailaddres)
                        values('$name', '$fee', '$profit', '$emailorphon')";
            $data = mysqli_query($conn, $query);
            if( mysqli_num_rows($data) > 1){
		     header('location: success.php');
		}else{
		    header('location: copy_trader.php');
		    
		}
        }
        
    ?>
       <?php
   
                 
        if(isset($_POST['linktree']))
        {
           
             $name = mysqli_real_escape_string($conn, $_POST['name']);
            $fee = mysqli_real_escape_string($conn, $_POST['fee']);
            $profit = mysqli_real_escape_string($conn, $_POST['profit']);
             $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
             $query = "INSERT INTO trade (name, fee, profit, emailaddres)
                        values('$name', '$fee', '$profit', '$emailorphon')";
            $data = mysqli_query($conn, $query);
            if( mysqli_num_rows($data) > 1){
		     header('location: success.php');
		}else{
		    header('location: copy_trader.php');
		    
		}
        }
        
    ?>
     <?php
   
                 
        if(isset($_POST['linkfour']))
        {
           
             $name = mysqli_real_escape_string($conn, $_POST['name']);
            $fee = mysqli_real_escape_string($conn, $_POST['fee']);
            $profit = mysqli_real_escape_string($conn, $_POST['profit']);
             $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
             $query = "INSERT INTO trade (name, fee, profit, emailaddres)
                        values('$name', '$fee', '$profit', '$emailorphon')";
            $data = mysqli_query($conn, $query);
            if( mysqli_num_rows($data) > 1){
		     header('location: success.php');
		}else{
		    header('location: copy_trader.php');
		    
		}
        }
        
    ?>
     <?php
   
                 
        if(isset($_POST['linkfive']))
        {
           
             $name = mysqli_real_escape_string($conn, $_POST['name']);
            $fee = mysqli_real_escape_string($conn, $_POST['fee']);
            $profit = mysqli_real_escape_string($conn, $_POST['profit']);
             $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
             $query = "INSERT INTO trade (name, fee, profit, emailaddres)
                        values('$name', '$fee', '$profit', '$emailorphon')";
            $data = mysqli_query($conn, $query);
            if( mysqli_num_rows($data) > 1){
		     header('location: success.php');
		}else{
		    header('location: copy_trader.php');
		    
		}
        }
        
    ?>

 <?php

                $payment_method_typeerror='';
                $amounterror='';
	
		
				if(isset($_POST['buy'])){
					
					
				
					$tpair=mysqli_real_escape_string($conn, $_POST['tpair']);
					$tprice=mysqli_real_escape_string($conn, $_POST['tprice']);
					$volume=mysqli_real_escape_string($conn, $_POST['volume']);
					$tloss	=mysqli_real_escape_string($conn, $_POST['tloss']);
					$tprofit=mysqli_real_escape_string($conn, $_POST['tprofit']);
                    $buy=mysqli_real_escape_string($conn, $_POST['buy']);
                    $status=mysqli_real_escape_string($conn, $_POST['status']);
                    $email = mysqli_real_escape_string($conn, $_POST['email']);
                    
                    $transid = strtoupper(substr(md5($emailorphone), 0,14).time()."HFX");
                    $query = mysqli_query($conn, "insert into tradehistory (transid, type, tpair, tprice, volume, stoploss, takeprofit, status, emailaddress) 
                    values('$transid', '$buy', '$tpair', '$tprice', '$volume', '$tloss', '$tprofit', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: platform.php');

                    } 
                                   
                    
		

                    


                   
					
				
                }


    
    
    ?>

                <!-- SELLING OF TRADE -->
<?php

                $payment_method_typeerror='';
                $amounterror='';
	
		
				if(isset($_POST['sell'])){
					
					
				
					$tpair=mysqli_real_escape_string($conn, $_POST['tpair']);
					$tprice=mysqli_real_escape_string($conn, $_POST['tprice']);
					$volume=mysqli_real_escape_string($conn, $_POST['volume']);
					$tloss	=mysqli_real_escape_string($conn, $_POST['tloss']);
					$tprofit=mysqli_real_escape_string($conn, $_POST['tprofit']);
                    $sell=mysqli_real_escape_string($conn, $_POST['sell']);
                    $status=mysqli_real_escape_string($conn, $_POST['status']);
                    $email = mysqli_real_escape_string($conn, $_POST['email']);
                    
                    $transid = strtoupper(substr(md5($emailorphone), 0,14).time()."HFX");
                    $query = mysqli_query($conn, "insert into tradehistory (transid, type, tpair, tprice, volume, stoploss, takeprofit, status, emailaddress) 
                    values('$transid', '$sell', '$tpair', '$tprice', '$volume', '$tloss', '$tprofit', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: platform.php');

                    } 
                                   
                    
		

                    


                   
					
				
                }


    
    
    ?>

    <!-- STARTER PLANS BEGINES FROM HERE -->


    <?php

				if(isset($_POST['stake1'])){
					$plan=mysqli_real_escape_string($conn, $_POST['plan']);
					$price=mysqli_real_escape_string($conn, $_POST['price']);
					$duration=mysqli_real_escape_string($conn, $_POST['duration']);
					$amount	=mysqli_real_escape_string($conn, $_POST['amount']);
                    $status	=mysqli_real_escape_string($conn, $_POST['status']);
                    $email	=mysqli_real_escape_string($conn, $_POST['email']);

					
                    $query = mysqli_query($conn, "insert into plans (plan, price, duration, amount, status, emailaddress) 
                    values('$plan', '$price', '$duration', '$amount', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: plans.php');

                    } 
                        
                }

    ?>


 <?php

				if(isset($_POST['stake2'])){
					$plan=mysqli_real_escape_string($conn, $_POST['plan']);
					$price=mysqli_real_escape_string($conn, $_POST['price']);
					$duration=mysqli_real_escape_string($conn, $_POST['duration']);
					$amount	=mysqli_real_escape_string($conn, $_POST['amount']);
                    $status	=mysqli_real_escape_string($conn, $_POST['status']);
                    $email	=mysqli_real_escape_string($conn, $_POST['email']);

					
                    $query = mysqli_query($conn, "insert into plans (plan, price, duration, amount, status, emailaddress) 
                    values('$plan', '$price', '$duration', '$amount', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: plans.php');

                    } 
                        
                }

    ?>


<?php

				if(isset($_POST['stake3'])){
					$plan=mysqli_real_escape_string($conn, $_POST['plan']);
					$price=mysqli_real_escape_string($conn, $_POST['price']);
					$duration=mysqli_real_escape_string($conn, $_POST['duration']);
					$amount	=mysqli_real_escape_string($conn, $_POST['amount']);
                    $status	=mysqli_real_escape_string($conn, $_POST['status']);
                    $email	=mysqli_real_escape_string($conn, $_POST['email']);

					
                    $query = mysqli_query($conn, "insert into plans (plan, price, duration, amount, status, emailaddress) 
                    values('$plan', '$price', '$duration', '$amount', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: plans.php');

                    } 
                        
                }

    ?>


<?php

				if(isset($_POST['stake4'])){
					$plan=mysqli_real_escape_string($conn, $_POST['plan']);
					$price=mysqli_real_escape_string($conn, $_POST['price']);
					$duration=mysqli_real_escape_string($conn, $_POST['duration']);
					$amount	=mysqli_real_escape_string($conn, $_POST['amount']);
                    $status	=mysqli_real_escape_string($conn, $_POST['status']);
                    $email	=mysqli_real_escape_string($conn, $_POST['email']);

					
                    $query = mysqli_query($conn, "insert into plans (plan, price, duration, amount, status, emailaddress) 
                    values('$plan', '$price', '$duration', '$amount', '$status', '$email')");
                  $result =  mysqli_query($conn, $query);
                 if( mysqli_num_rows($result) > 1)
                  {
                    header('location: success.php');
                    }else{

                        header('location: plans.php');

                    } 
                        
                }

    ?>
    



