<?php
$msg = '';
include("include/settings.php");
include("checksession.php");

if (isset($_POST['ajax_for']) && !empty($_POST['ajax_for'])) {

    $msg_html = "";
    if ($_POST['ajax_for'] == "unique_contact") {

        $msg_html = "pass";
        if (isset($_POST['contact_no']) && !empty($_POST['contact_no'])) {

            $contact_no = trim($_POST['contact_no']);

            $lead_id = 0;
            if (isset($_POST['lead_id']) && !empty($_POST['lead_id'])) {

                $lead_id = $_POST['lead_id'];
            }

            $check_query = "";
            $check_query .= "SELECT `lead_id` FROM rishta_leadmaster WHERE contact_no='" . $contact_no . "' ";
            if (!empty($lead_id)) {

                $check_query .= "  AND lead_id != '" . $lead_id . "'  ";
            }
            $check_query .= " LIMIT 1";

            $checkExists = $mysqli->prepare($check_query);
            $checkExists->execute();
            $checkExists = $checkExists->get_result();
            if (mysqli_num_rows($checkExists) > 0) {

                $msg_html = "fail";
                while ($rowData = mysqli_fetch_object($checkExists)) {

                    $msg_html = "";
                    $msg_html .= "<div class=\"row\">";
                    $msg_html .= "<div class=\"col-md-12\">";
                    $msg_html .= "<div class=\"alert alert-danger\">";
                    $msg_html .= "Already This Contact Number <a href=\"edit-rishta-lead.php?leadid=$rowData->lead_id\">This Lead</a>";
                    $msg_html .= "</div>";
                    $msg_html .= "</div>";
                    $msg_html .= "</div>";
                }
            }
        }
    }

    echo $msg_html;
    exit;
}


?>