From 42c204e098139f3e710869fc4afe724b34080fc8 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Thu, 29 Mar 2007 14:28:11 +0000 Subject: [PATCH] Ajout fonctions pour la configuration par l'interface --- .../telephonie.tarif.grille.class.php | 85 ++++++++++++- .../telephonie.tarif.prefix.class.php | 117 ++++++++++++++++++ 2 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 htdocs/telephonie/telephonie.tarif.prefix.class.php diff --git a/htdocs/telephonie/telephonie.tarif.grille.class.php b/htdocs/telephonie/telephonie.tarif.grille.class.php index 2b641257e9c..7c057bb15fc 100644 --- a/htdocs/telephonie/telephonie.tarif.grille.class.php +++ b/htdocs/telephonie/telephonie.tarif.grille.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2007 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 @@ -36,7 +36,8 @@ class TelephonieTarifGrille { - + //! Identifiant de la grille + var $id; var $_DB; var $tableau_tarif; var $prefixes; @@ -49,8 +50,88 @@ class TelephonieTarifGrille { function TelephonieTarifGrille($_DB) { $this->db = $_DB; + } + + function CreateGrille($user, $name, $type) + { + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_grille"; + $sql .= "(libelle, type_tarif)"; + $sql .= " VALUES ('".addslashes($name)."','".$type."');"; + + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'telephonie_tarif_grille'); + + $this->Perms($user, 2, $user->id); + } + else + { + dolibarr_syslog($this->db->error()); + } + + return $result; + } + function Perms($user, $perms, $user_grille) + { + + if ($perms == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights"; + $sql .= " WHERE fk_user = '".$user_grille."'"; + $sql .= " AND fk_grille = '".$this->id."';"; + $this->db->query($sql); + } + + if ($perms == 1) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights"; + $sql .= " SET pread= 1, pwrite = 0, fk_user_creat ='".$user->id."' WHERE fk_user = '".$user_grille."'"; + $sql .= " AND fk_grille = '".$this->id."';"; + if ( $this->db->query($sql) ) + { + if ($this->db->affected_rows($resql) == 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights"; + $sql .= " (pread,pwrite, fk_user, fk_grille, fk_user_creat) VALUES "; + $sql .= " (1,0,'".$user_grille."','".$this->id."','".$user->id."');"; + if ( $this->db->query($sql) ) + { + + } + } + } + } + + if ($perms == 2) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights"; + $sql .= " SET pread= 1, pwrite = 1, fk_user_creat ='".$user->id."' WHERE fk_user = '".$user_grille."'"; + $sql .= " AND fk_grille = '".$this->id."';"; + if ( $this->db->query($sql) ) + { + + if ($this->db->affected_rows($resql) == 0) + { + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights"; + $sql .= " (pread,pwrite, fk_user, fk_grille, fk_user_creat) VALUES "; + $sql .= " (1,1,'".$user_grille."','".$this->id."','".$user->id."');"; + if ( $this->db->query($sql) ) + { + + } + else + { + print $sql; + } + } + + } + } + } diff --git a/htdocs/telephonie/telephonie.tarif.prefix.class.php b/htdocs/telephonie/telephonie.tarif.prefix.class.php new file mode 100644 index 00000000000..37db355a25e --- /dev/null +++ b/htdocs/telephonie/telephonie.tarif.prefix.class.php @@ -0,0 +1,117 @@ + + * + * 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. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + * + */ + +/** + \file htdocs/telephonie.tarif.class.php + \ingroup facture + \brief Fichier de la classe des tarifs telephonies + \version $Revision$ +*/ + +/** + \class TelephonieTarif + \brief Classe permettant la gestion des prefix de tarifs de telephonie +*/ + +class TelephonieTarifPrefix { + //! Identifiant de la prefix + var $id; + var $_DB; + + /* + * Constructeur + * + */ + function TelephonieTarifPrefix($_DB) + { + $this->db = $_DB; + } + + function Create($user, $prefix, $tarif_id, $force='off') + { + if ($force == 'on') + { + $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_prefix"; + $sql .= " SET fk_tarif='".$tarif_id."'"; + $sql .= " WHERE prefix = '".$prefix."';"; + + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'telephonie_prefix'); + } + else + { + dolibarr_syslog($this->db->error()); + } + } + else + { + $this->fetch($prefix); + + if ($this->tarif_id == 0 && strlen(trim($prefix)) > 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_prefix"; + $sql .= "(prefix, fk_tarif)"; + $sql .= " VALUES ('".$prefix."','".$tarif_id."');"; + + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'telephonie_prefix'); + } + else + { + dolibarr_syslog($this->db->error()); + } + } + } + + return $result; + } + + function Fetch($prefix) + { + $this->tarif_id = 0; + + $sql = "SELECT fk_tarif FROM ".MAIN_DB_PREFIX."telephonie_prefix"; + $sql .= " WHERE prefix = '".$prefix."';"; + + $resql = $this->db->query($sql); + + if ( $resql ) + { + if ($row = $this->db->fetch_row($resql) ) + { + $this->tarif_id = $row[0]; + } + $this->db->free($resql); + + return 0; + } + else + { + return -1; + } + } +} + +?>