dolibarr  16.0.5
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 {
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->transnoentitiesnoconv("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 widthcentpercentminusx", 0, 0, '', '', $tmptitle);
59  $filter .= "</div>";
60 
61  return $filter;
62  }
63 
71  public function selectProductCategory($selected = 0, $htmlname = 'product_category_id', $showempty = 0)
72  {
73  global $conf;
74 
75  $sql = "SELECT cp.fk_categorie as cat_index, cat.label";
76  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_product as cp";
77  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie as cat ON cat.rowid = cp.fk_categorie";
78  $sql .= " GROUP BY cp.fk_categorie, cat.label";
79 
80  dol_syslog(get_class($this)."::selectProductCategory", LOG_DEBUG);
81  $resql = $this->db->query($sql);
82  if ($resql) {
83  print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
84  if ($showempty) {
85  print '<option value="0">&nbsp;</option>';
86  }
87 
88  $i = 0;
89  $num_rows = $this->db->num_rows($resql);
90  while ($i < $num_rows) {
91  $category = $this->db->fetch_object($resql);
92  if ($selected && $selected == $category->cat_index) {
93  print '<option value="'.$category->cat_index.'" selected>'.$category->label.'</option>';
94  } else {
95  print '<option value="'.$category->cat_index.'">'.$category->label.'</option>';
96  }
97  $i++;
98  }
99  print ('</select>');
100 
101  return $num_rows;
102  } else {
103  dol_print_error($this->db);
104  }
105  }
106 }
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormCategory
Class to manage forms for categories.
Definition: html.formcategory.class.php:30
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Form\select_all_categories
select_all_categories($type, $selected='', $htmlname="parent", $maxlength=64, $markafterid=0, $outputmode=0, $include=0, $morecss='')
Return list of categories having choosed type.
Definition: html.form.class.php:4818
Form\multiselectarray
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.
Definition: html.form.class.php:8256
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
FormCategory\getFilterBox
getFilterBox($type, array $preSelected)
Return a HTML filter box for a list filter view.
Definition: html.formcategory.class.php:39
FormCategory\selectProductCategory
selectProductCategory($selected=0, $htmlname='product_category_id', $showempty=0)
Prints a select form for products categories.
Definition: html.formcategory.class.php:71