From 74e6e1d34b9ac15f3aef6ca1e14b8ca597fb14c8 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 16 Feb 2005 15:39:48 +0000 Subject: [PATCH] Nouveau fichier --- .../telephonie/sql/llx_telephonie_service.sql | 39 +++++ .../telephonie/telephonie.service.class.php | 141 ++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 htdocs/telephonie/sql/llx_telephonie_service.sql create mode 100644 htdocs/telephonie/telephonie.service.class.php diff --git a/htdocs/telephonie/sql/llx_telephonie_service.sql b/htdocs/telephonie/sql/llx_telephonie_service.sql new file mode 100644 index 00000000000..bb2de6d978c --- /dev/null +++ b/htdocs/telephonie/sql/llx_telephonie_service.sql @@ -0,0 +1,39 @@ +-- ======================================================================== +-- Copyright (C) 2005 Rodolphe Quiedeville +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- $Id$ +-- $Source$ +-- +-- ======================================================================== +-- +-- +create table llx_telephonie_service ( + rowid integer AUTO_INCREMENT PRIMARY KEY, + ref varchar(25) NOT NULL, + + libelle varchar(255), + libelle_facture varchar(255), + montant real NOT NULL, + statut smallint DEFAULT 0 NOT NULL, + + fk_user_creat integer NOT NULL, + date_creat datetime NOT NULL, + fk_user_modif integer, + date_modif datetime +)type=innodb; + + diff --git a/htdocs/telephonie/telephonie.service.class.php b/htdocs/telephonie/telephonie.service.class.php new file mode 100644 index 00000000000..b9c3016133d --- /dev/null +++ b/htdocs/telephonie/telephonie.service.class.php @@ -0,0 +1,141 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ + +class TelephonieService { + var $db; + + var $id; + var $ligne; + + function TelephonieService($DB) + { + global $config; + + $this->db = $DB; + $this->error_message = ''; + $this->statuts[0] = "Inactif"; + $this->statuts[1] = "Actif"; + + return 0; + } + /* + * + * + */ + function update($user) + { + $this->montant = ereg_replace(",",".",$this->montant); + + $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_service"; + $sql .= " SET "; + $sql .= " libelle = '$this->libelle' "; + $sql .= ", libelle_facture = '$this->libelle' "; + $sql .= ", montant = '$this->montant' "; + $sql .= ", fk_user_modif = $user->id "; + $sql .= ", date_modif = now() "; + + $sql .= " WHERE rowid = $this->id"; + + if ( $this->db->query($sql) ) + { + return 0; + } + else + { + print $this->db->error(); + print $sql ; + return -1; + } + } + + /* + * + * + */ + function create($user) + { + + $this->montant = ereg_replace(",",".",$this->montant); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_service"; + $sql .= " (ref, libelle, libelle_facture, montant, fk_user_creat, date_creat)"; + $sql .= " VALUES ("; + $sql .= " '$this->ref','$this->libelle','$this->libelle_facture','$this->montant',$user->id, now())"; + + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(); + return 0; + } + else + { + + $this->error_message = "Echec de la création du service !"; + dolibarr_syslog("TelephonieService::Create Error -1"); + return -1; + } + } + /* + * + * + */ + + function fetch($id) + { + $sql = "SELECT s.rowid, s.libelle, s.libelle_facture, s.montant, s.statut"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_service as s"; + $sql .= " WHERE s.rowid = ".$id; + + if ($this->db->query($sql)) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object(0); + + $this->id = $obj->rowid; + $this->libelle = stripslashes($obj->libelle); + $this->libelle_facture = stripslashes($obj->libelle_facture); + $this->montant = $obj->montant; + $this->statut = $obj->statut; + + $result = 0; + } + else + { + $result = -2; + } + + $this->db->free(); + } + else + { + /* Erreur select SQL */ + print $this->db->error(); + $result = -1; + } + + return $result; + } + +} + +?>