<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page

$manualentry_appoinmentObj = new manual_entry_appoinment_sr();
$clinicObj = new clinic();


if (isset($_REQUEST['act']) && $_REQUEST['act']=='load' && 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,
                );
        //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'] == '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="">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;

}

$fields = array('clinic_name','clinic_id');
$clinicArg    = array('fields'=>$fields);
$allClinic = $clinicObj->getAllRecords($clinicArg);


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