[ Index ] |
|
Code source de Dolibarr 2.0.1 |
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: auteur.class.php,v 1.11 2005/03/18 23:56:41 eldy Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/boutique/auteur/auteur.class.php,v $ 20 * 21 */ 22 23 /*! \file htdocs/boutique/auteur/auteur.class.php 24 \brief Classe permettant de gèrer des auteurs 25 \author Rodolphe Quideville 26 \version $Revision: 1.11 $ 27 */ 28 29 /*! \class Auteur 30 \brief Classe permettant de gèrer des auteurs 31 */ 32 33 class Auteur { 34 var $db ; 35 36 var $id ; 37 var $nom; 38 39 function Auteur($DB, $id=0) { 40 $this->db = $DB; 41 $this->id = $id ; 42 } 43 44 /* 45 * 46 * 47 * 48 */ 49 50 function create($user) { 51 52 $sql = "INSERT INTO ".MAIN_DB_PREFIX."auteur (fk_user_author) VALUES (".$user->id.")"; 53 54 if ($this->db->query($sql) ) 55 { 56 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."auteur"); 57 58 if ( $this->update($id, $user) ) 59 { 60 return $id; 61 } 62 } 63 64 } 65 66 /* 67 * 68 * 69 */ 70 71 function liste_array () 72 { 73 $ga = array(); 74 75 $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."auteur ORDER BY nom"; 76 77 if ($this->db->query($sql) ) 78 { 79 $nump = $this->db->num_rows(); 80 81 if ($nump) 82 { 83 $i = 0; 84 while ($i < $nump) 85 { 86 $obj = $this->db->fetch_object(); 87 88 $ga[$obj->rowid] = $obj->nom; 89 $i++; 90 } 91 } 92 return $ga; 93 } 94 else 95 { 96 print $this->db->error(); 97 } 98 99 } 100 /* 101 * 102 * 103 * 104 */ 105 106 function update($id, $user) 107 { 108 109 $sql = "UPDATE ".MAIN_DB_PREFIX."auteur "; 110 $sql .= " SET nom = '" . trim($this->nom) ."'"; 111 112 $sql .= " WHERE rowid = " . $id; 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 * 125 */ 126 127 function liste_livre($id_type='', $status=0) 128 { 129 $ga = array(); 130 if ($id_type == 'oscid') 131 { 132 $sql = "SELECT a.oscid, "; 133 } 134 else 135 { 136 $sql = "SELECT a.rowid, "; 137 } 138 $sql .= " a.title FROM ".MAIN_DB_PREFIX."livre as a, ".MAIN_DB_PREFIX."livre_to_auteur as l"; 139 $sql .= " WHERE a.rowid = l.fk_livre AND l.fk_auteur = ".$this->id; 140 if ($status) 141 { 142 $sql .= " AND a.status = 1"; 143 } 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 $row = $this->db->fetch_row($i); 156 157 $ga[$row[0]] = $row[1]; 158 $i++; 159 } 160 } 161 return $ga; 162 } 163 else 164 { 165 print $this->db->error(); 166 } 167 } 168 169 /* 170 * 171 * 172 * 173 */ 174 175 function fetch ($id) { 176 177 $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."auteur WHERE rowid = $id"; 178 179 $result = $this->db->query($sql) ; 180 181 if ( $result ) 182 { 183 $result = $this->db->fetch_array(); 184 185 $this->id = $result["rowid"]; 186 $this->nom = stripslashes($result["nom"]); 187 188 $this->db->free(); 189 } 190 else 191 { 192 print $this->db->error(); 193 } 194 195 return $result; 196 } 197 198 199 /* 200 * 201 * 202 */ 203 204 function delete() { 205 206 $livres = $this->liste_livre(); 207 208 if (sizeof($livres) == 0) 209 { 210 $sql = "DELETE FROM ".MAIN_DB_PREFIX."auteur WHERE rowid = $this->id "; 211 $return = $this->db->query($sql) ; 212 } 213 214 215 } 216 217 218 } 219 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |