Nouveau fichier

This commit is contained in:
Rodolphe Quiedeville 2005-05-12 11:21:13 +00:00
parent cbc6e15570
commit a993e6b709
3 changed files with 672 additions and 0 deletions

View File

@ -0,0 +1,279 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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$
*
*/
require("./pre.inc.php");
$page = $_GET["page"];
$sortorder = $_GET["sortorder"];
$sortfield = $_GET["sortfield"];
$sql = "SELECT pwrite ";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights ";
$sql .= " WHERE fk_grille = '".$_GET["id"]."'";
$sql .= " AND fk_user = ".$user->id;
$auth_write = 0;
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows();
$i = 0;
if ($num > 0)
{
$row = $db->fetch_row($resql);
$auth_write = $row[0];
}
$db->free($resql);
}
/*
*
*
*/
if ($_POST["action"] == 'modif' && $auth_write)
{
$sortorder = "DESC";
$sortfield = "m.tms";
if ($_POST["temporel"] > 0)
{
require_once DOL_DOCUMENT_ROOT."/telephonie/telephonie.tarif.grille.class.php";
$obgrille = new TelephonieTarifGrille($db);
$obgrille->UpdateTarif($_GET["id"], $_POST["tarif"], $_POST["temporel"], $_POST["fixe"], $user);
Header("Location: grille.php?id=".$_GET["id"]);
}
}
llxHeader();
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
* Mode Liste
*
*
*
*/
print '<table width="100%" class="noborder">';
print '<tr><td valign="top" width="30%">';
$sql = "SELECT d.libelle as tarif_desc, d.type_tarif";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_grille as d";
$sql .= " WHERE d.rowid = '".$_GET["id"]."'";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows();
$i = 0;
if ($num > 0)
{
$grille = $db->fetch_row($resql);
}
}
print "Grille : ".$grille[0]."<br>";
print '<a href="grille-export.php?id='.$_GET["id"].'">Export tableur</a><br><br>';
if ($auth_write)
{
print '<form method="POST" action="grille.php?id='.$_GET["id"].'">';
print '<input type="hidden" name="action" value="modif">';
print '<table width="100%" class="border">';
print '<tr><td colspan="2">Modification</td></tr>';
print '<tr><td>Tarif</td>';
print '<td><select name="tarif">';
$sql = "SELECT rowid, libelle";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif";
$sql .= " WHERE tlink = 0";
$sql .= " ORDER BY libelle ASC";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row($resql);
print '<option value="'.$row[0].'">'.$row[1]."\n";
$i++;
}
}
print '</select></td></tr>';
print '<tr><td>Cout minute</td>';
print '<td><input type="text" name="temporel" value="0"></td></tr>';
print '<tr><td>Cout connexion</td>';
print '<td><input type="text" name="fixe" value="0"></td></tr>';
print '<tr><td colspan="2"><input type="submit"></td></tr>';
print '</table></form>';
}
print '<br><table width="100%" class="border">';
print '<tr><td>Personnes pouvant modifier cette grille</td></tr>';
$sql = "SELECT u.name, u.firstname";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_grille_rights as r";
$sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE r.fk_grille = '".$_GET["id"]."'";
$sql .= " AND r.fk_user = u.rowid ";
$sql .= " AND r.pwrite = 1";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows();
$i = 0;
while ($i < $num )
{
$row = $db->fetch_row($resql);
print '<tr><td>'.$row[1] . ' '.$row[0].'</td></tr>';
$i++;
}
}
print '</table>';
print '</td><td valign="top" width="70%">';
if ($sortorder == "") $sortorder="ASC";
if ($sortfield == "") $sortfield="t.libelle ASC, d.rowid ";
$offset = $conf->liste_limit * $page ;
$sql = "SELECT d.libelle as tarif_desc, d.type_tarif";
$sql .= " , t.libelle as tarif";
$sql .= " , m.temporel, m.fixe, t.rowid";
$sql .= " , u.code";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_grille as d";
$sql .= "," . MAIN_DB_PREFIX."telephonie_tarif_montant as m";
$sql .= "," . MAIN_DB_PREFIX."telephonie_tarif as t";
$sql .= "," . MAIN_DB_PREFIX."user as u";
$sqlc .= " WHERE d.rowid = m.fk_tarif_desc";
$sqlc .= " AND m.fk_tarif = t.rowid";
$sqlc .= " AND m.fk_user = u.rowid";
$sqlc .= " AND d.rowid = '".$_GET["id"]."'";
if ($_GET["search_libelle"])
{
$sqlc .=" AND t.libelle LIKE '%".$_GET["search_libelle"]."%'";
}
if ($_GET["search_prefix"])
{
$sqlc .=" AND tf.prefix LIKE '%".$_GET["search_prefix"]."%'";
}
if ($_GET["type"])
{
$sqlc .= " AND d.type_tarif = '".$_GET["type"]."'";
}
$sql = $sql . $sqlc . " ORDER BY $sortfield $sortorder";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0;
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print_liste_field_titre("Tarif","grille.php","d.libelle");
print_liste_field_titre("Destination","grille.php","t.libelle", "&type=".$_GET["type"]);
print_liste_field_titre("Cout / min","grille.php","temporel", "&type=".$_GET["type"]);
print "</td>";
print "<td>Cout fixe</td>";
print "<td>Type</td><td>User</td>";
print "</tr>\n";
$var=True;
while ($i < $num)
{
$obj = $db->fetch_object($i);
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".$obj->tarif_desc."</td>\n";
print '<td><a href="tarif.php?id='.$obj->rowid.'">'.$obj->tarif."</a></td>\n";
print "<td>".sprintf("%01.4f",$obj->temporel)."</td>\n";
print "<td>".sprintf("%01.4f",$obj->fixe)."</td>\n";
print "<td>".$obj->type_tarif."</td>\n";
print "<td>".$obj->code."</td>\n";
print "</tr>\n";
$i++;
}
print "</table>";
$db->free();
}
else
{
print $db->error() . ' ' . $sql;
}
print '</td></tr></table>';
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>

