<?php 
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['mobile'] == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    $mobile = strip_tags(mysqli_real_escape_string($con,$data['mobile']));
    $stage = strip_tags(mysqli_real_escape_string($con,$data['stage']));
    
    $che = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
    
    if($che->num_rows != 0)
    {
        if($stage == 1)
        {
            $ch = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
            if($row = $ch->fetch_assoc())
            {
                if($row['name'] != null)
                {
                    $p['name'] = $row['name'];
                    $p['last_name'] = $row['last_name'];
                    $p['email'] = $row['email'];
                    $p['selfie'] = $row['selfie_photo'];
                    $c = $p;
                }
                else
                {
                    $c = null;
                }
            }
            
            if($c != null)
            $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Success");
            else
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Error");
        }
        else if($stage == 2)
        {
            $ch = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
            if($row = $ch->fetch_assoc())
            {
                if($row['city'] != null)
                {
                    $p['address1'] = $row['address1'];
                    $p['address2'] = $row['address2'];
                    $p['city'] = $row['city'];
                    $p['pincode'] = $row['pincode'];
                    $c = $p;
                }
                else
                {
                    $c = null;
                }
            }
            
            if($c != null)
            $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Success");
            else
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Error");
        }
        else if($stage == 3)
        {
            $ch = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
            if($row = $ch->fetch_assoc())
            {
                if($row['pan_card'] != null)
                {
                    $p['pan_no'] = $row['pan_card'];
                    $p['aadhar_no'] = $row['aadhar_card'];
                    $p['driving_license'] = $row['driving_license'];
                    $p['vehicle_no'] = $row['vehicle_no'];
                    $p['vehicle_model'] = $row['vehicle_model'];
                    $p['pan_image'] = $row['pan_image'];
                    $p['dl_image'] = $row['dl_image'];
                    $c = $p;
                }
                else
                {
                    $c = null;
                }
            }
            
            if($c != null)
            $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Success");
            else
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Error");
        }
        else if($stage == 4)
        {
            $ch = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
            if($row = $ch->fetch_assoc())
            {
                if($row['ifsc_code'] != null)
                {
                $p['account_holder_name'] = $row['account_holder_name'];
                $p['bank_account_no'] = $row['bank_account_no'];
                $p['ifsc_code'] = $row['ifsc_code'];
                $p['bank_name'] = $row['bank_name'];
                $p['branch_name'] = $row['branch_name'];
                $p['bank_proof'] = $row['bank_proof'];
                $c = $p;
                }
                else
                {
                    $c = null;
                }
            }
            
            if($c != null)
            $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Success");
            else
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Error");
        }
        else if($stage == 5)
        {
            $ch = $con->query("select * from assist_details where mobile_no ='".$mobile."'");
            if($row = $ch->fetch_assoc())
            {
                if($row['fees_amount'] != null)
                {
                $p['work_hours'] = $row['work_hours'];
                $p['start_time'] = $row['start_time'];
                $p['end_time'] = $row['end_time'];
                $p['shirt_size'] = $row['shirt_size'];
                $p['fees_amount'] = $row['fees_amount'];
                $p['due_amount'] = $row['due_amount'];
                $p['fee_status'] = $row['fee_status'];
                $c = $p;
                }
                else
                {
                    $c = null;
                }
            }
            
            if($c != null)
            $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Success");
            else
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Error");
        }
        else
        {
            $returnArr = array("user"=>$c,"ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>$stage);
        }

    }
    else
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Mobile not Verified");
    }
}
echo json_encode($returnArr);
?>