From 89ea444f635ff88b55a4f1e78680fa0bdd084212 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Fri, 28 Jun 2002 22:46:44 +0000 Subject: [PATCH] . --- htdocs/{lib => }/product.class.php3 | 53 ++++++++++-- htdocs/product/fiche.php3 | 126 +++++++++++++++++++--------- htdocs/product/index.php3 | 61 +++++++------- htdocs/product/pre.inc.php3 | 18 ++-- htdocs/service/fiche.php3 | 6 +- htdocs/service/index.php3 | 6 +- 6 files changed, 180 insertions(+), 90 deletions(-) rename htdocs/{lib => }/product.class.php3 (64%) diff --git a/htdocs/lib/product.class.php3 b/htdocs/product.class.php3 similarity index 64% rename from htdocs/lib/product.class.php3 rename to htdocs/product.class.php3 index af753b2fb6d..edd358cdb04 100644 --- a/htdocs/lib/product.class.php3 +++ b/htdocs/product.class.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,24 +15,70 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ class Product { var $db ; - var $id ; var $ref; - var $label; + var $libelle; var $description; var $price ; Function Product($DB, $id=0) { $this->db = $DB; $this->id = $id ; + } + /* + * + * + * + */ + Function create($user) { + + $sql = "INSERT INTO llx_product (fk_user_author) VALUES (".$user->id.")"; + + if ($this->db->query($sql) ) { + $id = $this->db->last_insert_id(); + + if ( $this->update($id, $user) ) { + return $id; + } + } else { + print $this->db->error() . ' in ' . $sql; + } } + /* + * + * + * + */ + Function update($id, $user) { + $sql = "UPDATE llx_product "; + $sql .= " SET label = '" . trim($this->libelle) ."'"; + $sql .= ",ref = '" . trim($this->ref) ."'"; + $sql .= ",price = " . $this->price ; + $sql .= ",description = '" . trim($this->description) ."'"; + + $sql .= " WHERE rowid = " . $id; + + if ( $this->db->query($sql) ) { + return 1; + } else { + print $this->db->error() . ' in ' . $sql; + } + } + /* + * + * + * + */ Function fetch ($id) { $sql = "SELECT rowid, ref, label, description, price FROM llx_product WHERE rowid = $id"; diff --git a/htdocs/product/fiche.php3 b/htdocs/product/fiche.php3 index 0ae1d2a57b1..1eccc0c2cfc 100644 --- a/htdocs/product/fiche.php3 +++ b/htdocs/product/fiche.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ require("./pre.inc.php3"); @@ -26,55 +26,101 @@ llxHeader(); $db = new Db(); -if ($action == 'update') { +if ($action == 'add') { + $product = new Product($db); - $sql = "UPDATE llx_product SET description='$desc' where rowid = $rowid"; - $db->query($sql); + $product->ref = $ref; + $product->libelle = $libelle; + $product->price = $price; + $product->description = $desc; + + $id = $product->create($user); } -if ($id) { - +if ($action == 'update') { $product = new Product($db); - $result = $product->fetch($id); - if ( $result ) { - - print '
Fiche produit : '.$product->ref.'
'; + $product->ref = $ref; + $product->libelle = $libelle; + $product->price = $price; + $product->description = $desc; - print "

"; - - print ""; - print "\n"; - print "\n"; - - print "\n"; - - print ""; - - } - print "
Référence$product->ref
Libellé$product->label
Prix$product->price
Description".nl2br($product->description)."
"; - - if ($action == 'edit') { - - - print "


\n"; - print ""; - print "
"; - print ""; - print "
"; - - - - } + $product->update($id, $user); +} +/* + * + * + */ +if ($action == 'create') { + print "
\n"; + print ""; + + print 'Nouveau produit'; + print ""; + print ''; + print ''; + print ''; + print ""; + print ''; + print '
Référence
Libellé
Prix
Description"; + print '
 
'; + print '
'; + } else { - print "Error"; + if ($id) { + + $product = new Product($db); + $result = $product->fetch($id); + + if ( $result ) { + print '
Fiche produit : '.$product->ref.'
'; + + print ''; + print ""; + print "\n"; + print "\n"; + print ''; + print ""; + print "
Référence$product->ref
Libellé$product->label
Prix'.price($product->price).'
Description".nl2br($product->description)."
"; + } + + + if ($action == 'edit') { + print "
\n"; + print ""; + + print 'Edition de la fiche produit'; + print ""; + print ''; + print ''; + print ''; + print ""; + print ''; + print '
Référence
Libellé
Prix
Description"; + print '
 
'; + print '
'; + } + } else { + print "Error"; + } } +print '
'; +print ''; +print ''; +print ''; + +print ''; + +print ''; +print '
---[Editer]-

'; + $db->close(); diff --git a/htdocs/product/index.php3 b/htdocs/product/index.php3 index 15ffffbff0e..aa31b633a56 100644 --- a/htdocs/product/index.php3 +++ b/htdocs/product/index.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ require("./pre.inc.php3"); @@ -44,37 +44,38 @@ if ($page == -1) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; -print '
Liste des produits
'; +print_barre_liste("Liste des produits", $page, $PHP_SELF); - $sql = "SELECT p.rowid, p.label, p.price, p.duration,p.ref FROM llx_product as p"; +$sql = "SELECT p.rowid, p.label, p.price, p.ref FROM llx_product as p"; - $sql .= " ORDER BY $sortfield $sortorder "; - $sql .= $db->plimit( $limit ,$offset); +$sql .= " ORDER BY $sortfield $sortorder "; +$sql .= $db->plimit( $limit ,$offset); - if ( $db->query($sql) ) { - $num = $db->num_rows(); - $i = 0; - print "

"; - print ""; - print ""; - print ""; - print ""; - print "\n"; - $var=True; - while ($i < $num) { - $objp = $db->fetch_object( $i); - $var=!$var; - print ""; - print "\n"; - print "\n"; - print ''; - print "\n"; - $i++; - } - print "
RéfNomPrix
rowid\">$objp->ref$objp->label'.price($objp->price).'
"; - $db->free(); - } +if ( $db->query($sql) ) { + $num = $db->num_rows(); + $i = 0; + print "

"; + print ""; + print "\n"; + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print ''; + print "\n"; + $i++; + } + print "
"; + print_liste_field_titre("Réf",$PHP_SELF, "p.ref"); + print ""; + print_liste_field_titre("Libellé",$PHP_SELF, "p.label"); + print "Prix de vente
rowid\">$objp->ref$objp->label'.price($objp->price).'
"; + $db->free(); +} $db->close(); diff --git a/htdocs/product/pre.inc.php3 b/htdocs/product/pre.inc.php3 index e345a14f005..c53743a7e7f 100644 --- a/htdocs/product/pre.inc.php3 +++ b/htdocs/product/pre.inc.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ require("../main.inc.php3"); @@ -33,21 +33,21 @@ function llxHeader($head = "", $urlp = "") { $menu = new Menu(); $menu->add("/product/index.php3", "Produits"); - + $menu->add_submenu("fiche.php3?&action=create","Nouveau produit"); $menu->add("/service/index.php3", "Services"); - $menu->add("/comm/index.php3", "Clients"); + $menu->add("/comm/clients.php3", "Clients"); $menu->add("/fourn/index.php3", "Fournisseurs"); - $menu->add_submenu("/soc.php3?&action=create","Nouvelle sociétée"); $menu->add_submenu("contact.php3","Contacts"); - left_menu($menu->liste); - - + /* + * + * + */ } ?> diff --git a/htdocs/service/fiche.php3 b/htdocs/service/fiche.php3 index 510a69954a8..1d9babf159c 100644 --- a/htdocs/service/fiche.php3 +++ b/htdocs/service/fiche.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ require("./pre.inc.php3"); diff --git a/htdocs/service/index.php3 b/htdocs/service/index.php3 index a3f5a20970a..7f102e1ee8b 100644 --- a/htdocs/service/index.php3 +++ b/htdocs/service/index.php3 @@ -1,8 +1,5 @@ - * - * $Id$ - * $Source$ * * 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 @@ -18,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * $Source$ + * */ require("./pre.inc.php3");