<!-- NOTAMS Header -->
<div class="content-header">
    <div class="header-section">
        <h1><i class="gi gi-envelope"></i> <Strong>Friend Requests</Strong><br><small>Membership Department | <?php echo SITE_NAME?> &copy; <?php echo date("Y");?></small></h1>
    </div>
</div>
<!-- END NOTAMS Header -->


<div class="row">
	<div class="col-md-12">
		<?php
			$friendrequests = ICSFriends::getAllRequests(Auth::$userinfo->pilotid);
			$allreq = ICSFriends::getAll(Auth::$userinfo->pilotid);
			if($friendrequests) {
				echo "<div class='alert alert-warning'>You have a few pending requests!</div>";
				/*return;*/
		?>
	<div class="block">
			<div class="block-title">
				<h3><strong>Pending Requests</strong></h3>
			</div>
			
				<?php 
			if($friendrequests) {
	foreach ($friendrequests as $request) {
		$friend_data = PilotData::getPilotData($request->friend_id);
		?>
		<div class="alert alert-success alert-alt">
		<div class="alert alert-alt">
				<small><?php echo date("d/m/y", strtotime($request->date)); ?></small><br>
				<i class="fa fa-plus fa-fw"></i> <a href="<?php echo SITE_URL; ?>/index.php/profile/view/<?php echo $request->friend_id; ?>"><strong><?php echo $friend_data->firstname; ?> <?php echo $friend_data->lastname; ?></strong></a> would like to become friends!<br>				<form class="form form-horizontal" action="<?php echo SITE_URL; ?>/index.php/Friends/AcceptRequest" method="post">
					<div class="form-action form-group">
							<input type="hidden" name="friendid" value="<?php echo $request->friend_id; ?>" />
							<input type="hidden" name="id" value="<?php echo $request->id; ?>" />
							<input type="hidden" name="selfid" value="<?php echo $request->self_id; ?>" />
							<button type="submit" class="btn btn-sm btn-default btn-alt btn-success" name="action" value="accept" ><i class="fa fa-check"></i> Accept</button>
							<button type="submit" class="btn btn-sm btn-default btn-alt btn-danger" name="action" value="reject" ><i class="fa fa-times"></i> Reject</button>
                	</div>
				</form>
			</div>
		</div>
		<?php 
	}
			}
?>
			
			
		</div>
				<?php
			} 
		else if(!$friendrequests) {
	}
?>
		
		<div class="block">
			<div class="block-title">
				<h3>Previous Requests</h3>
			</div>
			<?php 
			if($allreq) {
				foreach ($allreq as $alq) {
					$friend_data = PilotData::getPilotData($alq->friend_id);
					if($alq->req_status == 1) {
						$all_status = 'Accepted';
					} else if($alq->req_status == 2) {
						$all_status = 'Rejected';
					}
				?>
					<div class="alert alert-alt">
						<small><?php echo date("d/m/y", strtotime($alq->date)); ?></small><br>
							<i class="fa fa-plus fa-fw"></i>
								You <?php echo $all_status; ?> <a href="<?php echo SITE_URL; ?>/index.php/profile/view/<?php echo $alq->friend_id; ?>">
								<strong><?php echo $friend_data->firstname; ?> <?php echo $friend_data->lastname; ?></strong></a>'s friend request!<br>
					</div>
				<?php 
					}
				}
			?>
		</div>
	</div>
</div>
