<?php

	class AdminView
	{
		var $paginationLink;
		var $sortField;
		var $sortDirection;
		var $numRecords = 0;
		
		/**
		* NoPermission
		* Display the no permission page
		*
		* @return void
		*/
		function NoPermission()
		{
			$GLOBALS['HidePermissionPanel'] = 'inline';

			$GLOBALS['AKB_CLASS_AUTH']->SetupHomePageLinks();

			$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('home');
			$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();

		}
		
		/**
		* SetupPagination
		*
		* Setup the pagination variables for the global Nav functionality.
		* This is based on the general function BuildNav, but slightly different logic to accomodate javascript links
		*
		* @return void
		*/
		function SetupPagination($countQuery,$currentPage,$totalRows) {
			$result = $GLOBALS['AKB_DB']->Query($countQuery);
			$this->numRecords = $GLOBALS['AKB_DB']->FetchOne($result);
			$numPages = ceil($this->numRecords / $totalRows);

			$this->paginationRowStart = ($currentPage == 1) ? 0 : ($currentPage * $totalRows) - ($totalRows-1)-1;

			$GLOBALS['PaginationNav'] = BuildNav($this->paginationLink, $numPages, $currentPage, "&amp;", true);
		}
		
		/**
		* SetupPaginationLink
		*
		* Setup the pagination link variables for the global Nav functionality.
		* This is the global javascript call for all admin tables.
		*
		* @return void
		*/		
		function SetupPaginationLink($todo,$direction,$field) {
			$this->paginationLink = "
				javascript: REMOTE_admin_table('
					REMOTE_".$todo."',
					'".ADMIN_TABLE_REMOTE_URL."',
					'".$todo."',
					'".$direction."',
					'".$field."',
					'__BUILDNAV_PAGENUMBER__'
				);
			";		
		}
		
		
		/**
		* SetupSortingParams
		*
		* Sets up the sorting and direction mechanism for all admin tables.
		*
		* @param $headingArray 	array This must be a headingArray for an AdminTable. Used for checking the field
		* @param $sortArray 	array This must be a sortArray for an AdminTable. This will contain all of the sort fields.
		*
		* @return void
		*/
		function SetupSortingParams(&$sortArray,$todo,$currentPage) {
			$tempDirection = (isset($_GET['direction'])) ? $_GET['direction'] : "d";
			$this->sortDirection = ($tempDirection == "d") ? "DESC" : "ASC";
			$this->sortField = (isset($_GET['field'])) ? $_GET['field'] : $this->defaultTableSort;
			
			$builtArray = array();

			if (is_array($sortArray)) {
				foreach ($sortArray as $field) {
					if ($field == $this->sortField) {
						if ($tempDirection == "d") {
							$sortTemplate = "RemoteSortDE";	
						} else {
							$sortTemplate = "RemoteSortED";	
						}
					} else {
						$sortTemplate = "RemoteSortEE";
					}
					
					$GLOBALS['ThisField'] = $field;
					$GLOBALS['RemoteURL'] = ADMIN_TABLE_REMOTE_URL;
					$GLOBALS['ATTODO'] = $todo;
					$GLOBALS['CurrentPageNumber'] = $currentPage;

					$builtArray[$field] = $GLOBALS['AKB_CLASS_TEMPLATE']->GetSnippet($sortTemplate);
				}
			}
			
			return $builtArray;
		}
		
		/**
		* CreateRandomGlobals
		*
		* Sometimes we need to create a bunch of random global template replacement vars for uniqueness.
		*
		* @param $num integer The number to create.
		*
		* @return void
		*/		
		function CreateRandomGlobals($num) {
			for ($i=0;$i<$num;$i++) {
				$GLOBALS['RAND_'.$i] = rand(0,1000);
			}
		}		
	}

?>