View File

@ -0,0 +1,246 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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 tarifs de telephonie
*/
class TelephonieTarif {
var $_DB;
var $tableau_tarif;
var $prefixes;
var $prefixe_max;
/*
* Constructeur
*
*/
function TelephonieTarif($_DB, $fournisseur_id, $type, $tarif_spec = 0, $client_id = 0)
{
$this->db = $_DB;
$this->tableau_tarif = array();
$this->prefixes = array();
$this->client_id = $client_id;
$this->tarif_spec = $tarif_spec;
for ($j = 0 ; $j++ ; $j < 10)
{
$this->prefixes[$j] = array();
$this->prefixe_max = array();
}
$this->_load_tarif($fournisseur_id, $type);
}
function _load_tarif($fournisseur_id, $type)
{
if ($type == 'achat')
{
$sql = "SELECT prefix, temporel, fixe";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_achat ";
$sql .= " WHERE fk_fournisseur = " . $fournisseur_id;
}
elseif ($type == 'vente')
{
$sql = "SELECT p.prefix, m.temporel, m.fixe, t.libelle";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_montant as m";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p";
$sql .= " WHERE t.rowid = m.fk_tarif";
$sql .= " AND t.rowid = p.fk_tarif";
$sql .= " AND m.fk_tarif_desc = 1";
}
if ( $this->db->query($sql) )
{
$num = $this->db->num_rows();
//print "$num tableau_tarif trouvés\n";
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$l = $row[0];
$this->tableau_tarif[$l] = $row;
// Tableaux des prefixes découpés en 10 tableaux
$pref = substr($row[0],0,1);
$i_pref = sizeof($this->prefixes[$pref]) + 1;
$this->prefixes[$pref][$i_pref] = $row[0];
// Taille maximale du prefixe
$this->prefixe_max[$pref] = max(strlen($row[0]), $this->prefixe_max[$pref]);
$i++;
}
$this->db->free();
}
else
{
dolibarr_syslog("TelephonieTarif::_load_tarif Erreur 1");
dolibarr_syslog($this->db->error());
}
/*
* Tarif Spécifique
*
*/
if ($this->tarif_spec <> 1)
{
$sql = "SELECT p.prefix, m.temporel, m.fixe, t.libelle";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_montant as m";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p";
$sql .= " WHERE t.rowid = m.fk_tarif";
$sql .= " AND t.rowid = p.fk_tarif";
$sql .= " AND m.fk_tarif_desc = ".$this->tarif_spec;
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
$l = $row[0];
$this->tableau_tarif[$l] = $row;
$i++;
}
$this->db->free($resql);
}
else
{
dolibarr_syslog("TelephonieTarif::_load_tarif Erreur 59");
dolibarr_syslog($this->db->error());
}
}
/*
* Tarifs client
*
*
*/
if ($type == 'vente' && ($this->client_id > 0))
{
$sql = "SELECT p.prefix, tc.temporel, tc.fixe, t.libelle";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_client as tc";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p ";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t";
$sql .= " WHERE tc.fk_tarif = t.rowid AND p.fk_tarif = t.rowid";
$sql .= " AND tc.fk_client = ".$this->client_id;
if ( $this->db->query($sql) )
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$l = $row[0];
$this->tableau_tarif[$l] = $row;
$i++;
}
}
else
{
print $this->db->error();
}
}
}
/*
*
*
*
*/
function cout($number, &$cout_tempo, &$cout_fixe, &$tarif_libelle)
{
$result = 0;
$first_char_in_prefix = substr($number,2,1);
$k = $this->prefixe_max[$first_char_in_prefix];
$goon = 1;
while ($goon == 1 && $k > 0)
{
$prefix_to_find = substr($number, 2, $k);
if (in_array($prefix_to_find, $this->prefixes[$first_char_in_prefix]))
{
// print "\t$prefix_to_find\n";
$cout_tempo = $this->tableau_tarif[$prefix_to_find][1];
$cout_fixe = $this->tableau_tarif[$prefix_to_find][2];
$tarif_libelle = $this->tableau_tarif[$prefix_to_find][3];
$goon = 0;
$result = 1;
}
$k = $k - 1;
}
return $result;
}
}
?>

