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

// Logical section of page
$inquiryObj =  new  inquiry();


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['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = " inquiry_id LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_fullname LIKE '%".$_REQUEST['search']['value']."%' OR  inquiry_email LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_phone LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_city LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_postalCode LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_practiceName LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_website LIKE '%".$_REQUEST['search']['value']."%' OR inquiry_status LIKE '%".$_REQUEST['search']['value']."%' ";
    }    
        
    $orderFields = array('inquiry_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(" inquiry_id desc ");
    }
    
     
    $data   = array('where'=>$where,'limit' => $limit);

    $inquiryDetails = $inquiryObj->getAllRecords($data);
    $recordsTotal   =   $inquiryObj->getAllCount($data);
     
    if ($inquiryDetails && count($inquiryDetails)>0){
        foreach ($inquiryDetails as $key => $inquiry){


            $response[] = array( 
                    $inquiry->inquiry_id,
                    "<b>Name : </b>".$inquiry->inquiry_fullname."<br/><b>Email : </b>".$inquiry->inquiry_email,                    
                    "<b>Phone : </b>".$inquiry->inquiry_phone."<br/><b>City : </b>".$inquiry->inquiry_city."<br/><b>PostalCode : </b>".$inquiry->inquiry_postalCode,

                    "<b>PracticeName : </b>".$inquiry->inquiry_practiceName."<br/><b>Website : </b>".$inquiry->inquiry_website,
                    $inquiry->inquiry_status,
                    $inquiry->inquiry_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')
?>