 <?php
 include_once('__data_app_db.php');
 include_once('catch.php');
 $errData = $alert_type = $notify_type = $notify_desc = $insertid= $goTo=$contact='';
 $__json_res_out = 'oopsfalse';
 if(isset($_POST["phone"]) && $_POST["phone"] !== ''){

    $phone = validate_jsnj_varchar($_POST['phone']);
	$query = $_app_conn_db->query("SELECT * FROM app_user_account WHERE phoneNumber = '$phone'");
	$row = $query->num_rows;
    $myData = $query->fetch_array();
		if($row > 0){
            $userType = show_jsnj_text($myData['userType']);
            $userId= show_jsnj_text($myData['userId']);
            $email = show_jsnj_text($myData['email']);
            if($userType == '1'){

			    $_SESSION['hiwa_user']['app_loggedin'] = 'false';

                $_SESSION['userId']= show_jsnj_text($myData['userId']);
                $_SESSION['name'] = show_jsnj_text($myData['name']);
                $_SESSION['phoneNumber'] = show_jsnj_text($myData['phoneNumber']);
                $_SESSION['popup'] = '2';
                $_ip_jsnj = validate_jsnj_varchar($ip);

                $appOptSalt = rand(100000, 999999);
                $appOpt = md5($appOptSalt);


                $db_in_query = 'insert into forget_password (userId, forgetOtp, forgetOtpSalt, forgetTime,ipAddress) values("'.$userId.'","'.$appOpt.'","'.$appOptSalt.'","'.$currentTime.'","'.$_ip_jsnj.'")';

                    if (mysqli_query($_app_conn_db, $db_in_query)) {
                        //otp sms
                        $curl = curl_init();
                        curl_setopt_array($curl, array(
                            CURLOPT_URL => "https://api.msg91.com/api/v2/sendsms?country=91",
                            CURLOPT_RETURNTRANSFER => true,
                            CURLOPT_ENCODING => "",
                            CURLOPT_MAXREDIRS => 10,
                            CURLOPT_TIMEOUT => 30,
                            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                            CURLOPT_CUSTOMREQUEST => "POST",
                            CURLOPT_POSTFIELDS => "{ \"sender\": \"HYVADA\", \"route\": \"4\", \"country\": \"91\", \"sms\": [ { \"message\": \"Your Hyva Adda verification code is $appOptSalt for verify your mobile number.\", \"to\": [ $phone ] } ] }",
                            CURLOPT_SSL_VERIFYHOST => 0,
                            CURLOPT_SSL_VERIFYPEER => 0,
                            CURLOPT_HTTPHEADER => array(
                                "authkey: 284970ABhTMw3Kf5d70e8a7",
                                "content-type: application/json"
                            ),
                        ));

                        $response = curl_exec($curl);
                        $err = curl_error($curl);
                        curl_close($curl);
                        //end otp

                    $__json_res_out = 'true';
                    $alert_type = '1';//1 notie -- 2 sweetalert
                    $notify_type = '1';// 1 Success -- 2 Warning -- 3 Error -- 4 Information

                $notify_desc = 'Otp Sent Successfully. Wait for confirmation page....';
                $file = "../forget-otp-config?data=$userId&contact=$phone&email=$email";
                $goTo = "http://$host$uri/$file";
                    }

            } else {
                $__json_res_out = 'false';
                $alert_type = '1';//1 notie -- 2 sweetalert
                $notify_type = '4';// 1 Success -- 2 Warning -- 3 Error -- 4 Information
                $notify_desc = 'Please verify your account. Wait for confirmation page....';
                $file = "../otp-config?data=$userId&contact=$phone&email=$email";
                $goTo = "http://$host$uri/$file";
            }
		}else{
            $alert_type = '1';//1 notie -- 2 sweetalert
            $notify_type = '4';// 1 Success -- 2 Warning -- 3 Error -- 4 Information
            $notify_desc = 'Mobile Number do not match.';
		}

} else {
    $alert_type = '1';//1 notie -- 2 sweetalert
    $notify_type = '2';// 1 Success -- 2 Warning -- 3 Error -- 4 Information
    $notify_desc = 'Oops something want wrong';
}
 $data = array('page' => 'sign_up', 'res' => $__json_res_out,  'alert_type' => $alert_type, 'notify_type' => $notify_type, 'notify_desc' => $notify_desc, 'goTo' => $goTo, 'contact' => $contact);
 echo json_encode($data);
?>