2005-10-19 16:11:53 +02:00
|
|
|
|
<?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$
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
2005-11-30 09:55:17 +01:00
|
|
|
|
* Commandes des lignes par API
|
2005-10-19 16:11:53 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
require ("../../master.inc.php");
|
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php";
|
|
|
|
|
|
|
2005-11-02 10:01:17 +01:00
|
|
|
|
$verbose = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($argv[$i] == "-v")
|
|
|
|
|
|
{
|
|
|
|
|
|
$verbose = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($argv[$i] == "-vv")
|
|
|
|
|
|
{
|
|
|
|
|
|
$verbose = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($argv[$i] == "-vvv")
|
|
|
|
|
|
{
|
|
|
|
|
|
$verbose = 3;
|
|
|
|
|
|
}
|
2005-12-05 10:25:50 +01:00
|
|
|
|
if (strlen($argv[$i]) == 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
$ligne = $argv[$i];
|
2005-12-05 10:27:53 +01:00
|
|
|
|
print "Filtre sur la ligne ".$ligne."\n";
|
2005-12-05 10:25:50 +01:00
|
|
|
|
}
|
2005-11-02 10:01:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$user = new User($db);
|
|
|
|
|
|
$user->id = 1; // C'est sale je sais !
|
|
|
|
|
|
|
|
|
|
|
|
$host = CMD_PRESEL_WEB_HOST;
|
|
|
|
|
|
$user_login = CMD_PRESEL_WEB_USER;
|
|
|
|
|
|
$user_passwd = CMD_PRESEL_WEB_PASS;
|
|
|
|
|
|
$user_contract = CMD_PRESEL_WEB_CONTRACT;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Lecture des lignes a commander
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
|
|
|
|
|
|
$sql .= ", l.ligne, l.statut, l.rowid";
|
|
|
|
|
|
|
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
|
|
|
|
|
$sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
|
|
|
|
|
|
$sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
|
|
|
|
|
|
$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
|
2005-12-05 10:25:50 +01:00
|
|
|
|
$sql .= " AND f.rowid = 4 AND l.statut = 9";
|
|
|
|
|
|
if ($ligne > 0)
|
|
|
|
|
|
{
|
2005-12-05 10:30:35 +01:00
|
|
|
|
$sql .= " AND l.ligne='".$ligne."'";
|
2005-12-05 10:25:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
$sql .= " ORDER BY l.rowid DESC";
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
|
$result = 1;
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
|
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
|
|
|
|
|
|
|
$num_abo = GetNumAbonne($db, $obj->socid, 4);
|
|
|
|
|
|
|
|
|
|
|
|
if ($num_abo == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$societe_nom = $obj->nom;
|
|
|
|
|
|
$societe_adresse = $obj->address;
|
|
|
|
|
|
$societe_codepostal = $obj->cp;
|
|
|
|
|
|
$societe_ville = $obj->ville;
|
|
|
|
|
|
|
|
|
|
|
|
$num_abo = CreateAbonne($host,
|
|
|
|
|
|
$user_login,
|
|
|
|
|
|
$user_passwd,
|
|
|
|
|
|
$user_contract,
|
|
|
|
|
|
$societe_nom,
|
|
|
|
|
|
$societe_adresse,
|
|
|
|
|
|
$societe_codepostal,
|
|
|
|
|
|
$societe_ville);
|
|
|
|
|
|
|
|
|
|
|
|
if ($num_abo > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = SetNumAbonne($db, $obj->socid, $num_abo, 4);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
2005-12-01 10:56:40 +01:00
|
|
|
|
|
|
|
|
|
|
$lint = new LigneTel($db);
|
|
|
|
|
|
$lint->fetch_by_id($obj->rowid);
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
if ($result == 0)
|
|
|
|
|
|
{
|
2005-12-01 10:56:40 +01:00
|
|
|
|
$result = CreatePreselection($host, $user_login, $user_passwd, $lint, $num_abo);
|
2005-10-19 16:11:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($result == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($lint->statut == 9)
|
|
|
|
|
|
{
|
|
|
|
|
|
$lint->set_statut($user, 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-12-01 10:56:40 +01:00
|
|
|
|
function CreatePreselection($host, $user_login, $user_passwd, $lint, $id_person)
|
2005-10-19 16:11:53 +02:00
|
|
|
|
{
|
2005-11-02 10:01:17 +01:00
|
|
|
|
global $verbose;
|
2005-11-30 09:55:17 +01:00
|
|
|
|
//dolibarr_syslog("Appel de CreatePreselection($host, $user_login, ****, $ligne, $id_person)");
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
$url = "/AzurApp_websvc_b3gdb/account.asmx/CreatePreselection?";
|
|
|
|
|
|
|
|
|
|
|
|
$url .= "user_login=". $user_login;
|
|
|
|
|
|
$url .= "&user_passwd=".$user_passwd;
|
|
|
|
|
|
$url .= "&id_person=".$id_person;
|
2005-12-01 10:59:14 +01:00
|
|
|
|
$url .= "&telnum=".$lint->numero;
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$url .= "&okCollecte=true";
|
2005-12-01 10:56:40 +01:00
|
|
|
|
if ($lint->support == 'sda')
|
|
|
|
|
|
{
|
|
|
|
|
|
$url .= "&okPreselection=false";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$url .= "&okPreselection=true";
|
|
|
|
|
|
}
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
2005-11-02 10:04:06 +01:00
|
|
|
|
if ($verbose > 2)
|
|
|
|
|
|
dolibarr_syslog("$host");
|
|
|
|
|
|
|
2005-11-02 10:01:17 +01:00
|
|
|
|
if ($verbose > 2)
|
|
|
|
|
|
dolibarr_syslog("$url");
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
$fp = fsockopen($host, 80, $errno, $errstr, 30);
|
|
|
|
|
|
if (!$fp)
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("$errstr ($errno)");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-11-02 10:04:06 +01:00
|
|
|
|
if ($verbose > 2)
|
|
|
|
|
|
dolibarr_syslog("Socket Opened send data");
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$out = "GET $url HTTP/1.1\r\n";
|
|
|
|
|
|
$out .= "Host: $host\r\n";
|
|
|
|
|
|
$out .= "Connection: Close\r\n\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
fwrite($fp, $out);
|
|
|
|
|
|
|
2005-11-02 10:05:15 +01:00
|
|
|
|
if ($verbose > 2)
|
|
|
|
|
|
dolibarr_syslog("Data sent, waiting for response");
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$parse = 0;
|
|
|
|
|
|
$result = "error";
|
2005-10-31 19:43:53 +01:00
|
|
|
|
|
|
|
|
|
|
$fresult = "";
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
while (!feof($fp))
|
|
|
|
|
|
{
|
|
|
|
|
|
$line = fgets($fp, 1024);
|
|
|
|
|
|
|
2005-11-02 10:01:17 +01:00
|
|
|
|
if ($verbose > 2)
|
|
|
|
|
|
dolibarr_syslog($line);
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
if ($parse == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
preg_match('/^<string xmlns=".*">(.*)<\/string>$/', $line, $results);
|
|
|
|
|
|
|
|
|
|
|
|
$result = $results[1];
|
2005-11-30 09:56:48 +01:00
|
|
|
|
//dolibarr_syslog($line);
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$parse = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (substr($line,0,38) == '<?xml version="1.0" encoding="utf-8"?>')
|
|
|
|
|
|
{
|
|
|
|
|
|
$parse = 1;
|
|
|
|
|
|
}
|
2005-10-31 19:43:53 +01:00
|
|
|
|
|
|
|
|
|
|
$fresult .= $line;
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-11-02 10:01:17 +01:00
|
|
|
|
if ($verbose > 1)
|
|
|
|
|
|
dolibarr_syslog("result = ".$result);
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
if (substr($result,0,2) == "OK")
|
|
|
|
|
|
{
|
2005-12-01 11:00:33 +01:00
|
|
|
|
dolibarr_syslog("Presel OK ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n");
|
2005-10-19 16:11:53 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-12-01 11:00:33 +01:00
|
|
|
|
dolibarr_syslog("Presel ERR ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n");
|
2005-10-31 19:43:53 +01:00
|
|
|
|
|
2005-12-01 10:59:14 +01:00
|
|
|
|
$fp = fopen("/tmp/".$lint->numero.".presel","w");
|
2005-10-31 19:43:53 +01:00
|
|
|
|
if ($fp)
|
|
|
|
|
|
{
|
|
|
|
|
|
fwrite($fp, $fresult);
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-19 16:11:53 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function GetNumAbonne($db, $socid, $fournid)
|
|
|
|
|
|
{
|
2005-11-30 09:56:48 +01:00
|
|
|
|
//dolibarr_syslog("Appel de GetNumAbonne($socid, $fournid)");
|
2005-10-19 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT fourn_id";
|
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_fournid";
|
|
|
|
|
|
$sql .= " WHERE fk_soc = ".$socid;
|
|
|
|
|
|
$sql .= " AND fk_fourn = ".$fournid;
|
|
|
|
|
|
|
|
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($db->num_rows($resql) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $db->fetch_row($resql);
|
|
|
|
|
|
return $row[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Erreur dans GetNumAbonne($socid, $fournid)");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function SetNumAbonne($db, $socid, $soc_fourn_id, $fournid)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_fournid";
|
|
|
|
|
|
$sql .= " (fk_soc, fourn_id, fk_fourn, datec) ";
|
|
|
|
|
|
$sql .= " VALUES ($socid, $soc_fourn_id, $fournid, now()) ;";
|
|
|
|
|
|
|
|
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Erreur dans SetNumAbonne($socid, $soc_fourn_id, $fournid)");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function CreateAbonne($host, $user_login, $user_passwd, $user_contract, $societe_nom, $societe_adresse, $societe_codepostal, $societe_ville)
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = "error";
|
|
|
|
|
|
|
|
|
|
|
|
$civilite = 1;
|
|
|
|
|
|
|
|
|
|
|
|
$url = "/AzurApp_websvc_b3gdb/account.asmx/CreateAbonne?";
|
|
|
|
|
|
|
|
|
|
|
|
$url .= "user_login=". $user_login;
|
|
|
|
|
|
$url .= "&user_passwd=".$user_passwd;
|
|
|
|
|
|
$url .= "&civilite=". urlencode($civilite);
|
|
|
|
|
|
$url .= "&id_contract=".$user_contract;
|
|
|
|
|
|
$url .= "&firstname=". urlencode("Societe");
|
2005-11-30 09:59:02 +01:00
|
|
|
|
$url .= "&lastname=". urlencode(ereg_replace("'","",($societe_nom)));
|
2005-10-19 16:11:53 +02:00
|
|
|
|
$url .= "&adresse=". urlencode($societe_adresse);
|
|
|
|
|
|
$url .= "&codepostal=". urlencode($societe_codepostal);
|
|
|
|
|
|
$url .= "&ville=". urlencode($societe_ville);
|
|
|
|
|
|
$url .= "&pays=". urlencode("NULL");
|
|
|
|
|
|
$url .= "&telnum=". urlencode("NULL");
|
|
|
|
|
|
|
|
|
|
|
|
$fp = fsockopen($host, 80, $errno, $errstr, 30);
|
|
|
|
|
|
if (!$fp)
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("$errstr ($errno)");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$out = "GET $url HTTP/1.1\r\n";
|
|
|
|
|
|
$out .= "Host: $host\r\n";
|
|
|
|
|
|
$out .= "Connection: Close\r\n\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
fwrite($fp, $out);
|
|
|
|
|
|
|
|
|
|
|
|
$parse = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (!feof($fp))
|
|
|
|
|
|
{
|
|
|
|
|
|
$line = fgets($fp, 1024);
|
|
|
|
|
|
|
|
|
|
|
|
if ($parse == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//print $line."\n";
|
|
|
|
|
|
|
|
|
|
|
|
preg_match('/^<string xmlns=".*">(.*):(.*)<\/string>$/', $line, $results);
|
|
|
|
|
|
|
|
|
|
|
|
$result = $results[1];
|
|
|
|
|
|
$client_id = $results[2];
|
|
|
|
|
|
dolibarr_syslog($line);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (substr($line,0,38) == '<?xml version="1.0" encoding="utf-8"?>')
|
|
|
|
|
|
{
|
|
|
|
|
|
$parse = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dolibarr_syslog("$result:$client_id");
|
|
|
|
|
|
|
|
|
|
|
|
if ($result == "OK")
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Commande r<>ussie id client ".$client_id);
|
|
|
|
|
|
return $client_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|