View File

@ -0,0 +1,147 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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 tarifs de telephonie
*/
class TelephonieTarifGrille {
var $_DB;
var $tableau_tarif;
var $prefixes;
var $prefixe_max;
/*
* Constructeur
*
*/
function TelephonieTarifGrille($_DB)
{
$this->db = $_DB;
}
function UpdateTarif($grille_id, $tarif_id, $temporel, $fixe, $user)
{
if ($temporel > 0)
{
$tarifs_linked = array();
$this->_DBUpdateTarif($grille_id, $tarif_id, $temporel, $fixe, $user);
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."telephonie_tarif";
$sql .= " WHERE tlink = ".$tarif_id;
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
$tarifs_linked[$i] = $row[0];
$i++;
}
}
else
{
dolibarr_syslog($this->db->error());
}
foreach($tarifs_linked as $tarif)
{
$this->_DBUpdateTarif($grille_id, $tarif, $temporel, $fixe, $user);
}
}
return $result;
}
/*
*
*/
function _DBUpdateTarif($grille_id, $tarif_id, $temporel, $fixe, $user)
{
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_montant";
$sql .= "(fk_tarif_desc, fk_user, fk_tarif, temporel,fixe)";
$sql .= " VALUES (".$grille_id.",".$user->id;
$sql .= " ,".$tarif_id;
$sql .= " ,".$temporel;
$sql .= " ,".$fixe.")";
if ( $this->db->query($sql) )
{
}
else
{
dolibarr_syslog($this->db->error());
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_montant_log";
$sql .= "(fk_tarif_desc, fk_user, fk_tarif, temporel,fixe)";
$sql .= " VALUES (".$grille_id.",".$user->id;
$sql .= " ,".$tarif_id;
$sql .= " ,".$temporel;
$sql .= " ,".$fixe.")";
if ( $this->db->query($sql) )
{
}
else
{
dolibarr_syslog($this->db->error());
}
return $result;
}
}
?>