[ 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/categorie/ -> categorie.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: categorie.class.php,v 1.9 2005/07/09 14:34:44 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/product/categorie/categorie.class.php,v $
  20   *
  21   */
  22  
  23  class Categorie {
  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 Categorie($DB, $id=0) {
  36      $this->db = $DB;
  37      $this->id   = $id ;
  38    }  
  39    /*
  40     *
  41     *
  42     *
  43     */
  44    function create($user) {
  45  
  46      $sql = "INSERT INTO ".MAIN_DB_PREFIX."album (osc_id, fk_user_author) VALUES ($idosc, ".$user->id.")";
  47      
  48      if ($this->db->query($sql) )
  49        {
  50      $id = $this->db->last_insert_id(MAIN_DB_PREFIX."album");
  51      
  52      if ( $this->update($id, $user) )
  53        {
  54          return $id;
  55        }
  56        }
  57      else
  58        {
  59      print $this->db->error() . ' in ' . $sql;
  60        }    
  61    }
  62  
  63    /*
  64     *
  65     *
  66     *
  67     */
  68    function linkga($id, $gaid)
  69    {
  70  
  71      $sql = "INSERT INTO ".MAIN_DB_PREFIX."album_to_groupart (fk_album, fk_groupart) values ($id, $gaid)";
  72  
  73      if ( $this->db->query($sql) ) {
  74        return 1;
  75      } else {
  76        print $this->db->error() . ' in ' . $sql;
  77      }
  78    }
  79    /*
  80     *
  81     *
  82     */
  83    function liste_array()
  84    {
  85      $cl = array();
  86  
  87      $sql = "SELECT c.categories_id, cd.categories_name ";
  88      $sql .= " FROM ".OSC_DB_NAME.".categories as c,".OSC_DB_NAME.".categories_description as cd";
  89      $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
  90      $sql .= " AND c.parent_id = 0 ORDER BY cd.categories_name";
  91      
  92      if ( $this->db->query($sql) )
  93        {
  94      $num = $this->db->num_rows();
  95      $i = 0;
  96      
  97      while ($i < $num)
  98        {
  99          $objp = $this->db->fetch_object( $i);
 100  
 101          $cl[$objp->categories_id] = $objp->categories_name;
 102  
 103          $var=!$var;
 104          $pc = array();
 105          $pc = $this->printc($objp->categories_id, 1);
 106          foreach($pc as $key => $value)
 107            {
 108          $cl[$key] = $value;
 109            } 
 110          $i++;
 111        }
 112        }
 113      return $cl;
 114    }
 115    /*
 116     *
 117     */
 118    function printc($id, $level)
 119    {
 120      $cr = array();
 121      $cat = new Categorie($this->db);
 122      $cat->fetch($id);
 123      
 124      for ($i = 0 ; $i < $level ; $i++)
 125        {
 126      $prefix .= "&nbsp;";
 127        }
 128      
 129      $cr[$cat->id] = $cat->name;
 130      
 131      $childs = array();
 132      $childs = $cat->liste_childs_array();
 133  
 134      if (sizeof($childs))
 135        {
 136      foreach($childs as $key => $value)
 137        {
 138          $pc = array();
 139          $pc = $this->printc($key,$level+1);
 140          foreach($pc as $key => $value)
 141            {
 142          $cr[$key] = $prefix . $value;
 143            } 
 144        }
 145        }
 146      return $cr;
 147    }
 148    
 149    /*
 150     *
 151     *
 152     */
 153    function liste_childs_array()
 154    {
 155      $ga = array();
 156  
 157      $sql = "SELECT c.categories_id, cd.categories_name";
 158      $sql .= " FROM ".OSC_DB_NAME.".categories as c,".OSC_DB_NAME.".categories_description as cd";
 159      $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
 160      $sql .= " AND c.parent_id = " . $this->id;
 161      $sql .= " ORDER BY cd.categories_name";
 162      
 163      $result=$this->db->query($sql);
 164      if ($result)
 165        {
 166      $nump = $this->db->num_rows($result);
 167      
 168      if ($nump)
 169        {
 170          $i = 0;
 171          while ($i < $nump)
 172            {
 173          $obj = $this->db->fetch_object($result);
 174          
 175          $ga[$obj->categories_id] = $obj->categories_name;
 176          $i++;
 177            }
 178          $this->db->free($result);
 179        }
 180      return $ga;
 181        }
 182      else
 183        {
 184      print $this->db->error();
 185      return -1;
 186        }    
 187    }
 188  
 189    /*
 190     *
 191     *
 192     *
 193     */
 194    function update($id, $user)
 195   {
 196  
 197      $sql = "UPDATE ".MAIN_DB_PREFIX."album ";
 198      $sql .= " SET title = '" . trim($this->titre) ."'";
 199      $sql .= ",description = '" . trim($this->description) ."'";
 200  
 201      $sql .= " WHERE rowid = " . $id;
 202  
 203      if ( $this->db->query($sql) ) {
 204        return 1;
 205      } else {
 206        print $this->db->error() . ' in ' . $sql;
 207      }
 208    }
 209    /*
 210     *
 211     *
 212     *
 213     */
 214    function fetch ($id) {
 215      
 216      $sql = "SELECT c.categories_id, cd.categories_name, c.parent_id";
 217      $sql .= " FROM ".OSC_DB_NAME.".categories as c,".OSC_DB_NAME.".categories_description as cd";
 218      $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".OSC_LANGUAGE_ID;
 219      $sql .= " AND c.categories_id = $id";
 220      $result = $this->db->query($sql) ;
 221  
 222      if ( $result ) {
 223        $result = $this->db->fetch_array();
 224  
 225        $this->id          = $result["categories_id"];
 226        $this->parent_id   = $result["parent_id"];
 227        $this->name        = $result["categories_name"];
 228        $this->titre       = $result["title"];
 229        $this->description = $result["description"];
 230        $this->oscid       = $result["osc_id"];
 231      }
 232      $this->db->free();
 233  
 234      return $result;
 235    }
 236  
 237  
 238    /*
 239     *
 240     *
 241     */
 242    function delete($user) {
 243  
 244      $sql = "DELETE FROM ".OSC_DB_NAME.".products WHERE products_id = $idosc ";
 245  
 246      $sql = "DELETE FROM ".OSC_DB_NAME.".products_to_categories WHERE products_id = $idosc";
 247  
 248      $sql = "DELETE FROM ".OSC_DB_NAME.".products_description WHERE products_id = $idosc";
 249            
 250      $sql = "DELETE FROM ".MAIN_DB_PREFIX."album WHERE rowid = $id";
 251          
 252      
 253    }
 254  
 255  
 256  }
 257  ?>


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