<?php
include_once 'includes/processes.php';
$Process = new Login_Process;
$pageLink = basename($_SERVER['REQUEST_URI']);
$Process->check_status($pageLink);
$requisitionData = $Process->getRequestInfo($_GET['rid']);
?>
	<div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 class="modal-title"><i class="fa fa-eye"></i> Requisition Items #<?php echo $_GET['rid']; ?></h3>
    </div>
	  <form action="requisition.php" method="post">
	  <input type="hidden" id="request_id" name="request_id" value="<?php echo $_GET['rid']; ?>" />
		<div class="modal-body">
			<div class="row">	
				<div class="col-sm-12">
					<?php $Process->getRequestItemList($_GET['rid']) ?>
				</div> <!-- /.col -->
				<?php if($requisitionData->request_status=="Completed"): ?>	
				<hr />
					<div class="col-lgm-6 col-sm-12">
						<h3>Request Details</h3>
						<table class="table table-striped table-bordered table-hover" border="1">
							<tbody>
								<tr>
									<td>Requested by</td>
									<td>
										<?php 
											$empData = $Process->getEmployeeInfo($requisitionData->requested_by); 
											echo $empData->firstname . " " . $empData->lastname;
										?>
									</td>
								</tr>
								<tr>
									<td>Date Requested</td>
									<td>
										<?php 
											echo date("D, d M Y : h:ia", $requisitionData->date_requested);
										?>
									</td>
								</tr>
								<tr>
									<td>Accepted by</td>
									<td>
										<?php 
											$empData = $Process->getEmployeeInfo($requisitionData->accepted_by); 
											echo $empData->firstname . " " . $empData->lastname;
										?>
									</td>
								</tr>
								<tr>
									<td>Date Requested</td>
									<td>
										<?php 
											echo date("D, d M Y : h:ia", $requisitionData->date_accepted);
										?>
									</td>
								</tr>
								<tr>
									<td>Completed by</td>
									<td>
										<?php 
											$empData = $Process->getEmployeeInfo($requisitionData->completed_by); 
											echo $empData->firstname . " " . $empData->lastname;
										?>
									</td>
								</tr>
								<tr>
									<td>Date Completed</td>
									<td>
										<?php 
											echo date("D, d M Y : h:ia", $requisitionData->dated_completed);
										?>
									</td>
								</tr>
								<tr>
									<td>Acknowledged by</td>
									<td>
										<?php 
											$empData = $Process->getEmployeeInfo($requisitionData->acknowledged_by); 
											echo $empData->firstname . " " . $empData->lastname;
										?>
									</td>
								</tr>
								<tr>
									<td>Date Acknowledged</td>
									<td>
										<?php 
											echo date("D, d M Y : h:ia", $requisitionData->date_acknowledged);
										?>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				<?php  endif; ?>
				<?php if(in_array("request_admin",$_SESSION['privileges'])): ?>
				<?php if($requisitionData->request_status!="Completed"): ?>	
					<div class="col-sm-6">
						<div class="form-group col-sm-12">
							<label for="status">Request Status</label>
							<select name="status" class="form-control select2-input" data-required="true">
							<option value="">Please Select</option>
							<option value="Pending" <?php if($requisitionData->request_status=="Pending") { echo "selected"; } ?>>Pending</option>
							<option value="Processing" <?php if($requisitionData->request_status=="Processing") { echo "selected"; } ?>>Processing</option>
							<option value="Completed" <?php if($requisitionData->request_status=="Completed") { echo "selected"; } ?>>Completed</option>
							</select>
						</div>
					</div>
					<?php endif; ?>
				<?php if($requisitionData->request_status=="Processing"): ?>										
					<div class="col-sm-12">
						<div class="form-group col-sm-12">
							<label for="item_remark">Additional Comments</label>
							<textarea name="item_comment" class="form-control"></textarea>
						</div>				
					</div>
				<?php endif; ?>
				<?php endif; ?>
				<br />
				<br />
				<div class="col-lg-12 col-sm-12">
					<h3>Request Details</h3>
					<table class="table table-striped table-bordered table-hover" border="1">
						<tbody>
							<tr>
								<td>Requested by</td>
								<td>
									<?php 
										$empData = $Process->getEmployeeInfo($requisitionData->requested_by); 
										echo $empData->firstname . " " . $empData->lastname;
									?>
								</td>
							</tr>
							<tr>
								<td>Date Requested</td>
								<td>
									<?php 
										echo date("D, d M Y : h:ia", $requisitionData->date_requested);
									?>
								</td>
							</tr>
						</tbody>
					</table>
			</div>			
			</div>			
		</div>
		<div class="modal-footer">
			<?php if(in_array("request_admin",$_SESSION['privileges'])): ?>	
				<button type="submit" class="btn btn-xs btn-success pull-left" name="update_request"><i class="fa fa-update"></i> Update request</button>
			<?php endif; ?>
			<button type="button" class="btn btn-xs btn-danger" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
		</div>
	  </form>