From 3760f247a2f21f0249cf4c1aa906c8afd66399d2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Oct 2015 22:12:11 +0100 Subject: [PATCH] NEW Can now select fields to show in product list. Extrafields are also supported. --- htdocs/core/class/extrafields.class.php | 52 ++- htdocs/product/list.php | 427 ++++++++++++++++-------- htdocs/societe/class/societe.class.php | 6 +- htdocs/societe/list.php | 64 +++- htdocs/user/index.php | 59 +++- 5 files changed, 447 insertions(+), 161 deletions(-) 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 '
'; if ($optioncss != '') print ''; print ''; + print ''; print ''; print ''; print ''; @@ -283,13 +338,6 @@ else // Filter on categories $moreforfilter=''; - $colspan=6; - if (! empty($conf->barcode->enabled)) $colspan++; - if (! empty($conf->service->enabled) && $type != 0) $colspan++; - if (empty($conf->global->PRODUIT_MULTIPRICES)) $colspan++; - if ($user->rights->fournisseur->lire) $colspan++; - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) $colspan+=2; - if (! empty($conf->categorie->enabled)) { $moreforfilter.='
'; @@ -307,93 +355,162 @@ else print '
'; } - // Lignes des titres - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder); - if (! empty($conf->barcode->enabled)) print_liste_field_titre($langs->trans("BarCode"), $_SERVER["PHP_SELF"], "p.barcode",$param,'','',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateModification"), $_SERVER["PHP_SELF"], "p.tms",$param,"",'align="center"',$sortfield,$sortorder); - if (! empty($conf->service->enabled) && $type != 0) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - if (empty($conf->global->PRODUIT_MULTIPRICES)) + if (empty($conf->global->PRODUIT_MULTIPRICES)) { - $titlefield=$langs->trans("SellingPrice"); + $titlesellprice=$langs->trans("SellingPrice"); if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { - $titlefield=$form->textwithpicto($langs->trans("SellingPrice"), $langs->trans("DefaultPriceRealPriceMayDependOnCustomer")); + $titlesellprice=$form->textwithpicto($langs->trans("SellingPrice"), $langs->trans("DefaultPriceRealPriceMayDependOnCustomer")); } - print_liste_field_titre($titlefield, $_SERVER["PHP_SELF"], "p.price",$param,"",'align="right"',$sortfield,$sortorder); } - if ($user->rights->fournisseur->lire) print_liste_field_titre($langs->trans("BuyingPriceMinShort"), '', '', '', '', 'align="right"'); - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print_liste_field_titre($langs->trans("DesiredStock"), '', '', '', '', 'align="right"'); - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print_liste_field_titre($langs->trans("PhysicalStock"), '', '', '', '', 'align="right"'); - print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Sell").')', $_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Buy").')', $_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); + + $arrayfields=array( + 'p.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'p.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1), + 'p.barcode'=>array('label'=>$langs->trans("Gencod"), 'checked'=>($contextpage != 'servicelist'), 'enabled'=>(! empty($conf->barcode->enabled))), + 'p.duration'=>array('label'=>$langs->trans("Duration"), 'checked'=>($contextpage != 'productlist'), 'enabled'=>(! empty($conf->service->enabled))), + 'p.sellprice'=>array('label'=>$titlesellprice, 'checked'=>1, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES)), + 'p.minbuyprice'=>array('label'=>$langs->trans("BuyingPriceMinShort"), 'checked'=>1, 'enabled'=>(! empty($user->rights->fournisseur->lire))), + 'p.desiredstock'=>array('label'=>$langs->trans("DesiredStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), + 'p.stock'=>array('label'=>$langs->trans("PhysicalStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), + 'p.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'p.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), + 'p.tosell'=>array('label'=>$langs->trans("Status").' ('.$langs->trans("Sell").')', 'checked'=>1, 'position'=>1000), + 'p.tobuy'=>array('label'=>$langs->trans("Status").' ('.$langs->trans("Purchases").')', 'checked'=>1, 'position'=>1000) + ); + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key]); + } + } + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; + $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + print '
'; + print ''; + if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder); + if (! empty($arrayfields['p.label']['checked'])) print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"],"p.label","",$param,"",$sortfield,$sortorder); + if (! empty($arrayfields['p.barcode']['checked'])) print_liste_field_titre($arrayfields['p.barcode']['label'], $_SERVER["PHP_SELF"],"p.barcode","",$param,"",$sortfield,$sortorder); + if (! empty($arrayfields['p.duration']['checked'])) print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"],"p.duration","",$param,"",$sortfield,$sortorder); + if (! empty($arrayfields['p.sellprice']['checked'])) print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['p.minbuyprice']['checked'])) print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['p.desiredstock']['checked'])) print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"],"p.desirestock","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['p.stock']['checked'])) print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"],"p.stock","",$param,'align="right"',$sortfield,$sortorder); + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + } + } + } + // Hook fields + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (! empty($arrayfields['p.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'],$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); + if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); + if (! empty($arrayfields['p.tosell']['checked'])) print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Sell").')',$_SERVER["PHP_SELF"],"p.tosell","",$param,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['p.tobuy']['checked'])) print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Buy").')',$_SERVER["PHP_SELF"],"p.tobuy","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; - // Lignes des champs de filtre + // Lines with input filters print ''; - print ''; - print ''; + if (! empty($arrayfields['p.ref']['checked'])) + { + print ''; + } + if (! empty($arrayfields['p.label']['checked'])) + { + print ''; + } // Barcode - if (! empty($conf->barcode->enabled)) + if (! empty($arrayfields['p.barcode']['checked'])) { print ''; } - // Date modification - print ''; - // Duration - if (! empty($conf->service->enabled) && $type != 0) + if (! empty($arrayfields['p.duration']['checked'])) { print ''; } - // Sell price - if (empty($conf->global->PRODUIT_MULTIPRICES)) + if (! empty($arrayfields['p.sellprice']['checked'])) { print ''; } - // Minimum buying Price - if ($user->rights->fournisseur->lire) { - print ''; - } - - // Stock - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) + if (! empty($arrayfields['p.minbuyprice']['checked'])) { print ''; - //desiredstock + } + // Desired stock + if (! empty($arrayfields['p.desiredstock']['checked'])) + { print ''; } - - print ''; - - print ''; - + // Stock + if (! empty($arrayfields['p.stock']['checked'])) + { + print ''; + } + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) print ''; + } + } + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['p.datec']['checked'])) + { + print ''; + } + // Date modification + if (! empty($arrayfields['p.tms']['checked'])) + { + print ''; + } + if (! empty($arrayfields['p.tosell']['checked'])) + { + print ''; + } + if (! empty($arrayfields['p.tobuy']['checked'])) + { + print ''; + } print ''; - - // Ref - print '\n"; + $product_static->status_buy = $objp->tobuy; + $product_static->status = $objp->tosell; + $var=!$var; + print ''; + + // Ref + if (! empty($arrayfields['p.ref']['checked'])) + { + print '\n"; + } + // Label - print ''; - + if (! empty($arrayfields['p.label']['checked'])) + { + print ''; + } + // Barcode - if (! empty($conf->barcode->enabled)) - { + if (! empty($arrayfields['p.barcode']['checked'])) + { print ''; } - // Modification Date - print '\n"; - // Duration - if (! empty($conf->service->enabled) && $type != 0) + if (! empty($arrayfields['p.duration']['checked'])) { print ''; } - // Show stock - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) + if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) // To optimize call of load_stock { if ($objp->fk_product_type != 1) { $product_static->id = $objp->rowid; $product_static->load_stock(); - print ''; - print ''; - } - else - { - print ''; - print ''; } } - - $product_static->status_buy = $objp->tobuy; - $product_static->status = $objp->tosell; + + // Desired stock + if (! empty($arrayfields['p.desiredstock']['checked'])) + { + print ''; + print ''; + } + + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + print 'getAlignFlag($key); + if ($align) print ' align="'.$align.'"'; + print '>'; + $tmpkey='options_'.$key; + print $extrafields->showOutputField($key, $objp->$tmpkey, '', 1); + print ''; + } + } + } + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['p.datec']['checked'])) + { + print ''; + } + // Date modification + if (! empty($arrayfields['p.tms']['checked'])) + { + print ''; + } + // Status (to sell) - print ''; - + if (! empty($arrayfields['p.tosell']['checked'])) + { + print ''; + } // Status (to buy) - print ''; - + if (! empty($arrayfields['p.tobuy']['checked'])) + { + print ''; + } + // Action print ''; print "\n"; $i++; } - $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:""; print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', '', '', 'paginationatbottom'); $db->free($resql); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index fb99f819af2..57049610390 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1760,7 +1760,7 @@ class Societe extends CommonObject if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; - if ($conf->global->SOCIETE_ADD_REF_IN_LIST && (!empty($withpicto))) + if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) { if (($this->client) && (! empty ( $this->code_client ))) { $code = $this->code_client . ' - '; @@ -1771,9 +1771,7 @@ class Societe extends CommonObject $name =$code.' '.$name; } - if (!empty($this->name_alias)) { - $name .= ' ('.$this->name_alias.')'; - } + if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')'; $result=''; $label=''; $link=''; $linkend=''; diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 732fe834728..6c554aa5137 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -75,13 +75,14 @@ $optioncss=GETPOST('optioncss','alpha'); $mode=GETPOST("mode"); $action=GETPOST('action'); +$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; $sortfield=GETPOST("sortfield",'alpha'); $sortorder=GETPOST("sortorder",'alpha'); $page=GETPOST("page",'int'); if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="s.nom"; if ($page == -1) { $page = 0 ; } -$offset = $conf->liste_limit * $page ; +$offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; @@ -296,13 +297,13 @@ if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user"; // We'll need these fields in order to filter by categ if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_soc"; // Add fields from extrafields -foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key; +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."societe as s"; -if (is_array($extrafields->attribute_list) && count($extrafields->attribute_list)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as ef on (s.rowid = ef.fk_object)"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as ef on (s.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays) "; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent) "; $sql.= " ,".MAIN_DB_PREFIX."c_stcomm as st"; @@ -529,6 +530,14 @@ if ($resql) 's.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 's.status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); + } + } $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields print '
'; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; - print ' '; - print ''; print ' '; print ''; print ''; - print ' '; - print ''; print ' '; print ''; print ' '; print ''; - print $form->selectarray('tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'),'1'=>$langs->trans('ProductStatusOnSellShort')),$tosell,1); - print ''; - print $form->selectarray('tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'),'1'=>$langs->trans('ProductStatusOnBuyShort')),$tobuy,1); - print ''; + print ' '; + print ''; + print ''; + print ''; + print $form->selectarray('tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'),'1'=>$langs->trans('ProductStatusOnSellShort')),$tosell,1); + print ''; + print $form->selectarray('tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'),'1'=>$langs->trans('ProductStatusOnBuyShort')),$tobuy,1); + print ''; print ''; print ''; @@ -427,32 +544,38 @@ else } } - $var=!$var; - print '
'; $product_static->id = $objp->rowid; $product_static->ref = $objp->ref; $product_static->label = $objp->label; $product_static->type = $objp->fk_product_type; - print $product_static->getNomUrl(1,'',24); - print "
'; + print $product_static->getNomUrl(1,'',24); + print "'.dol_trunc($objp->label,40).''.dol_trunc($objp->label,40).''.$objp->barcode.''.dol_print_date($db->jdate($objp->datem),'day')."'; if (preg_match('/([0-9]+)[a-z]/i',$objp->duration)) @@ -468,7 +591,7 @@ else } // Sell price - if (empty($conf->global->PRODUIT_MULTIPRICES)) + if (! empty($arrayfields['p.sellprice']['checked'])) { print ''; if ($objp->tosell) @@ -480,7 +603,7 @@ else } // Better buy price - if ($user->rights->fournisseur->lire) + if (! empty($arrayfields['p.minbuyprice']['checked'])) { print ''; if ($objp->tobuy && $objp->minsellprice != '') @@ -502,62 +625,102 @@ else print ''; - print $objp->desiredstock; - print ''; - if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' '; - print $product_static->stock_reel; - print ''; - print ' '; - print ''; - print ' '; - print ''; + if ($objp->fk_product_type != 1) + { + print $objp->desiredstock; + } + } + // Stock + if (! empty($arrayfields['p.stock']['checked'])) + { + print ''; + if ($objp->fk_product_type != 1) + { + if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' '; + print $product_static->stock_reel; + } + print ''; + print dol_print_date($objp->date_creation, 'dayhour'); + print ''; + print dol_print_date($objp->date_update, 'dayhour'); + print ''; - if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { - print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell'); - } else { - print $product_static->LibStatut($objp->tosell,5,0); - } - print ''; + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell'); + } else { + print $product_static->LibStatut($objp->tosell,5,0); + } + print ''; - if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { - print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy'); - } else { - print $product_static->LibStatut($objp->tobuy,5,1); - } - print ''; + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy'); + } else { + print $product_static->LibStatut($objp->tobuy,5,1); + } + print ' 
'; @@ -554,14 +563,15 @@ if ($resql) if (! empty($arrayfields['s.fk_prospectlevel']['checked'])) print_liste_field_titre($arrayfields['s.fk_prospectlevel']['label'],$_SERVER["PHP_SELF"],"s.fk_prospectlevel","",$param,'align="center"',$sortfield,$sortorder); if (! empty($arrayfields['s.fk_stcomm']['checked'])) print_liste_field_titre($arrayfields['s.fk_stcomm']['label'],$_SERVER["PHP_SELF"],"s.fk_stcomm","",$param,'align="center"',$sortfield,$sortorder); // Extra fields - if (is_array($extrafields->attribute_list) && count($extrafields->attribute_list)) + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_list as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if ($val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,"",$sortfield,$sortorder); - } + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + } } } // Hook fields @@ -740,7 +750,18 @@ if ($resql) print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2); print ''; } - + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + print ''; + } + } + } // Fields from hook $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook @@ -879,18 +900,21 @@ if ($resql) if (($obj->client==1 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) { $companystatic->name=$langs->trans("Customer"); + $companystatic->name_alias=''; $s.=$companystatic->getNomUrl(0,'customer'); } if (($obj->client==2 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) { if ($s) $s.=" / "; $companystatic->name=$langs->trans("Prospect"); - $s.=$companystatic->getNomUrl(0,'prospect'); + $companystatic->name_alias=''; + $s.=$companystatic->getNomUrl(0,'prospect'); } if (! empty($conf->fournisseur->enabled) && $obj->fournisseur) { if ($s) $s.=" / "; $companystatic->name=$langs->trans("Supplier"); + $companystatic->name_alias=''; $s.=$companystatic->getNomUrl(0,'supplier'); } print $s; @@ -916,7 +940,23 @@ if ($resql) } print ''; } - + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + print 'getAlignFlag($key); + if ($align) print ' align="'.$align.'"'; + print '>'; + $tmpkey='options_'.$key; + print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); + print ''; + } + } + } // Fields from hook $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 6b618552dc6..3af01d29046 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -55,14 +55,14 @@ $optioncss = GETPOST('optioncss','alpha'); if ($search_statut == '') $search_statut='1'; +$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 = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -$limit = $conf->liste_limit; if (! $sortfield) $sortfield="u.login"; if (! $sortorder) $sortorder="ASC"; @@ -93,6 +93,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $search_datepreviouslogin=""; $search_date_creation=""; $search_date_update=""; + $search_array_options=array(); } // List of fields to search into when doing a "search in all" @@ -135,12 +136,13 @@ $sql.= " u.tms as date_update, u.datec as date_creation,"; $sql.= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2,"; $sql.= " s.nom as name, s.canvas"; // Add fields from extrafields -foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key; +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."user as u"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields as ef on (u.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid"; if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && (! empty($conf->multicompany->transverse_mode) || (! empty($user->admin) && empty($user->entity)))) @@ -236,6 +238,14 @@ if ($result) 'u.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'u.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); + } + } $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields print '
'; + print '
'; @@ -251,17 +261,18 @@ if ($result) if (! empty($arrayfields['u.datelastlogin']['checked'])) print_liste_field_titre($langs->trans("LastConnexion"),$_SERVER['PHP_SELF'],"u.datelastlogin",$param,"",'align="center"',$sortfield,$sortorder); if (! empty($arrayfields['u.datepreviouslogin']['checked'])) print_liste_field_titre($langs->trans("PreviousConnexion"),$_SERVER['PHP_SELF'],"u.datepreviouslogin",$param,"",'align="center"',$sortfield,$sortorder); // Extra fields - if (is_array($extrafields->attribute_list) && count($extrafields->attribute_list)) + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_list as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if ($val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,"",$sortfield,$sortorder); - } + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + } } } - // Hook fields + // Hook fields $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; @@ -313,7 +324,14 @@ if ($result) { print ''; } - + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) print ''; + } + } // Fields from hook $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook @@ -480,11 +498,28 @@ if ($result) print ''; } + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + print 'getAlignFlag($key); + if ($align) print ' align="'.$align.'"'; + print '>'; + $tmpkey='options_'.$key; + print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); + print ''; + } + } + } // Fields from hook $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - // Date creation + // Date creation if (! empty($arrayfields['u.datec']['checked'])) { print '
'.dol_print_date($db->jdate($obj->datepreviouslogin),"dayhour").'';