[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/product/promotion/ -> promotion.class.php (source)

   1  <?php
   2  /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: promotion.class.php,v 1.7 2005/07/09 14:34:44 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/product/promotion/promotion.class.php,v $
  20   *
  21   */
  22  
  23  class Promotion {
  24    var $db ;
  25  
  26    var $id ;
  27    var $parent_id ;
  28    var $oscid ;
  29    var $ref;
  30    var $titre;
  31    var $description;
  32    var $price ;
  33    var $status ;
  34  
  35    function Promotion($DB, $id=0) {
  36      $this->db = $DB;
  37      $this->id   = $id ;
  38    }  
  39    /*
  40     *
  41     *
  42     *
  43     */
  44    function create($user, $pid, $percent) {
  45  
  46      $sql = "SELECT products_price ";
  47      $sql .= " FROM ".OSC_DB_NAME.".products as p";
  48      $sql .= " WHERE p.products_id = $pid";
  49  
  50      $result = $this->db->query($sql) ;
  51  
  52      if ( $result )
  53        {
  54      $result = $this->db->fetch_array();
  55      $this->price_init = $result["products_price"];
  56        }
  57  
  58      $newprice = 0.95 * $this->price_init;
  59  
  60      $date_exp = "2003-05-01";
  61  
  62      $sql = "INSERT INTO ".OSC_DB_NAME.".specials ";
  63      $sql .= " (products_id, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status) ";
  64      $sql .= " VALUES ($pid, $newprice, now(),NULL,'$date_exp',NULL,1)";
  65  
  66      if ($this->db->query($sql) )
  67        {
  68      $id = $this->db->last_insert_id(OSC_DB_NAME.".specials");
  69      
  70      return $id;
  71        }
  72      else
  73        {
  74      print $this->db->error() . ' in ' . $sql;
  75        }    
  76    }
  77    /*
  78     *
  79     *
  80     *
  81     */
  82    function update($id, $user)
  83    {
  84      $sql = "UPDATE ".MAIN_DB_PREFIX."album ";
  85      $sql .= " SET title = '" . trim($this->titre) ."'";
  86      $sql .= ",description = '" . trim($this->description) ."'";
  87  
  88      $sql .= " WHERE rowid = " . $id;
  89  
  90      if ( $this->db->query($sql) ) {
  91        return 1;
  92      } else {
  93        print $this->db->error() . ' in ' . $sql;
  94      }
  95    }
  96    /*
  97     *
  98     *
  99     *
 100     */
 101    function set_active($id)
 102    {
 103      $sql = "UPDATE ".OSC_DB_NAME.".specials";
 104      $sql .= " SET status = 1";
 105  
 106      $sql .= " WHERE products_id = " . $id;
 107  
 108      if ( $this->db->query($sql) ) {
 109        return 1;
 110      } else {
 111        print $this->db->error() . ' in ' . $sql;
 112      }
 113    }  
 114    /*
 115     *
 116     */
 117    function set_inactive($id)
 118    {
 119      $sql = "UPDATE ".OSC_DB_NAME.".specials";
 120      $sql .= " SET status = 0";
 121  
 122      $sql .= " WHERE products_id = " . $id;
 123  
 124      if ( $this->db->query($sql) ) {
 125        return 1;
 126      } else {
 127        print $this->db->error() . ' in ' . $sql;
 128      }
 129    }  
 130    /*
 131     *
 132     *
 133     *
 134     */
 135    function fetch ($id) {
 136      
 137      $sql = "SELECT c.categories_id, cd.categories_name, c.parent_id";
 138      $sql .= " FROM ".OSC_DB_NAME.".categories as c,".OSC_DB_NAME.".categories_description as cd";
 139      $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
 140      $sql .= " AND c.categories_id = $id";
 141      $result = $this->db->query($sql) ;
 142  
 143      if ( $result ) {
 144        $result = $this->db->fetch_array();
 145  
 146        $this->id          = $result["categories_id"];
 147        $this->parent_id   = $result["parent_id"];
 148        $this->name        = $result["categories_name"];
 149        $this->titre       = $result["title"];
 150        $this->description = $result["description"];
 151        $this->oscid       = $result["osc_id"];
 152      }
 153      $this->db->free();
 154  
 155      return $result;
 156    }
 157  
 158  
 159    /*
 160     *
 161     *
 162     */
 163    function delete($user) {
 164  
 165      $sql = "DELETE FROM ".OSC_DB_NAME.".products WHERE products_id = $idosc ";
 166  
 167      $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories WHERE products_id = $idosc";
 168  
 169      $sql = "DELETE FROM ".OSC_DB_NAME.".products_description WHERE products_id = $idosc";
 170            
 171      $sql = "DELETE FROM ".MAIN_DB_PREFIX."album WHERE rowid = $id";
 172          
 173      
 174    }
 175  
 176  
 177  }
 178  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics