<?php
// Include main file
include_once('../libs/main.php');
// Check clinic Login
include_once('checkLogin.php');
 
// Logical section of page
$clinicObj =  new  clinic();
$adminlogObj = new admin_log();
$modulepagesObj = new module_pages();

$filename=basename($_SERVER['SCRIPT_FILENAME']);

if($filename == 'cliniclist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
    $page_id = $adminlogObj->getPageId($filename);
    $allpages = $modulepagesObj->fromId($page_id);
    $pagename = $allpages->page;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='change_status' && isset($_REQUEST['clinic_id'])){
    if(isset($_REQUEST['status'])){

        $clinicDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
        if($clinicDetail->clinic_status == '1')
        {
            $old_status = 'Active';
        }else{
            $old_status = 'Inactive';
        }

        if($_REQUEST['status'] == '1')
        {
            $new_status = 'Inactive';
        }else{
            $new_status = 'Active';
        }
        $clinicObj->changeStatus($_REQUEST['clinic_id']);
        $clinic_detail = " <b>Id</b>:".$_REQUEST['clinic_id']." <br/><b>clinic status</b>: "." ".$old_status." <b>To</b> ".$new_status." ";
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        //echo RECORD_STATUS;
        if($_REQUEST['status'] == '1')
        {
            
            $messagecenter_accessObj = new messagecenter_access();
            $where = array("clinicid="=>$_REQUEST['clinic_id']);
            $messagecenter_accessArg = array('where'=>$where);
            $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
            
            if(isset($messagecenter_data->messagecenter_access_id) && $messagecenter_data->messagecenter_access_id != '')
            {
                 $data_msgcenterall['isenableremindernotification'] = '0';
                 $data_msgcenterall['isenablemarketingnotification'] = '0';
                 $data_msgcenterall['isenableadministrativenotification'] = '0';
                 $data_msgcenterall['isenabledigitaldocnotification'] = '0';
                 $data_msgcenterall['isenablepaymentnotification'] = '0';
                 $data_msgcenterall['isenablepaymentremindernotification'] = '0';
                 $data_msgcenterall['isenabledoubleappointmentnotification'] = '0';
                 $data_msgcenterall['isenablereviewlink'] = '0';
                 $data_msgcenterall['isenableprescreeninglink'] = '0';
                 $data_msgcenterall['isenableemailtemplate'] = '0';
        
                 $msgcenterrs=$messagecenter_accessObj->updateRecords($data_msgcenterall,$messagecenter_data->messagecenter_access_id);
            }
            
            $data_clinic['clinic_text_smschat'] = 'off';
            $clinic_rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['clinic_id']);

            
            $practiceObj = new practice();
            $where = array("practice_xcare_id="=>$_REQUEST['clinic_id']);
            $practiceArg = array('where'=>$where);
            $practice_data = $practiceObj->FromFields($practiceArg);
            if(isset($practice_data->practice_id) && $practice_data->practice_id != '')
            {
                $data_practiceall['practice_writeback'] = 'off';
                $data_practiceall['practice_patientwriteback'] = 'off';
                $data_practiceall['practice_appointmentwriteback'] = 'off';
                $data_practiceall['practice_statuswriteback'] = 'off';
                $data_practiceall['practice_sync'] = 'off';
        
                $practicedata=$practiceObj->updateRecords($data_practiceall,$practice_data->practice_id);
            }

            echo json_encode(array("msg" => RECORD_STATUS, "messagecenterid" => $messagecenter_data->messagecenter_access_id));
            

        }else{
            $messagecenter_accessObj = new messagecenter_access();
            $where = array("clinicid="=>$_REQUEST['clinic_id']);
            $messagecenter_accessArg = array('where'=>$where);
            $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
            
            echo json_encode(array("msg" => RECORD_STATUS,"messagecenterid" => $messagecenter_data->messagecenter_access_id));
        }
    }
    return true;
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='delete' && isset($_REQUEST['clinic_id'])){
    $clinicObj->deleteFromId($_REQUEST['clinic_id']);
    $successMsg = base64_encode(RECORD_DELETE);
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='messagechange_status' && isset($_REQUEST['messageaccess_id'])){
    
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '1')
    {

        /*echo $_REQUEST['status'];exit;*/
        //echo $_REQUEST['messageaccess_id'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenableremindernotification == '1')
        {
            $reminder = '0';
            $old_reminderdata = 'Enable';
            $new_reminderdata = 'Disable';
        }else{
            $reminder = '1';
            $old_reminderdata = 'Disable';
            $new_reminderdata = 'Enable';
        }

        $clinic_detail = " <b>Reminder status old</b> ".$old_reminderdata." <b>to</b> ".$new_reminderdata;

        $data_reminder['isenableremindernotification'] = $reminder;
        //echo $_REQUEST['clinic_id'];exit;
        $rs=$messagecenter_accessObj->updateRecords($data_reminder,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;

        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);

        echo json_encode(array("msg" => RECORD_STATUS, "reminder" => $reminder));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '2')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenablemarketingnotification == '1')
        {
            $marketing = '0';
            $old_marketingdata = 'Enable';
            $new_marketingdata = 'Disable';
        }else{
            $marketing = '1';
            $old_marketingdata = 'Disable';
            $new_marketingdata = 'Enable';
        }

        $clinic_detail = " <b>Marketing status old</b> ".$old_marketingdata." <b>to</b> ".$new_marketingdata;

        $data_marketing['isenablemarketingnotification'] = $marketing;
        $rs=$messagecenter_accessObj->updateRecords($data_marketing,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);

        echo json_encode(array("msg" => RECORD_STATUS, "marketing" => $marketing));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '3')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenableadministrativenotification == '1')
        {
            $adminstrative = '0';
            $old_adminstrativedata = 'Enable';
            $new_adminstrativedata = 'Disable';
        }else{
            $adminstrative = '1';
            $old_adminstrativedata = 'Disable';
            $new_adminstrativedata = 'Enable';
        }

        $clinic_detail = " <b>Adminstrative status old<b/> ".$old_adminstrativedata." <b>to</b> ".$new_adminstrativedata;

        $data_adminstrative['isenableadministrativenotification'] = $adminstrative;
        $rs=$messagecenter_accessObj->updateRecords($data_adminstrative,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "adminstrative" => $adminstrative));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '4')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenabledigitaldocnotification == '1')
        {
            $digitaldoc = '0';
            $old_digitaldocdata = 'Enable';
            $new_digitaldocdata = 'Disable';
        }else{
            $digitaldoc = '1';
            $old_digitaldocdata = 'Disable';
            $new_digitaldocdata = 'Enable';
        }

        $clinic_detail = " <b>Digitaldoc status old</b> ".$old_digitaldocdata." <b>to</b> ".$new_digitaldocdata;

        $data_digitaldoc['isenabledigitaldocnotification'] = $digitaldoc;
        $rs=$messagecenter_accessObj->updateRecords($data_digitaldoc,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "digitaldoc" => $digitaldoc));
        return true;
    }
    
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '5')
    {
        //echo $_REQUEST['status'];exit;
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        //print_r($messagecenter_data);exit;
        if($clinic_data->clinic_text_smschat == 'on')
        {
            $text_sms_chat = 'off'; 
            $old_text_smsdata = 'Enable';
            $new_text_smsdata = 'Disable';  
        }else{
            $text_sms_chat = 'on';
            $old_text_smsdata = 'Disable';
            $new_text_smsdata = 'Enable';
        }

        $clinic_detail = " <b>Text Sms status old</b> ".$old_text_smsdata." <b>to</b> ".$new_text_smsdata;

        $data_clinic['clinic_text_smschat'] = $text_sms_chat;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "text_sms" => $text_sms_chat));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '6')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenablepaymentnotification == '1')
        {
            $paymentinvoice = '0';
            $old_paymentinvoicedata = 'Enable';
            $new_paymentinvoicedata = 'Disable';
        }else{
            $paymentinvoice = '1';
            $old_paymentinvoicedata = 'Disable';
            $new_paymentinvoicedata = 'Enable';
        }

        $clinic_detail = " <b>Payment Invoice status old</b> ".$old_paymentinvoicedata." <b>to</b> ".$new_paymentinvoicedata;

        $data_paymentinvoice['isenablepaymentnotification'] = $paymentinvoice;
        $rs=$messagecenter_accessObj->updateRecords($data_paymentinvoice,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "paymentinvoice" => $paymentinvoice));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '7')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenablepaymentremindernotification == '1')
        {
            $reminderpaymentinvoice = '0';
            $old_reminderpaymentinvoicedata = 'Enable';
            $new_reminderpaymentinvoicedata = 'Disable';
        }else{
            $reminderpaymentinvoice = '1';
            $old_reminderpaymentinvoicedata = 'Disable';
            $new_reminderpaymentinvoicedata = 'Enable';
        }

        $clinic_detail = " <b>Reminder Payment Invoice status old</b> ".$old_reminderpaymentinvoicedata." <b>to</b> ".$new_reminderpaymentinvoicedata;

        $data_paymentinvoice['isenablepaymentremindernotification'] = $reminderpaymentinvoice;
        $rs=$messagecenter_accessObj->updateRecords($data_paymentinvoice,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "reminderpaymentinvoice" => $reminderpaymentinvoice));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '8')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenabledoubleappointmentnotification == '1')
        {
            $doubleappointment = '0';
            $old_doubleappointmentdata = 'Enable';
            $new_doubleappointmentdata = 'Disable'; 
        }else{
            $doubleappointment = '1';
            $old_doubleappointmentdata = 'Disable';
            $new_doubleappointmentdata = 'Enable';
        }

        $clinic_detail = " <b>double appoinment old</b> ".$old_doubleappointmentdata." <b>to</b> ".$new_doubleappointmentdata;

        $data_doubleappointment['isenabledoubleappointmentnotification'] = $doubleappointment;
        $rs=$messagecenter_accessObj->updateRecords($data_doubleappointment,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "doubleappoinment" => $doubleappointment));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '9')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenablereviewlink == '1')
        {
            $viewlink = '0';
            $old_viewlinkdata = 'Enable';
            $new_viewlinkdata = 'Disable'; 
        }else{
            $viewlink = '1';
            $old_viewlinkdata = 'Disable';
            $new_viewlinkdata = 'Enable';
        }

        $clinic_detail = " <b>Review link old</b> ".$old_viewlinkdata." <b>to</b> ".$new_viewlinkdata;

        $data_viewlink['isenablereviewlink'] = $viewlink;
        $rs=$messagecenter_accessObj->updateRecords($data_viewlink,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "viewlink" => $viewlink));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '10')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenableprescreeninglink == '1')
        {
            $prescreeninglink = '0';
            $old_prescreeninglinkdata = 'Enable';
            $new_prescreeninglinkdata = 'Disable'; 
        }else{
            $prescreeninglink = '1';
            $old_prescreeninglinkdata = 'Disable';
            $new_prescreeninglinkdata = 'Enable';
        }

        $clinic_detail = " <b>Pre-screening link old</b> ".$old_prescreeninglinkdata." <b>to</b> ".$new_prescreeninglinkdata;

        $data_prescreeninglink['isenableprescreeninglink'] = $prescreeninglink;
        $rs=$messagecenter_accessObj->updateRecords($data_prescreeninglink,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "prescreeninglink" => $prescreeninglink));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '11')
    {
        //echo $_REQUEST['status'];exit;
        $messagecenter_accessObj = new messagecenter_access();
        $where = array("messagecenter_access_id="=>$_REQUEST['messageaccess_id']);
        $messagecenter_accessArg = array('where'=>$where);
        $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
        //print_r($messagecenter_data);exit;
        if($messagecenter_data->isenableemailtemplate == '1')
        {
            $emailtemplate = '0';
            $old_emailtemplatedata = 'Enable';
            $new_emailtemplatedata = 'Disable'; 
        }else{
            $emailtemplate = '1';
            $old_emailtemplatedata = 'Disable';
            $new_emailtemplatedata = 'Enable';
        }

        $clinic_detail = " <b>Pre-screening link old</b> ".$old_emailtemplatedata." <b>to</b> ".$new_emailtemplatedata;

        $data_emailtemplate['isenableemailtemplate'] = $emailtemplate;
        $rs=$messagecenter_accessObj->updateRecords($data_emailtemplate,$_REQUEST['messageaccess_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "emailtemplate" => $emailtemplate));
        return true;
    }

}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='add_practicedata' && isset($_REQUEST['clinic_id']))
{
    $clinicId = $_REQUEST['clinic_id'];
    $practiceObj =  new  practice();
    $where = array("practice_xcare_id="=>$clinicId);
    $practiceArg = array('where'=>$where);
    $practice_data = $practiceObj->fromFields($practiceArg);

    if($practice_data)
    {
        echo json_encode(array("msg" => "Already Exists", "reminder" => $reminder));
        return true;
    }else
    {
        $clinicObj = new clinic();
        $clinicDetails = $clinicObj->fromId($clinicId);
        $practiceObj =  new  practice();
        $where = array("practice_name="=>'Dummy');
        $practiceArgChk = array('where'=>$where);
        $practicechk = $practiceObj->fromFields($practiceArgChk);
        if($practicechk->practice_name != '')
        {
            
            $dummy_id = (preg_replace('/\D/', '', $practicechk->practice_office_id) + 1);
            
            $dum_len = strlen((string)$dummy_id);

            if($dum_len == '1')
            {
                $dummy_offic_id = 'Dummy0'.$dummy_id;
            }else
            {
                $dummy_offic_id = 'Dummy'.$dummy_id;
            }

            
            $addpmsdata = array(
                "practice_name" =>$clinicDetails->clinic_name,
                "practice_office_id" =>$dummy_offic_id,
                "practice_secret_key" => "AAA678769KJUTZ2",
                "practice_pms" => 'Dummy',
                "practice_sikka_id" => "1",
                "practice_xcare_id" => $clinicId,
                );
            
            $rs_practice = $practiceObj->addRecords($addpmsdata);
        }else
        {
            $addpmsdata = array(
                "practice_name" =>$clinicDetails->clinic_name,
                "practice_office_id" =>"DUMMY01",
                "practice_secret_key" => "AAA678769KJUTZ1",
                "practice_pms" => 'Dummy',
                "practice_sikka_id" => "1",
                "practice_xcare_id" => $clinicId,
                );
            $rs_practice = $practiceObj->addRecords($addpmsdata);
        }

        echo json_encode(array("msg" => "Successfully Add", "prec_id" => $rs_practice));
        return true;
        
    }

}

