<?php

	CLASS AKB_POPULARSEARCHES_PANEL extends AKB_PANEL
	{
		/**
		* SetPanelSettings
		* This function is a chance to set any last minute global variables for
		* the template to use
		*
		* @return void
		*/
		function SetPanelSettings()
		{
			// Parse the panel of tokens, etc
			$GLOBALS['PopularSearchTermList'] = $this->GetPopularSearchTermList();
		}

		/**
		* GetPopularSearchTermList
		* Get a list of popular search terms and generate the html for
		* displaying the list to the user
		*
		* @return string The html for the list
		*/
		function GetPopularSearchTermList()
		{
			$query = 'SELECT searchstring
				FROM '.$GLOBALS['tablePrefix'].'searchhistory
				WHERE numresults > 0
				ORDER BY amount DESC
				'.$GLOBALS['AKB_DB']->AddLimit(0, 10);

			$result = $GLOBALS['AKB_DB']->Query($query);

			if ($GLOBALS['AKB_DB']->CountResult($query) > 0) {
				$output = $GLOBALS['AKB_CLASS_TEMPLATE']->GetSnippet('PopularQuestionsListHeader');
				while ($row = $GLOBALS['AKB_DB']->Fetch($result)) {
					$a = trim($row['searchstring']);
					if (!empty($a)) {
						$GLOBALS['Link'] = GetUrl('search', strip_tags($a));
						$GLOBALS['Text'] = $GLOBALS['AKB_CLASS_TEMPLATE']->DisablePlaceholders(htmlspecialchars(strip_tags($a), ENT_QUOTES, $GLOBALS['charset']));
						$output .= $GLOBALS['AKB_CLASS_TEMPLATE']->GetSnippet('PopularQuestionsListRow');
					}
				}
				$output .= $GLOBALS['AKB_CLASS_TEMPLATE']->GetSnippet('PopularQuestionsListFooter');
			} else {
				$output = GetLang('hpNoPopularSearchTerms');
			}
			return $output;
		}

	}

?>
