[ 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/editeur/ -> editeur.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: editeur.class.php,v 1.8 2005/03/18 23:56:41 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/boutique/editeur/editeur.class.php,v $
  20   *
  21   */
  22  
  23  class Editeur {
  24    var $db ;
  25  
  26    var $id ;
  27    var $nom;
  28  
  29    function Editeur($DB, $id=0) {
  30      $this->db = $DB;
  31      $this->id = $id ;
  32    }  
  33    /*
  34     *
  35     *
  36     *
  37     */
  38    function create($user) {
  39  
  40      $sql = "INSERT INTO ".MAIN_DB_PREFIX."editeur (fk_user_author) VALUES (".$user->id.")";
  41      
  42      if ($this->db->query($sql) )
  43        {
  44      $id = $this->db->last_insert_id(MAIN_DB_PREFIX."editeur");
  45      
  46      if ( $this->update($id, $user) )
  47        {
  48          return $id;
  49        }
  50        }
  51      
  52    }
  53  
  54    /*
  55     *
  56     *
  57     */
  58    function liste_array ()
  59    {
  60      $ga = array();
  61  
  62      $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."editeur ORDER BY nom";
  63  
  64      if ($this->db->query($sql) )
  65        {
  66      $nump = $this->db->num_rows();
  67      
  68      if ($nump)
  69        {
  70          $i = 0;
  71          while ($i < $nump)
  72            {
  73          $obj = $this->db->fetch_object();
  74          
  75          $ga[$obj->rowid] = $obj->nom;
  76          $i++;
  77            }
  78        }
  79      return $ga;
  80        }
  81      else
  82        {
  83      print $this->db->error();
  84        }
  85      
  86    }
  87    /*
  88     *
  89     *
  90     *
  91     */
  92    function update($id, $user)
  93    {
  94  
  95      $sql = "UPDATE ".MAIN_DB_PREFIX."editeur ";
  96      $sql .= " SET nom = '" . trim($this->nom) ."'";
  97  
  98      $sql .= " WHERE rowid = " . $id;
  99  
 100      if ( $this->db->query($sql) ) {
 101        return 1;
 102      } else {
 103        print $this->db->error() . ' in ' . $sql;
 104      }
 105    }
 106    /*
 107     *
 108     *
 109     *
 110     */
 111    function fetch ($id) {
 112      
 113      $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."editeur WHERE rowid = $id";
 114  
 115      $result = $this->db->query($sql) ;
 116  
 117      if ( $result )
 118        {
 119      $result = $this->db->fetch_array();
 120  
 121      $this->id      = $result["rowid"];
 122      $this->nom     = stripslashes($result["nom"]);
 123      
 124      $this->db->free();
 125        }
 126      else
 127        {
 128      print $this->db->error();
 129        }
 130      
 131      return $result;
 132    }
 133    /*
 134     *
 135     *
 136     *
 137     */
 138    function liste_livre()
 139    {
 140      $ga = array();
 141  
 142      $sql = "SELECT a.rowid, a.title FROM ".MAIN_DB_PREFIX."livre as a";
 143      $sql .= " WHERE a.fk_editeur = ".$this->id;
 144      $sql .= " ORDER BY a.title";
 145  
 146      if ($this->db->query($sql) )
 147        {
 148      $nump = $this->db->num_rows();
 149      
 150      if ($nump)
 151        {
 152          $i = 0;
 153          while ($i < $nump)
 154            {
 155          $obj = $this->db->fetch_object();
 156          
 157          $ga[$obj->rowid] = $obj->title;
 158          $i++;
 159            }
 160        }
 161      return $ga;
 162        }
 163      else
 164        {
 165      print $this->db->error();
 166        }    
 167    }
 168    /*
 169     *
 170     *
 171     */
 172    function delete() {
 173  
 174      $livres = $this->liste_livre();
 175  
 176      if (sizeof($livres) == 0)
 177        {
 178      $sql = "DELETE FROM ".MAIN_DB_PREFIX."editeur WHERE rowid = $this->id ";
 179      $return = $this->db->query($sql) ;
 180        }
 181  
 182  
 183    }
 184  }
 185  ?>


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