<?php
	$break = explode('/', $_SERVER["SCRIPT_NAME"]);
	if($break[count($break) - 1] != "index.php") { header("Location: ../index.php"); exit(); } 
?>
			<div class="componentheading">Buddy List</div>
<?php
	if(isset($_SESSION['errormsg']))
	{
?>
			<div class="module_menu">
				<div>
					<div>
						<div>
							<h3>Notification</h3>
								<b><?php echo $_SESSION['errormsg']; ?></b>
						</div>
					</div>
				</div>
			</div>
<?php
		unset($_SESSION['errormsg']);
	}
	// check for new buddy requests
	if($session->userHasBuddyNotification)
	{
?>
			<div class="module_menu">
				<div>
					<div>
						<div>
							<h3>New Buddy Request(s)</h3>
							<form action="process.php" method="POST" id="buddyacceptdenyform">
								<select name="buddyacceptdenylist" id="buddyacceptdenylist" size="5" STYLE="width: 100%; overflow: scroll">
								<?php $database->printCurrentBuddyNotifications($session->userDBid); ?>
								</select>
								<br>
								<input type="button" value="Accept Request" onclick="document.getElementById('buddyacceptdenyoperation').value='accept'; document.getElementById('buddyacceptdenyform').submit();">&nbsp;&nbsp;<input type="button" value="Deny Request" onclick="document.getElementById('buddyacceptdenyoperation').value='deny'; document.getElementById('buddyacceptdenyform').submit();">
								<input type="hidden" name="buddyacceptdeny" value="1">
								<input type="hidden" name="buddyacceptdenyoperation" id="buddyacceptdenyoperation" value="">
							</form>
						</div>
					</div>
				</div>
			</div>
<?php
	}
?>
			<div class="module_menu">
				<div>
					<div>
						<div>
							<h3>Add A New Buddy</h3>
							<form method="POST">
								Search For: &nbsp;<input type="text" name="buddysearchname" size="18" value="<?php if(isset($_POST['buddysearchname'])) echo stripslashes($_POST['buddysearchname']); ?>"> <input type="submit" value="Search">
							</form>
							<br><br>
							<form action="process.php" method="POST">
							Search Results:<br>
								<select name="buddysearchresults" size="10" STYLE="width: 100%; overflow: scroll">
								<?php $database->printBuddySearchResults(); ?>
								</select>
								<br>
								<input type="hidden" name="addbuddy" value="1">
								<input type="submit" value="Send Buddy Request to Selected User">
							</form>
						</div>
					</div>
				</div>
			</div>
			
			<div class="module_menu">
				<div>
					<div>
						<div>
							<h3><?php if(substr(strtoupper($session->username),-1) == "S") $postFix = "'"; else $postFix = "'s"; echo $session->username . $postFix; ?> Current Buddy List&nbsp;&nbsp;(<?php $database->printBuddyListCount($session->userDBid); ?> Buddies)</h3>
							<form action="process.php" method="POST">
								<select name="buddyid" size="10" STYLE="width: 100%; overflow: scroll">
								<?php $database->printBuddyListOptions($session->userDBid); ?>
								</select>
								<br>
								<input type="hidden" name="removebuddy" value="1">
								<input type="submit" value="Remove Selected Buddy">
							</form>
						</div>
					</div>
				</div>
			</div>
			
			<div class="module_menu">
				<div>
					<div>
						<div>
							<h3>Buddies Invited That Have Not Responded</h3>
							<form action="process.php" method="POST">
								<select name="buddyid" size="10" STYLE="width: 100%; overflow: scroll">
								<?php $database->printBuddyListNotResponded($session->userDBid); ?>
								</select>
								<br>
								<input type="hidden" name="cancelbuddyrequest" value="1">
								<input type="submit" value="Cancel Buddy Request">
							</form>
						</div>
					</div>
				</div>
			</div>