<?php 

// displays the table numbering buttons
function table_nav($total_pages = 1, $sort = '', $order = 'desc') {
	?>
	<p>Goto Page </p>
	<div class="btn-group btn-block">

			<?php 
			for ($i=1; $i <= $total_pages; $i++) { 
			 ?>
		<a href="?page=<?php echo $i; ?>&s=<?php echo $sort; ?>&o=<?php echo $order; ?>" class="btn btn-primary <?php echo (($_GET['page'] == $i) or (!isset($_GET['page']) && $i == 1)) ? 'active' : ''; ?>"><?php echo $i; ?></a>
		<?php } ?>
	</div>
	<?php
}

function sort_link($text, $page = 1, $sort = '', $order = 'desc') {
	?>
	<a href="?s=<?php echo $sort; ?>&page=<?php echo $page; ?>&o=<?php echo $order; ?>"><?php echo $text; ?></a>
	<?php
}

function order_key($page = 1, $sort = '', $order='') {
	?>
	<div class="btn-group btn-block">
		<a href="?o=asc&page=<?php echo $page; ?>&s=<?php echo $sort; ?>" class="btn btn-primary <?php echo ($order == 'asc') ? 'active' : ''; ?>" title="Ascending Order"><em class="fas fa-angle-up"></em></a>
		<a href="?o=desc&page=<?php echo $page; ?>&s=<?php echo $sort; ?>" class="btn btn-primary <?php echo ($order == 'desc') ? 'active' : ''; ?>" title="Descending Order"><em class="fas fa-angle-down"></em></a>
	</div>
	<?php
}

function action($args, $access, $actions) {
	global $post_meta;
	add_page_javascript('app/assets/js/page-scripts/js-functions.js');
	if(is_array($args) && _count($args) > 0) :
		if(_count($args) != _count($actions)) {
			return;
		}
		echo '<ul class="table_actions">';
		$i = 0;
		foreach ($args as $text => $link) {
			if(!is_array($access)) {
				$access_item = $access;
			} else {
				if(isset($access[$i])) {
					$access_item = $access[$i];
				} else $access_item = $access[0];
			}
			if(current_user_can($access_item)) :
				if($actions[$i]) :
					echo '<li><a class="ajax-action" data-title="Confirm your action" data-content="Are you sure you want to click on > '.ucwords($text).'?" href="javascript:void(0)" data-callback="refreshPage" data-action-callback="'.$actions[$i].'">'.$text.'</a></li>';
				else :
					echo '<li><a class="" href="'.$link.'">'.$text.'</a></li>';
				endif;
			endif;
			$i++;
		}
		echo '</ul>';
		add_page_javascript('app/assets/js/page-scripts/confirm.js');
	endif;
}