[ 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/album/ -> album.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: album.class.php,v 1.8 2005/07/09 14:34:44 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/product/album/album.class.php,v $
  20   *
  21   */
  22  
  23  class Album {
  24    var $db ;
  25  
  26    var $id ;
  27    var $oscid ;
  28    var $ref;
  29    var $annee;
  30    var $titre;
  31    var $description;
  32    var $price ;
  33    var $status ;
  34  
  35    function Album($DB, $id=0) {
  36      $this->db = $DB;
  37      $this->id   = $id ;
  38    }  
  39    /*
  40     *
  41     *
  42     *
  43     */
  44    function create($user) {
  45  
  46      if (strlen($this->annee))
  47        {
  48      $this->annee = 0;
  49        }
  50  
  51      $sql = "INSERT INTO ".OSC_DB_NAME.".products (products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_date_added) ";
  52      $sql .= "VALUES ('', '', 'Array', '', null, '', '0', '0', '8', now())";
  53  
  54      if ($this->db->query($sql) )
  55        {
  56      $idosc = $this->db->last_insert_id(OSC_DB_NAME.".products");
  57  
  58      $sql = "INSERT INTO ".OSC_DB_NAME.".products_to_categories (products_id, categories_id) VALUES ($idosc, 0)";
  59  
  60      if ($this->db->query($sql) )
  61        {
  62  
  63          $sql = "INSERT INTO ".OSC_DB_NAME.".products_description (products_name, products_description, products_url, products_id, language_id) VALUES ('".trim($this->titre)."', '".trim($this->description)."', '', $idosc, '1')";
  64          
  65          if ($this->db->query($sql) )        
  66            {
  67  
  68          $sql = "INSERT INTO ".MAIN_DB_PREFIX."album (osc_id, fk_user_author) VALUES ($idosc, ".$user->id.")";
  69          
  70          if ($this->db->query($sql) )
  71            {
  72              $id = $this->db->last_insert_id(MAIN_DB_PREFIX."album");
  73              
  74              if ( $this->update($id, $user) )
  75                {
  76              return $id;
  77                }
  78            }
  79          else
  80            {
  81              print $this->db->error() . ' in ' . $sql;
  82            }
  83          
  84            }
  85          else
  86            {
  87          print $this->db->error() . ' in ' . $sql;
  88            }
  89          
  90        }
  91      else
  92        {
  93          print $this->db->error() . ' in ' . $sql;
  94        }
  95      
  96        }
  97      else
  98        {
  99      print $this->db->error() . ' in ' . $sql;
 100        }
 101      
 102    }
 103  
 104    /*
 105     *
 106     *
 107     *
 108     */
 109    function linkga($id, $gaid)
 110    {
 111  
 112      $sql = "INSERT INTO ".MAIN_DB_PREFIX."album_to_groupart (fk_album, fk_groupart) VALUES ($id, $gaid)";
 113  
 114      if ( $this->db->query($sql) ) {
 115        return 1;
 116      } else {
 117        print $this->db->error() . ' in ' . $sql;
 118      }
 119    }
 120    /*
 121     *
 122     *
 123     */
 124    function liste_groupart()
 125    {
 126      $ga = array();
 127  
 128      $sql = "SELECT g.rowid, g.nom FROM ".MAIN_DB_PREFIX."groupart as g, ".MAIN_DB_PREFIX."album_to_groupart as l";
 129      $sql .= " WHERE g.rowid = l.fk_groupart AND l.fk_album = ".$this->id;
 130      $sql .= " ORDER BY g.nom";
 131  
 132      $result=$this->db->query($sql);
 133      if ($result)
 134        {
 135      $nump = $this->db->num_rows($result);
 136      
 137      if ($nump)
 138        {
 139          $i = 0;
 140          while ($i < $nump)
 141            {
 142          $obj = $this->db->fetch_object($result);
 143          
 144          $ga[$obj->rowid] = $obj->nom;
 145          $i++;
 146            }
 147            $this->db->free($result);
 148        }
 149      return $ga;
 150        }
 151      else
 152        {
 153          print $this->db->error();
 154          return -1;
 155        }    
 156    }
 157    /*
 158     *
 159     *
 160     *
 161     */
 162    function updateosc()
 163    {
 164  
 165      $sql = "UPDATE ".OSC_DB_NAME.".products_description ";
 166  
 167      $sql .= " SET products_name = '".$this->titre."'";
 168  
 169      $desc .= '<br>Info supplémentaires';
 170      $ga = array();
 171      $ga = $this->liste_groupart();
 172      if (sizeof($ga) == 1)
 173      {
 174        foreach ($ga as $key => $value)
 175      {
 176        $gaid = $key;
 177      }
 178  
 179  
 180        $groupart = new Groupart($this->db);
 181        $result = $groupart->fetch($gaid);
 182  
 183        if ( $result )
 184      { 
 185  
 186        $desc = $groupart->nom."<p>";
 187  
 188        $desc .= addslashes($this->description);
 189        
 190        $desc .= "<p><b>Autres albums</b> : ";
 191  
 192        $gas = $groupart->liste_albums();
 193        $i = 0;
 194        $sizegas = sizeof($gas) - 1;
 195        foreach ($gas as $key => $value)
 196          {
 197            if ($key <> $this->id)
 198          {
 199  
 200            $otha = new Album($this->db);
 201            $otha->fetch($key);
 202  
 203            $desc .= '<a href="'.OSC_CATALOG_URL.'product_info.php?products_id='.$otha->oscid.'">'.$value."</a>";
 204            $i++; 
 205            if ($sizegas > $i)
 206              {
 207                $desc .= ", ";
 208              }
 209          }
 210          }
 211      }
 212      }
 213  
 214  
 215      $sql .= ", products_description = '$desc'";
 216  
 217      $sql .= " WHERE products_id = " . $this->oscid;
 218  
 219      if ( $this->db->query($sql) ) {
 220        return 1;
 221      } else {
 222        print $this->db->error() . ' in ' . $sql;
 223      }
 224    }
 225    /*
 226     *
 227     *
 228     *
 229     */
 230    function update($id, $user)
 231    {
 232  
 233      if (strlen($this->annee)==0)
 234        {
 235      $this->annee = 0;
 236        }
 237  
 238      $sql = "UPDATE ".MAIN_DB_PREFIX."album ";
 239      $sql .= " SET title = '" . trim($this->titre) ."'";
 240      $sql .= ", ref = '" . trim(strtoupper($this->ref)) ."'";
 241      $sql .= ", annee = " . $this->annee ;
 242      $sql .= ",description = '" . trim($this->description) ."'";
 243  
 244      $sql .= " WHERE rowid = " . $id;
 245  
 246      if ( $this->db->query($sql) ) {
 247        return 1;
 248      } else {
 249        print $this->db->error() . ' in ' . $sql;
 250      }
 251    }
 252    /*
 253     *
 254     *
 255     *
 256     */
 257    function fetch ($id) {
 258      
 259      $sql = "SELECT rowid, ref, annee, osc_id, title, description FROM ".MAIN_DB_PREFIX."album WHERE rowid = $id";
 260  
 261      $result = $this->db->query($sql) ;
 262  
 263      if ( $result )
 264        {
 265      $result = $this->db->fetch_array();
 266  
 267      $this->id          = $result["rowid"];
 268      $this->ref         = $result["ref"];
 269      $this->annee       = $result["annee"];
 270      $this->titre       = $result["title"];
 271      $this->description = $result["description"];
 272      $this->oscid       = $result["osc_id"];
 273      
 274      $this->db->free();
 275  
 276  
 277      $sql = "SELECT products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_date_added";
 278      $sql .= " FROM  ".OSC_DB_NAME.".products WHERE products_id = " . $this->oscid;
 279      
 280      $result = $this->db->query($sql) ;
 281      
 282      if ( $result )
 283        {
 284          $result = $this->db->fetch_array();
 285          
 286          $this->status = $result["products_status"];
 287          $this->price  = $result["products_price"];
 288  
 289          $this->db->free();
 290        }
 291      else
 292        {
 293          print $this->db->error();
 294        }
 295        }
 296      else
 297        {
 298      print $this->db->error();
 299        }
 300      
 301      return $result;
 302    }
 303  
 304  
 305    /*
 306     *
 307     *
 308     */
 309    function delete($user) {
 310  
 311      $sql = "DELETE FROM ".OSC_DB_NAME.".products WHERE products_id = $idosc ";
 312  
 313      $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories WHERE products_id = $idosc";
 314  
 315      $sql = "DELETE FROM ".OSC_DB_NAME.".products_description WHERE products_id = $idosc";
 316            
 317      $sql = "DELETE FROM ".MAIN_DB_PREFIX."album WHERE rowid = $id";
 318          
 319      
 320    }
 321  
 322  
 323  }
 324  ?>


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