<?php 
// Include main file
include_once('../libs/main.php');
// Check doctor Login
include_once('checkLogin.php');

// Logical section of page
$patient_otp_verifiedObj =  new  patient_otp_verified();

if (isset($_REQUEST['act']) && $_REQUEST['act']=='load'){
    
    $records = $_REQUEST['length'];
    $start=0;
    if(isset($_GET['start']) && $_GET['start']!='0'){
        $page = $_GET['start'];
    }
    $start=($page-1)*$limit;
    $limit = array('start'=>$_GET['start'],'record'=>$records);
    
    $where = " 1=1 ";

    if(isset($_REQUEST['patientotp_id']) && $_REQUEST['patientotp_id'] != '')
    {
        $where .= " AND patient_verified_id LIKE  '%".$_REQUEST['patientotp_id']."%'";
    }
    if(isset($_REQUEST['patientotp_uniqueid']) && $_REQUEST['patientotp_uniqueid'] != '')
    {
        $where .= " AND  patient_verified_patientuniqueid = '".$_REQUEST['patientotp_uniqueid']."'";
    }
    if(isset($_REQUEST['patientotp_email']) && $_REQUEST['patientotp_email'] != '')
    {
        $where .= " AND  patient_verified_email = '".$_REQUEST['patientotp_email']."' ";
    }
    if(isset($_REQUEST['patientotp_phone']) && $_REQUEST['patientotp_phone'] != '')
    {
        $where .= " AND  patient_verified_phone = '".$_REQUEST['patientotp_phone']."' ";
    }
    
    if(isset($_REQUEST['patientotp_type']) && $_REQUEST['patientotp_type'] != '')
    {
        $where .= " AND  patient_verified_type = '".$_REQUEST['patientotp_type']."' ";
    }
        


    if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = "patient_verified_id LIKE '%".$_REQUEST['search']['value']."%' OR  patient_verified_patientuniqueid LIKE '%".$_REQUEST['search']['value']."%' OR patient_verified_email LIKE '%".$_REQUEST['search']['value']."%' OR patient_verified_phone LIKE '%".$_REQUEST['search']['value']."%' OR patient_verified_type LIKE '%".$_REQUEST['search']['value']."%' ";
    }    
        
    
    $orderFields = array('patient_verified_id');
    
    // Array of order by 
    $orderby=array();
    if (isset($_REQUEST['order']['0']['column']) && $_REQUEST['order']['0']['column']!=""){
        $orderby = array(" ".$orderFields[$_REQUEST['order']['0']['column']]." ".$_REQUEST['order']['0']['dir']);
    }else{
        $orderby = array(" patient_verified_id desc ");
    }

    //$tables = array('tbl_dependant d','tbl_clinic cl');
    //$jfields = array('d.dependant_id = c.clinic_patient_depid','cl.clinic_id = c.clinic_patient_cid');
    //$jtype   = array("INNER","INNER");
    //$data   = array('where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype,'orderBy'=>$orderby,'limit' => $limit);

    $data = array('where' => $where,'orderBy'=>$orderby,'limit' => $limit);
    $patientotpverifiedDetails = $patient_otp_verifiedObj->getAllRecords($data);
    //print_r($patientotpverifiedDetails);exit;
    $recordsTotal   =   $patient_otp_verifiedObj->getAllCount($data);
        
    if ($patientotpverifiedDetails && count($patientotpverifiedDetails)>0){
        foreach ($patientotpverifiedDetails as $key => $patientotpverified)
        {
    
            $response[] = array('<input type="checkbox" name="check[]" id="check[]" value="'.$patientotpverified->patient_verified_id.'" class="check_class" />', 

                    $patientotpverified->patient_verified_id,
                    $patientotpverified->patient_verified_patientuniqueid,
                    $patientotpverified->patient_verified_email,
                    $patientotpverified->patient_verified_phone,
                    $patientotpverified->patient_verified_type,
                    "<b>Email Otp: </b>".$patientotpverified->patient_verified_eotp."<br/><b>Phone Otp: </b>".$patientotpverified->patient_verified_potp,
                    $patientotpverified->patient_verified_created_at

            );
        }
        $result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response);
    }else{
        $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
    }
    echo json_encode($result);
    exit;
}

// Include Template 
include_once('../libs/routs.php');
?>