if(isset($_REQUEST['action']) && $_REQUEST['action']!=''){
    if($_REQUEST['action']=="activate_all"){
        $data=array("clinic_status" => '1');

        $chk_data = $_POST['check'];
        foreach($chk_data as $akey => $val_actchk)
        {
            $old_data = $clinicObj->fromId($val_actchk);
            if($old_data->clinic_status == '1')
            {
                $old_status = 'Active';
            }else{
                $old_status = 'Inactive';
            }

            if($old_data->clinic_status != '1')
            {
                $new_status = 'Active';
                $clinicdata = " <b>Id</b>:".$val_actchk." <br/><b>Status</b>: "." ".$old_status." <b>To</b> ".$new_status." ";
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinicdata);
            }
        }
        $rs = $clinicObj->updateManyRecords($data, $_POST['check']);
        $successMsg = base64_encode(RECORD_ALL_ACTIVE);
    }else if($_REQUEST['action']=="inactivate_all"){
        $data=array("clinic_status" => '0');
        $chk_data = $_POST['check'];
        foreach($chk_data as $akey => $val_actchk)
        {
            $old_data = $clinicObj->fromId($val_actchk);
            if($old_data->clinic_status == '1')
            {
                $old_status = 'Active';
            }else{
                $old_status = 'Inactive';
            }

            if($old_data->clinic_status != '0')
            {
                $new_status = 'Inactive';
                $clinicdata = " <b>Id</b>:".$val_actchk." <br/><b>Status</b>: "." ".$old_status." <b>To</b> ".$new_status." ";
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinicdata);
            }
        }
        $rs = $clinicObj->updateManyRecords($data, $_POST['check']);
        $successMsg = base64_encode(RECORD_ALL_INACTIVE);
    }else if($_REQUEST['action']=="delete_all"){

        $chk_del = implode(",",$_POST['check']);
        
        $clinicdata = " <b>Delete Id</b>: "." ".$chk_del;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinicdata);
            
        $rs = $clinicObj->deleteManyRecords($_POST['check']);
        $successMsg = base64_encode(RECORD_ALL_DELETE);
    }
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='add_pmsdata' && isset($_REQUEST['clinic_id']))
{
    $clinicId = $_REQUEST['clinic_id'];
    $practiceObj =  new  practice();
    $where = array("practice_xcare_id="=>$clinicId);
    $practiceArg = array('where'=>$where);
    $practice_data = $practiceObj->fromFields($practiceArg);

    if($practice_data)
    {
        echo json_encode(array("msg" => "Already Exists", "reminder" => $reminder));
        return true;
    }else
    {

        $practiceObj =  new  practice();
        $where = array("practice_name="=>'Dummy');
        $practiceArgChk = array('where'=>$where);
        $practicechk = $practiceObj->fromFields($practiceArgChk);
        if($practicechk->practice_name != '')
        {
            
            $dummy_id = (preg_replace('/\D/', '', $practicechk->practice_office_id) + 1);
            
            $dum_len = strlen((string)$dummy_id);

            if($dum_len == '1')
            {
                $dummy_offic_id = 'Dummy0'.$dummy_id;
            }else
            {
                $dummy_offic_id = 'Dummy'.$dummy_id;
            }

            
            $addpmsdata = array(
                "practice_name" =>"Dummy",
                "practice_office_id" =>$dummy_offic_id,
                "practice_secret_key" => "AAA678769KJUTZ2",
                "practice_pms" => 'Dummy',
                "practice_sikka_id" => "1",
                "practice_xcare_id" => $clinicId,
                );
            
            $rs_practice = $practiceObj->addRecords($addpmsdata);
        }else
        {
            $addpmsdata = array(
                "practice_name" =>"Dummy",
                "practice_office_id" =>"DUMMY01",
                "practice_secret_key" => "AAA678769KJUTZ1",
                "practice_pms" => 'Dummy',
                "practice_sikka_id" => "1",
                "practice_xcare_id" => $clinicId,
                );
            $rs_practice = $practiceObj->addRecords($addpmsdata);
        }

        echo json_encode(array("msg" => "Successfully Add", "prec_id" => $rs_practice));
        return true;
        
    }

}

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 and clinic_status = '1'";

    if(isset($_REQUEST['fullname']) && $_REQUEST['fullname'] != '')
    {
        $where .= " AND clinic_name LIKE  '%".$_REQUEST['fullname']."%'";
    }
    if(isset($_REQUEST['clinic_unique_id']) && $_REQUEST['clinic_unique_id'] != '')
    {
        $where .= " AND  clinic_unique_id = '".$_REQUEST['clinic_unique_id']."' ";
    }
    if(isset($_REQUEST['clinic_email']) && $_REQUEST['clinic_email'] != '')
    {
        $where .= " AND  (clinic_email = '".$_REQUEST['clinic_email']."' OR user_email_address = '".$_REQUEST['clinic_email']."') ";
    }
    if(isset($_REQUEST['clinic_phone']) && $_REQUEST['clinic_phone'] != '')
    {
        $where .= " AND  clinic_phone = '".$_REQUEST['clinic_phone']."' ";
    }
    if(isset($_REQUEST['clinic_specality']) && $_REQUEST['clinic_specality'] != '')
    {
        $where .= " AND FIND_IN_SET('".$_REQUEST['clinic_specality']."', clinic_primary_speciality)";
    }
    if(isset($_REQUEST['clinic_website']) && $_REQUEST['clinic_website'] != '')
    {
        $where .= " AND  clinic_website = '".$_REQUEST['clinic_website']."' ";
    }
    if(isset($_REQUEST['clinic_user']) && $_REQUEST['clinic_user'] != '')
    {
        $where .= " AND  clinic_user_id = '".$_REQUEST['clinic_user']."' ";
    }
    if(isset($_REQUEST['clinic_status']) && $_REQUEST['clinic_status'] != '')
    {
        $where .= " AND  clinic_status = '".$_REQUEST['clinic_status']."' ";
    }
    if(isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
    {
        $where .= " AND clinic_id = '".$_REQUEST['clinic_id']."'";
    }
    if(isset($_REQUEST['clinic_date']) && $_REQUEST['clinic_date'] != '')
    {
        $where .= " AND date(clinic_created_at) = '".$_REQUEST['clinic_date']."'";
    }
    if(isset($_REQUEST['clinic_feature']) && $_REQUEST['clinic_feature'] != '')
    {
        $where .= " AND FIND_IN_SET('".$_REQUEST['clinic_feature']."', clinic_feature)";
    }

    if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = " clinic_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR clinic_id LIKE '%".$_REQUEST['search']['value']."%' OR clinic_name LIKE '%".$_REQUEST['search']['value']."%' OR clinic_email LIKE '%".$_REQUEST['search']['value']."%' OR clinic_phone LIKE '%".$_REQUEST['search']['value']."%' OR clinic_website LIKE '%".$_REQUEST['search']['value']."%' OR user_fname LIKE '%".$_REQUEST['search']['value']."%'  OR user_lname LIKE '%".$_REQUEST['search']['value']."%'   OR user_email_address LIKE '%".$_REQUEST['search']['value']."%' OR clinic_rating LIKE '%".$_REQUEST['search']['value']."%' OR clinic_reviewCount LIKE '%".$_REQUEST['search']['value']."%' OR ( CONCAT(user_fname,'',user_lname) LIKE '%".$_REQUEST['search']['value']."%' ) OR ( CONCAT(user_fname,' ',user_lname) LIKE '%".$_REQUEST['search']['value']."%' ) OR date(clinic_created_at) LIKE '%".$_REQUEST['search']['value']."%' ";
    }    
        
    $orderFields = array('','clinic_id','clinic_unique_id','clinic_name,user_fname,user_lname,user_email_address','clinic_email,clinic_phone','clinic_created_at');
    
    // 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(" clinic_id desc ");
    }
     $fields  = array('c.*','u.*','a.*');
    $tables = array('tbl_user u','tbl_address a');
    $jfields = array('c.clinic_user_id = u.user_id','c.clinic_id = a.address_clinic_id');
    $jtype   = array("INNER","LEFT"); 
    $data    = array('fields' => $fields, 'where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype,'orderBy'=>$orderby,'limit' => $limit);

    $clinicDetails = $clinicObj->getAllRecords($data);
    $recordsTotal   =   $clinicObj->getAllCount($data);
        $t = "";
    if ($clinicDetails && count($clinicDetails)>0){
        $reminder = "";
        $marketing = "";
        $administrative = "";
        $digitaldoc = "";
        foreach ($clinicDetails as $key => $clinic){

            $stripecardObj = new stripecard();
            $where = array("stripecard_user_id="=>$clinic->clinic_user_id,'stripecard_status='=>'Active');
            $stripeArg = array('where'=>$where);
            $cardExist = $stripecardObj->FromFields($stripeArg);
            $last4="<b style='color:red;'>Card Not Added Yet.</b>";
            if($cardExist){
                $last4 = "<b style='color:green;'>*****".$cardExist->stripecard_last4."</b>";
            }

            //$pamsStatus = $clinic->clinic_pmsStatus;



            $messagecenter_accessObj = new messagecenter_access();
            $where = array("clinicid="=>$clinic->clinic_id);
            $messagecenter_accessArg = array('where'=>$where);
            $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
            //echo $messagecenter_data->clinicid ."==". $clinic->clinic_id;
            //exit;
            if($messagecenter_data->clinicid == $clinic->clinic_id)
            {
              //  echo 'ttt';exit;
                if($messagecenter_data->isenableremindernotification == '1')
                  {
                    $messagecenter_reminder = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,1,'.$clinic->clinic_id.')"';
                    $reminder_check ='checked';
                  }else{
                    $messagecenter_reminder = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,1,'.$clinic->clinic_id.')"';
                    $reminder_check = "";
                  }

                  if($messagecenter_data->isenablemarketingnotification == '1')
                  {
                    $messagecenter_marketing = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,2,'.$clinic->clinic_id.')"';
                    $marketing_check ='checked';
                  }else{
                    $messagecenter_marketing = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,2,'.$clinic->clinic_id.')"';
                    $marketing_check = "";
                  }

                  if($messagecenter_data->isenableadministrativenotification == '1')
                  {
                    $messagecenter_administrative = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,3,'.$clinic->clinic_id.')"';
                    $administrative_check ='checked';
                  }else{
                    $messagecenter_administrative = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,3,'.$clinic->clinic_id.')"';
                    $administrative_check = "";
                  }
                  
                  if($messagecenter_data->isenabledigitaldocnotification == '1')
                  {
                    $messagecenter_digitaldoc = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,4,'.$clinic->clinic_id.')"';
                    $digitaldoc_check ='checked';
                  }else{
                    $messagecenter_digitaldoc = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,4,'.$clinic->clinic_id.')"';
                    $digitaldoc_check = "";
                  }

                  if($messagecenter_data->isenablepaymentnotification == '1')
                  {
                    $messagecenter_paymentinvoice = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,6,'.$clinic->clinic_id.')"';
                    $paymentinvoice_check ='checked';
                  }else{
                    $messagecenter_paymentinvoice = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,6,'.$clinic->clinic_id.')"';
                    $paymentinvoice_check = "";
                  }

                  if($messagecenter_data->isenablepaymentremindernotification == '1')
                  {
                    $messagecenter_reminderpaymentinvoice = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,7,'.$clinic->clinic_id.')"';
                    $reminderpaymentinvoice_check ='checked';
                  }else{
                    $messagecenter_reminderpaymentinvoice = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,7,'.$clinic->clinic_id.')"';
                    $reminderpaymentinvoice_check = "";
                  }

                  if($messagecenter_data->isenabledoubleappointmentnotification == '1')
                  {
                    $messagecenter_doubleappoinment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,8,'.$clinic->clinic_id.')"';
                    $doubleappoinment_check ='checked';
                  }else{
                    $messagecenter_doubleappoinment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,8,'.$clinic->clinic_id.')"';
                    $doubleappoinment_check = "";
                  }

                  if($messagecenter_data->isenablereviewlink == '1')
                  {
                    $messagecenter_viewlink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,9,'.$clinic->clinic_id.')"';
                    $viewlink_check ='checked';
                  }else{
                    $messagecenter_viewlink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,9,'.$clinic->clinic_id.')"';
                    $viewlink_check = "";
                  }

                  if($messagecenter_data->isenableprescreeninglink == '1')
                  {
                    $messagecenter_prescreeninglink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,10,'.$clinic->clinic_id.')"';
                    $prescreeninglink_check ='checked';
                  }else{
                    $messagecenter_prescreeninglink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,10,'.$clinic->clinic_id.')"';
                    $prescreeninglink_check = "";
                  }

                  if($messagecenter_data->isenableemailtemplate == '1')
                  {
                    $messagecenter_emailtemplate = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,11,'.$clinic->clinic_id.')"';
                    $emailtemplate_check ='checked';
                  }else{
                    $messagecenter_emailtemplate = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,11,'.$clinic->clinic_id.')"';
                    $emailtemplate_check = "";
                  }
                  
                  /*if($clinic->clinic_status == '0')
                  {
                      $messagecenter_reminder = 'onclick="check_status()"';
                   }*/  
              
                /*$reminder = "Reminder : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_reminder' name='mesg_reminder' value='reminder' 
                                $messagecenter_reminder $reminder_check >
                                <span class='slider'></span>
                            </label>";*/

                $reminder = "Reminder : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_reminder_$messagecenter_data->messagecenter_access_id' name='mesg_reminder' value='reminder' reminder-data='$messagecenter_data->isenableremindernotification' 
                                $messagecenter_reminder $reminder_check  clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>"; 

                /*$marketing = "Marketing : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_marketing' name='mesg_marketing' value='marketing'
                                $messagecenter_marketing  $marketing_check >
                                <span class='slider'></span>
                            </label>";*/


                $marketing = "<br/><br/>Marketing : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_marketing_$messagecenter_data->messagecenter_access_id' name='mesg_marketing' value='marketing' marketing-data='$messagecenter_data->isenablemarketingnotification'
                                $messagecenter_marketing  $marketing_check  clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                /*$administrative = "Administrative : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_administrative' name='mesg_administrative' 
                                $messagecenter_administrative value='administrative' $administrative_check >
                                <span class='slider'></span>
                            </label>";*/

                $administrative = "<br/><br/>Administrative : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_administrative_$messagecenter_data->messagecenter_access_id' name='mesg_administrative' 
                                $messagecenter_administrative value='administrative' adminstrative-data='$messagecenter_data->isenableadministrativenotification' $administrative_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                /*$digitaldoc = "Digitaldoc : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_digitaldoc' name='mesg_digitaldoc' 
                                $messagecenter_digitaldoc value='digitaldoc' $digitaldoc_check >
                                <span class='slider'></span>
                            </label>";*/

                $digitaldoc = "<br/><br/>Digitaldoc : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_digitaldoc_$messagecenter_data->messagecenter_access_id' name='mesg_digitaldoc' 
                                $messagecenter_digitaldoc value='digitaldoc' digitaldoc-data='$messagecenter_data->isenabledigitaldocnotification' $digitaldoc_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $paymentinvoice = "<br/><br/>Payment Invoice : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_paymentinvoice_$messagecenter_data->messagecenter_access_id' name='mesg_paymentinvoice' 
                                $messagecenter_paymentinvoice value='paymentinvoice' paymentinvoice-data='$messagecenter_data->isenablepaymentnotification' $paymentinvoice_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $reminderpaymentinvoice = "<br/><br/>Reminder Payment : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_reminderpaymentinvoice_$messagecenter_data->messagecenter_access_id' name='mesg_reminderpaymentinvoice' 
                                $messagecenter_reminderpaymentinvoice value='reminderpaymentinvoice' reminderpaymentinvoice-data='$messagecenter_data->isenablepaymentremindernotification' $reminderpaymentinvoice_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $doubleappoinment_data = "<br/><br/>Double Appoinment : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_doubleappoinment_$messagecenter_data->messagecenter_access_id' name='mesg_doubleappoinmente' 
                                $messagecenter_doubleappoinment value='doubleappoinment' doubleappoinment-data='$messagecenter_data->isenabledoubleappointmentnotification' $doubleappoinment_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $viewlink_data = "<br/><br/>Review Link : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_viewlink_$messagecenter_data->messagecenter_access_id' name='mesg_viewlinke' 
                                $messagecenter_viewlink value='viewlink' viewlink-data='$messagecenter_data->isenablereviewlink' $viewlink_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $prescreeninglink_data = "<br/><br/>Prescreening : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_prescreeninglink_$messagecenter_data->messagecenter_access_id' name='mesg_prescreeninglink' 
                                $messagecenter_prescreeninglink value='prescreeninglink' prescreeninglink-data='$messagecenter_data->isenableprescreeninglink' $prescreeninglink_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

                $emailtemplate_data = "<br/><br/>Email Template : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_emailtemplate_$messagecenter_data->messagecenter_access_id' name='mesg_emailtemplate' 
                                $messagecenter_emailtemplate value='emailtemplate' emailtemplate-data='$messagecenter_data->isenableemailtemplate' $emailtemplate_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";



            }else{
                //echo 'asfs';exit;
                $reminder = "";
                $marketing = "";
                $administrative = "";
                $digitaldoc = "";
                $paymentinvoice = "";
                $reminderpaymentinvoice = "";
                $doubleappoinment_data = "";
                $viewlink_data = "";
                $prescreeninglink_data = "";
                $emailtemplate_data = "";
            }
            //echo $reminder;exit;
         if($clinic->clinic_text_smschat == 'on')
            {

                $text_sms = ' onclick="messagecenter_change_status(0,0,5,'.$clinic->clinic_id.')"';
                $textsms_check ='checked';
            }else{
                $text_sms = ' onclick="messagecenter_change_status(0,1,5,'.$clinic->clinic_id.')"';
                $textsms_check = "";
            }

            
            $clinictextsms = "<br/><br/>Text SMS : <br/><label class='switch switch-primary mr-3 text_sms_clinic'>
                                <input type='checkbox' id='text_sms_clinic_$clinic->clinic_id' name='text_sms_clinic' text_sms_clinic-data='$clinic->clinic_text_smschat' 
                                 $text_sms  $textsms_check  clinicstatus-data = $clinic->clinic_status>
                                <span class='slider'></span>
                            </label>";


            $address="";
            if($clinic->address_country=="" || $clinic->address_latitude=="" || $clinic->address_longitude==""){
                $address = "<a href='clinicadd.php?act=edit&clinic_id=".$clinic->clinic_id."' style='color:red;'>Add address</a>";
            }
            if($clinic->clinic_status =='1'){
              $status = '<a href="javascript:void(0)" onclick="change_status('.$clinic->clinic_id.',1)" title="Inactivate"><span class="badge badge-success">Active</span></a>';
            }else{
              $status = '<a href="javascript:void(0)" onclick="change_status('.$clinic->clinic_id.',0)" title="Activate"><span class="badge badge-danger">Inactive</span></a>';
            }
            if($clinic->clinic_onBoard =='1'){
              $board = '<i style="color:green;" class="i-Car-Wheel"></i>';
            }else{
              $board = '<i style="color:red;" class="i-Car-Wheel"></i>';
            }

            $setup ="";
            if (strpos(SITE_URL, 'dev') !== false || strpos(SITE_URL, 'staging') !== false) {
                $setup ="<a href='setup_practice.php?id=".$clinic->clinic_id."'>Demo PMS Setup</a>";
            }
            $response[] = array('<input type="checkbox" name="check[]" id="check[]" value="'.$clinic->clinic_id.'" class="check_class" />', 

                    "<b>ClinicId: </b>".$clinic->clinic_id." ".$board.'<br/><b>UniqueId</b>: '.$clinic->clinic_unique_id,
                    //$clinic->clinic_unique_id,
                    "<b><a href='clinicdetail.php?clinic_id=".$clinic->clinic_id."'>".$clinic->clinic_name."</a></b><br/>Owner: ".$clinic->user_fname." ".$clinic->user_lname."<br/>Owner Email: ".$clinic->user_email_address."<br/>".$last4."<br/>".$address,
                    "<b>Email: </b>".$clinic->clinic_email."<br/><b>Phone: </b>".$clinic->clinic_phone."<br/><b>Website: </b>".$clinic->clinic_website."<br/><b>Rating: </b>".$clinic->clinic_rating."<br/><b>ReviewCount: </b>".$clinic->clinic_reviewCount,

                    date('Y-m-d',strtotime($clinic->clinic_created_at)),

                    "<div id='td_status_".$clinic->clinic_id."'>".$status."</div>"."<br/>".$reminder."".$marketing."".$administrative."".$digitaldoc."".$clinictextsms."".$paymentinvoice."".$reminderpaymentinvoice."".$doubleappoinment_data."".$viewlink_data."".$prescreeninglink_data."".$emailtemplate_data,

                    '<a href="clinic_setting.php?act=setting&clinic_id='.$clinic->clinic_id.'" class="btn btn-success white-btn"><i class="nav-icon i-Pen-2 "></i></a> <br/><br/>'.$setup


                    // '<a href="clinicadd.php?act=edit&clinic_id='.$clinic->clinic_id.'" class="btn btn-success white-btn"><i class="nav-icon i-Pen-2 "></i></a>
                    // <a id="delete-confirm" onclick="delete_entry('.$clinic->clinic_id.');" class="btn btn-danger white-btn"><i class="nav-icon i-Close-Window "></i></a>'

            );
        }
        //exit;
        $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');
?>