dolibarr  19.0.0-dev
html.formcategory.class.php
Go to the documentation of this file.
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 
24 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
25 
26 
30 class FormCategory extends Form
31 {
44  public function getFilterBox($type, array $preSelected, $morecss = "minwidth300imp widthcentpercentminusx", $searchCategoryProductOperator = -1, $multiselect = 1, $nocateg = 1, $showempty = '')
45  {
46  global $langs, $db;
47 
48  if (empty($preSelected) || !is_array($preSelected)) {
49  $preSelected = array();
50  }
51 
52  if ($showempty && !is_numeric($showempty)) {
53  $tmptitle = $showempty;
54  } else {
55  $tmptitle = $langs->transnoentitiesnoconv("Category");
56  }
57 
58  $filter = '';
59  $filter .= '<div class="divsearchfield">';
60  $filter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
61  if ($multiselect) {
62  $categoryArray = $this->select_all_categories($type, '', '', 64, 0, 2);
63  if ($nocateg) {
64  $categoryArray[-2] = "- ".$langs->trans('NotCategorized')." -";
65  }
66  $htmlName = "search_category_".$type."_list";
67  $htmlName2 = "search_category_".$type."_operator";
68 
69  $filter .= Form::multiselectarray($htmlName, $categoryArray, $preSelected, 0, 0, $morecss, 0, 0, '', '', $tmptitle);
70  } else {
71  $htmlName = "search_".$type."_category";
72  $htmlName2 = "";
73  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
74  $formother = new FormOther($db);
75 
76  $filter .= $formother->select_categories($type, $preSelected[0], $htmlName, $nocateg, $tmptitle, $morecss);
77  }
78  if ($searchCategoryProductOperator >= 0) {
79  $filter .= ' <input type="checkbox" class="valignmiddle" id="'.$htmlName2.'" name="'.$htmlName2.'" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="'.$htmlName2.'">'.$langs->trans('UseOrOperatorForCategories').'</label>';
80  }
81  $filter .= "</div>";
82 
83  return $filter;
84  }
85 
93  public function selectProductCategory($selected = 0, $htmlname = 'product_category_id', $showempty = 0)
94  {
95  global $conf;
96 
97  $sql = "SELECT cp.fk_categorie as cat_index, cat.label";
98  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_product as cp";
99  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie as cat ON cat.rowid = cp.fk_categorie";
100  $sql .= " GROUP BY cp.fk_categorie, cat.label";
101 
102  dol_syslog(get_class($this)."::selectProductCategory", LOG_DEBUG);
103  $resql = $this->db->query($sql);
104  if ($resql) {
105  print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
106  if ($showempty) {
107  print '<option value="0">&nbsp;</option>';
108  }
109 
110  $i = 0;
111  $num_rows = $this->db->num_rows($resql);
112  while ($i < $num_rows) {
113  $category = $this->db->fetch_object($resql);
114  if ($selected && $selected == $category->cat_index) {
115  print '<option value="'.$category->cat_index.'" selected>'.$category->label.'</option>';
116  } else {
117  print '<option value="'.$category->cat_index.'">'.$category->label.'</option>';
118  }
119  $i++;
120  }
121  print ('</select>');
122 
123  return $num_rows;
124  } else {
125  dol_print_error($this->db);
126  }
127  }
128 }
Class to manage forms for categories.
getFilterBox($type, array $preSelected, $morecss="minwidth300imp widthcentpercentminusx", $searchCategoryProductOperator=-1, $multiselect=1, $nocateg=1, $showempty='')
Return a HTML filter box for a list filter view.
selectProductCategory($selected=0, $htmlname='product_category_id', $showempty=0)
Prints a select form for products categories.
Class to manage generation of HTML components Only common components must be here.
select_all_categories($type, $selected='', $htmlname="parent", $maxlength=64, $markafterid=0, $outputmode=0, $include=0, $morecss='')
Return list of categories having choosed type.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Classe permettant la generation de composants html autre Only common components are here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.