diff --git a/htdocs/telephonie/script/api/presel-resiliation.php b/htdocs/telephonie/script/api/presel-resiliation.php new file mode 100644 index 00000000000..00bdc561182 --- /dev/null +++ b/htdocs/telephonie/script/api/presel-resiliation.php @@ -0,0 +1,188 @@ + + * + * 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$ + * + * + * Resiliation de lignes par API + * + */ +require ("../../../master.inc.php"); +require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"; + +$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; + } +} + + +$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 résilier + * + */ +$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"; +$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.idp ASC"; + +$resql = $db->query($sql); +$result = 1; +if ($resql) +{ + $i = 0; + $num = $db->num_rows($resql); + + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $result = ResiliationPreselection($host, $user_login, $user_passwd, $obj->ligne, $num_abo); + + if ($result == 0) + { + $lint = new LigneTel($db); + $lint->fetch_by_id($obj->rowid); + if ($lint->statut == 4) + { + $lint->set_statut($user, 5); + } + } + + $i++; + } +} + +function ResiliationPreselection($host, $user_login, $user_passwd, $ligne, $id_person) +{ + global $verbose; + //dolibarr_syslog("Appel de DeletePreselection($host, $user_login, ****, $ligne, $id_person)"); + + $url = "/AzurApp_websvc_b3gdb/account.asmx/UpdatePreselection?"; + + $url .= "user_login=". $user_login; + $url .= "&user_passwd=".$user_passwd; + $url .= "&telnum=".$ligne; + $url .= "&okCollecte=false"; + $url .= "&okPreselection=false"; + + if ($verbose > 2) + dolibarr_syslog("$host"); + + if ($verbose > 2) + dolibarr_syslog("$url"); + + $fp = fsockopen($host, 80, $errno, $errstr, 30); + if (!$fp) + { + dolibarr_syslog("$errstr ($errno)"); + } + else + { + if ($verbose > 2) + dolibarr_syslog("Socket Opened send data"); + + $out = "GET $url HTTP/1.1\r\n"; + $out .= "Host: $host\r\n"; + $out .= "Connection: Close\r\n\r\n"; + + fwrite($fp, $out); + + if ($verbose > 2) + dolibarr_syslog("Data sent, waiting for response"); + + $parse = 0; + $result = "error"; + + $fresult = ""; + + while (!feof($fp)) + { + $line = fgets($fp, 1024); + + if ($verbose > 2) + dolibarr_syslog($line); + + if ($parse == 1) + { + preg_match('/^(.*)<\/string>$/', $line, $results); + + $result = $results[1]; + //dolibarr_syslog($line); + $parse = 0; + } + + if (substr($line,0,38) == '') + { + $parse = 1; + } + + $fresult .= $line; + + } + fclose($fp); + } + + if ($verbose > 1) + dolibarr_syslog("result = ".$result); + + if (substr($result,0,2) == "OK") + { + dolibarr_syslog("Resiliation réussie ligne ".$ligne." id client ".$id_person." $result\n"); + return 0; + } + else + { + dolibarr_syslog("Resiliation échouée ligne ".$ligne." id client ".$id_person." $result\n"); + + $fp = fopen("/tmp/$ligne.delete","w"); + if ($fp) + { + fwrite($fp, $fresult); + fclose($fp); + } + + return -1; + } +} + +?> diff --git a/htdocs/telephonie/script/api/presel-view.php b/htdocs/telephonie/script/api/presel-view.php new file mode 100644 index 00000000000..e16db28fc14 --- /dev/null +++ b/htdocs/telephonie/script/api/presel-view.php @@ -0,0 +1,199 @@ + + * + * 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$ + * + * Visualisation de l'etat des lignes preselectionnées + * + */ +require ("../../../master.inc.php"); +require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"; +require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"; + +$host = CMD_PRESEL_WEB_HOST; +$user_login = CMD_PRESEL_WEB_USER; +$user_passwd = CMD_PRESEL_WEB_PASS; + +$user = new User($db); +$user->id = 1; + +$ids = array(); + +if ($argv[1]) +{ + $debug = 0; + array_push($ids, $argv[1]); +} +else +{ + $sql = "SELECT rowid,ligne"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne"; + $sql .= " WHERE fk_fournisseur = 4"; + $sql .= " AND statut = 3"; + if ($debug) + { + $sql .= " LIMIT 1"; + } + $resql = $db->query($sql); + + if ($resql) + { + while ($row = $db->fetch_row($resql)) + { + array_push($ids, $row[1]); + } + } + else + { + print $db->error(); + exit(1); + } +} + +GetPreselection_byRef($db, $host, $user_login, $user_passwd, $ids, $debug, $user); + +/* + * Fonctions + * + */ + +function GetPreselection_byRef($db, $host, $user_login, $user_passwd, $ids, $debug, $user) +{ + $numcli = sizeof($ids); + $i = 0; + print "Nombre de lignes $numcli\n"; + foreach($ids as $cli) + { + $i++; + $fp = @fsockopen($host, 80, $errno, $errstr, 30); + if (!$fp) + { + print "Impossible de se connecter au server $errstr ($errno)"; + } + else + { + $ligne_numero = ""; + $ligne_service = ""; + $ligne_presel = ""; + + //GetPreselection_byRef + $url = "/AzurApp_websvc_b3gdb/account.asmx/GetPreselection_byRef?"; + + $url .= "user_login=". $user_login; + $url .= "&user_passwd=".$user_passwd; + $url .= "&telnum=".$cli; + + $out = "GET $url HTTP/1.1\r\n"; + $out .= "Host: $host\r\n"; + $out .= "Connection: Close\r\n\r\n"; + + fwrite($fp, $out); + + while (!feof($fp)) + { + $line = fgets($fp, 1024); + if ($debug) + { + print $line; + } + if (preg_match("//",$line)) + { + $results = split(" ",trim($line)); + //print_r($results); + + $array = array(); + preg_match('/telnum="([0123456789]*)"/', $line, $array); + $ligne_numero = $array[1]; + + $array = array(); + preg_match('/ServiceActive="([\S]*)"/i', $line, $array); + $service_active = $array[1]; + + $array = array(); + preg_match('/PreSelectionActive="([\S]*)"/i', $line, $array); + $presel_active = $array[1]; + + $array = array(); + preg_match('/Service_Statut="([\S]*)"/i', $line, $array); + $ligne_service = $array[1]; + + $array = array(); + preg_match('/PreSelection_Statut="([\S]*)"/i', $line, $array); + $ligne_presel = $array[1]; + + if ($ligne_service.$ligne_presel <> 'TRAITE_OKTRAITE_OK') + { + print "$i/$numcli "; + print $ligne_numero." "; + print "$service_active/$presel_active "; + print substr($ligne_service.str_repeat(" ",20),0,20); + print substr($ligne_presel.str_repeat(" ",20),0,20); + print "\n"; + } + + $situation_key = $ligne_service.' / '.$ligne_presel; + + if ($situation_key == 'TRAITE_OK / ATTENTE') + { + $ligne = new LigneTel($db); + + if ($ligne->fetch($ligne_numero) == 1) + { + if ($ligne->statut == 3) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande_retour"; + $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur,traite)"; + $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4,1);"; + + $resql = $db->query($sql); + + $statut = 6; + $date_resiliation = time(); + $datea = $db->idate($date_resiliation); + + if ($ligne->set_statut($user, $statut, $datea,'',4) <> 0) + { + $error++; + print "ERROR\n"; + } + } + } + else + { + print "Erreur de lecture\n"; + } + } + + + } + + if (preg_match("//",$line)) + { + $array = array(); + preg_match('/libelle="(.*)" xmlns:d4p1/', $line, $array); + + print "$i/$numcli "; + print "$cli ErreurAPI ".$array[1]."\n"; + } + } + fclose($fp); + } + } +} + +?>