| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: commande_presel.php,v 1.16 2005/12/05 09:30:35 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/commande_presel.php,v $ 20 * 21 * 22 * Commandes des lignes par API 23 * 24 */ 25 require ("../../master.inc.php"); 26 require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"; 27 28 $verbose = 0; 29 30 for ($i = 1 ; $i < sizeof($argv) ; $i++) 31 { 32 if ($argv[$i] == "-v") 33 { 34 $verbose = 1; 35 } 36 if ($argv[$i] == "-vv") 37 { 38 $verbose = 2; 39 } 40 if ($argv[$i] == "-vvv") 41 { 42 $verbose = 3; 43 } 44 if (strlen($argv[$i]) == 10) 45 { 46 $ligne = $argv[$i]; 47 print "Filtre sur la ligne ".$ligne."\n"; 48 } 49 } 50 51 52 $user = new User($db); 53 $user->id = 1; // C'est sale je sais ! 54 55 $host = CMD_PRESEL_WEB_HOST; 56 $user_login = CMD_PRESEL_WEB_USER; 57 $user_passwd = CMD_PRESEL_WEB_PASS; 58 $user_contract = CMD_PRESEL_WEB_CONTRACT; 59 60 /* 61 * Lecture des lignes a commander 62 * 63 */ 64 $sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville"; 65 $sql .= ", l.ligne, l.statut, l.rowid"; 66 67 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; 68 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 69 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f"; 70 $sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid"; 71 $sql .= " AND f.rowid = 4 AND l.statut = 9"; 72 if ($ligne > 0) 73 { 74 $sql .= " AND l.ligne='".$ligne."'"; 75 } 76 $sql .= " ORDER BY l.rowid DESC"; 77 $resql = $db->query($sql); 78 $result = 1; 79 if ($resql) 80 { 81 $i = 0; 82 $num = $db->num_rows($resql); 83 84 while ($i < $num) 85 { 86 $obj = $db->fetch_object($resql); 87 88 $num_abo = GetNumAbonne($db, $obj->socid, 4); 89 90 if ($num_abo == 0) 91 { 92 $societe_nom = $obj->nom; 93 $societe_adresse = $obj->address; 94 $societe_codepostal = $obj->cp; 95 $societe_ville = $obj->ville; 96 97 $num_abo = CreateAbonne($host, 98 $user_login, 99 $user_passwd, 100 $user_contract, 101 $societe_nom, 102 $societe_adresse, 103 $societe_codepostal, 104 $societe_ville); 105 106 if ($num_abo > 0) 107 { 108 $result = SetNumAbonne($db, $obj->socid, $num_abo, 4); 109 } 110 else 111 { 112 $result = 1; 113 } 114 } 115 else 116 { 117 $result = 0; 118 } 119 120 $lint = new LigneTel($db); 121 $lint->fetch_by_id($obj->rowid); 122 123 if ($result == 0) 124 { 125 $result = CreatePreselection($host, $user_login, $user_passwd, $lint, $num_abo); 126 } 127 128 if ($result == 0) 129 { 130 if ($lint->statut == 9) 131 { 132 $lint->set_statut($user, 2); 133 } 134 } 135 136 $i++; 137 } 138 } 139 140 function CreatePreselection($host, $user_login, $user_passwd, $lint, $id_person) 141 { 142 global $verbose; 143 //dolibarr_syslog("Appel de CreatePreselection($host, $user_login, ****, $ligne, $id_person)"); 144 145 $url = "/AzurApp_websvc_b3gdb/account.asmx/CreatePreselection?"; 146 147 $url .= "user_login=". $user_login; 148 $url .= "&user_passwd=".$user_passwd; 149 $url .= "&id_person=".$id_person; 150 $url .= "&telnum=".$lint->numero; 151 $url .= "&okCollecte=true"; 152 if ($lint->support == 'sda') 153 { 154 $url .= "&okPreselection=false"; 155 } 156 else 157 { 158 $url .= "&okPreselection=true"; 159 } 160 161 if ($verbose > 2) 162 dolibarr_syslog("$host"); 163 164 if ($verbose > 2) 165 dolibarr_syslog("$url"); 166 167 $fp = fsockopen($host, 80, $errno, $errstr, 30); 168 if (!$fp) 169 { 170 dolibarr_syslog("$errstr ($errno)"); 171 } 172 else 173 { 174 if ($verbose > 2) 175 dolibarr_syslog("Socket Opened send data"); 176 177 $out = "GET $url HTTP/1.1\r\n"; 178 $out .= "Host: $host\r\n"; 179 $out .= "Connection: Close\r\n\r\n"; 180 181 fwrite($fp, $out); 182 183 if ($verbose > 2) 184 dolibarr_syslog("Data sent, waiting for response"); 185 186 $parse = 0; 187 $result = "error"; 188 189 $fresult = ""; 190 191 while (!feof($fp)) 192 { 193 $line = fgets($fp, 1024); 194 195 if ($verbose > 2) 196 dolibarr_syslog($line); 197 198 if ($parse == 1) 199 { 200 preg_match('/^<string xmlns=".*">(.*)<\/string>$/', $line, $results); 201 202 $result = $results[1]; 203 //dolibarr_syslog($line); 204 $parse = 0; 205 } 206 207 if (substr($line,0,38) == '<?xml version="1.0" encoding="utf-8"?>') 208 { 209 $parse = 1; 210 } 211 212 $fresult .= $line; 213 214 } 215 fclose($fp); 216 } 217 218 if ($verbose > 1) 219 dolibarr_syslog("result = ".$result); 220 221 if (substr($result,0,2) == "OK") 222 { 223 dolibarr_syslog("Presel OK ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n"); 224 return 0; 225 } 226 else 227 { 228 dolibarr_syslog("Presel ERR ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n"); 229 230 $fp = fopen("/tmp/".$lint->numero.".presel","w"); 231 if ($fp) 232 { 233 fwrite($fp, $fresult); 234 fclose($fp); 235 } 236 237 return -1; 238 } 239 } 240 241 function GetNumAbonne($db, $socid, $fournid) 242 { 243 //dolibarr_syslog("Appel de GetNumAbonne($socid, $fournid)"); 244 245 $sql = "SELECT fourn_id"; 246 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_fournid"; 247 $sql .= " WHERE fk_soc = ".$socid; 248 $sql .= " AND fk_fourn = ".$fournid; 249 250 $resql = $db->query($sql); 251 252 if ($resql) 253 { 254 if ($db->num_rows($resql) > 0) 255 { 256 $row = $db->fetch_row($resql); 257 return $row[0]; 258 } 259 else 260 { 261 return 0; 262 } 263 } 264 else 265 { 266 dolibarr_syslog("Erreur dans GetNumAbonne($socid, $fournid)"); 267 return -1; 268 } 269 } 270 271 function SetNumAbonne($db, $socid, $soc_fourn_id, $fournid) 272 { 273 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_fournid"; 274 $sql .= " (fk_soc, fourn_id, fk_fourn, datec) "; 275 $sql .= " VALUES ($socid, $soc_fourn_id, $fournid, now()) ;"; 276 277 $resql = $db->query($sql); 278 279 if ($resql) 280 { 281 return 0; 282 } 283 else 284 { 285 dolibarr_syslog("Erreur dans SetNumAbonne($socid, $soc_fourn_id, $fournid)"); 286 return -1; 287 } 288 } 289 290 function CreateAbonne($host, $user_login, $user_passwd, $user_contract, $societe_nom, $societe_adresse, $societe_codepostal, $societe_ville) 291 { 292 $result = "error"; 293 294 $civilite = 1; 295 296 $url = "/AzurApp_websvc_b3gdb/account.asmx/CreateAbonne?"; 297 298 $url .= "user_login=". $user_login; 299 $url .= "&user_passwd=".$user_passwd; 300 $url .= "&civilite=". urlencode($civilite); 301 $url .= "&id_contract=".$user_contract; 302 $url .= "&firstname=". urlencode("Societe"); 303 $url .= "&lastname=". urlencode(ereg_replace("'","",($societe_nom))); 304 $url .= "&adresse=". urlencode($societe_adresse); 305 $url .= "&codepostal=". urlencode($societe_codepostal); 306 $url .= "&ville=". urlencode($societe_ville); 307 $url .= "&pays=". urlencode("NULL"); 308 $url .= "&telnum=". urlencode("NULL"); 309 310 $fp = fsockopen($host, 80, $errno, $errstr, 30); 311 if (!$fp) 312 { 313 dolibarr_syslog("$errstr ($errno)"); 314 } 315 else 316 { 317 $out = "GET $url HTTP/1.1\r\n"; 318 $out .= "Host: $host\r\n"; 319 $out .= "Connection: Close\r\n\r\n"; 320 321 fwrite($fp, $out); 322 323 $parse = 0; 324 325 while (!feof($fp)) 326 { 327 $line = fgets($fp, 1024); 328 329 if ($parse == 1) 330 { 331 //print $line."\n"; 332 333 preg_match('/^<string xmlns=".*">(.*):(.*)<\/string>$/', $line, $results); 334 335 $result = $results[1]; 336 $client_id = $results[2]; 337 dolibarr_syslog($line); 338 } 339 340 if (substr($line,0,38) == '<?xml version="1.0" encoding="utf-8"?>') 341 { 342 $parse = 1; 343 } 344 } 345 fclose($fp); 346 } 347 348 dolibarr_syslog("$result:$client_id"); 349 350 if ($result == "OK") 351 { 352 dolibarr_syslog("Commande réussie id client ".$client_id); 353 return $client_id; 354 } 355 else 356 { 357 return 0; 358 } 359 } 360 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|