diff --git a/htdocs/boutique/client/pre.inc.php b/htdocs/boutique/client/pre.inc.php index 70bd38177ca..76e9a759ed2 100644 --- a/htdocs/boutique/client/pre.inc.php +++ b/htdocs/boutique/client/pre.inc.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -17,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -41,6 +41,7 @@ function llxHeader($head = "", $urlp = "") $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); diff --git a/htdocs/boutique/commande/pre.inc.php b/htdocs/boutique/commande/pre.inc.php index aab44cd6bc8..f9d09384f65 100644 --- a/htdocs/boutique/commande/pre.inc.php +++ b/htdocs/boutique/commande/pre.inc.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -17,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -40,6 +40,7 @@ function llxHeader($head = "", $urlp = "") $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); diff --git a/htdocs/boutique/critiques/bestproduct.php b/htdocs/boutique/critiques/bestproduct.php new file mode 100644 index 00000000000..cb299dbc295 --- /dev/null +++ b/htdocs/boutique/critiques/bestproduct.php @@ -0,0 +1,92 @@ + + * Copyright (C) 2003 Éric Seigne + * + * 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$ + * $Source$ + */ + +/** + \file htdocs/boutique/critiques/bestproduct.php + \ingroup boutique + \brief Page affichage meilleures critiques OS Commerce + \version $Revision$ +*/ + +require("./pre.inc.php"); + +llxHeader(); + +if ($sortfield == "") { + $sortfield="rat"; +} +if ($sortorder == "") { + $sortorder="DESC"; +} + + +if ($page == -1) { $page = 0 ; } +$limit = $conf->liste_limit; +$offset = $limit * $page ; + + +print_barre_liste("Liste des produits classés pas critiques", $page, "bestproduct.php"); + +$sql = "SELECT sum(r.reviews_rating)/count(r.reviews_rating) as rat, r.products_id, p.products_model, p.products_quantity, p.products_status"; +$sql .= " FROM ".OSC_DB_NAME.".reviews as r,".OSC_DB_NAME.".products as p "; +$sql .= " WHERE r.products_id = p.products_id"; +$sql .= " GROUP BY r.products_id, p.products_model, p.products_quantity, p.products_status"; + +$sql .= " ORDER BY $sortfield $sortorder "; +$sql .= $db->plimit( $limit ,$offset); + +print "

