[ 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/boutique/livre/ -> livre.class.php (source)

   1  <?php
   2  /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2003 Éric Seigne <erics@rycks.com>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License
  16   * along with this program; if not, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: livre.class.php,v 1.32 2005/07/09 14:34:44 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/boutique/livre/livre.class.php,v $
  21   *
  22   */
  23  
  24  class Livre {
  25    var $db ;
  26  
  27    var $id ;
  28    var $oscid ;
  29    var $ref;
  30    var $price;
  31    var $annee;
  32    var $editeurid;
  33    var $titre;
  34    var $image;
  35    var $description;
  36    var $price ;
  37    var $status ;
  38  
  39    function Livre($DB, $id=0) {
  40      $this->db = $DB;
  41      $this->id   = $id ;
  42    }  
  43    /*
  44     *
  45     *
  46     *
  47     */
  48    function create($user) {
  49  
  50      if (strlen($this->annee))
  51        {
  52      $this->annee = 0;
  53        }
  54  
  55      $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) ";
  56      $sql .= "VALUES ('', '', 'Array', '', null, '', '0', '0', '8', now())";
  57  
  58      if ($this->db->query($sql) )
  59        {
  60      $idosc = $this->db->last_insert_id(OSC_DB_NAME.".products");
  61  
  62      $sql = "INSERT INTO ".OSC_DB_NAME.".products_to_categories (products_id, categories_id) VALUES ($idosc, 0)";
  63  
  64      if ($this->db->query($sql) )
  65        {
  66  
  67          $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, '".OSC_LANGUAGE_ID."')";
  68          
  69          if ($this->db->query($sql) )        
  70            {
  71  
  72          $sql = "INSERT INTO ".MAIN_DB_PREFIX."livre (oscid, fk_user_author, date_ajout) VALUES ($idosc, ".$user->id.", now())";
  73          
  74          if ($this->db->query($sql) )
  75            {
  76              $id = $this->db->last_insert_id(MAIN_DB_PREFIX."livre");
  77              
  78              if ( $this->update($id, $user) )
  79                {
  80              return $id;
  81                }
  82            }
  83          else
  84            {
  85              print $this->db->error() . ' in ' . $sql;
  86            }
  87          
  88            }
  89          else
  90            {
  91          print $this->db->error() . ' in ' . $sql;
  92            }
  93          
  94        }
  95      else
  96        {
  97          print $this->db->error() . ' in ' . $sql;
  98        }
  99      
 100        }
 101      else
 102        {
 103      print $this->db->error() . ' in ' . $sql;
 104        }
 105      
 106    }
 107  
 108    /*
 109     *
 110     *
 111     *
 112     */
 113    function linkga($id, $gaid)
 114    {
 115  
 116      $sql = "INSERT INTO ".MAIN_DB_PREFIX."livre_to_auteur (fk_livre, fk_auteur) VALUES ($id, $gaid)";
 117  
 118      if ( $this->db->query($sql) )
 119        {      
 120      return 1;
 121        }
 122      else
 123        {
 124      print $this->db->error() . ' in ' . $sql;
 125        }
 126    }
 127    /*
 128     *
 129     *
 130     */
 131    function liste_auteur()
 132    {
 133      $ga = array();
 134  
 135      $sql = "SELECT a.rowid, a.nom FROM ".MAIN_DB_PREFIX."auteur as a, ".MAIN_DB_PREFIX."livre_to_auteur as l";
 136      $sql .= " WHERE a.rowid = l.fk_auteur AND l.fk_livre = ".$this->id;
 137      $sql .= " ORDER BY a.nom";
 138  
 139      if ($this->db->query($sql) )
 140        {
 141      $nump = $this->db->num_rows();
 142      
 143      if ($nump)
 144        {
 145          $i = 0;
 146          while ($i < $nump)
 147            {
 148          $obj = $this->db->fetch_object();
 149          
 150          $ga[$obj->rowid] = $obj->nom;
 151          $i++;
 152            }
 153        }
 154      return $ga;
 155        }
 156      else
 157        {
 158      print $this->db->error();
 159        }    
 160    }
 161    /*
 162     *
 163     *
 164     */
 165    function auteur_unlink($auteur_id)
 166    {
 167  
 168      $sql = "DELETE FROM ".MAIN_DB_PREFIX."livre_to_auteur ";
 169  
 170      $sql .= " WHERE fk_livre=".$this->id;
 171      $sql .= " AND fk_auteur=".$auteur_id;
 172  
 173      if ( $this->db->query($sql) )
 174        {
 175      return 1;
 176        }
 177      else
 178        {
 179      print $this->db->error() . ' in ' . $sql;
 180        }
 181      }
 182    /*
 183     *
 184     *
 185     */
 186    function unlinkcategorie($categories_id)
 187    {
 188  
 189      $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories ";
 190  
 191      $sql .= " WHERE products_id=".$this->oscid;
 192      $sql .= " AND categories_id=".$categories_id;
 193  
 194      if ( $this->db->query($sql) )
 195        {
 196      return 1;
 197        }
 198      else
 199        {
 200      print $this->db->error() . ' in ' . $sql;
 201        }
 202      }
 203    /*
 204     *
 205     *
 206     */
 207    function linkcategorie($categories_id)
 208    {
 209  
 210      $sql = "INSERT INTO ".OSC_DB_NAME.".products_to_categories ";
 211  
 212      $sql .= " (products_id, categories_id)";
 213      $sql .= " VALUES (".$this->oscid.",".$categories_id.")";
 214  
 215      if ( $this->db->query($sql) )
 216        {
 217      return 1;
 218        }
 219      else
 220        {
 221      print $this->db->error() . ' in ' . $sql;
 222        }
 223      }
 224    /*
 225     *
 226     *
 227     */
 228    function listcategorie()
 229    {
 230      global $conf;
 231  
 232      $listecat = new Categorie($this->db);
 233      $cats = $listecat->liste_array();
 234  
 235      $pcat = array();
 236  
 237      $sql = "SELECT products_id, categories_id";
 238      $sql .= " FROM ".OSC_DB_NAME.".products_to_categories ";
 239      $sql .= " WHERE products_id = " . $this->oscid;
 240  
 241      if ($this->db->query($sql) )
 242        {
 243      $nump = $this->db->num_rows();
 244      
 245      if ($nump)
 246        {
 247          $i = 0;
 248          while ($i < $nump)
 249            {
 250          $obj = $this->db->fetch_object();           
 251          $pcat[$i] = $obj->categories_id;
 252          $i++;
 253            }
 254        }
 255        }
 256      
 257        foreach ($cats as $key => $value)
 258      {
 259        $test = 0;
 260        for ($i = 0 ; $i < $nump ; $i++)
 261          {
 262            if ($pcat[$i] == $key)
 263          {
 264            $test = 1;
 265          }
 266          }
 267        if ($test)
 268          {
 269            print '<a href="'.DOL_URL_ROOT.'/boutique/livre/fiche.php?id='.$this->id.'&action=delcat&catid='.$key.'">';
 270            print '<img src="/theme/'.$conf->theme.'/img/editdelete.png" height="16" width="16" alt="Supprimer" border="0">';
 271            print "</a><b>$value</b><br>";
 272          }
 273        else
 274          {
 275            print '<img src="/theme/'.$conf->theme.'/img/transparent.png" height="16" width="16" alt="Supprimer" border="0">';
 276            print "$value<br>";
 277          }
 278      }
 279    }
 280    /*
 281     *
 282     *
 283     */
 284    function update_status($status)
 285    {
 286      $sql = "UPDATE ".OSC_DB_NAME.".products ";
 287      $sql .= " SET products_status = ".$status;
 288      $sql .= " WHERE products_id = " . $this->oscid;
 289  
 290      if ( $this->db->query($sql) )
 291        {
 292      $sql = "UPDATE ".MAIN_DB_PREFIX."livre ";
 293      $sql .= " SET status = ".$status;
 294      $sql .= " WHERE rowid = " . $this->id;
 295      
 296      if ( $this->db->query($sql) )
 297        {
 298          return 1;
 299        }
 300  
 301        }
 302      else
 303        {
 304      print $this->db->error() . ' in ' . $sql;
 305        }
 306    }
 307    /*
 308     *
 309     *
 310     *
 311     */
 312    function updateosc($noupdate_other=0)
 313    {
 314      $desc = trim(addslashes($this->description));
 315      $desc .= "<p>";
 316  
 317      $auteurs = array();
 318      $auteurs = $this->liste_auteur();
 319  
 320  
 321      if (sizeof($auteurs)>0)
 322        {
 323      $desc .= 'Auteur(s) : <ul>';
 324  
 325      reset($auteurs);
 326      foreach ($auteurs as $key => $value)
 327        {
 328          $auteursid = $key;
 329          $auteur = new Auteur($this->db);
 330          $result = $auteur->fetch($auteursid);
 331          
 332          if ( $result )
 333            { 
 334          $livraut = array();
 335          $livraut = $auteur->liste_livre('oscid', 1);
 336  
 337          $desc .= '<li>'.addslashes($auteur->nom);
 338  
 339          if (sizeof($livraut) > 1)
 340            {
 341              
 342              $desc .= " : ";
 343              
 344              foreach ($livraut as $lakey => $lavalue)
 345                {
 346              if ($lakey <> $this->oscid)
 347                {
 348                  if (!$noupdate_other)
 349                    {
 350                  $lix = new Livre($this->db);
 351                  $lix->fetch(0, $lakey);
 352                  $lix->updateosc(1);
 353                    }
 354  
 355                  $desc .= '<a href="product_info.php?products_id='.$lakey.'">'.addslashes($lavalue) . "</a> ";
 356                }
 357                }
 358            }
 359  
 360          $desc .= "</li>";
 361            }
 362        }
 363      $desc .= "</ul>";
 364        }
 365      else
 366        {
 367  
 368        }
 369  
 370  
 371      $desc .= '<br>Année de parution : '.$this->annee;
 372  
 373  
 374      $editeur = new Editeur($this->db);
 375      $result = $editeur->fetch($this->editeurid);
 376      if (result)
 377        {
 378      $desc .= '<br>Editeur : ' . addslashes($editeur->nom);
 379        }
 380  
 381  
 382      $sql = "UPDATE ".OSC_DB_NAME.".products_description ";
 383  
 384      $sql .= " SET products_name = '".addslashes($this->titre)."'";
 385  
 386      $sql .= ", products_description = '$desc'";
 387  
 388      $sql .= " WHERE products_id = " . $this->oscid;
 389  
 390      $this->image = $this->ref.".jpg";
 391  
 392      if(! file_exists(OSC_CATALOG_DIRECTORY."images/".$this->ref.".jpg"))
 393        {
 394      $this->image = OSC_IMAGE_DEFAULT;
 395        }
 396  
 397      if ( $this->db->query($sql) )
 398        {
 399      $sql = "UPDATE ".OSC_DB_NAME.".products ";
 400      $sql .= "SET products_model = '".$this->ref."'";
 401      $sql .= ", products_image = '".$this->image."'";
 402      $sql .= ", products_price = ".ereg_replace(",",".",$this->price)."";
 403      if ($this->frais_de_port)
 404        {
 405          $sql .= ", products_weight = ".ereg_replace(",",".",$this->price)."";
 406        }
 407      else
 408        {
 409          $sql .= ", products_weight = -1";
 410        }
 411  
 412      $sql .= " WHERE products_id = " . $this->oscid;
 413  
 414      if ( $this->db->query($sql) )
 415        {
 416          return 1;
 417        }
 418      else
 419        {
 420          print $this->db->error() . ' in <br />' . $sql;
 421        }
 422        }
 423      else
 424        {
 425      print $this->db->error() . ' in ' . $sql;
 426        }
 427    }
 428    /*
 429     *
 430     *
 431     */
 432  
 433    /*
 434     *
 435     *
 436     */
 437    function update($id, $user)
 438    {
 439  
 440      if (strlen($this->annee)==0)
 441        {
 442      $this->annee = 0;
 443        }
 444  
 445      $sql = "UPDATE ".MAIN_DB_PREFIX."livre ";
 446      $sql .= " SET title = '" . trim($this->titre) ."'";
 447      $sql .= ", ref = '" . trim($this->ref) ."'";
 448      $sql .= ", prix = " . ereg_replace(",",".",$this->price)."";
 449      $sql .= ", annee = " . $this->annee ;
 450      $sql .= ", fk_editeur = " . $this->editeurid ;
 451      $sql .= ", description = '" . trim($this->description) ."'";
 452      $sql .= ", frais_de_port = " . $this->frais_de_port ."";
 453  
 454      $sql .= " WHERE rowid = " . $id;
 455  
 456      if ( $this->db->query($sql) )
 457        {
 458      return 1;
 459        }
 460      else
 461        {
 462      print $this->db->error() . ' in ' . $sql;
 463        }
 464    }
 465    /*
 466     *
 467     *
 468     *
 469     */
 470    function fetch ($id, $oscid=0) {
 471      
 472      $sql = "SELECT rowid, fk_editeur, ref, prix, annee, oscid, title, description, frais_de_port FROM ".MAIN_DB_PREFIX."livre";
 473      if ($id)
 474        {
 475      $sql .= " WHERE rowid = $id";
 476        }
 477      if ($oscid)
 478        {
 479      $sql .= " WHERE oscid = $oscid";
 480        }
 481  
 482      $result = $this->db->query($sql) ;
 483  
 484      if ( $result )
 485        {
 486      $result = $this->db->fetch_array();
 487  
 488      $this->id            = $result["rowid"];
 489      $this->ref           = $result["ref"];
 490      $this->price         = $result["prix"];
 491      $this->frais_de_port = $result["frais_de_port"];
 492      $this->annee         = $result["annee"];
 493      $this->editeurid     = $result["fk_editeur"];
 494      $this->titre         = stripslashes($result["title"]);
 495      $this->description   = stripslashes($result["description"]);
 496      $this->oscid         = $result["oscid"];
 497      
 498      $this->db->free();
 499  
 500  
 501      $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";
 502      $sql .= " FROM  ".OSC_DB_NAME.".products WHERE products_id = " . $this->oscid;
 503      
 504      $result = $this->db->query($sql) ;
 505      
 506      if ( $result )
 507        {
 508          $result = $this->db->fetch_array();
 509          
 510          $this->status = $result["products_status"];
 511          $this->image  = $result["products_image"];
 512  
 513          if ($this->status)
 514            {
 515          $this->status_text = "En vente";
 516            }
 517          else
 518            {
 519          $this->status_text = "Cet article n'est pas en vente";
 520            }
 521  
 522          $this->db->free();
 523        }
 524      else
 525        {
 526          print $this->db->error();
 527        }
 528        }
 529      else
 530        {
 531      print $this->db->error();
 532        }
 533      
 534      return $result;
 535    }
 536    /*
 537     *
 538     *
 539     */
 540    function update_image($file_name)
 541    {
 542      $sql = "UPDATE ".OSC_DB_NAME.".products SET products_image='".$file_name."'";
 543      $sql .= " WHERE products_id = " . $this->oscid;
 544      
 545      $result = $this->db->query($sql) ;
 546      
 547      if ( $result )
 548        {
 549        }
 550    }
 551  
 552    /*
 553     *
 554     *
 555     */
 556    function delete()
 557    {    
 558      $sql = "DELETE FROM ".OSC_DB_NAME.".products WHERE products_id = ".$this->oscid;
 559      $result = $this->db->query($sql) ;
 560      $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories WHERE products_id = ".$this->oscid;
 561      $result = $this->db->query($sql) ;
 562      $sql = "DELETE FROM ".OSC_DB_NAME.".products_description WHERE products_id = ".$this->oscid;
 563      $result = $this->db->query($sql) ;
 564      $sql = "DELETE FROM ".MAIN_DB_PREFIX."livre WHERE rowid = ".$this->id;
 565      $result = $this->db->query($sql) ;
 566    }
 567  
 568  
 569  }
 570  ?>


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