<?php
include_once("../public/config.php");

$do = $_GET['do'];
$Programsettingdata = R::getRow('select * from programsettings where programsettingsid = 1');
$smarty->assign('daysremaining', -1);
if(empty($do) || $do =="show"){
    $smarty->display("header.html");
    $smarty->display("patientPlace/show.html");
    $smarty->display("footer.html");
}else if($do == "getPlaceForERP"){
    $clientid = $_POST['clientid'];
    $obygyPatientId = R::getCell("select obygyPatientId from client where clientid = $clientid");
    $allDataObygyArray = array();
    if ($Programsettingdata['obygyFolder'] != "" && $obygyPatientId > 0) {
        try{
        $bill_pay = array();
        $bill_pay['patient_id'] = $obygyPatientId;
        array_push($allDataObygyArray, $bill_pay);

        $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $Programsettingdata['obygyFolder'] . '/core/controllers/operationreport.php?ac=getPlaceForERP';
        $post = [
            'patient_id'=>$obygyPatientId,
            'curlpost'=>1,
        ];
        $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
            $response = curl_exec($ch);
            $data = json_decode($response);
            curl_close($ch);
            echo $data->place;
        }catch(Exception $e){
            echo -1;
        }
    }
}