"; +print "'; +print ''; +print "\n"; + + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + + $var=True; + while ($i < $num) { + $objp = $db->fetch_object($resql); + $var=!$var; + print ""; + print ''; + print '\n"; + print '\n"; + print '\n"; + print "\n"; + $i++; + } + $db->free(); +} + +print "
".$langs->trans("Ref"); +print 'Indice critiquesQuantité'; +print 'Status
'.$objp->products_model.''.$objp->rat."'.$objp->products_quantity."'.$objp->products_status."
"; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/boutique/critiques/critique.class.php b/htdocs/boutique/critiques/critique.class.php new file mode 100644 index 00000000000..3f08cd40694 --- /dev/null +++ b/htdocs/boutique/critiques/critique.class.php @@ -0,0 +1,84 @@ + + * + * 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$ + * $Source$ + */ + +/* + \file htdocs/boutique/critiques/critique.class.php + \ingroup prelevement + \brief Fichier de la classe des critiques OSCommerce + \version $Revision$ +*/ + + +/** + \class Critique + \brief Classe permettant la gestion des critiques OSCommerce +*/ + +class Critique { + var $db ; + + var $id ; + var $nom; + + function Critique($DB, $id=0) { + $this->db = $DB; + $this->id = $id ; + } + /* + * + * + * + */ + function fetch ($id) { + + + $sql = "SELECT r.reviews_id, r.reviews_rating, d.reviews_text, p.products_name"; + + $sql .= " FROM ".OSC_DB_NAME.".reviews as r, ".OSC_DB_NAME.".reviews_description as d"; + $sql .= " ,".OSC_DB_NAME.".products_description as p"; + + $sql .= " WHERE r.reviews_id = d.reviews_id AND r.products_id=p.products_id"; + $sql .= " AND p.language_id = ".OSC_LANGUAGE_ID. " AND d.languages_id=".OSC_LANGUAGE_ID; + $sql .= " AND r.reviews_id=$id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_array(); + + $this->id = $result["reviews_id"]; + $this->product_name = stripslashes($result["products_name"]); + $this->text = stripslashes($result["reviews_text"]); + + $this->db->free(); + } + else + { + print $this->db->error(); + print "

$sql"; + } + + return $result; + } + +} +?> diff --git a/htdocs/boutique/critiques/fiche.php b/htdocs/boutique/critiques/fiche.php new file mode 100644 index 00000000000..8c14a866cb3 --- /dev/null +++ b/htdocs/boutique/critiques/fiche.php @@ -0,0 +1,84 @@ + + * + * 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$ + * $Source$ + */ + +/** + \file htdocs/boutique/critiques/fiche.php + \ingroup boutique + \brief Page fiche critique OS Commerce + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$id=$_GET["id"]; + + +llxHeader(); + +if ($id) +{ + + $critique = new Critique($db); + $result = $critique->fetch($id); + + if ( $result ) + { + + print '

Fiche Critique

'; + + print ''; + print ""; + print ''; + + print ''; + print "
Produit'.$critique->product_name.'
Texte'.nl2br($critique->text).'
"; + + + + } + else + { + print "Fetch failed"; + } + +} + +/* ************************************************************************** */ +/* */ +/* Barre d'action */ +/* */ +/* ************************************************************************** */ + +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print '
-----

'; + + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); + +?> diff --git a/htdocs/boutique/critiques/index.php b/htdocs/boutique/critiques/index.php new file mode 100644 index 00000000000..63c021b69f9 --- /dev/null +++ b/htdocs/boutique/critiques/index.php @@ -0,0 +1,90 @@ + + * + * 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$ + * $Source$ + */ + +/** + \file htdocs/boutique/critiques/fiche.php + \ingroup boutique + \brief Page gestion critiques OS Commerce + \version $Revision$ +*/ + +require("./pre.inc.php"); + +llxHeader(); + +if ($sortfield == "") { + $sortfield="date_added"; +} +if ($sortorder == "") { + $sortorder="DESC"; +} + + +if ($page == -1) { $page = 0 ; } +$limit = $conf->liste_limit; +$offset = $limit * $page ; + +print_barre_liste("Critiques", $page, "index.php"); + +$sql = "SELECT r.reviews_id, r.reviews_rating, d.reviews_text, p.products_name FROM ".OSC_DB_NAME.".reviews as r, ".OSC_DB_NAME.".reviews_description as d, ".OSC_DB_NAME.".products_description as p"; +$sql .= " WHERE r.reviews_id = d.reviews_id AND r.products_id=p.products_id"; +$sql .= " AND p.language_id = ".OSC_LANGUAGE_ID. " AND d.languages_id=".OSC_LANGUAGE_ID; +$sql .= " ORDER BY $sortfield $sortorder "; +$sql .= $db->plimit( $limit ,$offset); + +print "

"; +print ''; +print ""; +print ""; +print ""; +print ""; +print "\n"; + +$resql=$db->query($sql); +if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + $var=True; + while ($i < $num) { + $objp = $db->fetch_object($resql); + $var=!$var; + print ""; + print "\n"; + print '\n"; + print "\n"; + print "\n"; + $i++; + } + $db->free(); +} +else +{ + dolibarr_print_error($db); +} + +print "
ProduitCritiqueNote
".substr($objp->products_name, 0, 30)."'.substr($objp->reviews_text, 0, 40)." ...$objp->reviews_rating
"; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/boutique/critiques/pre.inc.php b/htdocs/boutique/critiques/pre.inc.php new file mode 100644 index 00000000000..1de7068ee46 --- /dev/null +++ b/htdocs/boutique/critiques/pre.inc.php @@ -0,0 +1,52 @@ + + * Copyright (C) 2006 Laurent Destailleur + * + * 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$ + * $Source$ + */ + +/** + \file htdocs/boutique/critiques/pre.inc.php + \ingroup boutique + \brief Fichier gestionnaire du menu gauche des critiques OSCommerce + \version $Revision$ +*/ + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/boutique/critiques/critique.class.php"); + +function llxHeader($head = "", $urlp = "") +{ + global $user, $conf; + + top_menu($head); + + $menu = new Menu(); + + $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/bestproduct.php", "Meilleurs produits",2); + $menu->add_submenu(DOL_URL_ROOT."/boutique/promotion/index.php", $langs->trans("Promotion")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); + + left_menu($menu->liste); +} + +?> diff --git a/htdocs/boutique/pre.inc.php b/htdocs/boutique/pre.inc.php index c577cc15ecf..6d9534cbeb4 100644 --- a/htdocs/boutique/pre.inc.php +++ b/htdocs/boutique/pre.inc.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -42,6 +43,9 @@ function llxHeader($head = "", $urlp = "") $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/bestproduct.php", "Meilleurs produits",2); + $menu->add_submenu(DOL_URL_ROOT."/boutique/promotion/index.php", $langs->trans("Promotion")); $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); diff --git a/htdocs/boutique/produits/osc-liste.php b/htdocs/boutique/produits/osc-liste.php index d5f4ebe079c..342349cc742 100644 --- a/htdocs/boutique/produits/osc-liste.php +++ b/htdocs/boutique/produits/osc-liste.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -17,9 +18,15 @@ * * $Id$ * $Source$ - * */ +/** + \file htdocs/boutique/produits/osc-liste.php + \ingroup boutique + \brief Page gestion produits du module OsCommerce + \version $Revision$ +*/ + require("./pre.inc.php"); llxHeader(); @@ -59,15 +66,17 @@ print "Titre"; print "Groupe"; print 'Stock'; print 'Status'; - print "\n"; +print "\n"; -if ( $db->query($sql) ) { - $num = $db->num_rows(); +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); $i = 0; $var=True; while ($i < $num) { - $objp = $db->fetch_object( $i); + $objp = $db->fetch_object($resql); $var=!$var; print ""; print "$objp->products_id\n"; @@ -81,11 +90,15 @@ if ( $db->query($sql) ) { } $db->free(); } +else +{ + dolibarr_print_error($db); +} print ""; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/boutique/produits/pre.inc.php b/htdocs/boutique/produits/pre.inc.php index 1c02e59e7c9..e30ada71472 100644 --- a/htdocs/boutique/produits/pre.inc.php +++ b/htdocs/boutique/produits/pre.inc.php @@ -39,6 +39,9 @@ function llxHeader($head = "", $urlp = "") $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/bestproduct.php", "Meilleurs produits",2); + $menu->add_submenu(DOL_URL_ROOT."/boutique/promotion/index.php", $langs->trans("Promotion")); $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); diff --git a/htdocs/boutique/promotion/index.php b/htdocs/boutique/promotion/index.php new file mode 100644 index 00000000000..3d57cb176b5 --- /dev/null +++ b/htdocs/boutique/promotion/index.php @@ -0,0 +1,117 @@ + + * Copyright (C) 2004 Laurent Destailleur + * + * 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$ + * $Source$ + * + */ + +require("./pre.inc.php"); + +llxHeader(); + +if ($action == "inactive") +{ + $promotion = new Promotion($db); + $promotion->set_inactive($id); +} +if ($action == "active") +{ + $promotion = new Promotion($db); + $promotion->set_active($id); +} + +if ($sortfield == "") +{ + $sortfield="pd.products_name"; +} +if ($sortorder == "") +{ + $sortorder="ASC"; +} + +if ($page == -1) { $page = 0 ; } +$limit = $conf->liste_limit; +$offset = $limit * $page ; + +print_barre_liste("Liste des promotions", $page, "index.php", "",$sortfield, $sortorder); + +$urladd = "&sortorder=$sortorder&sortfield=$sortfield"; + +$sql = "SELECT pd.products_name, s.specials_new_products_price, p.products_price, p.products_model, s.status, p.products_id"; +$sql .= ",".$db->pdate("expires_date")." as fin"; +$sql .= " FROM ".OSC_DB_NAME.".specials as s,".OSC_DB_NAME.".products_description as pd,".OSC_DB_NAME.".products as p"; +$sql .= " WHERE s.products_id = pd.products_id AND pd.products_id = p.products_id AND pd.language_id = ".OSC_LANGUAGE_ID; +$sql .= " ORDER BY $sortfield $sortorder "; +$sql .= $db->plimit( $limit ,$offset); + +if ( $db->query($sql) ) +{ + $num = $db->num_rows(); + $i = 0; + print ''; + print ""; + print_liste_field_titre($langs->trans("Ref"),"index.php", "p.products_model"); + print_liste_field_titre("Titre","index.php", "pd.products_name"); + print ""; + print ''; + print ''; + print "\n"; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + $var=!$var; + + print ""; + print '"; + print '"; + + if ($objp->status == 1) + { + print ''; + print ''; + } + else + { + print ''; + print ''; + } + print ""; + print '"; + print '"; + print ""; + $i++; + } + print "
  FinPrix initialPrix remisé
