<?php
if(!isset($System)){
	exit("No direct script access allowed!");
}

if(isset($_GET['id']) && ($id = trim($_GET['id'])) && strlen($id) > 0){
	if($System->loadClass("%CLASS_NAME%")){
		if((!$data = $%CLASS_NAME%->info($id)) || !is_array($data) || count($data) <= 0){ // info function can take a username or an account ID
			$System->redirect("./?" . strtolower(FEATURE) . "=view-all"); // feature not found
		} // use $data array for info about user on this page
		if(!$System->hasDeletePermission(FEATURE, $id)){
			exit($System->error);
		}
	} else {
		die($System->error);
	}
} else {
	$System->redirect("./?" . strtolower(FEATURE) . "=view-all"); // username not set in URL
}
?>

<div class="row">
	<div class="col-md-12">
		<div class="db-add-list-wrap">
				<div class="act-title">
						<h5><i class="fa fa-%FA_ICON%"></i>Delete %LANG_SINGULAR%</h5>
				</div>
				<div class="db-add-listing">
						Are you sure you wish to delete this %LANG_SINGULAR%?
						<hr>
						<strong>ID</strong>: <?php echo $data[0]['id'] ?> <br />
%INFORMATION_VIEW_DETAILS%
						<hr>

						<a href="#" class="btn btn-md btn-danger" id="confirm_delete">
							Delete
						</a>

						<?php if($System->hasFeaturePermission(FEATURE, "VIEW-ALL")){ ?>
							<a href="./?<?php echo FEATURE ?>=view-all" class="btn btn-md btn-default">Cancel</a>
						<?php } ?>


						<br/>
						<div class="messagebox">
								<div id="alert-message"></div>
						</div>
				</div>

		</div>
	</div>
</div>



<script>
    $(document).ready(function () {
        $("#confirm_delete").on("click", function (e) {
						e.preventDefault();
            $.ajax({
                type: "POST",
                url: "controllers/<?php echo FEATURE ?>/<?php echo PERMISSION ?>.php",
                data: {
									id: <?php echo $_GET['id'] ?>
								},
                success: function (msg) {
                    if(msg.trim() == 'success'){
											window.location.href = './?<?php echo FEATURE ?>=view-all';
										} else {
											$('.messagebox').hide();
											$('#alert-message').html(msg);
											$('.messagebox').slideDown('slow');
										}
                }
            });
            return false;
        });
    });
</script>