<?php
$date=date("F j, Y - g:i A");
if (getCharacterGM($users['id']) >= 3){
	if(!isset($_GET['id'])){
		$exception=allException();
		if($exception=='error' || $exception=='empty'){
		}
		else{
			$count=countExceptions();
			echo ''.$count[0].' Exceptions waiting approval<br><table class="table table-hover">';
			foreach($exception as $exc) {
				if($exc['exception']=='0000-00-00 00:00:00'){
					echo '<tr><td><a href=?p=gm&tool=exception&id='.$exc['accid'].'>'.$exc['accid'].'</a></td><td><b><font color=red>'.$exc['exception'].'</font></b></td><td>'.$exc['comment'].'</td></tr>';
				}
				else{
					echo '<tr><td><a href=?p=gm&tool=exception&id='.$exc['accid'].'>'.$exc['accid'].'</a></td><td>'.$exc['exception'].'</td><td>'.$exc['comment'].'</td></tr>';
				}
			}
			echo '</table>';
		}
	}
	else{
		if (!isset($_POST['exception'])) {
		}
		elseif(empty($_POST['exception'])) {
			echo getPanel("danger","Failed","Please enter a time period.");
		}
		elseif(empty($_POST['comment'])) {
			echo getPanel("danger","Failed","Please enter a reason.");
		}
		else{
			$_POST['comment']=str_replace(' ','_',$_POST['comment']);
			changeException($_POST['id'],$_POST['exception'],$_POST['comment']);
			echo getPanel("success","Success","The exception has been updated.");
		}
		if (!isset($_POST['delete'])) {
		}
			elseif(empty($_POST['delete'])) {
			echo getPanel("danger","Failed","Delete is wrong.");
		}
		else{
			deleteException($_POST['delete']);
			echo getPanel("success","Success","The exception has been deleted.");
		}
		$id=$_GET['id'];
		echo '<table class="table table-hover">';
		$acc=hasException($id);
		foreach($acc as $exc) {
			if($exc!='empty'){
				echo '<tr><td>Account ID</td><td>'.$exc['accid'].'</td></tr>
				<tr><td>Date<br>Reason</td><td><form action="" method="post"><input type=hidden name="id" value="'.$id.'">
				<input type="text" name="exception" value='.$exc['exception'].'></input>';
				if($exc['exception']=='0000-00-00 00:00:00'){
					echo '<b><font color=red>This needs to be set</font></b> ';
				}
				else{
				}
				echo '(year-month-day)
				<br>
				<input type="text" name="comment" value='.$exc['comment'].'></input> (1 is one week, 2 is two weeks, 3 is perm request.)<br>';
				if($exc['exception']=='0000-00-00 00:00:00'){
					echo '<input type="submit" value="Approve Exception"></input></form></td></tr>';
				}
				else{
					echo '<input type="submit" value="Edit IP Exception"></input></form></td></tr>';
				}
				echo '<tr><td>Delete</td><td><form action="" method="post"><input type=hidden name="delete" value="'.$id.'"><input type="submit" value="Delete IP Exception"></input></form></td></tr>';
			}
		}
		echo '</table><a href=?p=gm&tool=exception>Back</a>';
	}
}
?>
