<?php

if (!isset($_SESSION)) {
	session_start();
}

if(!empty($_POST["id"])){
	require_once('../Connections/courier.php'); 
	require_once("../Connections/constants.php");
	include("../function/function.php");
	$action = $_POST['act'];
	$typeofdrug = $_POST['typeofdrug'];
	$apikey = $_SESSION['apikey'];
	$username = $_SESSION['facility_name'];
	$password = $_SESSION['password'];
	$providerId = $_SESSION['provider_id'];
	$member_plan = $_SESSION['member_plan']; 

	$num_rows = array(
		'METHOD' => urlencode('NUM_ROWS_ITEM'),
		'APIKEY' => $apikey,
		'USERNAME' => $username,
		'PASSWORD' => $password,
		'PROVIDERID' => $providerId,
		'POSTID' => $_POST["id"],
		'MEMBER_PLAN' => $member_plan,
		'TYPEOFDRUG' => $typeofdrug,


	);
	$get_saved_record = APICall($num_rows);
	$get_saved_record_json = json_decode($get_saved_record,"true");
	$savedRecord = $get_saved_record_json['RESULT'];
	foreach ($savedRecord as $savedRecords) {
		$totalRowCount = $savedRecords['num_rows']; 
	}
	//echo $totalRowCount; 
   //print_r(json_encode($get_saved_record));

	$showLimit = 10;
	 ////////////// Get number of rows ///////////////
	$GETNEXTRECORD = array(
		'METHOD' => urlencode('NEXTRECORDITEM'),
		'APIKEY' => $apikey,
		'USERNAME' => $username,
		'PASSWORD' => $password,
		'PROVIDERID' => $providerId,
		'POSTID' => $_POST["id"],
		'SHOWLIMIT' => $showLimit,
		'MEMBER_PLAN' => $member_plan,
		'TYPEOFDRUG' => $typeofdrug,

	);
	$get_saved_next_record = APICall($GETNEXTRECORD);
	$get_saved_record_next_json = json_decode($get_saved_next_record,"true");
	$savedRecord_next = $get_saved_record_next_json['RESULT'];

	//print_r(json_encode($get_saved_record_next_json));

	if($get_saved_record_next_json['STATCODE'] !='200'){
		echo '<div class="alert alert-solid-danger alert-bold" role="alert">
    <div class="alert-text">No Record Found</div>
  </div>';
	}else{
		foreach ($savedRecord_next as $savedRecord_drugs){
			$itemName = $savedRecord_drugs['item'];
			$recordIdSub = $savedRecord_drugs['id'];
			$drug_class = $savedRecord_drugs['drug_class'];
			?>
			<span class="postList_item_<?php echo $recordIdSub ?>">

				<table cellspacing="2" width="92%" style="line-height: 3; font-weight: 400;"> 
					<tr>
						<td><?php echo $itemName; ?></td>
						<td style="text-align: right;"><?php echo ($drug_class == '' || is_null($drug_class)) ? '-' : $drug_class ?></td>
					</tr>
				</table>
			</span>
			<?php 
		}
		?>
		<?php if($totalRowCount > $showLimit){ ?>
			<div class="show_more_sub" id="show_more_sub<?php echo $recordIdSub ?>">
				<span id="<?php echo $recordIdSub.'@@'.$typeofdrug.'@@'.$member_plan; ?>" class="show_more_more" title="Load more Drugs" style="color: #5578eb; cursor: pointer;">Show more</span>

			</div>
			<?php
		}
	}
}
?>
