<?php
if (!isset($_SESSION)) {
    session_start();
}

require_once("Connections/constants.php");
include("function/function.php");
$apikey = $_SESSION['apikey'];
$username = $_SESSION['facility_name'];
$password = $_SESSION['password'];
$providerId = $_SESSION['provider_id'];
$edit_id = $_POST['id'];

$GET_VISIT_HISTORY_LOCAL_SINGLE = array(
    'METHOD' => urlencode('GET_VISIT_HISTORY_DRUGS_LOCAL_SINGLE'),
    'APIKEY' => $apikey,
    'USERNAME' => $username,
    'PASSWORD' => $password,
    'PROVIDERID' => $providerId,
    'ITEM_ID' => $edit_id,

);
$get_saved_record_local = APICall($GET_VISIT_HISTORY_LOCAL_SINGLE);
$get_saved_record_json_local = json_decode($get_saved_record_local,"true");
$savedRecord_local = $get_saved_record_json_local['RESULT'];

if ($get_saved_record_json_local['STATCODE'] == "200") {
    foreach ($savedRecord_local as $savedRecords_local) {
        $medication_id = $savedRecords_local['id'];
        $date_of_consultation_local = $savedRecords_local['date_time'];
        $item_name = $savedRecords_local['item'];
        $description = $savedRecords_local['description'];
        $facility_image1 = $savedRecords_local['image'];
        $facility_name1 = $savedRecords_local['pharmacy'];
        $facility_image = "assets/images/pharmacy/".$facility_image1;
    }
}

//var_dump($get_saved_record_local);
?>

<form name="" id="update_medication" method="post">
    <div class="row">
        <div class="col-4">
            <div class="kt-avatar kt-avatar--outline kt-avatar--circle" id="kt_apps_user_add_avatar">
                <div class="kt-avatar__holder" style="background-image: url()">
                    <?php
                    if(empty($facility_image1)){?>
                        <img alt='no_photo' width='110' height='40' src='<?php echo BASE_URL ?>assets/images/avatar-placeholder.png' style='text-align:center; border-radius: 80px; height:115px; object-fit: cover;' id='display1' />
                    <?php }else{?>
                        <img alt='no_photo' width='110' height='40' src='<?php echo $facility_image ?>' style='text-align:center; border-radius: 80px; height:115px; object-fit: cover;' id='display1'>
                    <?php }
                    ?>
                </div>
                <label class="kt-avatar__upload" data-toggle="kt-tooltip" title="" data-original-title="Change avatar">
                    <i class="fa fa-pen"></i>
                    <input type="file" name="imageUpload_update" id="imageUpload" aria-invalid="false" multiple accept=".jpg, .png, .gif, .jpeg" onchange="readURL1(this);">
                </label>
                <span class="kt-avatar__cancel" data-toggle="kt-tooltip" title="" data-original-title="Cancel avatar">
					<i class="fa fa-times"></i>
					</span>
            </div>
        </div>

        <input type="hidden" name="member_no" id="member_no" value="<?php echo $member_no ?>">

        <div class="col-7">
            <h3 class="kt-portlet__head-title" id="adding_user">
                <input type="text" name="drugname_update" class="form-control" style="width: 100%" placeholder="Enter drug name" id="drugname_update" value="<?php echo $item_name ?>"/>
            </h3>
        </div>
    </div>

    <div class="row">
        <div class="col-4">

        </div>

        <div class="col-7">
            <h3 class="kt-portlet__head-title" id="adding_user">
                <input type="text" name="pharmacy_name_update" class="form-control" style="width: 100%" placeholder="Enter Pharmacy"  id="pharmacy_name_update" value="<?php echo $facility_name1  ?>"/>
            </h3>
        </div>
    </div>

    <div class="row">
        <div class="col-4">

        </div>

        <div class="col-7">
            <h3 class="kt-portlet__head-title" id="adding_user">
                <textarea class="form-control" cols="20" rows="5" name="medication_desceription_update">
                    <?php echo $description ?>
                </textarea>
            </h3>
        </div>
    </div>

    <div class="row">
        <div class="col-4">

        </div>

        <div class="col-7">
            <div class="kt-portlet__foot">
                <div class="row">
                    <div class="col kt-align-right">
                        <button id="save_principal_member_btn" onclick="getstepInsert('update_medication', '<?php echo $edit_id ?>');return false;" type="submit"
                                class="btn btn-success">Save</button>

                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<script>
    function readURL1(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#display1')
                    .attr('src', e.target.result)
                    .width(110)
                    .height(115);

            };

            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
