diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index aa2f014c7ba..55cf274e78c 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1111,7 +1111,7 @@ class ExtraFields * * @param string $key Key of attribute * @param string $value Value to show - * @param string $moreparam More param + * @param string $moreparam To add more parametes on html input tag (only checkbox use html input for output rendering) * @return string Formated value */ function showOutputField($key,$value,$moreparam='') @@ -1128,6 +1128,8 @@ class ExtraFields $perms=$this->attribute_perms[$key]; $list=$this->attribute_list[$key]; + $showsize=0; + if ($type == 'date') { $showsize=10; @@ -1357,11 +1359,59 @@ class ExtraFields $showsize=round($size); if ($showsize > 48) $showsize=48; } + //print $type.'-'.$size; $out=$value; + return $out; } + /** + * Return tag to describe alignement to use for this extrafield + * + * @param string $key Key of attribute + * @return string Formated value + */ + function getAlignFlag($key) + { + global $conf,$langs; + + $type=$this->attribute_type[$key]; + + $align=''; + + if ($type == 'date') + { + $align="center"; + } + elseif ($type == 'datetime') + { + $align="center"; + } + elseif ($type == 'int') + { + $align="right"; + } + elseif ($type == 'double') + { + $align="right"; + } + elseif ($type == 'boolean') + { + $align="center"; + } + elseif ($type == 'radio') + { + $align="center"; + } + elseif ($type == 'checkbox') + { + $align="center"; + } + + return $align; + } + /** * Return HTML string to print separator extrafield * diff --git a/htdocs/product/list.php b/htdocs/product/list.php index d54db832d7e..dc9dcb7ed58 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -56,18 +56,28 @@ $fourn_id = GETPOST("fourn_id",'int'); $catid = GETPOST('catid','int'); $optioncss = GETPOST('optioncss','alpha'); +$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } -$offset = $conf->liste_limit * $page; +$offset = $liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortfield) $sortfield="p.ref"; if (! $sortorder) $sortorder="ASC"; -$limit = $conf->liste_limit; +$contextpage='productservicelist'; +if ($type === '1') { $contextpage='servicelist'; if ($search_type=='') $search_type='1'; } +if ($type === '0') { $contextpage='productlist'; if ($search_type=='') $search_type='0'; } +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array($contextpage)); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('product'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas=GETPOST("canvas"); @@ -107,15 +117,18 @@ if (! empty($conf->barcode->enabled)) { * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { - $sref=""; $sall=""; - $sbarcode=""; + $sref=""; $snom=""; + $sbarcode=""; $search_categ=0; $tosell=""; $tobuy=""; + $search_array_options=array(); } @@ -152,10 +165,17 @@ else } $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; - $sql.= ' p.fk_product_type, p.tms as datem,'; - $sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,'; + $sql.= ' p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,'; + $sql.= ' p.datec as date_creation, p.tms as date_update,'; $sql.= ' MIN(pfp.unitprice) as minsellprice'; + // Add fields from extrafields + foreach ($extrafields->attribute_label as $key => $val) $sql.=",ef.".$key.' as options_'.$key; + // Add fields from hooks + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; // multilang @@ -181,11 +201,33 @@ else if ($search_categ > 0) $sql.= " AND cp.fk_categorie = ".$db->escape($search_categ); if ($search_categ == -2) $sql.= " AND cp.fk_categorie IS NULL"; if ($fourn_id > 0) $sql.= " AND pfp.fk_soc = ".$fourn_id; + // Add where from extra fields + foreach ($search_array_options as $key => $val) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attribute_type[$tmpkey]; + $mode=0; + if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); + } + } + // Add where from hooks + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,"; - $sql.= " p.fk_product_type, p.tms,"; - $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock"; + $sql.= " p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,"; + $sql.= ' p.datec, p.tms'; + // Add fields from extrafields + foreach ($extrafields->attribute_label as $key => $val) $sql.=",ef.".$key; + // Add fields from hooks + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldSelect',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet - $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { @@ -230,12 +272,24 @@ else setEventMessage($langs->trans("ProductDeleted", GETPOST('delprod'))); } - $param="&sref=".$sref.($sbarcode?"&sbarcode=".$sbarcode:"")."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy; - $param.=($fourn_id?"&fourn_id=".$fourn_id:""); - $param.=($search_categ?"&search_categ=".$search_categ:""); - $param.=isset($type)?"&type=".$type:""; + if ($sref) $param="&sref=".$sref; + if ($sbarcode) $param.=($sbarcode?"&sbarcode=".$sbarcode:""); + if ($snom) $param.="&snom=".$snom; + if ($sall) $param.="&sall=".$sall; + if ($tosell != '') $param.="&tosell=".$tosell; + if ($tobuy != '') $param.="&tobuy=".$tobuy; + if ($fourn_id) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); + if ($seach_categ) $param.=($search_categ?"&search_categ=".$search_categ:""); + if ($type != '') $param.='&type='.urlencode($type); if ($optioncss != '') $param.='&optioncss='.$optioncss; - + // Add $param from extra fields + foreach ($search_array_options as $key => $val) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); + } + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords,'title_products.png'); if (! empty($catid)) @@ -270,6 +324,7 @@ else print '