[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 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: service.class.php,v 1.7 2005/08/12 21:48:39 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/service.class.php,v $ 21 * 22 */ 23 24 /** 25 \file htdocs/service.class.php 26 \ingroup service 27 \brief Fichier de la classe des services prédéfinis 28 \version $Revision: 1.7 $ 29 */ 30 31 32 /** 33 \class Service 34 \brief Classe permettant la gestion des services prédéfinis 35 */ 36 37 class Service 38 { 39 var $db; 40 41 var $id; 42 var $libelle; 43 var $price; 44 var $tms; 45 var $debut; 46 var $fin; 47 48 var $debut_epoch; 49 var $fin_epoch; 50 51 52 function Service($DB, $id=0) { 53 $this->db = $DB; 54 $this->id = $id; 55 56 return 1; 57 } 58 59 /* 60 * 61 * 62 * 63 */ 64 65 function create($user) { 66 67 $sql = "INSERT INTO ".MAIN_DB_PREFIX."service (datec, fk_user_author) VALUES (now(), ".$user->id.")"; 68 69 if ($this->db->query($sql) ) { 70 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."service"); 71 72 if ( $this->update($id, $user) ) { 73 return $id; 74 } 75 } else { 76 print $this->db->error() . ' in ' . $sql; 77 return -1; 78 } 79 } 80 81 /* 82 * 83 * 84 * 85 */ 86 87 function update($id, $user) { 88 89 $sql = "UPDATE ".MAIN_DB_PREFIX."service "; 90 $sql .= " SET label = '" . trim($this->libelle) ."'"; 91 $sql .= ",ref = '" . trim($this->ref) ."'"; 92 $sql .= ",price = " . $this->price ; 93 $sql .= ",description = '" . trim($this->description) ."'"; 94 $sql .= ",fk_user_modif = " . $user->id ; 95 96 $sql .= " WHERE rowid = " . $id; 97 98 if ( $this->db->query($sql) ) { 99 return 1; 100 } else { 101 print $this->db->error() . ' in ' . $sql; 102 } 103 } 104 105 /* 106 * 107 * 108 * 109 */ 110 111 function start_comm($id, $user, $datedeb=0) { 112 113 $sql = "UPDATE ".MAIN_DB_PREFIX."service "; 114 if ($datedeb) { 115 $sql .= " SET debut_comm = '$datedeb'"; 116 } else { 117 $sql .= " SET debut_comm = now()"; 118 } 119 $sql .= ",fk_user_modif = " . $user->id ; 120 121 $sql .= " WHERE rowid = " . $id; 122 123 if ( $this->db->query($sql) ) { 124 return 1; 125 } else { 126 print $this->db->error() . ' in ' . $sql; 127 } 128 } 129 130 /* 131 * 132 * 133 * 134 */ 135 136 function stop_comm($id, $user, $datefin=0) { 137 138 $sql = "UPDATE ".MAIN_DB_PREFIX."service "; 139 if ($datefin) { 140 $sql .= " SET fin_comm = '$datefin'"; 141 } else { 142 $sql .= " SET fin_comm = now()"; 143 } 144 $sql .= ",fk_user_modif = " . $user->id ; 145 146 $sql .= " WHERE rowid = " . $id; 147 148 if ( $this->db->query($sql) ) { 149 return 1; 150 } else { 151 print $this->db->error() . ' in ' . $sql; 152 } 153 } 154 155 /* 156 * 157 * 158 * 159 */ 160 161 function fetch($id) { 162 163 $sql = "SELECT s.ref,s.label,s.price,s.tms,s.debut_comm,s.fin_comm,s.description,"; 164 $sql .= $this->db->pdate("s.debut_comm") . ' as debut_epoch,'; 165 $sql .= $this->db->pdate("s.fin_comm") . ' as fin_epoch'; 166 $sql .= " FROM ".MAIN_DB_PREFIX."service as s"; 167 $sql .= " WHERE s.rowid = $id"; 168 169 $result = $this->db->query($sql); 170 171 if ($result) { 172 if ($this->db->num_rows()) { 173 $obj = $this->db->fetch_object($result); 174 175 $this->id = $obj->rowid; 176 $this->ref = $obj->ref; 177 $this->libelle = $obj->label; 178 $this->price = $obj->price; 179 $this->description = $obj->description; 180 181 $this->tms = $obj->tms; 182 183 $this->debut = $obj->debut_comm; 184 $this->fin = $obj->fin_comm; 185 186 $this->debut_epoch = $obj->debut_epoch; 187 $this->fin_epoch = $obj->fin_epoch; 188 189 } 190 $this->db->free(); 191 192 } else { 193 print $this->db->error(); 194 } 195 } 196 197 /** 198 * \brief Charge indicateurs this->nb de tableau de bord 199 * \return int <0 si ko, >0 si ok 200 */ 201 function load_state_board() 202 { 203 global $conf; 204 205 $this->nb=array(); 206 207 $sql = "SELECT count(p.rowid) as nb"; 208 $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; 209 $sql.= " WHERE p.fk_product_type = 1"; 210 $resql=$this->db->query($sql); 211 if ($resql) 212 { 213 while ($obj=$this->db->fetch_object($resql)) 214 { 215 $this->nb["services"]=$obj->nb; 216 } 217 return 1; 218 } 219 else 220 { 221 dolibarr_print_error($this->db); 222 $this->error=$this->db->error(); 223 return -1; 224 } 225 226 } 227 228 } 229 ?>
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 |
![]() |