From da5f951ff5532b377c18c399d099cc5b656cd5db Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 Mar 2010 11:10:24 +0000 Subject: [PATCH] Works on canvas capability Works on custom list --- .../install/mysql/tables/llx_c_field_list.sql | 35 +++++++ .../canvas/default/product.default.class.php | 95 +++++++++---------- .../canvas/default/templates/liste.tpl | 2 +- htdocs/product/liste.php | 2 +- 4 files changed, 82 insertions(+), 52 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_c_field_list.sql diff --git a/htdocs/install/mysql/tables/llx_c_field_list.sql b/htdocs/install/mysql/tables/llx_c_field_list.sql new file mode 100644 index 00000000000..24be3974539 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_field_list.sql @@ -0,0 +1,35 @@ +-- ======================================================================== +-- Copyright (C) 2010 Regis Houssin +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- $Id$ +-- ======================================================================== + +create table llx_c_field_list +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + element varchar(64) NOT NULL, -- name of element list + entity integer DEFAULT 1 NOT NULL, -- entity id + name varchar(32) NOT NULL, -- name of field (ex: ref) + alias varchar(32) DEFAULT NULL, -- alias of field (ex: prodref) + title varchar(32) NOT NULL, -- title (translation) of field (ex: Ref) + align varchar(6) DEFAULT 'left', -- align (left,center,right) + search tinyint DEFAULT 0 NOT NULL, -- add search field + enabled varchar(255) DEFAULT 1, -- Condition to show or hide + rang integer DEFAULT 0 + +)type=innodb; diff --git a/htdocs/product/canvas/default/product.default.class.php b/htdocs/product/canvas/default/product.default.class.php index 376070525dd..b6b6ac4fc63 100644 --- a/htdocs/product/canvas/default/product.default.class.php +++ b/htdocs/product/canvas/default/product.default.class.php @@ -39,13 +39,14 @@ class ProductDefault extends Product */ function ProductDefault($DB=0, $id=0, $user=0) { - $this->db = $DB; - $this->id = $id ; - $this->user = $user; - $this->module = "produit"; - $this->canvas = "default"; - $this->name = "default"; - $this->description = "Canvas par défaut"; + $this->db = $DB; + $this->id = $id ; + $this->user = $user; + $this->module = "produit"; + $this->canvas = "default"; + $this->name = "default"; + $this->list = "product_default"; + $this->description = "Canvas par défaut"; $this->next_prev_filter = "canvas='default'"; } @@ -60,51 +61,46 @@ class ProductDefault extends Product */ function getFieldList() { - global $langs; + global $conf, $langs; - $this->list_title = array(); + $this->field_list = array(); - $titlelist["name"] = 'ref'; - $titlelist["title"] = $langs->trans("Ref"); - $titlelist["sortfield"] = 'p.ref'; - $titlelist["align"] = 'left'; - array_push($this->list_title,$titlelist); + $sql = "SELECT rowid, name, alias, title, align, search, enabled, rang"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_field_list"; + $sql.= " WHERE element = '".$this->list."'"; + $sql.= " AND entity = ".$conf->entity; - $titlelist["name"] = 'label'; - $titlelist["title"] = $langs->trans("Label"); - $titlelist["sortfield"] = 'p.label'; - $titlelist["align"] = 'left'; - array_push($this->list_title,$titlelist); - - $titlelist["name"] = 'barcode'; - $titlelist["title"] = $langs->trans("BarCode"); - $titlelist["sortfield"] = 'p.barcode'; - $titlelist["align"] = 'center'; - array_push($this->list_title,$titlelist); - - $titlelist["name"] = 'datem'; - $titlelist["title"] = $langs->trans("DateModification"); - $titlelist["sortfield"] = 'p.tms'; - $titlelist["align"] = 'center'; - array_push($this->list_title,$titlelist); - - $titlelist["name"] = 'sellingprice'; - $titlelist["title"] = $langs->trans("SellingPrice"); - $titlelist["sortfield"] = 'p.price'; - $titlelist["align"] = 'right'; - array_push($this->list_title,$titlelist); - - $titlelist["name"] = 'stock'; - $titlelist["title"] = $langs->trans("Stock"); - $titlelist["sortfield"] = ''; - $titlelist["align"] = 'right'; - array_push($this->list_title,$titlelist); - - $titlelist["name"] = 'status'; - $titlelist["title"] = $langs->trans("Status"); - $titlelist["sortfield"] = 'p.envente'; - $titlelist["align"] = 'right'; - array_push($this->list_title,$titlelist); + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + + $i = 0; + while ($i < $num) + { + $fieldlist = array(); + + $obj = $this->db->fetch_object($resql); + + $fieldlist["id"] = $obj->rowid; + $fieldlist["name"] = $obj->name; + $fieldlist["alias"] = $obj->alias; + $fieldlist["title"] = $obj->title; + $fieldlist["align"] = $obj->align; + $fieldlist["search"] = $obj->search; + $fieldlist["enabled"] = $obj->enabled; + $fieldlist["order"] = $obj->rang; + + array_push($this->field_list,$fieldlist); + + $i++; + } + $this->db->free($resql); + } + else + { + print $sql; + } } /** @@ -169,7 +165,6 @@ class ProductDefault extends Product $i = 0; while ($i < min($num,$limit)) { - $titlelist = array(); $datas = array(); $obj = $this->db->fetch_object($resql); diff --git a/htdocs/product/canvas/default/templates/liste.tpl b/htdocs/product/canvas/default/templates/liste.tpl index 31f18637d91..ba7cf0163a3 100644 --- a/htdocs/product/canvas/default/templates/liste.tpl +++ b/htdocs/product/canvas/default/templates/liste.tpl @@ -73,7 +73,7 @@ {strip} {foreach name=valueline key=key item=value from=$line} - {foreach name=fieldline item=field from=$titlelist} + {foreach name=fieldline item=field from=$fieldlist} {if $field.name == $key} {$value} {/if} diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 446819806f2..8b57ccb3821 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -225,7 +225,7 @@ if ($resql) if ($_GET["canvas"] <> '' && file_exists('canvas/'.$_GET["canvas"].'/product.'.$_GET["canvas"].'.class.php')) { - $smarty->assign('titlelist', $object->list_title); + $smarty->assign('fieldlist', $object->field_list); $smarty->assign('datas', $object->list_datas); $smarty->assign('url_root', $dolibarr_main_url_root); $smarty->assign('theme', $conf->theme);