'.$objp->products_model."'.$objp->products_name."actif'; + print ''; + print ''; + print ''; + print 'inactif".strftime("%d/%m/%Y", $objp->fin)."'.price($objp->products_price)."'.price($objp->specials_new_products_price)."
"; + $db->free(); +} +else +{ + print $db->error(); +} +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); + + +?> diff --git a/htdocs/boutique/promotion/pre.inc.php b/htdocs/boutique/promotion/pre.inc.php new file mode 100644 index 00000000000..b35a4c04141 --- /dev/null +++ b/htdocs/boutique/promotion/pre.inc.php @@ -0,0 +1,51 @@ + + * Copyright (C) 2006 Laurent Destailleur + * + * 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$ + * $Source$ + */ + +/** + \file htdocs/boutique/promotion/pre.inc.php + \ingroup boutique + \brief Fichier gestionnaire du menu gauche des promotions OSCommerce + \version $Revision$ +*/ + +require("../../main.inc.php"); +require("./promotion.class.php"); + +function llxHeader($head = "", $urlp = "") +{ + global $user, $conf; + + top_menu($head); + + $menu = new Menu(); + + $menu->add(DOL_URL_ROOT."/boutique/index.php", $langs->trans("OSCommerceShop")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/produits/osc-liste.php", $langs->trans("Products")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/index.php", $langs->trans("Critiques")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/critiques/bestproduct.php", "Meilleurs produits",2); + $menu->add_submenu(DOL_URL_ROOT."/boutique/promotion/index.php", $langs->trans("Promotion")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/client/", $langs->trans("Customers")); + $menu->add_submenu(DOL_URL_ROOT."/boutique/commande/", $langs->trans("Orders")); + + left_menu($menu->liste); +} +?> diff --git a/htdocs/boutique/promotion/promotion.class.php b/htdocs/boutique/promotion/promotion.class.php new file mode 100644 index 00000000000..86c0b66bf34 --- /dev/null +++ b/htdocs/boutique/promotion/promotion.class.php @@ -0,0 +1,178 @@ + + * + * 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$ + * $Source$ + * + */ + +class Promotion { + var $db ; + + var $id ; + var $parent_id ; + var $oscid ; + var $ref; + var $titre; + var $description; + var $price ; + var $status ; + + function Promotion($DB, $id=0) { + $this->db = $DB; + $this->id = $id ; + } + /* + * + * + * + */ + function create($user, $pid, $percent) { + + $sql = "SELECT products_price "; + $sql .= " FROM ".OSC_DB_NAME.".products as p"; + $sql .= " WHERE p.products_id = $pid"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_array(); + $this->price_init = $result["products_price"]; + } + + $newprice = 0.95 * $this->price_init; + + $date_exp = "2003-05-01"; + + $sql = "INSERT INTO ".OSC_DB_NAME.".specials "; + $sql .= " (products_id, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status) "; + $sql .= " VALUES ($pid, $newprice, now(),NULL,'$date_exp',NULL,1)"; + + if ($this->db->query($sql) ) + { + $id = $this->db->last_insert_id(OSC_DB_NAME.".specials"); + + return $id; + } + else + { + print $this->db->error() . ' in ' . $sql; + } + } + /* + * + * + * + */ + function update($id, $user) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."album "; + $sql .= " SET title = '" . trim($this->titre) ."'"; + $sql .= ",description = '" . trim($this->description) ."'"; + + $sql .= " WHERE rowid = " . $id; + + if ( $this->db->query($sql) ) { + return 1; + } else { + print $this->db->error() . ' in ' . $sql; + } + } + /* + * + * + * + */ + function set_active($id) + { + $sql = "UPDATE ".OSC_DB_NAME.".specials"; + $sql .= " SET status = 1"; + + $sql .= " WHERE products_id = " . $id; + + if ( $this->db->query($sql) ) { + return 1; + } else { + print $this->db->error() . ' in ' . $sql; + } + } + /* + * + */ + function set_inactive($id) + { + $sql = "UPDATE ".OSC_DB_NAME.".specials"; + $sql .= " SET status = 0"; + + $sql .= " WHERE products_id = " . $id; + + if ( $this->db->query($sql) ) { + return 1; + } else { + print $this->db->error() . ' in ' . $sql; + } + } + /* + * + * + * + */ + function fetch ($id) { + + $sql = "SELECT c.categories_id, cd.categories_name, c.parent_id"; + $sql .= " FROM ".OSC_DB_NAME.".categories as c,".OSC_DB_NAME.".categories_description as cd"; + $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID; + $sql .= " AND c.categories_id = $id"; + $result = $this->db->query($sql) ; + + if ( $result ) { + $result = $this->db->fetch_array(); + + $this->id = $result["categories_id"]; + $this->parent_id = $result["parent_id"]; + $this->name = $result["categories_name"]; + $this->titre = $result["title"]; + $this->description = $result["description"]; + $this->oscid = $result["osc_id"]; + } + $this->db->free(); + + return $result; + } + + + /* + * + * + */ + function delete($user) { + + $sql = "DELETE FROM ".OSC_DB_NAME.".products WHERE products_id = $idosc "; + + $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories WHERE products_id = $idosc"; + + $sql = "DELETE FROM ".OSC_DB_NAME.".products_description WHERE products_id = $idosc"; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."album WHERE rowid = $id"; + + + } + + +} +?>