<?php

/**************************************************************
* This file is part of Remository
* Copyright (c) 2006 Martin Brampton
* Issued as open source under GNU/GPL
* For support and other information, visit http://remository.com
* To contact Martin Brampton, write to martin@remository.com
*
* Remository started life as the psx-dude script by psx-dude@psx-dude.net
* It was enhanced by Matt Smith up to version 2.10
* Since then development has been primarily by Martin Brampton,
* with contributions from other people gratefully accepted
*/

if (!defined('_DOWN_SEARCH_CATEGORY_SELECT')) define ('_DOWN_SEARCH_CATEGORY_SELECT', 'Choose which categories to include');

class remositorySearchBoxHTML extends remositoryUserHTML {

	public function searchBoxHTML($categories, $catselector, $search_words='') {
		$formurl = remositoryRepository::getInstance()->RemositoryBasicFunctionURL('search');
		$this->pathwayHTML(null);
		echo <<<SEARCH_FORM
		
		<form method="post" action="$formurl">
			<div id="remositorysearch">
				<h2>{$this->showHTML(_DOWN_SEARCH)}</h2>
				<p class="remositoryformentry">
					<label for="search_text">{$this->showHTML(_DOWN_SEARCH_TEXT)}</label>
					<input class="inputbox" type="text" name="search_text" id="search_text" value="{$this->show($search_words)}" />
					<input class="button" type="submit" name="submit" value="{$this->showHTML(_DOWN_SUB_BUTTON)}" />
				</p>
				{$this->simpleTickBox(_DOWN_SEARCH_FILETITLE, 'search_filetitle')}
				{$this->simpleTickBox(_DOWN_SEARCH_FILEDESC, 'search_filedesc')}
				{$this->showCategorySelector($categories, $catselector)}
				<input type="hidden" name="submit" value="submit" />
			</div>
		</form>
		
SEARCH_FORM;

	}
	
	private function showCategorySelector ($categories, $catselector) {
		$cathtml = '';
		foreach ($categories as $category) {
			$selected = (0 == count($catselector) OR isset($catselector[$category->id])) ? true : false;
			$cathtml .= $this->simpleTickBox($category->name, "catsearch[$category->id]", $selected);
		}
		return <<<CAT_SELECT
		
			<div>
				<h3>{$this->showHTML(_DOWN_SEARCH_CATEGORY_SELECT)}</h3>
				$cathtml
			</div>
		
CAT_SELECT;
		
	}
}