1<?php
2/* Copyright (C) 2020		Tobias Sekan	<tobias.sekan@startmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18/**
19 *	\file		htdocs/core/class/html.formcategory.class.php
20 *	\ingroup	core
21 *	\brief		File of class to build HTML component for category filtering
22 */
23
24require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
25
26
27/**
28 *	Class to manage forms for categories
29 */
30class FormCategory extends Form
31{
32	/**
33	 * Return a HTML filter box for a list filter view
34	 *
35	 * @param string	$type			The categorie type (e.g Categorie::TYPE_WAREHOUSE)
36	 * @param Array		$preSelected	A list with the elements that should pre-selected
37	 * @return string					A HTML filter box (Note: selected results can get with GETPOST("search_category_".$type."_list"))
38	 */
39	public function getFilterBox($type, array $preSelected)
40	{
41		global $langs;
42
43		if (empty($preSelected) || !is_array($preSelected)) {
44			$preSelected = array();
45		}
46
47		$htmlName = "search_category_".$type."_list";
48
49		$categoryArray = $this->select_all_categories($type, "", "", 64, 0, 1);
50		$categoryArray[-2] = "- ".$langs->trans('NotCategorized')." -";
51
52		$tmptitle = $langs->trans("Category");
53
54		$filter = '';
55		$filter .= '<div class="divsearchfield">';
56		$filter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
57		//$filter .= $langs->trans('Categories').": ";
58		$filter .= Form::multiselectarray($htmlName, $categoryArray, $preSelected, 0, 0, "minwidth300", 0, 0, '', '', $tmptitle);
59		$filter .= "</div>";
60
61		return $filter;
62	}
63}
64