<?php
	class check_otp{
		private $db;
		private $query;
		private $response;
		private $data;
		private $db_otp;
		private $user_otp;
		private $result;

		function __construct()
		{
			require_once("../db.php");
			$this->db = new websupportservice();
            $this->db = $this->db->__construct();
            if(!$this->db->connect_error)
            {
            	$this->query = $this->db->prepare("SELECT * FROM user_login");
            	$this->query->execute();
            	$this->response = $this->query->get_result();
            	if($this->response->num_rows !=0)
            	{
            		$this->data = $this->response->fetch_assoc();
            		$this->db_otp = $this->data['forgot_otp'];

            		$this->user_otp = trim($_POST['otp']);
            		$this->user_otp = htmlspecialchars($this->user_otp,ENT_QUOTES);
            		$this->user_otp = mysqli_real_escape_string($this->db,$this->user_otp);

            		if($this->db_otp == $this->user_otp)
            		{
            			$this->result = array(
							"status" => "ok"
						);
						echo json_encode($this->result);
            		}
            		else{
            			$this->result = array(
							"status" => "error",
							"cause" => "Wrong otp"	
						);
						echo json_encode($this->result);
		            }



            	}
            }
            else{
            	$this->result = array(
					"status" => "error",
					"cause" => "Database not connected"	
				);
				echo json_encode($this->result);
            }
    	}

    	function __destruct(){
          $this->query->close();
          $this->db->close();

           unset($this->db);
           unset($this->query);
           unset($this->response);
           unset($this->data);
           unset($this->db_otp);
           unset($this->user_otp);
           unset($this->result);
        }
	}

	new check_otp();
?>