<?php  
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page
$clinicObj =  new  clinic();
$adminlogObj = new admin_log();
$modulepagesObj = new module_pages();
$userObj =  new user();
$filename=basename($_SERVER['SCRIPT_FILENAME']);

if($filename == 'clinic_setting.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']=='setting' && isset($_REQUEST['clinic_id'])){
    $clinicDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
}

if(isset($_REQUEST['clinic_id'])){
    $clinicDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    $iscreditcard = $clinicDetail->clinic_onboarding_with_creditcard;
    $rating = $clinicDetail->clinic_displayRating;

    if(isset($clinicDetail->clinic_user_id)){
      $userDetail = $userObj->fromId($clinicDetail->clinic_user_id);
    }
    //$pmsappointmentstatusObj = new pmsappointmentstatus();
    $pmsappointmentstatusObj = new pmsAppointmentStatus();
    $where = array("pmsAppointmentStatus_clinic_id="=>$_REQUEST['clinic_id']);
    $pmsappointmentstatusArg = array('where'=>$where);
    $pmsAppointmentStatusDetails = $pmsappointmentstatusObj->getAllRecords($pmsappointmentstatusArg);


    $fields = array('clinic_id','clinic_overdue','clinic_new_patient_status');
    $where = array("clinic_id="=>$_REQUEST['clinic_id']);
    $clinicArg    = array('fields'=>$fields,'where' => $where);
    $clinicObj->resultAs = "array";
    $clinicDetails = $clinicObj->fromFields($clinicArg);
    if($clinicDetails)
    {
        if(!empty($clinicDetails['clinic_overdue']))
        {
            $overduedata = json_decode($clinicDetails['clinic_overdue'],1);
            if(!empty($overduedata['0-6']))
            {
                $initiation_days_6 = $overduedata['0-6']['initiation_days'];
                $status_6 = explode(",",$overduedata['0-6']['status']);
                $procedure_category_6 = explode(",",$overduedata['0-6']['procedure_category']);
                $procedure_code_6 = explode(",",$overduedata['0-6']['procedure_code']);

                if(!empty($procedure_category_6) && count($procedure_category_6) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_6 ) . "'";
                    
                    $procedure_code_data6 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data6;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_6 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }

            }

            if(!empty($overduedata['7-12']))
            {
                $initiation_days_12 = $overduedata['7-12']['initiation_days'];
                $status_12 = explode(",",$overduedata['7-12']['status']);
                $procedure_category_12 = explode(",",$overduedata['7-12']['procedure_category']);
                $procedure_code_12 = explode(",",$overduedata['7-12']['procedure_code']);

                if(!empty($procedure_category_12) && count($procedure_category_12) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_12 ) . "'";
                    
                    $procedure_code_data12 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data12;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_12 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }

            if(!empty($overduedata['13-18']))
            {
                $initiation_days_18 = $overduedata['13-18']['initiation_days'];
                $status_18 = explode(",",$overduedata['13-18']['status']);
                $procedure_category_18 = explode(",",$overduedata['13-18']['procedure_category']);
                $procedure_code_18 = explode(",",$overduedata['13-18']['procedure_code']);

                if(!empty($procedure_category_18) && count($procedure_category_18) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_18 ) . "'";
                    
                    $procedure_code_data18 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data18;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_18 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }

            if(!empty($overduedata['19-24']))
            {
                $initiation_days_24 = $overduedata['19-24']['initiation_days'];
                $status_24 = explode(",",$overduedata['19-24']['status']);
                $procedure_category_24 = explode(",",$overduedata['19-24']['procedure_category']);
                $procedure_code_24 = explode(",",$overduedata['19-24']['procedure_code']);

                if(!empty($procedure_category_24) && count($procedure_category_24) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_24 ) . "'";
                    
                    $procedure_code_data24 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data24;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_24 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }
        }

        $clinic_patient_status = array('');
        if(!empty($clinicDetails['clinic_new_patient_status']))
        {

            $clinic_patient_status = explode(",",$clinicDetails['clinic_new_patient_status']);
        }
    }

    /*Practice Features starts here*/

    $messagecenter_accessObj = new messagecenter_access();
    $where = array("clinicid="=>$_REQUEST['clinic_id']);
    $messagecenter_accessArg = array('where'=>$where);
    $messagecenter_data = $messagecenter_accessObj->FromFields($messagecenter_accessArg);
    //print_r($messagecenter_data);
    //exit;
    if($messagecenter_data->clinicid == $_REQUEST['clinic_id'])
    {
      //  echo 'ttt';exit;

      
        if($messagecenter_data->isenableremindernotification == '1')
        {
          $messagecenter_reminder = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,1,'.$clinicDetail->clinic_id.')"';
          $reminder_check ='checked';
        }else{
          $messagecenter_reminder = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,1,'.$clinicDetail->clinic_id.')"';
          $reminder_check = "";
        }
      

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

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

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

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

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

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

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

          if($messagecenter_data->isenableemailtemplate == '1')
          {
            $messagecenter_emailtemplate = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,11,'.$clinicDetail->clinic_id.')"';
            $emailtemplate_check ='checked';
          }else{
            $messagecenter_emailtemplate = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,11,'.$clinicDetail->clinic_id.')"';
            $emailtemplate_check = "";
          }

          if($messagecenter_data->isenablereschedulelink == '1')
          {
            $messagecenter_reschedulelink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,13,'.$clinic->clinic_id.')"';
            $reschedulelink_check ='checked';
          }else{
            $messagecenter_reschedulelink = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,13,'.$clinic->clinic_id.')"';
            $reschedulelink_check = "";
          }

          if($messagecenter_data->isenabledoublebookappointmentpatient == '1')
          {
            $messagecenter_bookappointment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,14,'.$clinic->clinic_id.')"';
            $bookappointment_check ='checked';
          }else{
            $messagecenter_bookappointment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,14,'.$clinic->clinic_id.')"';
            $bookappointment_check = "";
          }

          if($messagecenter_data->isenableonemessageformultipleappt == '1')
          {
            $messagecenter_multiappointment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,16,'.$clinic->clinic_id.')"';
            $multiappointment_check ='checked';
          }else{
            $messagecenter_multiappointment = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,16,'.$clinic->clinic_id.')"';
            $multiappointment_check = "";
          }

          if($messagecenter_data->isenableemailtemplatemarketing == '1')
          {
            $messagecenter_emailtemplatemarketing = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,17,'.$clinic->clinic_id.')"';
            $emailtemplatemarketing_check ='checked';
          }else{
            $messagecenter_emailtemplatemarketing = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,17,'.$clinic->clinic_id.')"';
            $emailtemplatemarketing_check = "";
          }

          if($messagecenter_data->isenableconfirmtextinsms == '1')
          {
            $messagecenter_confirmtextinsms = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,18,'.$clinic->clinic_id.')"';
            $confirmtextinsms_check ='checked';
          }else{
            $messagecenter_confirmtextinsms = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,18,'.$clinic->clinic_id.')"';
            $confirmtextinsms_check = "";
          }

          if($messagecenter_data->issrtminguarantor == '1')
          {
            $messagecenter_rcvdtxtguarantor = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',0,20,'.$clinic->clinic_id.')"';
            $rcvdtxtguarantor_check ='checked';
          }else{
            $messagecenter_rcvdtxtguarantor = ' onclick="messagecenter_change_status('.$messagecenter_data->messagecenter_access_id.',1,20,'.$clinic->clinic_id.')"';
            $rcvdtxtguarantor_check = "";
          }

        $reminder = "Reminder Message : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>"; 

        $marketing = "<br/><br/>Marketing Message : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $administrative = "<br/><br/>Administrative Message : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $digitaldoc = "Digitaldoc Document : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $paymentinvoice = "<br/><br/>Payment Admin Message : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $reminderpaymentinvoice = "<br/><br/>Payment Reminder Message : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $doubleappoinment_data = "Double Appt Clinic-Email : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $viewlink_data = "<br/><br/>Patient Review for Mobile App : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $prescreeninglink_data = "<br/><br/>Pre-screening : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $emailtemplate_data = "<br/><br/>Template based Email : <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 = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

        $reschedulelink_data = "<br/><br/>Reschedule Appointment for Mobile App : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_reschedulelink_$messagecenter_data->messagecenter_access_id' name='mesg_reschedulelink' 
                                $messagecenter_reschedulelink value='reschedulelink' reschedulelink-data='$messagecenter_data->isenablereschedulelink' $reschedulelink_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

        $bookappointment_data = "<br/><br/>Multiple Appointment Text-Patient: <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_bookappointment_$messagecenter_data->messagecenter_access_id' name='mesg_bookappointment' 
                                $messagecenter_bookappointment value='bookappointment' bookappointment-data='$messagecenter_data->isenabledoublebookappointmentpatient' $bookappointment_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

        $multiappointment_message_data = "<br/><br/>One Message for Multiple Appointment: <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_multiappointment_$messagecenter_data->messagecenter_access_id' name='mesg_multiappointment' 
                                $messagecenter_multiappointment value='multiappointment' multiappointment-data='$messagecenter_data->isenableonemessageformultipleappt' $multiappointment_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

          $emailtemplatemarketing_data = "<br/><br/>Email Template for Marketing: <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_emailtemplatemarketing_$messagecenter_data->messagecenter_access_id' name='mesg_emailtemplatemarketing' 
                                $messagecenter_emailtemplatemarketing value='emailtemplatemarketing' emailtemplatemarketing-data='$messagecenter_data->isenableemailtemplatemarketing' $emailtemplatemarketing_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

          $confirmtextinsms_data = "<br/><br/>Confirm Text in SMS: <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='mesg_confirmtextinsms_$messagecenter_data->messagecenter_access_id' name='mesg_confirmtextinsms' 
                                $messagecenter_confirmtextinsms value='confirmtextinsms' confirmtextinsms-data='$messagecenter_data->isenableconfirmtextinsms' $confirmtextinsms_check clinicstatus-data = $clinic->clinic_status >
                                <span class='slider'></span>
                            </label>";

          $issrtminguarantor = "<br/><br/>Show Received Text message in Guarantor : <label class='switch switch-primary mr-3'>
                        <input type='checkbox' id='mesg_issrtminguarantor_$messagecenter_data->messagecenter_access_id' name='mesg_issrtminguarantor' 
                        $messagecenter_rcvdtxtguarantor value='issrtminguarantor' issrtminguarantor-data='$messagecenter_data->issrtminguarantor' $rcvdtxtguarantor_check clinicstatus-data = $clinicDetail->clinic_status >
                        <span class='slider'></span>
                    </label>";

    }else{
        $reminder                      = "";
        $marketing                     = "";
        $administrative                = "";
        $digitaldoc                    = "";
        $paymentinvoice                = "";
        $reminderpaymentinvoice        = "";
        $doubleappoinment_data         = "";
        $viewlink_data                 = "";
        $prescreeninglink_data         = "";
        $emailtemplate_data            = "";
        $reschedulelink_data           = "";
        $bookappointment_data          = "";
        $multiappointment_message_data = "";
        $emailtemplatemarketing_data   = "";
        $confirmtextinsms_data         = "";
    }
    
    /*fields that are in clinic table start*/
    if($clinicDetail->clinic_text_smschat == 'on')
    {

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


    if($clinicDetail->clinic_notes_show == '1')
    {

        $note_show = ' onclick="messagecenter_change_status(0,0,12,'.$clinicDetail->clinic_id.')"';
        $note_show_check ='checked';
    }else{
        $note_show = ' onclick="messagecenter_change_status(0,1,12,'.$clinicDetail->clinic_id.')"';
        $note_show_check = "";
    }

    
    if($clinicDetail->clinic_payment_feature == '1')
    {

        $paymentfeature = ' onclick="messagecenter_change_status(0,0,15,'.$clinicDetail->clinic_id.')"';
        $paymentfeature_check ='checked';
    }else{
        $paymentfeature = ' onclick="messagecenter_change_status(0,1,15,'.$clinicDetail->clinic_id.')"';
        $paymentfeature_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling == '1')
    {

        $onlineScheduling = ' onclick="messagecenter_change_status(0,0,19,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_check ='checked';
    }else{
        $onlineScheduling = ' onclick="messagecenter_change_status(0,1,19,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_aboutus == '1')
    {

        $onlineScheduling_aboutus = ' onclick="messagecenter_change_status(0,0,21,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_aboutus_check ='checked';
    }else{
        $onlineScheduling_aboutus = ' onclick="messagecenter_change_status(0,1,21,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_aboutus_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_practicephoto == '1')
    {

        $onlineScheduling_practicephoto = ' onclick="messagecenter_change_status(0,0,22,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_practicephoto_check ='checked';
    }else{
        $onlineScheduling_practicephoto = ' onclick="messagecenter_change_status(0,1,22,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_practicephoto_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_prodviders == '1')
    {

        $onlineScheduling_prodviders = ' onclick="messagecenter_change_status(0,0,23,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_prodviders_check ='checked';
    }else{
        $onlineScheduling_prodviders = ' onclick="messagecenter_change_status(0,1,23,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_prodviders_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_reviews == '1')
    {

        $onlineScheduling_reviews = ' onclick="messagecenter_change_status(0,0,24,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_reviews_check ='checked';
    }else{
        $onlineScheduling_reviews = ' onclick="messagecenter_change_status(0,1,24,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_reviews_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_features == '1')
    {

        $onlineScheduling_features = ' onclick="messagecenter_change_status(0,0,25,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_features_check ='checked';
    }else{
        $onlineScheduling_features = ' onclick="messagecenter_change_status(0,1,25,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_features_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_services == '1')
    {

        $onlineScheduling_services = ' onclick="messagecenter_change_status(0,0,26,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_services_check ='checked';
    }else{
        $onlineScheduling_services = ' onclick="messagecenter_change_status(0,1,26,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_services_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_logobanner == '1')
    {

        $onlineScheduling_logobanner = ' onclick="messagecenter_change_status(0,0,27,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_logobanner_check ='checked';
    }else{
        $onlineScheduling_logobanner = ' onclick="messagecenter_change_status(0,1,27,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_logobanner_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_location == '1')
    {

        $onlineScheduling_location = ' onclick="messagecenter_change_status(0,0,28,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_location_check ='checked';
    }else{
        $onlineScheduling_location = ' onclick="messagecenter_change_status(0,1,28,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_location_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_pageheader == '1')
    {

        $onlineScheduling_pageheader = ' onclick="messagecenter_change_status(0,0,29,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_pageheader_check ='checked';
    }else{
        $onlineScheduling_pageheader = ' onclick="messagecenter_change_status(0,1,29,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_pageheader_check = "";
    }

    if($clinicDetail->clinic_onlineScheduling_flexibleschedule == '1')
    {

        $onlineScheduling_flexibleschedule = ' onclick="messagecenter_change_status(0,0,36,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_flexibleschedule_check ='checked';
    }else{
        $onlineScheduling_flexibleschedule = ' onclick="messagecenter_change_status(0,1,36,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_flexibleschedule_check = "";
    }
    if($clinicDetail->clinic_onlineScheduling_officehours == '1')
    {

        $onlineScheduling_officehours = ' onclick="messagecenter_change_status(0,0,38,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_officehours_check ='checked';
    }else{
        $onlineScheduling_officehours = ' onclick="messagecenter_change_status(0,1,38,'.$clinicDetail->clinic_id.')"';
        $onlineScheduling_officehours_check = "";
    }
    /*provider online scheduling start*/

    $cdoctorObj =  new  cdoctor();
    //$fields = array('cdoctor_id','cdoctor_clinic_id','clinic_new_patient_status');
    $where = array("cdoctor_clinic_id="=>$_REQUEST['clinic_id']);
    $cdoctorArg    = array('where' => $where);
    $cdoctorDetails = $cdoctorObj->fromFields($cdoctorArg);
    if($cdoctorDetails->cdoctor_onlineScheduling_aboutus == '1')
    {

        $cdoctor_onlineScheduling_aboutus = ' onclick="messagecenter_change_status(0,0,30,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_aboutus_check ='checked';
    }else{
        $cdoctor_onlineScheduling_aboutus = ' onclick="messagecenter_change_status(0,1,30,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_aboutus_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_practicephoto == '1')
    {

        $cdoctor_onlineScheduling_practicephoto = ' onclick="messagecenter_change_status(0,0,31,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_practicephoto_check ='checked';
    }else{
        $cdoctor_onlineScheduling_practicephoto = ' onclick="messagecenter_change_status(0,1,31,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_practicephoto_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_reviews == '1')
    {

        $cdoctor_onlineScheduling_reviews = ' onclick="messagecenter_change_status(0,0,32,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_reviews_check ='checked';
    }else{
        $cdoctor_onlineScheduling_reviews = ' onclick="messagecenter_change_status(0,1,32,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_reviews_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_logobanner == '1')
    {

        $cdoctor_onlineScheduling_logobanner = ' onclick="messagecenter_change_status(0,0,33,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_logobanner_check ='checked';
    }else{
        $cdoctor_onlineScheduling_logobanner = ' onclick="messagecenter_change_status(0,1,33,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_logobanner_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_location == '1')
    {

        $cdoctor_onlineScheduling_location = ' onclick="messagecenter_change_status(0,0,34,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_location_check ='checked';
    }else{
        $cdoctor_onlineScheduling_location = ' onclick="messagecenter_change_status(0,1,34,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_location_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_pageheader == '1')
    {

        $cdoctor_onlineScheduling_pageheader = ' onclick="messagecenter_change_status(0,0,35,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_pageheader_check ='checked';
    }else{
        $cdoctor_onlineScheduling_pageheader = ' onclick="messagecenter_change_status(0,1,35,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_pageheader_check = "";
    }

    if($cdoctorDetails->cdoctor_onlineScheduling_flexibleschedule == '1')
    {

        $cdoctor_onlineScheduling_flexibleschedule = ' onclick="messagecenter_change_status(0,0,37,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_flexibleschedule_check ='checked';
    }else{
        $cdoctor_onlineScheduling_flexibleschedule = ' onclick="messagecenter_change_status(0,1,37,'.$clinicDetail->clinic_id.')"';
        $cdoctor_onlineScheduling_flexibleschedule_check = "";
    }
    /*provider online scheduling end*/


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

    $clinicnotesshow = "<br/><br/>Appt Note Show Clinic : <label class='switch switch-primary mr-3 note_show_clinic'>
                                <input type='checkbox' id='note_show_clinic_$clinicDetail->clinic_id' name='note_show_clinic' note_show_clinic-data='$clinicDetail->clinic_notes_show' 
                                 $note_show  $note_show_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $clinicpaymentfeature = "<br/><br/>Payment : <label class='switch switch-primary mr-3 paymentfeature_clinic'>
                                <input type='checkbox' id='paymentfeature_clinic_$clinicDetail->clinic_id' name='paymentfeature_clinic' paymentfeature_clinic-data='$clinicDetail->clinic_payment_feature' 
                                 $paymentfeature  $paymentfeature_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineScheduling = "<br/><br/>Online Scheduling : <label class='switch switch-primary mr-3 onlineScheduling_clinic'>
                                <input type='checkbox' id='onlineScheduling_clinic_$clinicDetail->clinic_id' name='onlineScheduling_clinic' onlineScheduling_clinic-data='$clinicDetail->clinic_onlineScheduling' 
                                 $onlineScheduling  $onlineScheduling_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    /*clinic online scheduling*/
    $cliniconlineSchedulingaboutus = "<br/><br/>Online Scheduling About US : <label class='switch switch-primary mr-3 onlineScheduling_clinic_aboutus'>
                                <input type='checkbox' id='onlineScheduling_clinic_aboutus_$clinicDetail->clinic_id' name='onlineScheduling_clinic_aboutus' onlineScheduling_clinic_aboutus-data='$clinicDetail->clinic_onlineScheduling_aboutus' 
                                 $onlineScheduling_aboutus  $onlineScheduling_aboutus_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingpracticephoto = "<br/><br/>Online Scheduling Practice Photos : <label class='switch switch-primary mr-3 onlineScheduling_practicephoto'>
                                <input type='checkbox' id='onlineScheduling_clinic_practicephoto_$clinicDetail->clinic_id' name='onlineScheduling_clinic_practicephoto' onlineScheduling_clinic_practicephoto-data='$clinicDetail->clinic_onlineScheduling_practicephoto' 
                                 $onlineScheduling_practicephoto  $onlineScheduling_practicephoto_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingprodviders = "<br/><br/>Online Scheduling Providers : <label class='switch switch-primary mr-3 onlineScheduling_clinic_prodviders'>
                                <input type='checkbox' id='onlineScheduling_clinic_prodviders_$clinicDetail->clinic_id' name='onlineScheduling_clinic_prodviders' onlineScheduling_clinic_prodviders-data='$clinicDetail->clinic_onlineScheduling_prodviders' 
                                 $onlineScheduling_prodviders  $onlineScheduling_prodviders_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingreviews = "<br/><br/>Online Scheduling Reviews : <label class='switch switch-primary mr-3 onlineScheduling_clinic_reviews'>
                                <input type='checkbox' id='onlineScheduling_clinic_reviews_$clinicDetail->clinic_id' name='onlineScheduling_clinic_reviews' onlineScheduling_clinic_reviews-data='$clinicDetail->clinic_onlineScheduling_reviews' 
                                 $onlineScheduling_reviews  $onlineScheduling_reviews_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingfeatures = "<br/><br/>Online Scheduling Features : <label class='switch switch-primary mr-3 onlineScheduling_clinic_features'>
                                <input type='checkbox' id='onlineScheduling_clinic_features_$clinicDetail->clinic_id' name='onlineScheduling_clinic_features' onlineScheduling_clinic_features-data='$clinicDetail->clinic_onlineScheduling_features' 
                                 $onlineScheduling_features  $onlineScheduling_features_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingservices = "<br/><br/>Online Scheduling Services: <label class='switch switch-primary mr-3 onlineScheduling_clinic_services'>
                                <input type='checkbox' id='onlineScheduling_clinic_services_$clinicDetail->clinic_id' name='onlineScheduling_clinic_services' onlineScheduling_clinic_services-data='$clinicDetail->clinic_onlineScheduling_services' 
                                 $onlineScheduling_services  $onlineScheduling_services_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulinglogobanner = "<br/><br/>Online Scheduling Logo Banner : <label class='switch switch-primary mr-3 onlineScheduling_clinic'>
                                <input type='checkbox' id='onlineScheduling_clinic_logobanner_$clinicDetail->clinic_id' name='onlineScheduling_clinic_logobanner' onlineScheduling_clinic_logobanner-data='$clinicDetail->clinic_onlineScheduling_logobanner' 
                                 $onlineScheduling_logobanner  $onlineScheduling_logobanner_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulinglocation = "<br/><br/>Online Scheduling Location : <label class='switch switch-primary mr-3 onlineScheduling_clinic_location'>
                                <input type='checkbox' id='onlineScheduling_clinic_location_$clinicDetail->clinic_id' name='onlineScheduling_clinic_location' onlineScheduling_clinic_location-data='$clinicDetail->clinic_onlineScheduling_location' 
                                 $onlineScheduling_location  $onlineScheduling_location_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingpageheader = "<br/><br/>Online Scheduling Page Header : <label class='switch switch-primary mr-3 onlineScheduling_clinic_pageheader'>
                                <input type='checkbox' id='onlineScheduling_clinic_pageheader_$clinicDetail->clinic_id' name='onlineScheduling_clinic_pageheader' onlineScheduling_clinic_pageheader-data='$clinicDetail->clinic_onlineScheduling_pageheader' 
                                 $onlineScheduling_pageheader  $onlineScheduling_pageheader_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingflexibleschedule = "<br/><br/>Online Scheduling Flexible Schedule : <label class='switch switch-primary mr-3 onlineScheduling_clinic_flexibleschedule'>
                                <input type='checkbox' id='onlineScheduling_clinic_flexibleschedule_$clinicDetail->clinic_id' name='onlineScheduling_clinic_flexibleschedule' onlineScheduling_clinic_flexibleschedule-data='$clinicDetail->clinic_onlineScheduling_flexibleschedule' 
                                 $onlineScheduling_flexibleschedule  $onlineScheduling_flexibleschedule_check  clinicstatus-data = $clinicDetail->clinic_status>
                                  <span class='slider'></span>
                            </label>";

    $cliniconlineSchedulingofficehours = "<br/><br/>Online Scheduling Office Hours : <label class='switch switch-primary mr-3 onlineScheduling_clinic_officehours'>
                            <input type='checkbox' id='onlineScheduling_clinic_officehours_$clinicDetail->clinic_id' name='onlineScheduling_clinic_officehours' onlineScheduling_clinic_officehours-data='$clinicDetail->clinic_onlineScheduling_officehours' 
                                $onlineScheduling_officehours  $onlineScheduling_officehours_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    /*provider online scheduling*/

    $cdoctoronlineSchedulingaboutus = "<br/><br/>Provider Online Scheduling About us : <label class='switch switch-primary mr-3 onlineScheduling_provider_aboutus'>
                                <input type='checkbox' id='onlineScheduling_provider_aboutus_$clinicDetail->clinic_id' name='onlineScheduling_provider_aboutus' onlineScheduling_provider_aboutus-data='$cdoctorDetails->cdoctor_onlineScheduling_aboutus' 
                                 $cdoctor_onlineScheduling_aboutus  $cdoctor_onlineScheduling_aboutus_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cdoctoronlineSchedulingpracticephoto = "<br/><br/>Provider Online Scheduling Practice Photos : <label class='switch switch-primary mr-3 onlineScheduling_provider_practicephoto'>
                                <input type='checkbox' id='onlineScheduling_provider_practicephoto_$clinicDetail->clinic_id' name='onlineScheduling_provider_practicephoto' onlineScheduling_provider_practicephoto-data='$cdoctorDetails->cdoctor_onlineScheduling_practicephoto' 
                                 $cdoctor_onlineScheduling_practicephoto  $cdoctor_onlineScheduling_practicephoto_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cdoctoronlineSchedulingreviews = "<br/><br/>Provider Online Scheduling Reviews : <label class='switch switch-primary mr-3 onlineScheduling_provider_reviews'>
                                <input type='checkbox' id='onlineScheduling_provider_reviews_$clinicDetail->clinic_id' name='onlineScheduling_provider_reviews' onlineScheduling_provider_reviews-data='$cdoctorDetails->cdoctor_onlineScheduling_reviews' 
                                 $cdoctor_onlineScheduling_reviews  $cdoctor_onlineScheduling_reviews_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

      $cdoctoronlineSchedulinglogobanner = "<br/><br/>Provider Online Scheduling Logo Banner : <label class='switch switch-primary mr-3 onlineScheduling_provider_logobanner'>
                                <input type='checkbox' id='onlineScheduling_provider_logobanner_$clinicDetail->clinic_id' name='onlineScheduling_provider_logobanner' onlineScheduling_provider_logobanner-data='$cdoctorDetails->cdoctor_onlineScheduling_logobanner' 
                                 $cdoctor_onlineScheduling_logobanner  $cdoctor_onlineScheduling_logobanner_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cdoctoronlineSchedulinglocation = "<br/><br/>Provider Online Scheduling Location : <label class='switch switch-primary mr-3 onlineScheduling_provider_location'>
                                <input type='checkbox' id='onlineScheduling_provider_location_$clinicDetail->clinic_id' name='onlineScheduling_provider_location' onlineScheduling_provider_location-data='$cdoctorDetails->cdoctor_onlineScheduling_location' 
                                 $cdoctor_onlineScheduling_location  $cdoctor_onlineScheduling_location_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

    $cdoctoronlineSchedulingpageheader = "<br/><br/>Provider Online Scheduling Page Header : <label class='switch switch-primary mr-3 onlineScheduling_provider_pageheader'>
                                <input type='checkbox' id='onlineScheduling_provider_pageheader_$clinicDetail->clinic_id' name='onlineScheduling_provider_pageheader' onlineScheduling_provider_pageheader-data='$cdoctorDetails->cdoctor_onlineScheduling_pageheader' 
                                 $cdoctor_onlineScheduling_pageheader  $cdoctor_onlineScheduling_pageheader_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";

      $cdoctoronlineSchedulingflexibleschedule = "<br/><br/>Provider Online Scheduling Flexible Schedule : <label class='switch switch-primary mr-3 onlineScheduling_provider_flexibleschedule'>
                                <input type='checkbox' id='onlineScheduling_provider_flexibleschedule_$clinicDetail->clinic_id' name='onlineScheduling_provider_flexibleschedule' onlineScheduling_provider_flexibleschedule-data='$cdoctorDetails->cdoctor_onlineScheduling_flexibleschedule' 
                                 $cdoctor_onlineScheduling_flexibleschedule  $cdoctor_onlineScheduling_flexibleschedule_check  clinicstatus-data = $clinicDetail->clinic_status>
                                <span class='slider'></span>
                            </label>";
}
/*fields that are in clinic table end*/

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);
        if($messagecenter_data)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }
        

        //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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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') // in clinic table
    {
        //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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        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>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><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['status']) && $_REQUEST['status_data'] == '12')// in clinic table
    {
        //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_notes_show == '1')
        {
            $note_show = '0'; 
            $old_text_smsdata = 'Enable';
            $new_text_smsdata = 'Disable';  
        }else{
            $note_show = '1';
            $old_text_smsdata = 'Disable';
            $new_text_smsdata = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Text Sms status old</b> ".$old_text_smsdata." <b>to</b> ".$new_text_smsdata;

        $data_clinic['clinic_notes_show'] = $note_show;
        $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, "note_show" => $note_show));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '13')
    {
        //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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->isenablereschedulelink == '1')
        {
            $reschedulelink = '0';
            $old_reschedulelinkdata = 'Enable';
            $new_reschedulelinkdata = 'Disable'; 
        }else{
            $reschedulelink = '1';
            $old_reschedulelinkdata = 'Disable';
            $new_reschedulelinkdata = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Reschedule link old</b> ".$old_reschedulelinkdata." <b>to</b> ".$new_reschedulelinkdata;

        $data_reschedulelink['isenablereschedulelink'] = $reschedulelink;
        $rs=$messagecenter_accessObj->updateRecords($data_reschedulelink,$_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, "reschedulelink" => $reschedulelink));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '14')
    {
        //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)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->isenabledoublebookappointmentpatient == '1')
        {
            $bookappointment = '0';
            $old_bookappointmentdata = 'Enable';
            $new_bookappointmentdata = 'Disable'; 
        }else{
            $bookappointment = '1';
            $old_bookappointmentdata = 'Disable';
            $new_bookappointmentdata = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Book Appointment old</b> ".$old_bookappointmentdata." <b>to</b> ".$new_bookappointmentdata;

        $data_bookappointment['isenabledoublebookappointmentpatient'] = $bookappointment;
        $rs=$messagecenter_accessObj->updateRecords($data_bookappointment,$_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, "bookappointment" => $bookappointment));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '15') // in clinic table
    {
        //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($clinic_data);exit;
        if($clinic_data->clinic_payment_feature == '1')
        {
            $payment_feature = '0'; 
            $old_payment_feature = 'Enable';
            $new_payment_feature = 'Disable';  
        }else{
            $payment_feature = '1';
            $old_payment_feature = 'Disable';
            $new_payment_feature = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Text Sms status old</b> ".$old_payment_feature." <b>to</b> ".$new_payment_feature;

        $data_clinic['clinic_payment_feature'] = $payment_feature;
        $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, "paymentfeature" => $payment_feature));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '16')
    {
        
        $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);
        if($messagecenter_data)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->isenableonemessageformultipleappt == '1')
        {
            $singlemsgmultiappt     = '0';

            $old_singlemsgmultidata = 'Enable';
            $new_singlemsgmultidata = 'Disable';
        }else{
            $singlemsgmultiappt     = '1';

            /*TEMP OFF PRESCREENING IF THIS SWITCH IS ON*/
            $prescreeninglink = '0';
            $data_singlemsgmultiappt['isenableprescreeninglink'] = $prescreeninglink;
            /*END*/

            $old_singlemsgmultidata = 'Disable';
            $new_singlemsgmultidata = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Reminder status old</b> ".$old_singlemsgmultidata." <b>to</b> ".$new_singlemsgmultidata;

        $data_singlemsgmultiappt['isenableonemessageformultipleappt'] = $singlemsgmultiappt;
        echo "<pre>";print_r($data_singlemsgmultiappt);echo "</pre>";
        
        $rs=$messagecenter_accessObj->updateRecords($data_singlemsgmultiappt,$_REQUEST['messageaccess_id']);
        

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

        echo json_encode(array("msg" => RECORD_STATUS, "reminder" => $singlemsgmultiappt));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '17')
    {
        
        $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);
        if($messagecenter_data)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->isenableemailtemplatemarketing == '1')
        {
            $emailtemplatemarketing     = '0';
            $old_emailtemplatemarketing = 'Enable';
            $new_emailtemplatemarketing = 'Disable';
        }else{
            $emailtemplatemarketing     = '1';
            $old_emailtemplatemarketing = 'Disable';
            $new_emailtemplatemarketing = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Reminder status old</b> ".$old_emailtemplatemarketing." <b>to</b> ".$new_emailtemplatemarketing;

        $data_emailtemplatemarketing['isenableemailtemplatemarketing'] = $emailtemplatemarketing;
        
        $rs=$messagecenter_accessObj->updateRecords($data_emailtemplatemarketing,$_REQUEST['messageaccess_id']);
        

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

        echo json_encode(array("msg" => RECORD_STATUS, "reminder" => $emailtemplatemarketing));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '18')
    {
        
        $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);
        if($messagecenter_data)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->isenableconfirmtextinsms == '1')
        {
            $confirmtextinsms     = '0';
            $old_confirmtextinsms = 'Enable';
            $new_confirmtextinsms = 'Disable';
        }else{
            $confirmtextinsms     = '1';
            $old_confirmtextinsms = 'Disable';
            $new_confirmtextinsms = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Reminder status old</b> ".$old_confirmtextinsms." <b>to</b> ".$new_confirmtextinsms;

        $data_confirmtextinsms['isenableconfirmtextinsms'] = $confirmtextinsms;
        
        $rs=$messagecenter_accessObj->updateRecords($data_confirmtextinsms,$_REQUEST['messageaccess_id']);
        

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

        echo json_encode(array("msg" => RECORD_STATUS, "reminder" => $confirmtextinsms));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '19') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling == '1')
        {
            $onlineScheduling = '0'; 
            $old_onlineScheduling = 'Enable';
            $new_onlineScheduling = 'Disable';  
        }else{
            $onlineScheduling = '1';
            $old_onlineScheduling = 'Disable';
            $new_onlineScheduling = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling status old</b> ".$old_onlineScheduling." <b>to</b> ".$new_onlineScheduling;

        $data_clinic['clinic_onlineScheduling'] = $onlineScheduling;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineScheduling" => $onlineScheduling));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '20')
    {
        $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);

        if($messagecenter_data)
        {
            $clinic_data = $clinicObj->fromId($messagecenter_data->clinicid);    
        }

        if($messagecenter_data->issrtminguarantor == '1')
        {
            $issrtminguarantor = '0';
            $old_issrtminguarantor = 'Enable';
            $new_issrtminguarantor = 'Disable'; 
        }else{
            $issrtminguarantor = '1';
            $old_issrtminguarantor = 'Disable';
            $new_issrtminguarantor = 'Enable';
        }

        $clinic_detail = " <b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Show Received Text message in Guarantor old</b> ".$old_issrtminguarantor." <b>to</b> ".$new_issrtminguarantor;

        $data_issrtminguarantor['issrtminguarantor'] = $issrtminguarantor;
        $rs=$messagecenter_accessObj->updateRecords($data_issrtminguarantor,$_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, "issrtminguarantor" => $issrtminguarantor));
        return true;
    }
    //clinic online scheduling
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '21') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_aboutus == '1')
        {
            $onlineSchedulingaboutus = '0'; 
            $old_onlineSchedulingaboutus = 'Enable';
            $new_onlineSchedulingaboutus = 'Disable';  
        }else{
            $onlineSchedulingaboutus = '1';
            $old_onlineSchedulingaboutus = 'Disable';
            $new_onlineSchedulingaboutus = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling about us status old</b> ".$old_onlineSchedulingaboutus." <b>to</b> ".$new_onlineSchedulingaboutus;

        $data_clinic['clinic_onlineScheduling_aboutus'] = $onlineSchedulingaboutus;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingaboutus" => $onlineSchedulingaboutus));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '22') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_practicephoto == '1')
        {
            $onlineSchedulingpracticephoto = '0'; 
            $old_onlineSchedulingpracticephoto = 'Enable';
            $new_onlineSchedulingpracticephoto = 'Disable';  
        }else{
            $onlineSchedulingpracticephoto = '1';
            $old_onlineSchedulingpracticephoto = 'Disable';
            $new_onlineSchedulingpracticephoto = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling practice photos status old</b> ".$old_onlineSchedulingpracticephoto." <b>to</b> ".$new_onlineSchedulingpracticephoto;

        $data_clinic['clinic_onlineScheduling_practicephoto'] = $onlineSchedulingpracticephoto;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingpracticephoto" => $onlineSchedulingpracticephoto));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '23') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_prodviders == '1')
        {
            $onlineSchedulingprodviders = '0'; 
            $old_onlineSchedulingprodviders = 'Enable';
            $new_onlineSchedulingprodviders = 'Disable';  
        }else{
            $onlineSchedulingprodviders = '1';
            $old_onlineSchedulingprodviders = 'Disable';
            $new_onlineSchedulingprodviders = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling providers status old</b> ".$old_onlineSchedulingprodviders." <b>to</b> ".$new_onlineSchedulingprodviders;

        $data_clinic['clinic_onlineScheduling_prodviders'] = $onlineSchedulingprodviders;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        /// added logic on 24-08-2024
        $cdoctorData =array(
          "cdoctor_onlineScheduling_added"=>1
        );
        $cdoctorWhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $cdoctorObj = new cdoctor();
        $cdoctorObj->updateFromFields($cdoctorData,$cdoctorWhere);
        

        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingprodviders" => $onlineSchedulingprodviders));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '24') // in clinic table
    {
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_reviews == '1')
        {
            $onlineSchedulingreviews = '0'; 
            $old_onlineSchedulingreviews = 'Enable';
            $new_onlineSchedulingreviews = 'Disable';  
        }else{
            $onlineSchedulingreviews = '1';
            $old_onlineSchedulingreviews = 'Disable';
            $new_onlineSchedulingreviews = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling reviews status old</b> ".$old_onlineSchedulingreviews." <b>to</b> ".$new_onlineSchedulingreviews;

        $data_clinic['clinic_onlineScheduling_reviews'] = $onlineSchedulingreviews;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingreviews" => $onlineSchedulingreviews));
        return true;
        
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '25') // in clinic table
    {
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_features == '1')
        {
            $onlineSchedulingfeatures = '0'; 
            $old_onlineSchedulingfeatures = 'Enable';
            $new_onlineSchedulingfeatures = 'Disable';  
        }else{
            $onlineSchedulingfeatures = '1';
            $old_onlineSchedulingfeatures = 'Disable';
            $new_onlineSchedulingfeatures = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling features status old</b> ".$old_onlineSchedulingfeatures." <b>to</b> ".$new_onlineSchedulingfeatures;

        $data_clinic['clinic_onlineScheduling_features'] = $onlineSchedulingfeatures;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingfeatures" => $onlineSchedulingfeatures));
        return true;
        
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '26') // in clinic table
    {
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_services == '1')
        {
            $onlineSchedulingservices = '0'; 
            $old_onlineSchedulingservices = 'Enable';
            $new_onlineSchedulingservices = 'Disable';  
        }else{
            $onlineSchedulingservices = '1';
            $old_onlineSchedulingservices = 'Disable';
            $new_onlineSchedulingservices = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling service status old</b> ".$old_onlineSchedulingservices." <b>to</b> ".$new_onlineSchedulingservices;

        $data_clinic['clinic_onlineScheduling_services'] = $onlineSchedulingservices;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingservices" => $onlineSchedulingservices));
        return true;
        
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '27') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_logobanner == '1')
        {
            $onlineSchedulinglogobanner = '0'; 
            $old_onlineSchedulinglogobanner = 'Enable';
            $new_onlineSchedulinglogobanner = 'Disable';  
        }else{
            $onlineSchedulinglogobanner = '1';
            $old_onlineSchedulinglogobanner = 'Disable';
            $new_onlineSchedulinglogobanner = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling logo banner status old</b> ".$old_onlineSchedulinglogobanner." <b>to</b> ".$new_onlineSchedulinglogobanner;

        $data_clinic['clinic_onlineScheduling_logobanner'] = $onlineSchedulinglogobanner;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulinglogobanner" => $onlineSchedulinglogobanner));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '28') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_location == '1')
        {
            $onlineSchedulinglocation = '0'; 
            $old_onlineSchedulinglocation = 'Enable';
            $new_onlineSchedulinglocation = 'Disable';  
        }else{
            $onlineSchedulinglocation = '1';
            $old_onlineSchedulinglocation = 'Disable';
            $new_onlineSchedulinglocation = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling location status old</b> ".$old_onlineSchedulinglocation." <b>to</b> ".$new_onlineSchedulinglocation;

        $data_clinic['clinic_onlineScheduling_location'] = $onlineSchedulinglocation;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulinglocation" => $onlineSchedulinglocation));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '29') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_pageheader == '1')
        {
            $onlineSchedulingpageheader = '0'; 
            $old_onlineSchedulingpageheader = 'Enable';
            $new_onlineSchedulingpageheader = 'Disable';  
        }else{
            $onlineSchedulingpageheader = '1';
            $old_onlineSchedulingpageheader = 'Disable';
            $new_onlineSchedulingpageheader = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling page header status old</b> ".$old_onlineSchedulingpageheader." <b>to</b> ".$new_onlineSchedulingpageheader;

        $data_clinic['clinic_onlineScheduling_pageheader'] = $onlineSchedulingpageheader;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingpageheader" => $onlineSchedulingpageheader));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '36') // in clinic table
    {
        
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        
        if($clinic_data->clinic_onlineScheduling_flexibleschedule == '1')
        {
            $onlineSchedulingflexibleschedule = '0'; 
            $old_onlineSchedulingflexibleschedule = 'Enable';
            $new_onlineSchedulingflexibleschedule = 'Disable';  
        }else{
            $onlineSchedulingflexibleschedule = '1';
            $old_onlineSchedulingflexibleschedule = 'Disable';
            $new_onlineSchedulingflexibleschedule = 'Enable';
        }

        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling page flexible schedule status old</b> ".$old_onlineSchedulingflexibleschedule." <b>to</b> ".$new_onlineSchedulingflexibleschedule;

        $data_clinic['clinic_onlineScheduling_flexibleschedule'] = $onlineSchedulingflexibleschedule;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingflexibleschedule" => $onlineSchedulingflexibleschedule));
        return true;
    }
    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '38') // in clinic table
    {
        $clinicObj = new clinic();
        $where = array("clinic_id="=>$_REQUEST['messageaccess_id']);
        $clinicArg = array('where'=>$where);
        $clinic_data = $clinicObj->FromFields($clinicArg);
        if($clinic_data->clinic_onlineScheduling_officehours == '1')
        {
            $onlineSchedulingofficehours = '0'; 
            $old_onlineSchedulingofficehours = 'Enable';
            $new_onlineSchedulingofficehours = 'Disable';  
        }else{
            $onlineSchedulingofficehours = '1';
            $old_onlineSchedulingofficehours = 'Disable';
            $new_onlineSchedulingofficehours = 'Enable';
        }
        $clinic_detail = "<b>Id</b>:".$clinic_data->clinic_id."<br/><b>Name</b>:".$clinic_data->clinic_name."<br/><b>Online Scheduling page office hours status old</b> ".$old_onlineSchedulingofficehours." <b>to</b> ".$new_onlineSchedulingofficehours;
        $data_clinic['clinic_onlineScheduling_officehours'] = $onlineSchedulingofficehours;
        $rs=$clinicObj->updateRecords($data_clinic,$_REQUEST['messageaccess_id']);
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "onlineSchedulingofficehours" => $onlineSchedulingofficehours));
        return true;
    }
    /*provider online scheduling*/

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '30') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_aboutus == '1')
        {
            $cdoctoronlineSchedulingaboutus = '0'; 
            $old_cdoctoronlineSchedulingaboutus = 'Enable';
            $new_cdoctoronlineSchedulingaboutus = 'Disable';  
        }else{
            $cdoctoronlineSchedulingaboutus = '1';
            $old_cdoctoronlineSchedulingaboutus = 'Disable';
            $new_cdoctoronlineSchedulingaboutus = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page about us old</b> ".$old_cdoctoronlineSchedulingaboutus." <b>to</b> ".$new_cdoctoronlineSchedulingaboutus;

        $data_cdoctor['cdoctor_onlineScheduling_aboutus'] = $cdoctoronlineSchedulingaboutus;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulingaboutus" => $cdoctoronlineSchedulingaboutus));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '31') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_practicephoto == '1')
        {
            $cdoctoronlineSchedulingpracticephoto = '0'; 
            $old_cdoctoronlineSchedulingpracticephoto = 'Enable';
            $new_cdoctoronlineSchedulingpracticephoto = 'Disable';  
        }else{
            $cdoctoronlineSchedulingpracticephoto = '1';
            $old_cdoctoronlineSchedulingpracticephoto = 'Disable';
            $new_cdoctoronlineSchedulingpracticephoto = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page practice photos old</b> ".$old_cdoctoronlineSchedulingpracticephoto." <b>to</b> ".$new_cdoctoronlineSchedulingpracticephoto;

        $data_cdoctor['cdoctor_onlineScheduling_practicephoto'] = $cdoctoronlineSchedulingpracticephoto;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulingpracticephoto" => $cdoctoronlineSchedulingpracticephoto));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '32') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_reviews == '1')
        {
            $cdoctoronlineSchedulingreviews = '0'; 
            $old_cdoctoronlineSchedulingreviews = 'Enable';
            $new_cdoctoronlineSchedulingreviews = 'Disable';  
        }else{
            $cdoctoronlineSchedulingreviews = '1';
            $old_cdoctoronlineSchedulingreviews = 'Disable';
            $new_cdoctoronlineSchedulingreviews = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page Reviews old</b> ".$old_cdoctoronlineSchedulingreviews." <b>to</b> ".$new_cdoctoronlineSchedulingreviews;

        $data_cdoctor['cdoctor_onlineScheduling_reviews'] = $cdoctoronlineSchedulingreviews;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulingreviews" => $cdoctoronlineSchedulingreviews));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '33') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_logobanner == '1')
        {
            $cdoctoronlineSchedulinglogobanner = '0'; 
            $old_cdoctoronlineSchedulinglogobanner = 'Enable';
            $new_cdoctoronlineSchedulinglogobanner = 'Disable';  
        }else{
            $cdoctoronlineSchedulinglogobanner = '1';
            $old_cdoctoronlineSchedulinglogobanner = 'Disable';
            $new_cdoctoronlineSchedulinglogobanner = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page logo banner old</b> ".$old_cdoctoronlineSchedulinglogobanner." <b>to</b> ".$new_cdoctoronlineSchedulinglogobanner;

        $data_cdoctor['cdoctor_onlineScheduling_logobanner'] = $cdoctoronlineSchedulinglogobanner;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulinglogobanner" => $cdoctoronlineSchedulinglogobanner));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '34') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_location == '1')
        {
            $cdoctoronlineSchedulinglocation = '0'; 
            $old_cdoctoronlineSchedulinglocation = 'Enable';
            $new_cdoctoronlineSchedulinglocation = 'Disable';  
        }else{
            $cdoctoronlineSchedulinglocation = '1';
            $old_cdoctoronlineSchedulinglocation = 'Disable';
            $new_cdoctoronlineSchedulinglocation = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page location old</b> ".$old_cdoctoronlineSchedulinglocation." <b>to</b> ".$new_cdoctoronlineSchedulinglocation;

        $data_cdoctor['cdoctor_onlineScheduling_location'] = $cdoctoronlineSchedulinglocation;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulinglocation" => $cdoctoronlineSchedulinglocation));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '35') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_pageheader == '1')
        {
            $cdoctoronlineSchedulingpageheader = '0'; 
            $old_cdoctoronlineSchedulingpageheader = 'Enable';
            $new_cdoctoronlineSchedulingpageheader = 'Disable';  
        }else{
            $cdoctoronlineSchedulingpageheader = '1';
            $old_cdoctoronlineSchedulingpageheader = 'Disable';
            $new_cdoctoronlineSchedulingpageheader = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling page page header old</b> ".$old_cdoctoronlineSchedulingpageheader." <b>to</b> ".$new_cdoctoronlineSchedulingpageheader;

        $data_cdoctor['cdoctor_onlineScheduling_pageheader'] = $cdoctoronlineSchedulingpageheader;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulingpageheader" => $cdoctoronlineSchedulingpageheader));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['status_data'] == '37') // in cdoctor table
    {
        
        $cdoctorObj = new cdoctor();
        $where = array("cdoctor_clinic_id="=>$_REQUEST['messageaccess_id']);
        $cdoctorArg = array('where'=>$where);
        $cdoctor_data = $cdoctorObj->FromFields($cdoctorArg);
        
        if($cdoctor_data->cdoctor_onlineScheduling_flexibleschedule == '1')
        {
            $cdoctoronlineSchedulingflexibleschedule = '0'; 
            $old_cdoctoronlineSchedulingflexibleschedule = 'Enable';
            $new_cdoctoronlineSchedulingflexibleschedule = 'Disable';  
        }else{
            $cdoctoronlineSchedulingflexibleschedule = '1';
            $old_cdoctoronlineSchedulingflexibleschedule = 'Disable';
            $new_cdoctoronlineSchedulingflexibleschedule = 'Enable';
        }

        $cdoctor_detail = "<b>Id</b>:".$cdoctor_data->cdoctor_clinic_id."<br/><b>Name</b>:".$cdoctor_data->cdoctor_fullname."<br/><b>Online Provider Scheduling flexible schedule old</b> ".$old_cdoctoronlineSchedulingflexibleschedule." <b>to</b> ".$new_cdoctoronlineSchedulingflexibleschedule;

        $data_cdoctor['cdoctor_onlineScheduling_flexibleschedule'] = $cdoctoronlineSchedulingflexibleschedule;
        $updatewhere =array('cdoctor_clinic_id='=>$_REQUEST['messageaccess_id']);
        $rs=$cdoctorObj->updateFromFields($data_cdoctor,$updatewhere);
        //$rs=$clinicObj->updateRecords($data_cdoctor,$_REQUEST['messageaccess_id']);
        
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$cdoctor_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "cdoctoronlineSchedulingflexibleschedule" => $cdoctoronlineSchedulingflexibleschedule));
        return true;
    }

}
/*Practice Features ends here*/

if(isset($_REQUEST['act']) && $_REQUEST['act']=='communicationprovider' && isset($_REQUEST['clinic_id'])){
    $clinicproviderDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    if(!empty($clinicproviderDetail)){
        $clinicsettingData = json_decode($clinicproviderDetail->clinic_setting,1);
        
        if(isset($_REQUEST['communicationprovider']) && $_REQUEST['communicationprovider'] != '')
        {
            $clinicsettingData['communicationprovider']=$_REQUEST['communicationprovider'];    
        }else{
            unset($clinicsettingData['communicationprovider']);
        }
        
        $settingData['clinic_setting'] = json_encode($clinicsettingData);
        
        $clinicseting = $clinicObj->updateRecords($settingData,$_REQUEST['clinic_id']);
        if($clinicseting)
        {
            header('Location:cliniclist.php');
            exit;
        }
    }
}
/*Appointment Chat Pin start*/
if(isset($_REQUEST['act']) && $_REQUEST['act']=='apptchatpin' && isset($_REQUEST['clinic_id'])){
    $clinicChatPinDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    $id = $_REQUEST['clinic_id'];
    
    if(!empty($clinicChatPinDetail)){
        $clinicsettingData = json_decode($clinicChatPinDetail['clinic_setting'],1);
        
        if(isset($_REQUEST['apptchatpin']) && $_REQUEST['apptchatpin'] != '')
        {
            $clinicsettingData['appointmentChatPin']=$_REQUEST['apptchatpin'];    
        }else{
            unset($clinicsettingData['appointmentChatPin']);
        }
        
        $settingData['clinic_setting'] = json_encode($clinicsettingData);
        
        $clinicseting = $clinicObj->updateRecords($settingData,$_REQUEST['clinic_id']);
        if($clinicseting)
        {
            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
}

/*Appointment Chat Pin end*/


/*Subscription Card Add start*/
if(isset($_REQUEST['act']) && $_REQUEST['act']=='subscreditcard' && isset($_REQUEST['clinic_id'])){
    $stripeObj= new stripePay();
    $stripeToken = $stripeObj->createToken();
    
    $clinicDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    $id = $_REQUEST['clinic_id'];

    $stripeObj= new stripePay();
    if(!empty($stripeToken)){

        $userObj = new user();
        $where = array('user_unique_id=' => $_REQUEST['clinicuseruniqueid']);
        $userArg    = array('where' => $where);
        $userObj->resultAs = 'array';
        $result = $userObj->fromFields($userArg);
        if($result && $result['user_owner']=='1'){
            if($result['user_stripedata']!="" && is_array(json_decode($result['user_stripedata'],1))){
                if(array_key_exists("customerId", json_decode($result['user_stripedata'],1))){
                    $customerData = json_decode($result['user_stripedata'],1);
                    $stripeCustomer = $customerData['customerId'];
                }else{
                    $stripUserData = json_decode($result['user_stripedata'],1);
                    $customerDetails = array(
                        'email' => $result['user_email_address'],
                        'name' =>  $result['user_fname']." ".$result['user_lname'],
                        'description' => "XCAREPRO Customer created."
                    );
                    $stripeCustomerResponse = $stripeObj->addCustomer($customerDetails);
                    if($stripeCustomerResponse){
                        $stripUserData['customerId'] = $stripeCustomerResponse['id'];
                        $userData = array(
                            "user_stripedata"=>json_encode($stripUserData)
                        );
                        $stripeCustomer =$stripeCustomerResponse['id'];
                        $userObj->updateRecords($userData,$result['user_id']);
                    }else{
                        $resStatus['error']=true;
                        $resStatus['msg']="Error while create customer in stripe.";
                        $response['status'] =$resStatus;
                        echo json_encode($response);
                        exit;
                    } 
                }
                
            }else{
                $customerDetails = array(
                    'email' => $result['user_email_address'],
                    'name' =>  $result['user_fname']." ".$result['user_lname'],
                    'description' => "XCAREPRO Customer created."
                );
                $stripeCustomerResponse = $stripeObj->addCustomer($customerDetails);
                if($stripeCustomerResponse){
                    $userData = array(
                        "user_stripedata"=>json_encode(["customerId"=>$stripeCustomerResponse['id']])
                    );
                    $stripeCustomer =$stripeCustomerResponse['id'];
                    $userObj->updateRecords($userData,$result['user_id']);
                }else{
                    $resStatus['error']=true;
                    $resStatus['msg']="Error while create customer in stripe.";
                    $response['status'] =$resStatus;
                    echo json_encode($response);
                    exit;
                }    
            }    

             
             if($stripeCustomer){
                $sourceData = array('source' => $stripeToken->id);
                $cardResponse = $stripeObj->createCustomerSource($stripeCustomer,$sourceData); 
                if($cardResponse){
                   $stripecardObj = new stripecard();
                   $cardData =array(
                        "stripecard_user_id" =>$result['user_id'],
                        "stripecard_name" =>$cardResponse['name'],
                        "stripecard_stripeId"=> $cardResponse['id'],
                        "stripecard_brand"=> $cardResponse['brand'],
                        "stripecard_last4"=> $cardResponse['last4'],
                        "stripecard_fingerprint"=> $cardResponse['fingerprint'],
                        "stripecard_expMonth"=> $cardResponse['exp_month'],
                        "stripecard_expYear"=> $cardResponse['exp_year'],
                        "stripecard_status" => 'Active'  
                   ); 
                   $rs = $stripecardObj->addRecords($cardData);
                   if($rs){
                        $card = array(
                            "id" => $rs,
                            "brand" =>$cardResponse['brand'],
                            "last4" =>$cardResponse['last4'],
                            "status" =>"Active",
                        );

                        $resStatus['msg']="Successfully added.";
                        $response['card'] = $card;
                        $response['status'] =$resStatus;
                        echo json_encode($response);
                        exit;                
                   }  
                }/*else{
                    $resStatus['error']=true;
                    $resStatus['msg']="Error while store card in stripe.";
                    $response['status'] =$resStatus;
                    echo json_encode($response);
                    exit;
                }*/
            }/*else{
                $resStatus['error']=true;
                $resStatus['msg']="Something went wrong";
                $response['status'] =$resStatus;
                echo json_encode($response);
                exit; 
            }*/
        }/*else{
            $resStatus['error']=true;
            $resStatus['msg']="Something went wrong.";
            $response['status'] =$resStatus;
            echo json_encode($response);  exit;
        }*/
      header('Location:clinic_setting.php?clinic_id='.$id);
      exit;
    }/*else{
        $resStatus['error']=true;
        $resStatus['msg']="Missing parameter";
        $result['status'] =$resStatus;
        echo json_encode($result); exit; 
    }*/
    
}

/*Subscription Card Add end*/

/*start updatedisplayrating */
 
 if(isset($_REQUEST['act']) && $_REQUEST['act']=='updatedisplayrating' && isset($_REQUEST['clinic_id'])){
    $clinicupdatedisplayrating = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    $id = $_REQUEST['clinic_id'];
    
    if(!empty($clinicupdatedisplayrating)){
        
        if(isset($_REQUEST['updatedisplayrating']) && $_REQUEST['updatedisplayrating'] != '')
        {
            $updatedisplayratingDetails = array(
                        'clinic_displayRating' => $_REQUEST['updatedisplayrating']
                    );
        }
        
        $clinicseting = $clinicObj->updateRecords($updatedisplayratingDetails,$_REQUEST['clinic_id']);
        if($clinicseting)
        {
            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
} 

/* end updatedisplayrating */

//if(isset($_POST['submit'])){
    if (isset($_REQUEST['act']) && $_REQUEST['act']=='setting'){
      
    $field_settingvalues1 = $_POST['field_setting1'];
    $field_settingvalues2 = $_POST['field_setting2'];
    if(!empty($field_settingvalues1) && !empty($field_settingvalues2))
    {
    $clinicsetting_details = array();
        foreach ($field_settingvalues1 as $skey => $settingkey) 
        {        
            if(isset($settingkey) && $settingkey != '' && $field_settingvalues2[$skey] != '')
            {
                $clinicsetting_details[$settingkey] = $field_settingvalues2[$skey];
            }
        }
        $clinicsetting_details['communicationprovider']=$_POST['communicationprovider'];
        $all_setting = json_encode($clinicsetting_details);
        $data=array(
            'clinic_setting'=>trim($all_setting),
        );
    }    
    $oldclinicDetail = $clinicObj->fromId($_POST['clinic_id']);
    //print_r($oldclinicDetail->clinic_setting);exit;
    $clinic_detail = " <b>Setting data</b>: ".$oldclinicDetail->clinic_setting." to ".$all_setting;

    //echo $_POST['clinic_id'];exit;
    if (isset($_POST['clinic_id'])){    
        $id=$_POST['clinic_id'];
        //print_r($data);exit;
        $rs=$clinicObj->updateRecords($data,$id);
        if ($rs){

             $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$clinic_detail);
            //$successMsg = RECORD_UPDATE;
            //header('Location:clinic_setting.php?act=setting&clinic_id='.$id);
            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
}


if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getprocedurecode' && isset($_REQUEST['procedure_code']) && $_REQUEST['procedure_code'] != '')
{
    $procedure_code = explode(",", $_REQUEST['procedure_code']);
    if(count($procedure_code) > 1)
    {
        $procedurearg =  "'" . implode ( "', '", $procedure_code ) . "'";
        
        $procedure_code_data .= " procedure_code_category IN (".$procedurearg.")";

    }else{
        $procedure_code_data = " procedure_code_category IN ('".$_REQUEST['procedure_code']."') ";
    }
    $procedure_codeObj = new procedure_code();
    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data;
    //echo $where;exit;
    //$groupBy = array(" procedure_code_category_id desc ");
    $procedurecodeArg    = array('where' => $where);
    $sikkaDetails = $procedure_codeObj->getAllRecords($procedurecodeArg);
    ?>
    <!-- <option value="">Select Code</option> -->
    <?php
    foreach ($sikkaDetails as $key => $sikkayvalue) 
    { ?>
        <option value="<?php echo $sikkayvalue->procedure_code_sikkaId; ?>" ><?php echo $sikkayvalue->procedure_code_sikkaId; ?></option> 
                             
    <?php }
    //echo json_encode($sikkaDetails);
    exit;
}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='overdueupdate' && $_REQUEST['clinicId'] != ''){
        
    $cliniId = $_POST['clinicId'];
    $clinic_overdueval_6 = $_POST['clinic_overdueval_6'];
    $clinic_initiation_days_6 = $_POST['clinic_initiation_days_6'];
    $clinic_overdue_status_6 = $_POST['clinic_overdue_status_6'];
    $clinic_procedure_category_6 = $_POST['clinic_procedure_category_6'];
    $clinic_procedure_code_6 = $_POST['clinic_procedure_code_6'];

    $clinic_overdueval_12 = $_POST['clinic_overdueval_12'];
    $clinic_initiation_days_12 = $_POST['clinic_initiation_days_12'];
    $clinic_overdue_status_12 = $_POST['clinic_overdue_status_12'];
    $clinic_procedure_category_12 = $_POST['clinic_procedure_category_12'];
    $clinic_procedure_code_12 = $_POST['clinic_procedure_code_12'];

    $clinic_overdueval_18 = $_POST['clinic_overdueval_18'];
    $clinic_initiation_days_18 = $_POST['clinic_initiation_days_18'];
    $clinic_overdue_status_18 = $_POST['clinic_overdue_status_18'];
    $clinic_procedure_category_18 = $_POST['clinic_procedure_category_18'];
    $clinic_procedure_code_18 = $_POST['clinic_procedure_code_18'];

    $clinic_overdueval_24 = $_POST['clinic_overdueval_24'];
    $clinic_initiation_days_24 = $_POST['clinic_initiation_days_24'];
    $clinic_overdue_status_24 = $_POST['clinic_overdue_status_24'];
    $clinic_procedure_category_24 = $_POST['clinic_procedure_category_24'];
    $clinic_procedure_code_24 = $_POST['clinic_procedure_code_24'];

    $clinicOverdue_details6 = array();
    $clinicOverdue_details12 = array();
    $clinicOverdue_details18 = array();
    $clinicOverdue_details24 = array();
    $data = array();
    
    if(isset($clinic_initiation_days_6) && $clinic_initiation_days_6 != '')
    {
        $clinicOverdue_details6['initiation_days'] = $clinic_initiation_days_6;
    }
    if(!empty($clinic_overdue_status_6))
    {
    
        foreach ($clinic_overdue_status_6 as $ps6key => $pc6status) 
        {        
            $status_6 .= $pc6status.",";
            
        }
        $clinicOverdue_details6['status'] = rtrim($status_6,",");
    }
    if(!empty($clinic_procedure_category_6))
    {
    
        foreach ($clinic_procedure_category_6 as $pc6key => $pc6category) 
        {        
            $procedure_category_6 .= $pc6category.",";
            
        }
        $clinicOverdue_details6['procedure_category'] = rtrim($procedure_category_6,",");
    }else{
        $clinicOverdue_details6['procedure_category'] = '';
    }
    if(!empty($clinic_procedure_code_6))
    {
    
        foreach ($clinic_procedure_code_6 as $pcd6key => $pc6code) 
        {        
            $procedure_code_6 .= $pc6code.",";
            
        }
        $clinicOverdue_details6['procedure_code'] = rtrim($procedure_code_6,",");
    }else{
        $clinicOverdue_details6['procedure_code'] = '';
    }

    if(isset($clinic_initiation_days_12) && $clinic_initiation_days_12 != '')
    {
        $clinicOverdue_details12['initiation_days'] = $clinic_initiation_days_12;
    }
    if(!empty($clinic_overdue_status_12))
    {
    
        foreach ($clinic_overdue_status_12 as $ps12key => $pc12status) 
        {        
            $status_12 .= $pc12status.",";
            
        }
        $clinicOverdue_details12['status'] = rtrim($status_12,",");
    }
    if(!empty($clinic_procedure_category_12))
    {
    
        foreach ($clinic_procedure_category_12 as $pc12key => $pc12category) 
        {        
            $procedure_category_12 .= $pc12category.",";
            
        }
        $clinicOverdue_details12['procedure_category'] = rtrim($procedure_category_12,",");
    }else{
        $clinicOverdue_details12['procedure_category'] = '';
    }
    if(!empty($clinic_procedure_code_12))
    {
    
        foreach ($clinic_procedure_code_12 as $pcd12key => $pc12code) 
        {        
            $procedure_code_12 .= $pc12code.",";
            
        }
        $clinicOverdue_details12['procedure_code'] = rtrim($procedure_code_12,",");
    }else{
        $clinicOverdue_details12['procedure_code'] = '';
    }

    if(isset($clinic_initiation_days_18) && $clinic_initiation_days_18 != '')
    {
        $clinicOverdue_details18['initiation_days'] = $clinic_initiation_days_18;
    }
    if(!empty($clinic_overdue_status_18))
    {
    
        foreach ($clinic_overdue_status_18 as $ps18key => $pc18status) 
        {        
            $status_18 .= $pc18status.",";
            
        }
        $clinicOverdue_details18['status'] = rtrim($status_18,",");
    }
    if(!empty($clinic_procedure_category_18))
    {
    
        foreach ($clinic_procedure_category_18 as $pc18key => $pc18category) 
        {        
            $procedure_category_18 .= $pc18category.",";
            
        }
        $clinicOverdue_details18['procedure_category'] = rtrim($procedure_category_18,",");
    }else{
        $clinicOverdue_details18['procedure_category'] ='';
    }
    if(!empty($clinic_procedure_code_18))
    {
    
        foreach ($clinic_procedure_code_18 as $pcd18key => $pc18code) 
        {        
            $procedure_code_18 .= $pc18code.",";
            
        }
        $clinicOverdue_details18['procedure_code'] = rtrim($procedure_code_18,",");
    }else{
        $clinicOverdue_details18['procedure_code'] = '';
    }

    if(isset($clinic_initiation_days_24) && $clinic_initiation_days_24 != '')
    {
        $clinicOverdue_details24['initiation_days'] = $clinic_initiation_days_24;
    }
    if(!empty($clinic_overdue_status_24))
    {
    
        foreach ($clinic_overdue_status_24 as $ps24key => $pc24status) 
        {        
            $status_24 .= $pc24status.",";
            
        }
        $clinicOverdue_details24['status'] = rtrim($status_24,",");
    }
    if(!empty($clinic_procedure_category_24))
    {
    
        foreach ($clinic_procedure_category_24 as $pc24key => $pc24category) 
        {        
            $procedure_category_24 .= $pc24category.",";
            
        }
        $clinicOverdue_details24['procedure_category'] = rtrim($procedure_category_24,",");
    }else{
        $clinicOverdue_details24['procedure_category'] = '';
    }
    if(!empty($clinic_procedure_code_24))
    {
    
        foreach ($clinic_procedure_code_24 as $pcd24key => $pc24code) 
        {        
            $procedure_code_24 .= $pc24code.",";
            
        }
        $clinicOverdue_details24['procedure_code'] = rtrim($procedure_code_24,",");
    }else{
        $clinicOverdue_details24['procedure_code'] = '';
    }

    $data[$clinic_overdueval_6] = $clinicOverdue_details6;
    $data[$clinic_overdueval_12] = $clinicOverdue_details12;
    $data[$clinic_overdueval_18] = $clinicOverdue_details18;
    $data[$clinic_overdueval_24] = $clinicOverdue_details24;
    $all_overdue = json_encode($data);
    $data=array(
            'clinic_overdue'=>($all_overdue),
        );
    if (isset($cliniId)){    
        $id=$cliniId;
        //print_r($data);exit;
        $rs=$clinicObj->updateRecords($data,$id);
        if ($rs){

            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='overdue' && $_REQUEST['clinic_id'] != ''){
    

    $fields = array('clinic_id','clinic_overdue','clinic_new_patient_status');
    $where = array("clinic_id="=>$_REQUEST['clinic_id']);
    $clinicArg    = array('fields'=>$fields,'where' => $where);
    $clinicObj->resultAs = "array";
    $clinicDetails = $clinicObj->fromFields($clinicArg);
    if($clinicDetails)
    {
        if(!empty($clinicDetails['clinic_overdue']))
        {
            $overduedata = json_decode($clinicDetails['clinic_overdue'],1);
            if(!empty($overduedata['0-6']))
            {
                $initiation_days_6 = $overduedata['0-6']['initiation_days'];
                $status_6 = explode(",",$overduedata['0-6']['status']);
                $procedure_category_6 = explode(",",$overduedata['0-6']['procedure_category']);
                $procedure_code_6 = explode(",",$overduedata['0-6']['procedure_code']);

                if(!empty($procedure_category_6) && count($procedure_category_6) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_6 ) . "'";
                    
                    $procedure_code_data6 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data6;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_6 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }

            }

            if(!empty($overduedata['7-12']))
            {
                $initiation_days_12 = $overduedata['7-12']['initiation_days'];
                $status_12 = explode(",",$overduedata['7-12']['status']);
                $procedure_category_12 = explode(",",$overduedata['7-12']['procedure_category']);
                $procedure_code_12 = explode(",",$overduedata['7-12']['procedure_code']);

                if(!empty($procedure_category_12) && count($procedure_category_12) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_12 ) . "'";
                    
                    $procedure_code_data12 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data12;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_12 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }

            if(!empty($overduedata['13-18']))
            {
                $initiation_days_18 = $overduedata['13-18']['initiation_days'];
                $status_18 = explode(",",$overduedata['13-18']['status']);
                $procedure_category_18 = explode(",",$overduedata['13-18']['procedure_category']);
                $procedure_code_18 = explode(",",$overduedata['13-18']['procedure_code']);

                if(!empty($procedure_category_18) && count($procedure_category_18) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_18 ) . "'";
                    
                    $procedure_code_data18 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data18;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_18 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }

            if(!empty($overduedata['19-24']))
            {
                $initiation_days_24 = $overduedata['19-24']['initiation_days'];
                $status_24 = explode(",",$overduedata['19-24']['status']);
                $procedure_category_24 = explode(",",$overduedata['19-24']['procedure_category']);
                $procedure_code_24 = explode(",",$overduedata['19-24']['procedure_code']);

                if(!empty($procedure_category_24) && count($procedure_category_24) > 0)
                {
                    $procedurearg =  "'" . implode ( "', '", $procedure_category_24 ) . "'";
                    
                    $procedure_code_data24 .= " procedure_code_category IN (".$procedurearg.")";
                    $procedure_codeObj = new procedure_code();
                    $where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_sikkaId != '' and ".$procedure_code_data24;
                    $procedurecodeArg    = array('where' => $where);
                    $codeDetails_24 = $procedure_codeObj->getAllRecords($procedurecodeArg);

                }
            }
        }

        $clinic_patient_status = array('');
        if(!empty($clinicDetails['clinic_new_patient_status']))
        {

            $clinic_patient_status = explode(",",$clinicDetails['clinic_new_patient_status']);
        }
    }
   // exit;
}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='patient_status' && $_REQUEST['clinicId'] != ''){
        
    $cliniId = $_POST['clinicId'];
    $clinic_patient_status = $_POST['clinic_patient_status'];
    
    $patient_status =  implode ( ",", $clinic_patient_status );

    $data=array(
            'clinic_new_patient_status'=>($patient_status),
        );
    if (isset($cliniId)){    
        $id=$cliniId;
        //print_r($data);exit;
        $rs=$clinicObj->updateRecords($data,$id);
        if ($rs){

            //header('Location:clinic_overdue.php?act=overdue&clinic_id='.$id);
            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
}


if(isset($_REQUEST['act']) && $_REQUEST['act']=='getcode' && $_REQUEST['goto_clientId'] != '' && $_REQUEST['goto_client_secret'] != '')
{
    $client_id = trim($_REQUEST['goto_clientId']);
    $client_secret = trim($_REQUEST['goto_client_secret']);
    $redirect_url = SITE_URL_GOTO."x-admin/gotocode.php";
    $url = "https://authentication.logmeininc.com/oauth/authorize?client_id=".$client_id."&response_type=code&redirect_uri=".$redirect_url."";

    $clinicproviderDetail = $clinicObj->fromId($_REQUEST['clinic_id']);
    if(!empty($clinicproviderDetail)){
        
        $clinicsettingData = json_decode($clinicproviderDetail['clinic_setting'],1);
        
        if(isset($client_id) && $client_id != '')
        {
            $clinicsettingData['clientid']=$client_id;    
        }else{
            unset($clinicsettingData['clientid']);
        }

        if(isset($client_secret) && $client_secret != '')
        {
            $clinicsettingData['clientsecret']=$client_secret;    
        }else{
            unset($clinicsettingData['clientsecret']);
        }
        
        
        $settingData['clinic_setting'] = json_encode($clinicsettingData);
        
        $clinicseting = $clinicObj->updateRecords($settingData,$_REQUEST['clinic_id']);
        
    }

   echo "<script type=\"text/javascript\">
            window.open('".$url."', '_blank')
        </script>";

    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='addcodetoken' && $_REQUEST['clinic_id'] != '')
{
    $clinicObj = new clinic();
    $clinic_detail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    $client_id = trim($_REQUEST['goto_clientId']);
    
    if(isset($_REQUEST['goto_code']) && $_REQUEST['goto_code'] != '')
    {
      $curl = curl_init();

      
      $client_secret = trim($_REQUEST['goto_client_secret']);
      $allclient_data = $client_id.":".$client_secret;
      $authorizationdata = base64_encode($allclient_data);
      //$rdirect_url = urlencode('https://google.com');
      $redirect_url = urlencode(SITE_URL_GOTO."x-admin/gotocode.php");
      $data = 'redirect_uri='.$redirect_url.'&grant_type=authorization_code&code='.$_REQUEST['goto_code'];
      $authorized_val = $authorizationdata;
      //$authorized_header = "authorization: Basic ".GOTO_HEADER_TOKEN;
      $authorized_header = "authorization: Basic ".$authorized_val;

      curl_setopt_array($curl, array(
        CURLOPT_URL => "https://authentication.logmeininc.com/oauth/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $data,
        CURLOPT_HTTPHEADER => array(
          $authorized_header,
          "cache-control: no-cache",
          "content-type: application/x-www-form-urlencoded"
        ),
      ));
      
      $response = curl_exec($curl);
      $err = curl_error($curl);
      curl_close($curl);

      if ($err) {
        echo "cURL Error #:" . $err;
      }else
      {
         $gotoresponse =  json_decode($response,1);
         //print_r($gotoresponse);exit;
         if(isset($gotoresponse['error']) && $gotoresponse['error'] != '')
         {
            echo $gotoresponse['error'].' => '.$gotoresponse['error_description'];
            $responseerror = $gotoresponse['error'].' and '.$gotoresponse['error_description'];
            $admin_detail .= " <b>ClinicId</b>: ".$_REQUEST['clinic_id']."<br/><b>Gotosetting</b>: ".$responseerror;

            $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);
         }
         else{
            
            echo 'success';
            $clinicsettingData = json_decode($clinic_detail->clinic_setting,1);
            if(isset($gotoresponse['access_token']) && $gotoresponse['access_token'] != '')
            {
                $clinicsettingData['gotoaccess_token']=$gotoresponse['access_token'];
                
            }
            if(isset($gotoresponse['refresh_token']) && $gotoresponse['refresh_token'] != '')
            {
                $clinicsettingData['gotorefersh_token']=$gotoresponse['refresh_token'];
                
            }
            if(isset($authorized_val) && $authorized_val != '')
            {
                $clinicsettingData['gotoheaderauthorized']=$authorized_val;
                
            }
                    
            
            $settingdata['clinic_setting'] = json_encode($clinicsettingData);
            $clinicseting = $clinicObj->updateRecords($settingdata,$_REQUEST['clinic_id']); 
            $admin_detail .= " <b>ClinicId</b> ".$_REQUEST['clinic_id']."<br/><b>Gotosetting</b>".$response;
            $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);
         }
      }
      exit;
    }
    exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='getcode' && $_REQUEST['ghl_clientId'] != '' && $_REQUEST['ghl_client_secret'] != '')
{
    $client_id = trim($_REQUEST['ghl_clientId']);
    $client_secret = trim($_REQUEST['ghl_client_secret']);
    $redirect_url = SITE_URL."x-admin/gohl.php";
    $url = "https://marketplace.leadconnectorhq.com/oauth/chooselocation?response_type=code&client_id=".$client_id."&redirect_uri=".$redirect_url."&scope=locations.write contacts.write contacts.readonly campaigns.readonly locations.readonly locations/customValues.readonly locations/customValues.write oauth.write oauth.readonly companies.readonly locations/customFields.readonly locations/customFields.write businesses.readonly";

    echo "<script type=\"text/javascript\">
            window.open('".$url."', '_blank')
        </script>";

    exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='GHLaddcodetoken' && $_REQUEST['clinic_id'] != '' && $_REQUEST['ghl_code']!=""){
    $clinicObj = new clinic();
    $clinic_detail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    $client_id = trim($_REQUEST['ghl_clientId']);
    
    if(isset($_REQUEST['ghl_code']) && $_REQUEST['ghl_code'] != ''){
        $curl = curl_init();
        $client_secret = trim($_REQUEST['ghl_client_secret']);
        $ghl_code =$_REQUEST['ghl_code'];
      

        curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://services.leadconnectorhq.com/oauth/token',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => 'client_id='.$client_id.'&client_secret='.$client_secret.'&grant_type=authorization_code&code='.$ghl_code,
        CURLOPT_HTTPHEADER => array(
            'Accept: application/json',
            'Content-Type: application/x-www-form-urlencoded'
        ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {
            echo "cURL Error #:" . $err;
        }else{
            $ghlresponse =  json_decode($response,1);
            if(isset($ghlresponse['error']) && $ghlresponse['error'] != ''){
                echo $ghlresponse['error'].' => '.$ghlresponse['error_description'];
                $responseerror = $ghlresponse['error'].' and '.$ghlresponse['error_description'];
                $admin_detail .= " <b>ClinicId</b>: ".$_REQUEST['clinic_id']."<br/><b>GHL setting</b>: ".$responseerror;
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);
            }else{
            
                echo 'success';
                $clinicsettingData = json_decode($clinic_detail->clinic_setting,1);
                if(isset($ghlresponse['access_token']) && $ghlresponse['access_token'] != ''){
                    $clinicsettingData['ghl_access_token']=$ghlresponse['access_token'];
                }
                if(isset($ghlresponse['refresh_token']) && $ghlresponse['refresh_token'] != ''){
                    $clinicsettingData['ghl_refersh_token']=$ghlresponse['refresh_token'];
                }
                if(isset($ghlresponse['companyId']) && $ghlresponse['companyId'] != ''){
                    $clinicsettingData['ghl_companyId']=$ghlresponse['companyId'];
                }
                if(isset($ghlresponse['locationId']) && $ghlresponse['locationId'] != ''){
                    $clinicsettingData['ghl_locationId']=$ghlresponse['locationId'];
                }
                if(isset($ghlresponse['userId']) && $ghlresponse['userId'] != ''){
                    $clinicsettingData['ghl_userId']=$ghlresponse['userId'];
                }
                
                $settingdata['clinic_setting'] = json_encode($clinicsettingData);
                $clinicseting = $clinicObj->updateRecords($settingdata,$_REQUEST['clinic_id']); 
                $admin_detail .= " <b>ClinicId</b> ".$_REQUEST['clinic_id']."<br/><b>GHL setting</b>".$response;
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);
            }
        }
      exit;
    }
    exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='gotosubs' && $_REQUEST['clinic_id'] != '')
{
    $clinicObj = new clinic();
    $clinic_detail = $clinicObj->fromId($_REQUEST['clinic_id']);
    
    if(isset($_REQUEST['goto_accesstoken']) && $_REQUEST['goto_accesstoken'] != '' && isset($_REQUEST['goto_owner_phone']) && $_REQUEST['goto_owner_phone'] != '')
    {
      $curl = curl_init();

      
      $goto_accesstoken = trim($_REQUEST['goto_accesstoken']);
      
      $goto_owner_phone = trim($_REQUEST['goto_owner_phone']);
      
      $authorized_header = "Authorization: Bearer ".$goto_accesstoken;
      $environment      = parse_url(SITE_URL); 
      if(isset($environment['host']) && $environment['host'] != ''){
       if (strpos(SITE_URL, 'staging') !== false){
          $channel         = 'xcare-staging-webhook';
          $url             = SITE_URL."webhook/goto.php";
          $goto_channel_id = '"url": "'.$url.'"';
       }else{
          $channel         = 'xcare-live-webhook';
          $url             = SITE_URL."webhook/goto.php";
          $goto_channel_id = '"url": "'.$url.'"';
       }
      }

      $CURLOPT_URL = 'https://api.goto.com/notification-channel/v1/channels/'.$channel;
    
      /*Curl to get channel ID*/
      curl_setopt_array($curl, array(
        CURLOPT_URL => $CURLOPT_URL,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{
          "channelType": "Webhook",
          "webhookChannelData": {
            "webhook": {
              '.$goto_channel_id.'
            }
          }
        }',
        CURLOPT_HTTPHEADER => array(
          $authorized_header,
          'Content-Type: application/json'
        ),
      ));
      
      $response = curl_exec($curl);
      $gotoresponse =  json_decode($response,1);
      /*echo "<pre>";print_r($gotoresponse);echo "</pre>";
      exit;*/
      $err = curl_error($curl);
      curl_close($curl);

      if ($err) {
        echo "cURL Error #:" . $err;
      }else
      {
         $gotoresponse =  json_decode($response,1);
         
         
         if(isset($gotoresponse['errorCode']) && $gotoresponse['errorCode'] != '')
         {
            echo $gotoresponse['errorCode'].' and '.$gotoresponse['message'];
            $responseerror = $gotoresponse['error'].' and '.$gotoresponse['error_description'];
            $admin_detail .= " <b>ClinicId</b>: ".$_REQUEST['clinic_id']."<br/><b>Gotosetting</b>: ".$responseerror;

            $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);
         }
         else{

            $clinicsettingData = json_decode($clinic_detail->clinic_setting,1);
            if(isset($gotoresponse['channelId']) && $gotoresponse['channelId'] != '')
            {
                $curl = curl_init();

                if(isset($goto_owner_phone) && $goto_owner_phone != ''){
                  $goto_owner_phonenumber = '"ownerPhoneNumber": "'.$goto_owner_phone.'"';
                  $goto_channel_id        = '"channelId": "'.$gotoresponse['channelId'].'"';

                  /*Curl to subscribe the number based on channel ID and Phone number*/
                  
                  curl_setopt_array($curl, array(
                  CURLOPT_URL => 'https://api.goto.com/messaging/v1/subscriptions',
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_ENCODING => '',
                  CURLOPT_MAXREDIRS => 10,
                  CURLOPT_TIMEOUT => 0,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_CUSTOMREQUEST => 'POST',
                  CURLOPT_POSTFIELDS =>'{
                    '.$goto_owner_phonenumber.',
                    "eventTypes": [
                        "INCOMING_MESSAGE",
                        "OUTGOING_MESSAGE"
                    ],
                    '.$goto_channel_id.'
                }',
                  CURLOPT_HTTPHEADER => array(
                    $authorized_header,
                    'Content-Type: application/json'
                  ),
                ));

                $response = curl_exec($curl);
                
                $err = curl_error($curl);
                $admin_detail .= " <b>ClinicId</b> ".$_REQUEST['clinic_id']."<br/><b>Gotosetting</b>".$response;
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$admin_detail);

                  if ($err) {
                    echo "cURL Error #:" . $err;
                  }else{
                    $gotosubsresponse =  json_decode($response,1);
                    echo $gotosubsresponse['message'];
                  }
                curl_close($curl);
              }
                
            }
         }
      }
      exit;
    }
    exit;
}


//if(isset($_POST) && $_POST['submit']=='Submit'){
if (isset($_REQUEST['act']) && $_REQUEST['act']=='settingPractice'){

    $clinicId = $_REQUEST['clinic_id'];
    $practiceObj =  new  practice();
    $practiceObj->resultAs =  "array";
    $where = array("practice_xcare_id="=>$clinicId);
    $practiceArg = array('where'=>$where);
    $practice_data = $practiceObj->fromFields($practiceArg);

    if(empty($practice_data)){
        $clinicObj = new clinic();
        $clinicDetails = $clinicObj->fromId($clinicId);
        $addpmsdata = array(
            "practice_name" =>$clinicDetails->clinic_name,
            "practice_office_id" =>"DUMMY".$clinicId,
            "practice_secret_key" => "AAA678769KJUTZ1",
            "practice_pms" => 'Dummy',
            "practice_sikka_id" => "1",
            "practice_xcare_id" => $clinicId,
            );
        $rs_practice = $practiceObj->addRecords($addpmsdata);
        $dummy_offic_id  ="DUMMY".$clinicId;
        
    }else{
        $dummy_offic_id  =$practice_data['practice_office_id'];
    }

    $pmsProviderObj = new pmsProvider();
    $pmsProviderObj->resultAs = 'array';
    $where =array('pmsProvider_clinic_id='=>$clinicId);
    $arg =array('where'=>$where);
    $pmsProvider  =$pmsProviderObj->getAllRecords($arg);
    

    // if(empty($pmsProvider)){
        $fname  =$_POST['fname'];
        $lname  =$_POST['lname'];
        $code = $_POST['code'];
        if($fname && count($fname)>0){
            foreach($fname as $key =>$f){
                if($f!="" && $code[$key]!="" && $lname[$key]!=""){
                    $pmsProviderData =array(
                        "pmsProvider_sikka_id"=>$code[$key],
                        "pmsProvider_lname"=>$lname[$key],
                        "pmsProvider_fname"=>$f,
                        "pmsProvider_type"=>"Dentist",
                        "pmsProvider_status"=>"Active",
                        "pmsProvider_office_id"=>$dummy_offic_id,
                        "pmsProvider_clinic_id"=>$clinicId
                    );
                    $pmsProviderObj->addRecords($pmsProviderData);
                }
            }
        }
    //}


    $pmsAppointmentStatusObj = new pmsAppointmentStatus();
    $pmsAppointmentStatusObj->resultAs = 'array';
    $where =array('pmsAppointmentStatus_clinic_id='=>$clinicId);
    $arg =array('where'=>$where);
    $pmsAppointmentStatus  =$pmsAppointmentStatusObj->getAllRecords($arg);
    if(empty($pmsAppointmentStatus)){
        $statuses =array('PRECON','COMPLETE','LM','BOOKED','CONFIRM','ADVAN','None');
        if($statuses && count($statuses)>0){
            foreach($statuses as $key =>$s){
                $pmsAppointmentStatusData =array(
                    "pmsAppointmentStatus_status"=>$s,
                    "pmsAppointmentStatus_office_id"=>$dummy_offic_id,
                    "pmsAppointmentStatus_clinic_id"=>$clinicId
                );
                $pmsAppointmentStatusObj->addRecords($pmsAppointmentStatusData);
            }
        }
    }
    /*header("Location:".SITE_URL."x-admin/setup_practice.php?id=".$clinicId."&msg=Successfull created demo.");*/
    header('Location:clinic_setting.php?clinic_id='.$clinicId);
    exit;
}


if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getremindertemplate' && isset($_REQUEST['ClinicId']) && $_REQUEST['ClinicId'] != '')
{
    $clinic_id = $_REQUEST['ClinicId'];
    $url = MESSAGE_CENTER_API."notification/getactiveremindernotificationtemplatelist";
        $data = array(
                    "clinicid" => $clinic_id,
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $all_template =  json_decode($result,1);
        //print_r($all_template['data']);exit;

     ?>   
     <option value="0">Select Template</option>
     <?php
    foreach ($all_template['data'] as $key => $templatevalue) 
    { ?>

       <option value="<?php echo $templatevalue['messagecenternotificationtemplate_id'] ?>" ><?php echo $templatevalue['notificationname'] ?></option>
                             
    <?php }
    exit;

}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'chkreminder' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $messagecentermanualtasklogObj = new messagecentermanualtasklog();
    $where = "notificationid = '".$_REQUEST['reminder_template_id']."' and clinicid = '".$_REQUEST['clinic_id']."' and eventdate = '".$_REQUEST['manual_remider_date']."' AND taskname ='reminder' ";
    $orderby = array("id desc");
    $messagecentermanualtaskArg    = array('where' => $where,'orderBy'=> $orderby);
    $messagecentermanualtaskDetails = $messagecentermanualtasklogObj->getAllRecords($messagecentermanualtaskArg);
    
    if(count($messagecentermanualtaskDetails) > 0)
    {
        echo 'already';
    }else{
        echo 'firsttime';
    }
    exit;

}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'clrtable' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $messagecentersingleremindertrackObj = new messagecentersingleremindertrack();
    $messagecentermanualtaskDetails = $messagecentersingleremindertrackObj->truncateRecords();
    
    if($messagecentermanualtaskDetails)
    {
        echo 'success';
    }else{
        echo 'faliure';
    }
    exit;

}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='savemanualreminder' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
        $clinic_id = $_REQUEST['clinic_id'];
        $reminder_template_id = $_REQUEST['reminder_template_id'];
        $manual_remider_date = $_REQUEST['manual_remider_date'];
        
        $url = MESSAGE_CENTER_API."notification/sendmanualremindernotification";
        $data = array(
                    "clinicid" => $clinic_id,
                    "eventdate" =>$manual_remider_date,
                    "notificationtemplateid" => $reminder_template_id,
                    "adminid" => $_SESSION['admin_id'],
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $addreminder =  json_decode($result,1);
        if($addreminder['code'] == '200')
        {
            echo $addreminder['message'];
        }else{
            echo $addreminder['message'];
        }
        
        exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getfollowuptemplate' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $clinic_id = $_REQUEST['clinic_id'];
    $url = MESSAGE_CENTER_API."followup/getfollowuplist";
        $data = array(
                    "clinicid" => $clinic_id,
                    "notificationtemplatetype_id"=>'1',
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $all_template =  json_decode($result,1);
        //print_r($all_template['data']);exit;

     ?>   
     <option value="0">Select Template</option>
     <?php
    foreach ($all_template['data'] as $key => $templatevalue) 
    { ?>

       <option value="<?php echo $templatevalue['messagecenterfollowuptemplate_id'] ?>" ><?php echo $templatevalue['notificationname'] ?></option>
                             
    <?php }
    exit;

}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'chkfollowup' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $messagecentermanualtasklogObj = new messagecentermanualtasklog();
    $where = "notificationid = '".$_REQUEST['followup_template_id']."' and clinicid = '".$_REQUEST['clinic_id']."' and eventdate = '".$_REQUEST['manual_followup_date']."' AND taskname ='followup' ";
    $orderby = array("id desc");
    $messagecentermanualtaskArg    = array('where' => $where,'orderBy'=> $orderby);
    $messagecentermanualtaskDetails = $messagecentermanualtasklogObj->getAllRecords($messagecentermanualtaskArg);
    
    if(count($messagecentermanualtaskDetails) > 0)
    {
        echo 'already';
    }else{
        echo 'firsttime';
    }
    exit;

}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='savemanualfollowup' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
        $clinic_id = $_REQUEST['clinic_id'];
        $followup_template_id = $_REQUEST['followup_template_id'];
        $manual_followup_date = $_REQUEST['manual_followup_date'];
        
        $url = MESSAGE_CENTER_API."followup/sendmanualfollowupreminder";
        $data = array(
                    "clinicid" => $clinic_id,
                    "eventdate" =>$manual_followup_date,
                    "notificationtemplateid" => $followup_template_id,
                    "adminid" => $_SESSION['admin_id'],
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $addfollowup =  json_decode($result,1);
        if($addfollowup['code'] == '200')
        {
            echo $addfollowup['message'];
        }else{
            echo $addfollowup['message'];
        }
        
        exit;
}


if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getrecalltemplate' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $clinic_id = $_REQUEST['clinic_id'];
    $url = MESSAGE_CENTER_API."campaign/getcampaignlistbystatus";
        $data = array(
                    "clinicid" => $clinic_id,
                    "campaigntype" =>'recall',
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $all_template =  json_decode($result,1);
        //print_r($all_template['data']);exit;

     ?>   
     <option value="0">Select Template</option>
     <?php
    foreach ($all_template['data'] as $key => $templatevalue) 
    { ?>

       <option value="<?php echo $templatevalue['messagecentercampaign_id'] ?>" ><?php echo $templatevalue['title'] ?></option>
                             
    <?php }
    exit;

}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'chkrecall' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
    $messagecentermanualtasklogObj = new messagecentermanualtasklog();
    $where = "notificationid = '".$_REQUEST['recall_template_id']."' and clinicid = '".$_REQUEST['clinic_id']."' and eventdate = '".$_REQUEST['manual_recall_date']."' AND taskname ='recall' ";
    $orderby = array("id desc");
    $messagecentermanualtaskArg    = array('where' => $where,'orderBy'=> $orderby);
    $messagecentermanualtaskDetails = $messagecentermanualtasklogObj->getAllRecords($messagecentermanualtaskArg);
    
    if(count($messagecentermanualtaskDetails) > 0)
    {
        echo 'already';
    }else{
        echo 'firsttime';
    }
    exit;

}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='savemanualrecall' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
{
        $clinic_id = $_REQUEST['clinic_id'];
        $recall_template_id = $_REQUEST['recall_template_id'];
        $manual_recall_date = $_REQUEST['manual_recall_date'];
        
        $url = MESSAGE_CENTER_API."campaign/sendmanualrecall";
        $data = array(
                    "clinicid" => $clinic_id,
                    "eventdate" =>$manual_recall_date,
                    "notificationtemplateid" => $recall_template_id,
                    "adminid" => $_SESSION['admin_id'],
                );
        //print_r($data);exit;
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array(
                'Content-Type:application/json',
                'Content-Length: ' . strlen($data_string)
            )
        );

        $result = curl_exec($ch);
        curl_close($ch);
        //print_r($result);exit;
        $addrecall =  json_decode($result,1);
        if($addrecall['code'] == '200')
        {
            echo $addrecall['message'];
        }else{
            echo $addrecall['message'];
        }
        
        exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getallmsgtemplate' && isset($_REQUEST['fclinicId']) && $_REQUEST['fclinicId'] != '')
{
    if($_REQUEST['fclinicId'] != 'master')
    {
        $messagecenteremailtemplateObj = new messagecenteremailtemplate();
        $mtfield = array("messagecenteremailtemplate_id","clinicid","templatename");
        $mtwhere = "clinicid = '".$_REQUEST['fclinicId']."' and isdeleted = '0' ";
        $messagecenteremailtemplateArg    = array('fields'=>$mtfield,'where' => $mtwhere);
        $messagecenteremailtemplateDetails = $messagecenteremailtemplateObj->getAllRecords($messagecenteremailtemplateArg);
        
        ?>
            
        <?php
        foreach ($messagecenteremailtemplateDetails as $mtkey => $messagecenteremailtemplatevalue) 
        { ?>
            <option value="<?php echo $messagecenteremailtemplatevalue->messagecenteremailtemplate_id; ?>" ><?php echo $messagecenteremailtemplatevalue->templatename; ?></option> 
                                 
        <?php }
    }else if($_REQUEST['fclinicId'] == 'master')
    {
        $master_messagecenteremailtemplateObj = new master_messagecenteremailtemplate();
        $masterfield = array("master_messagecenteremailtemplate_id","templatename");
        $masterwhere = "isdeleted = '0' ";
        $mastermessagecenteremailtemplateArg    = array('fields'=>$masterfield,'where' => $masterwhere);
        $mastermessagecenteremailtemplate = $master_messagecenteremailtemplateObj->getAllRecords($mastermessagecenteremailtemplateArg);
        
        ?>
            
        <?php
        foreach ($mastermessagecenteremailtemplate as $mtkey => $mastermessagecenteremailtemplatevalue) 
        { ?>
            <option value="<?php echo $mastermessagecenteremailtemplatevalue->master_messagecenteremailtemplate_id; ?>" ><?php echo $mastermessagecenteremailtemplatevalue->templatename; ?></option> 
                                 
        <?php }
    } 
    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'saveallmsgtemplate')
{   
    if($_REQUEST['fclinic_id'] != 'master' && $_REQUEST['tclinic_id'] != 'master')
    {
        $msgtemplate_id = $_REQUEST['msgtemplate_id'];
        $tclinic_id = $_REQUEST['tclinic_id'];
        
        if(count($msgtemplate_id) > 1)
        {
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            
            $msgtemplate_data .= " messagecenteremailtemplate_id IN (".$msgtemplatearg.")";

        }else{
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            $msgtemplate_data = " messagecenteremailtemplate_id IN (".$msgtemplatearg.") ";
        }
        $messagecenteremailtemplateObj = new messagecenteremailtemplate();
        $where = $msgtemplate_data;
        //echo $where;exit;
        $messagecenteremailtemplateArg    = array('where' => $where);
        $messagecenteremailtemplateDetails = $messagecenteremailtemplateObj->getAllRecords($messagecenteremailtemplateArg);

        if(!empty($messagecenteremailtemplateDetails))
        {
            foreach($messagecenteremailtemplateDetails as $mtkey => $tempvalue)
            {

                $chkfield = array("messagecenteremailtemplate_id","clinicid","templatename","isactive");
                $chkwhere = "clinicid = '".$tclinic_id."' and templatename = '".$tempvalue->templatename."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $messagecenteremailtemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "clinicid"=>$tclinic_id,
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecenteremailtemplateObj->updateRecords($alltemplateData,$chktemplate->messagecenteremailtemplate_id);
                }else{
                    $alltemplateData = array(
                            "clinicid"=>$tclinic_id,
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>'0',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecenteremailtemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fclinic_id'] == 'master' && $_REQUEST['tclinic_id'] != 'master')
    {
        $msgtemplate_id = $_REQUEST['msgtemplate_id'];
        $tclinic_id = $_REQUEST['tclinic_id'];
        
        if(count($msgtemplate_id) > 1)
        {
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            
            $msgtemplate_data .= " master_messagecenteremailtemplate_id IN (".$msgtemplatearg.")";

        }else{
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            $msgtemplate_data = " master_messagecenteremailtemplate_id IN (".$msgtemplatearg.") ";
        }
        $master_messagecenteremailtemplateObj = new master_messagecenteremailtemplate();
        $where = $msgtemplate_data;
        //echo $where;exit;
        $messagecenteremailtemplateArg    = array('where' => $where);
        $messagecenteremailtemplateDetails = $master_messagecenteremailtemplateObj->getAllRecords($messagecenteremailtemplateArg);

        if(!empty($messagecenteremailtemplateDetails))
        {
            foreach($messagecenteremailtemplateDetails as $mtkey => $tempvalue)
            {
                $messagecenteremailtemplateObj = new messagecenteremailtemplate();
                $chkfield = array("messagecenteremailtemplate_id","clinicid","templatename","isactive");
                $chkwhere = "clinicid = '".$tclinic_id."' and templatename = '".$tempvalue->templatename."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $messagecenteremailtemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "clinicid"=>$tclinic_id,
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecenteremailtemplateObj->updateRecords($alltemplateData,$chktemplate->messagecenteremailtemplate_id);
                }else{
                    $alltemplateData = array(
                            "clinicid"=>$tclinic_id,
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>'0',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecenteremailtemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fclinic_id'] == 'master' && $_REQUEST['tclinic_id'] == 'master')
    {
        $msgtemplate_id = $_REQUEST['msgtemplate_id'];
        
        
        if(count($msgtemplate_id) > 1)
        {
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            
            $msgtemplate_data .= " master_messagecenteremailtemplate_id IN (".$msgtemplatearg.")";

        }else{
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            $msgtemplate_data = " master_messagecenteremailtemplate_id IN (".$msgtemplatearg.") ";
        }
        $master_messagecenteremailtemplateObj = new master_messagecenteremailtemplate();
        $where = $msgtemplate_data;
        //echo $where;exit;
        $messagecenteremailtemplateArg    = array('where' => $where);
        $messagecenteremailtemplateDetails = $master_messagecenteremailtemplateObj->getAllRecords($messagecenteremailtemplateArg);
        
        if(!empty($messagecenteremailtemplateDetails))
        {
            foreach($messagecenteremailtemplateDetails as $mtkey => $tempvalue)
            {
                
                $chkfield = array("master_messagecenteremailtemplate_id","templatename","isactive");
                $chkwhere = "templatename = '".$tempvalue->templatename."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $master_messagecenteremailtemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecenteremailtemplateObj->updateRecords($alltemplateData,$chktemplate->master_messagecenteremailtemplate_id);
                }else{
                    $alltemplateData = array(
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>'0',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecenteremailtemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fclinic_id'] != 'master' && $_REQUEST['tclinic_id'] == 'master')
    {
        $msgtemplate_id = $_REQUEST['msgtemplate_id'];
        
        if(count($msgtemplate_id) > 1)
        {
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            
            $msgtemplate_data .= " messagecenteremailtemplate_id IN (".$msgtemplatearg.")";

        }else{
            $msgtemplatearg =  "'" . implode ( "', '", $msgtemplate_id ) . "'";
            $msgtemplate_data = " messagecenteremailtemplate_id IN (".$msgtemplatearg.") ";
        }
        $messagecenteremailtemplateObj = new messagecenteremailtemplate();
        $where = $msgtemplate_data;
        //echo $where;exit;
        $messagecenteremailtemplateArg    = array('where' => $where);
        $messagecenteremailtemplateDetails = $messagecenteremailtemplateObj->getAllRecords($messagecenteremailtemplateArg);

        if(!empty($messagecenteremailtemplateDetails))
        {
            foreach($messagecenteremailtemplateDetails as $mtkey => $tempvalue)
            {
                $master_messagecenteremailtemplateObj = new master_messagecenteremailtemplate();
                $chkfield = array("master_messagecenteremailtemplate_id","templatename","isactive");
                $chkwhere = "templatename = '".$tempvalue->templatename."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $master_messagecenteremailtemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){
                    
                    $alltemplateData = array(
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecenteremailtemplateObj->updateRecords($alltemplateData,$chktemplate->messagecenteremailtemplate_id);
                }else{
                    
                    $alltemplateData = array(
                            "templatename"=>$tempvalue->templatename,
                            "templatehtml"=>$tempvalue->templatehtml,
                            "templatejson"=>$tempvalue->templatejson,
                            "isactive"=>'0',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecenteremailtemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }
    
    exit;
}


if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getallmsgmarketingtemplate' && isset($_REQUEST['fmclinicId']) && $_REQUEST['fmclinicId'] != '')
{
    if($_REQUEST['fmclinicId'] != 'master')
    {
        $messagecentercampaigntemplateObj = new messagecentercampaigntemplate();
        $mktfield = array("messagecentercampaigntemplate_id","clinicid","name");
        $mktwhere = "clinicid = '".$_REQUEST['fmclinicId']."' and isdeleted = '0' ";
        $messagecentercampaigntemplateArg    = array('fields'=>$mktfield,'where' => $mktwhere);
        $messagecentercampaigntemplateDetails = $messagecentercampaigntemplateObj->getAllRecords($messagecentercampaigntemplateArg);
        
        ?>
            
        <?php
        foreach ($messagecentercampaigntemplateDetails as $mktkey => $messagecentercampaigntemplatevalue) 
        { ?>
            <option value="<?php echo $messagecentercampaigntemplatevalue->messagecentercampaigntemplate_id; ?>" ><?php echo $messagecentercampaigntemplatevalue->name; ?></option> 
                                 
        <?php }
    }else if($_REQUEST['fmclinicId'] == 'master')
    {
        $master_messagecentercampaigntemplateObj = new master_messagecentercampaigntemplate();
        $masterfield = array("master_messagecentercampaigntemplate_id","name");
        $masterwhere = "isdeleted = '0' ";
        $mastermessagecentercampaigntemplateArg    = array('fields'=>$masterfield,'where' => $masterwhere);
        $mastermessagecentercampaigntemplate = $master_messagecentercampaigntemplateObj->getAllRecords($mastermessagecentercampaigntemplateArg);
        
        ?>
            
        <?php
        foreach ($mastermessagecentercampaigntemplate as $mtkey => $mastermessagecentercampaigntemplatevalue) 
        { ?>
            <option value="<?php echo $mastermessagecentercampaigntemplatevalue->master_messagecentercampaigntemplate_id; ?>" ><?php echo $mastermessagecentercampaigntemplatevalue->name; ?></option> 
                                 
        <?php }
    } 
    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'saveallmsgmarketingtemplate')
{   
    if($_REQUEST['fmclinic_id'] != 'master' && $_REQUEST['tmclinic_id'] != 'master')
    {
        $msgmarketingtemplate_id = $_REQUEST['msgmarketingtemplate_id'];
        $tmclinic_id = $_REQUEST['tmclinic_id'];
        
        if(count($msgmarketingtemplate_id) > 1)
        {
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            
            $msgmarketingtemplate_data .= " messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.")";

        }else{
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            $msgmarketingtemplate_data = " messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.") ";
        }
        $messagecentercampaigntemplateObj = new messagecentercampaigntemplate();
        $mrkwhere = $msgmarketingtemplate_data;
        //echo $where;exit;
        $messagecentercampaigntemplateArg    = array('where' => $mrkwhere);
        $messagecentercampaigntemplateDetails = $messagecentercampaigntemplateObj->getAllRecords($messagecentercampaigntemplateArg);

        if(!empty($messagecentercampaigntemplateDetails))
        {
            foreach($messagecentercampaigntemplateDetails as $mtkey => $tempvalue)
            {

                $chkfield = array("messagecentercampaigntemplate_id","clinicid","name","isactive");
                $chkwhere = "clinicid = '".$tmclinic_id."' and name = '".$tempvalue->name."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $messagecentercampaigntemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "clinicid"=>$tmclinic_id,
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecentercampaigntemplateObj->updateRecords($alltemplateData,$chktemplate->messagecentercampaigntemplate_id);
                }else{
                    $alltemplateData = array(
                            "clinicid"=>$tmclinic_id,
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>'1',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecentercampaigntemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fmclinic_id'] == 'master' && $_REQUEST['tmclinic_id'] != 'master')
    {
        $msgmarketingtemplate_id = $_REQUEST['msgmarketingtemplate_id'];
        $tmclinic_id = $_REQUEST['tmclinic_id'];
        
        if(count($msgmarketingtemplate_id) > 1)
        {
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            
            $msgmarketingtemplate_data .= " master_messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.")";

        }else{
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            $msgmarketingtemplate_data = " master_messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.") ";
        }
        $master_messagecentercampaigntemplateObj = new master_messagecentercampaigntemplate();
        $marktwhere = $msgmarketingtemplate_data;
        //echo $where;exit;
        $messagecentercampaigntemplateArg    = array('where' => $marktwhere);
        $messagecentercampaigntemplateDetails = $master_messagecentercampaigntemplateObj->getAllRecords($messagecentercampaigntemplateArg);

        if(!empty($messagecentercampaigntemplateDetails))
        {
            foreach($messagecentercampaigntemplateDetails as $mtkey => $tempvalue)
            {
                $messagecentercampaigntemplateObj = new messagecentercampaigntemplate();
                $chkfield = array("messagecentercampaigntemplate_id","clinicid","name","isactive");
                $chkwhere = "clinicid = '".$tclinic_id."' and name = '".$tempvalue->name."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $messagecentercampaigntemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "clinicid"=>$tmclinic_id,
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecentercampaigntemplateObj->updateRecords($alltemplateData,$chktemplate->messagecentercampaigntemplate_id);
                }else{
                    $alltemplateData = array(
                            "clinicid"=>$tmclinic_id,
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>'1',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $messagecentercampaigntemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fmclinic_id'] == 'master' && $_REQUEST['tmclinic_id'] == 'master')
    {
        $msgmarketingtemplate_id = $_REQUEST['msgmarketingtemplate_id'];
        
        
        if(count($msgmarketingtemplate_id) > 1)
        {
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            
            $msgmarketingtemplate_data .= " master_messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.")";

        }else{
            $msgmarketingtemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            $msgmarketingtemplate_data = " master_messagecentercampaigntemplate_id IN (".$msgmarketingtemplatearg.") ";
        }
        $master_messagecentercampaigntemplateObj = new master_messagecentercampaigntemplate();
        $where = $msgmarketingtemplate_data;
        //echo $where;exit;
        $master_messagecentercampaigntemplateArg    = array('where' => $where);
        $master_messagecentercampaigntemplateDetails = $master_messagecentercampaigntemplateObj->getAllRecords($master_messagecentercampaigntemplateArg);
        
        if(!empty($master_messagecentercampaigntemplateDetails))
        {
            foreach($master_messagecentercampaigntemplateDetails as $mstkey => $tempvalue)
            {
                
                $chkfield = array("master_messagecentercampaigntemplate_id","name","isactive");
                $chkwhere = "name = '".$tempvalue->name."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $master_messagecentercampaigntemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){

                    $alltemplateData = array(
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecentercampaigntemplateObj->updateRecords($alltemplateData,$chktemplate->master_messagecentercampaigntemplate_id);
                }else{
                    $alltemplateData = array(
                            
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>'1',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecentercampaigntemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }else if($_REQUEST['fmclinic_id'] != 'master' && $_REQUEST['tmclinic_id'] == 'master')
    {
        $msgmarketingtemplate_id = $_REQUEST['msgmarketingtemplate_id'];
        
        if(count($msgmarketingtemplate_id) > 1)
        {
            $msgmastertemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            
            $msgmastertemplate_data .= " messagecentercampaigntemplate_id  IN (".$msgmastertemplatearg.")";

        }else{
            $msgmastertemplatearg =  "'" . implode ( "', '", $msgmarketingtemplate_id ) . "'";
            $msgmastertemplate_data = " messagecentercampaigntemplate_id  IN (".$msgmastertemplatearg.") ";
        }
        $messagecentercampaigntemplateObj = new messagecentercampaigntemplate();
        $where = $msgmastertemplate_data;
        //echo $where;exit;
        $messagecentercampaigntemplateArg    = array('where' => $where);
        $messagecentercampaigntemplateDetails = $messagecentercampaigntemplateObj->getAllRecords($messagecentercampaigntemplateArg);

        if(!empty($messagecentercampaigntemplateDetails))
        {
            foreach($messagecentercampaigntemplateDetails as $mtkey => $tempvalue)
            {
                $master_messagecentercampaigntemplateObj = new master_messagecentercampaigntemplate();
                $chkfield = array("master_messagecentercampaigntemplate_id ","name","isactive");
                $chkwhere = "name = '".$tempvalue->name."' ";

                $chktemplateArg    = array('fields'=>$chkfield,'where' => $chkwhere);
                $chktemplate = $master_messagecentercampaigntemplateObj->fromFields($chktemplateArg);
                
                if($chktemplate){
                    
                    $alltemplateData = array(
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>$chktemplate->isactive,
                            "updated_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecentercampaigntemplateObj->updateRecords($alltemplateData,$chktemplate->master_messagecentercampaigntemplate_id);
                }else{
                    
                    $alltemplateData = array(
                            
                            "name"=>$tempvalue->name,
                            "category"=>$tempvalue->category,
                            "logourl"=>$tempvalue->logourl,
                            "bannerurl"=>$tempvalue->bannerurl,
                            "subject"=>$tempvalue->subject,
                            "body"=>$tempvalue->body,
                            "issocialmedialink"=>$tempvalue->issocialmedialink,
                            "socialmedialink"=>$tempvalue->socialmedialink,
                            "smstext"=>$tempvalue->smstext,
                            "appnotificationtext"=>$tempvalue->appnotificationtext,
                            "isactive"=>'1',
                            "created_at"=>date("Y-m-d H:i:s"),
                          );
                          
                    $templateadd= $master_messagecentercampaigntemplateObj->addRecords($alltemplateData);    
                }
            }
            echo 'Successfully copy template';
        }else{
            echo 'Somthing went wrong';
        }
    }
    
    exit;
}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='cnfrwitebackstatus' && $_REQUEST['clinicId'] != ''){
        
    $cliniId = $_POST['clinicId'];
    $cnfrwitebackstatus = $_POST['clinic_cnfrwitebackstatus'];
    
    $data=array(
            'clinic_cnf_writebackStatus'=>($cnfrwitebackstatus),
        );
    if (isset($cliniId)){    
        $id=$cliniId;
        //print_r($data);exit;
        $rs=$clinicObj->updateRecords($data,$id);
        if ($rs){

            header('Location:clinic_setting.php?clinic_id='.$id);
            exit;
        }
    }
}

if (isset($_REQUEST['act']) && $_REQUEST['act']=='downloadpatient' && $_REQUEST['clinic_id'] != ''){
  
  if(isset($_REQUEST['patient_contact_start_date']) && $_REQUEST['patient_contact_start_date'] != ''){

    /*$clinic_patientObj =  new  clinic_patient();
    $fields = array('dependant_id','dependant_fname','dependant_lname','dependant_email_address','dependant_phone','clinic_patient_cid','clinic_patient_depid','dependant_created_at','guarantor_id','dependant_guarantor_id','guarantor_cell');
    $where = "c.clinic_patient_cid  = '".$_REQUEST['clinic_id']."' ";

    $where .= " AND (date(dependant_created_at) >= '".$_REQUEST['patient_contact_start_date']."' AND date(dependant_created_at) <= '".$_REQUEST['patient_contact_end_date']."')";
    

    $tables = array('tbl_dependant d','tbl_guarantor g');
    $jfields = array('d.dependant_id = c.clinic_patient_depid','g.guarantor_id = d.dependant_guarantor_id');
    $jtype   = array("INNER","INNER");
    $data   = array('fields'=>$fields,'where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype);

    $clinicpatientDetails = $clinic_patientObj->getAllRecords($data);
    $recordsTotal   =   $clinic_patientObj->getAllCount($data);*/

    $data['clinicid']  = $_REQUEST['clinic_id'];
    $data['startdate'] = $_REQUEST['patient_contact_start_date'];
    $data['enddate']   = $_REQUEST['patient_contact_end_date'];
    $passdata          = json_encode($data);

      $curl = curl_init();

      curl_setopt_array($curl, array(
        CURLOPT_URL => MESSAGE_CENTER_API.'analytics/activeuserdatalist',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>$passdata,
        CURLOPT_HTTPHEADER => array(
          'Content-Type: application/json'
        ),
      ));

      $response = curl_exec($curl);
      $clinicpatientDetails = json_decode($response,1);
      curl_close($curl);
      /*echo "<pre>";print_r($clinicpatientDetails);echo "</pre>";
      exit;*/
    if ($clinicpatientDetails['data'] && count($clinicpatientDetails['data'])>0){
      foreach($clinicpatientDetails['data'] as $key => $value){
        if($value['dependantphone'] != '')
          $phone = '1'.$value['dependantphone'];
        elseif($value['dependantphone'] == '' && $value['guarantor_phone'] != '')
          $phone = '1'.$value['guarantor_phone'];
        else
          $phone = '';

        if($value['dependantemailaddress'] != '')
          $email = $value['dependantemailaddress'];
        elseif($value['dependantemailaddress'] == '' && $value['guarantor_email'] != '')
          $email = $value['guarantor_email'];
        else
          $email = '';

        /*if($phone == '' && $email = ''){
            continue;
        }*/
        if($phone == ''){
            continue;
        }
        /*if($email == ''){
            continue;
        }*/
        $patientdetails[$key]['firstname']    = $value['patientfname'];
        $patientdetails[$key]['lastname']     = $value['patientlname'];
        $patientdetails[$key]['companyname']  = "";
        $patientdetails[$key]['phonenumber']  = $phone;
        $patientdetails[$key]['emailaddress'] = $email;
      }
      $patientdetails = array_values($patientdetails);
      $result=array('patients'=>$patientdetails);
      echo json_encode($patientdetails);
    }
  }
  return true;    
}

$procedure_codeObj = new procedure_code();
$where = "procedure_code_clinic_id = '".$_REQUEST['clinic_id']."' and procedure_code_category != ''";
$groupBy = array("procedure_code_category");
$procedurecodeArg    = array('where' => $where,'groupBy'=>$groupBy);
$categoryDetails = $procedure_codeObj->getAllRecords($procedurecodeArg);




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